* [Qemu-devel] [PATCH v4 0/2] trivial changes on util/mmap-alloc
@ 2016-11-02 13:44 Cao jin
2016-11-02 13:44 ` [Qemu-devel] [PATCH v4 1/2] util/mmap-alloc: check parameter before using Cao jin
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Cao jin @ 2016-11-02 13:44 UTC (permalink / raw)
To: qemu-devel, qemu-trivial; +Cc: thuth, peter.maydell, eblake, armbru, mst
Cao jin (2):
util/mmap-alloc: check parameter before using
util/mmap-alloc: refactor a little bit for readability
util/mmap-alloc.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
--
2.1.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH v4 1/2] util/mmap-alloc: check parameter before using
2016-11-02 13:44 [Qemu-devel] [PATCH v4 0/2] trivial changes on util/mmap-alloc Cao jin
@ 2016-11-02 13:44 ` Cao jin
2016-11-02 20:41 ` Thomas Huth
2016-12-21 6:35 ` Cao jin
2016-11-02 13:44 ` [Qemu-devel] [PATCH v4 2/2] util/mmap-alloc: refactor a little bit for readability Cao jin
2017-01-12 11:12 ` [Qemu-devel] [PATCH v4 0/2] trivial changes on util/mmap-alloc Michael Tokarev
2 siblings, 2 replies; 6+ messages in thread
From: Cao jin @ 2016-11-02 13:44 UTC (permalink / raw)
To: qemu-devel, qemu-trivial; +Cc: thuth, peter.maydell, eblake, armbru, mst
Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
---
util/mmap-alloc.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
index 5a85aa3..d713a72 100644
--- a/util/mmap-alloc.c
+++ b/util/mmap-alloc.c
@@ -12,6 +12,7 @@
#include "qemu/osdep.h"
#include "qemu/mmap-alloc.h"
+#include "qemu/host-utils.h"
#define HUGETLBFS_MAGIC 0x958458f6
@@ -61,18 +62,18 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared)
#else
void *ptr = mmap(0, total, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
#endif
- size_t offset = QEMU_ALIGN_UP((uintptr_t)ptr, align) - (uintptr_t)ptr;
+ size_t offset;
void *ptr1;
if (ptr == MAP_FAILED) {
return MAP_FAILED;
}
- /* Make sure align is a power of 2 */
- assert(!(align & (align - 1)));
+ assert(is_power_of_2(align));
/* Always align to host page size */
assert(align >= getpagesize());
+ offset = QEMU_ALIGN_UP((uintptr_t)ptr, align) - (uintptr_t)ptr;
ptr1 = mmap(ptr + offset, size, PROT_READ | PROT_WRITE,
MAP_FIXED |
(fd == -1 ? MAP_ANONYMOUS : 0) |
--
2.1.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH v4 2/2] util/mmap-alloc: refactor a little bit for readability
2016-11-02 13:44 [Qemu-devel] [PATCH v4 0/2] trivial changes on util/mmap-alloc Cao jin
2016-11-02 13:44 ` [Qemu-devel] [PATCH v4 1/2] util/mmap-alloc: check parameter before using Cao jin
@ 2016-11-02 13:44 ` Cao jin
2017-01-12 11:12 ` [Qemu-devel] [PATCH v4 0/2] trivial changes on util/mmap-alloc Michael Tokarev
2 siblings, 0 replies; 6+ messages in thread
From: Cao jin @ 2016-11-02 13:44 UTC (permalink / raw)
To: qemu-devel, qemu-trivial; +Cc: thuth, peter.maydell, eblake, armbru, mst
1st mmap returns *ptr* which aligns to host page size,
| size + align |
------------------------------------------
ptr
input param *align* could be 1M, or 2M, or host page size. After
QEMU_ALIGN_UP, offset will >= 0
2nd mmap use flag MAP_FIXED, then it return ptr+offset, or else fail.
If it success, then we will have something like:
| offset | size |
--------------------------------------
ptr ptr1
*ptr1* is what we really want to return, it equals ptr+offset.
Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
---
util/mmap-alloc.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
This one may be controversial, take it or not as you will:)
diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
index d713a72..2f55f5e 100644
--- a/util/mmap-alloc.c
+++ b/util/mmap-alloc.c
@@ -84,22 +84,20 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared)
return MAP_FAILED;
}
- ptr += offset;
- total -= offset;
-
if (offset > 0) {
- munmap(ptr - offset, offset);
+ munmap(ptr, offset);
}
/*
* Leave a single PROT_NONE page allocated after the RAM block, to serve as
* a guard page guarding against potential buffer overflows.
*/
+ total -= offset;
if (total > size + getpagesize()) {
- munmap(ptr + size + getpagesize(), total - size - getpagesize());
+ munmap(ptr1 + size + getpagesize(), total - size - getpagesize());
}
- return ptr;
+ return ptr1;
}
void qemu_ram_munmap(void *ptr, size_t size)
--
2.1.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v4 1/2] util/mmap-alloc: check parameter before using
2016-11-02 13:44 ` [Qemu-devel] [PATCH v4 1/2] util/mmap-alloc: check parameter before using Cao jin
@ 2016-11-02 20:41 ` Thomas Huth
2016-12-21 6:35 ` Cao jin
1 sibling, 0 replies; 6+ messages in thread
From: Thomas Huth @ 2016-11-02 20:41 UTC (permalink / raw)
To: Cao jin, qemu-devel, qemu-trivial; +Cc: peter.maydell, eblake, armbru, mst
On 02.11.2016 14:44, Cao jin wrote:
> Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
> ---
> util/mmap-alloc.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
> index 5a85aa3..d713a72 100644
> --- a/util/mmap-alloc.c
> +++ b/util/mmap-alloc.c
> @@ -12,6 +12,7 @@
>
> #include "qemu/osdep.h"
> #include "qemu/mmap-alloc.h"
> +#include "qemu/host-utils.h"
>
> #define HUGETLBFS_MAGIC 0x958458f6
>
> @@ -61,18 +62,18 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared)
> #else
> void *ptr = mmap(0, total, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
> #endif
> - size_t offset = QEMU_ALIGN_UP((uintptr_t)ptr, align) - (uintptr_t)ptr;
> + size_t offset;
> void *ptr1;
>
> if (ptr == MAP_FAILED) {
> return MAP_FAILED;
> }
>
> - /* Make sure align is a power of 2 */
> - assert(!(align & (align - 1)));
> + assert(is_power_of_2(align));
> /* Always align to host page size */
> assert(align >= getpagesize());
>
> + offset = QEMU_ALIGN_UP((uintptr_t)ptr, align) - (uintptr_t)ptr;
> ptr1 = mmap(ptr + offset, size, PROT_READ | PROT_WRITE,
> MAP_FIXED |
> (fd == -1 ? MAP_ANONYMOUS : 0) |
>
Reviewed-by: Thomas Huth <thuth@redhat.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v4 1/2] util/mmap-alloc: check parameter before using
2016-11-02 13:44 ` [Qemu-devel] [PATCH v4 1/2] util/mmap-alloc: check parameter before using Cao jin
2016-11-02 20:41 ` Thomas Huth
@ 2016-12-21 6:35 ` Cao jin
1 sibling, 0 replies; 6+ messages in thread
From: Cao jin @ 2016-12-21 6:35 UTC (permalink / raw)
To: qemu-devel, qemu-trivial; +Cc: peter.maydell, thuth, armbru, mst
ping
On 11/02/2016 09:44 PM, Cao jin wrote:
> Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
> ---
> util/mmap-alloc.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
> index 5a85aa3..d713a72 100644
> --- a/util/mmap-alloc.c
> +++ b/util/mmap-alloc.c
> @@ -12,6 +12,7 @@
>
> #include "qemu/osdep.h"
> #include "qemu/mmap-alloc.h"
> +#include "qemu/host-utils.h"
>
> #define HUGETLBFS_MAGIC 0x958458f6
>
> @@ -61,18 +62,18 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared)
> #else
> void *ptr = mmap(0, total, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
> #endif
> - size_t offset = QEMU_ALIGN_UP((uintptr_t)ptr, align) - (uintptr_t)ptr;
> + size_t offset;
> void *ptr1;
>
> if (ptr == MAP_FAILED) {
> return MAP_FAILED;
> }
>
> - /* Make sure align is a power of 2 */
> - assert(!(align & (align - 1)));
> + assert(is_power_of_2(align));
> /* Always align to host page size */
> assert(align >= getpagesize());
>
> + offset = QEMU_ALIGN_UP((uintptr_t)ptr, align) - (uintptr_t)ptr;
> ptr1 = mmap(ptr + offset, size, PROT_READ | PROT_WRITE,
> MAP_FIXED |
> (fd == -1 ? MAP_ANONYMOUS : 0) |
>
--
Sincerely,
Cao jin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v4 0/2] trivial changes on util/mmap-alloc
2016-11-02 13:44 [Qemu-devel] [PATCH v4 0/2] trivial changes on util/mmap-alloc Cao jin
2016-11-02 13:44 ` [Qemu-devel] [PATCH v4 1/2] util/mmap-alloc: check parameter before using Cao jin
2016-11-02 13:44 ` [Qemu-devel] [PATCH v4 2/2] util/mmap-alloc: refactor a little bit for readability Cao jin
@ 2017-01-12 11:12 ` Michael Tokarev
2 siblings, 0 replies; 6+ messages in thread
From: Michael Tokarev @ 2017-01-12 11:12 UTC (permalink / raw)
To: Cao jin, qemu-devel, qemu-trivial
Cc: peter.maydell, thuth, eblake, armbru, mst
02.11.2016 16:44, Cao jin wrote:
> Cao jin (2):
> util/mmap-alloc: check parameter before using
> util/mmap-alloc: refactor a little bit for readability
>
> util/mmap-alloc.c | 17 ++++++++---------
> 1 file changed, 8 insertions(+), 9 deletions(-)
Applied (finally) to -trivial, thank you very much!
/mjt
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-01-12 11:12 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-02 13:44 [Qemu-devel] [PATCH v4 0/2] trivial changes on util/mmap-alloc Cao jin
2016-11-02 13:44 ` [Qemu-devel] [PATCH v4 1/2] util/mmap-alloc: check parameter before using Cao jin
2016-11-02 20:41 ` Thomas Huth
2016-12-21 6:35 ` Cao jin
2016-11-02 13:44 ` [Qemu-devel] [PATCH v4 2/2] util/mmap-alloc: refactor a little bit for readability Cao jin
2017-01-12 11:12 ` [Qemu-devel] [PATCH v4 0/2] trivial changes on util/mmap-alloc Michael Tokarev
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.