From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41136) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aw3lB-0007E6-OX for qemu-devel@nongnu.org; Fri, 29 Apr 2016 04:26:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aw3l3-0000eH-UR for qemu-devel@nongnu.org; Fri, 29 Apr 2016 04:26:48 -0400 Received: from e06smtp09.uk.ibm.com ([195.75.94.105]:47405) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aw3l3-0000TS-MQ for qemu-devel@nongnu.org; Fri, 29 Apr 2016 04:26:41 -0400 Received: from localhost by e06smtp09.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 29 Apr 2016 09:26:08 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 7DDF81B0806E for ; Fri, 29 Apr 2016 09:26:53 +0100 (BST) Received: from d06av08.portsmouth.uk.ibm.com (d06av08.portsmouth.uk.ibm.com [9.149.37.249]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u3T8Q5p254001856 for ; Fri, 29 Apr 2016 08:26:05 GMT Received: from d06av08.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u3T8Q4gY002747 for ; Fri, 29 Apr 2016 02:26:05 -0600 Date: Fri, 29 Apr 2016 10:26:03 +0200 From: Dominik Dingel Message-ID: <20160429102603.29310efa@BR9TG4T3.de.ibm.com> In-Reply-To: <20160429073222.GL1421@ad.usersys.redhat.com> References: <1461585338-45863-1-git-send-email-dingel@linux.vnet.ibm.com> <20160429073222.GL1421@ad.usersys.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] exec.c: Ensure right alignment also for file backed ram List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng , Paolo Bonzini Cc: qemu-devel@nongnu.org, Halil Pasic , Richard Henderson , Peter Crosthwaite On Fri, 29 Apr 2016 15:32:22 +0800 Fam Zheng wrote: > On Mon, 04/25 13:55, Dominik Dingel wrote: > > While in the anonymous ram case we already take care of the right alignment > > such an alignment gurantee does not exist for file backed ram allocation. > > s/gurantee/guarantee/ > > Otherwise looks good to me, > > Reviewed-by: Fam Zheng Thank you very much! Paolo do you want me to fix the typo, add the r-b and resend the patch? > > > > Instead, pagesize is used for alignment. On s390 this is not enough for gmap, > > as we need to satisfy an alignment up to segments. > > > > Reported-by: Halil Pasic > > Signed-off-by: Dominik Dingel > > > > --- > > > > v2 -> v3: > > Skipping additional variable and just use alignment of memory region. > > As memory will not be backpropagated it is enough to round up to page_sizes. > > > > v1 -> v2: > > While enforcing alignments we allow memory sizes on page_size. > > On mmap the memory size will be round up to alignments. > > > > I thought about moving this alignment into qemu_ram_mmap but the result > > was a lot of code churn, the other possibility was to create an additional > > define ending up with two defines with the same semantics. > > --- > > exec.c | 5 +++-- > > include/qemu/osdep.h | 13 +++++++++++++ > > util/oslib-posix.c | 13 ------------- > > 3 files changed, 16 insertions(+), 15 deletions(-) > > > > diff --git a/exec.c b/exec.c > > index c4f9036..fc75266 100644 > > --- a/exec.c > > +++ b/exec.c > > @@ -1296,7 +1296,7 @@ static void *file_ram_alloc(RAMBlock *block, > > } > > > > page_size = qemu_fd_getpagesize(fd); > > - block->mr->align = page_size; > > + block->mr->align = MAX(page_size, QEMU_VMALLOC_ALIGN); > > > > if (memory < page_size) { > > error_setg(errp, "memory size 0x" RAM_ADDR_FMT " must be equal to " > > @@ -1317,7 +1317,8 @@ static void *file_ram_alloc(RAMBlock *block, > > perror("ftruncate"); > > } > > > > - area = qemu_ram_mmap(fd, memory, page_size, block->flags & RAM_SHARED); > > + area = qemu_ram_mmap(fd, memory, block->mr->align, > > + block->flags & RAM_SHARED); > > if (area == MAP_FAILED) { > > error_setg_errno(errp, errno, > > "unable to map backing store for guest RAM"); > > diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h > > index 408783f..783270f 100644 > > --- a/include/qemu/osdep.h > > +++ b/include/qemu/osdep.h > > @@ -247,6 +247,19 @@ void qemu_anon_ram_free(void *ptr, size_t size); > > > > #endif > > > > +#if defined(__linux__) && \ > > + (defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)) > > + /* Use 2 MiB alignment so transparent hugepages can be used by KVM. > > + Valgrind does not support alignments larger than 1 MiB, > > + therefore we need special code which handles running on Valgrind. */ > > +# define QEMU_VMALLOC_ALIGN (512 * 4096) > > +#elif defined(__linux__) && defined(__s390x__) > > + /* Use 1 MiB (segment size) alignment so gmap can be used by KVM. */ > > +# define QEMU_VMALLOC_ALIGN (256 * 4096) > > +#else > > +# define QEMU_VMALLOC_ALIGN getpagesize() > > +#endif > > + > > int qemu_madvise(void *addr, size_t len, int advice); > > > > int qemu_open(const char *name, int flags, ...); > > diff --git a/util/oslib-posix.c b/util/oslib-posix.c > > index 6cc4b8f..4adde93 100644 > > --- a/util/oslib-posix.c > > +++ b/util/oslib-posix.c > > @@ -26,19 +26,6 @@ > > * THE SOFTWARE. > > */ > > > > -#if defined(__linux__) && \ > > - (defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)) > > - /* Use 2 MiB alignment so transparent hugepages can be used by KVM. > > - Valgrind does not support alignments larger than 1 MiB, > > - therefore we need special code which handles running on Valgrind. */ > > -# define QEMU_VMALLOC_ALIGN (512 * 4096) > > -#elif defined(__linux__) && defined(__s390x__) > > - /* Use 1 MiB (segment size) alignment so gmap can be used by KVM. */ > > -# define QEMU_VMALLOC_ALIGN (256 * 4096) > > -#else > > -# define QEMU_VMALLOC_ALIGN getpagesize() > > -#endif > > - > > #include "qemu/osdep.h" > > #include > > #include > > -- > > 2.6.6 > > > > >