From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id E47798E8C for ; Thu, 12 Nov 2015 03:35:07 +0100 (CET) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP; 11 Nov 2015 18:35:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,279,1444719600"; d="scan'208";a="683440369" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by orsmga003.jf.intel.com with ESMTP; 11 Nov 2015 18:35:06 -0800 Received: from fmsmsx112.amr.corp.intel.com (10.18.116.6) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.248.2; Wed, 11 Nov 2015 18:35:03 -0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX112.amr.corp.intel.com (10.18.116.6) with Microsoft SMTP Server (TLS) id 14.3.248.2; Wed, 11 Nov 2015 18:35:03 -0800 Received: from shsmsx152.ccr.corp.intel.com ([169.254.6.193]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.88]) with mapi id 14.03.0248.002; Thu, 12 Nov 2015 10:35:01 +0800 From: "Tan, Jianfeng" To: "Xie, Huawei" , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH] vhost: fix mmap failure as len not aligned with hugepage size Thread-Index: AQHRHDUJy3viCSYoOUS4nI85Eik6QZ6Xl2/g Date: Thu, 12 Nov 2015 02:35:00 +0000 Message-ID: References: <1446162713-130100-1-git-send-email-jianfeng.tan@intel.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] vhost: fix mmap failure as len not aligned with hugepage size X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Nov 2015 02:35:08 -0000 > -----Original Message----- > From: Xie, Huawei > Sent: Wednesday, November 11, 2015 11:57 AM > To: Tan, Jianfeng; dev@dpdk.org > Subject: Re: [dpdk-dev] [PATCH] vhost: fix mmap failure as len not aligne= d with > hugepage size >=20 > On 10/30/2015 2:52 PM, Jianfeng Tan wrote: > > This patch fixes a bug under lower version linux kernel, mmap() fails > > when > Since which version Linux hugetlbfs changes the requirement of size align= ment? > > length is not aligned with hugepage size. This link shows this bug was fixed in Linux kernel commit: dab2d3dc45ae7343= 216635d981d43637e1cb7d45 After my check, that patch was applied to long term version 3.4.110+ So distributions using 2.6.32 and 3.2.72 need this patch to make vhost work= well. https://bugzilla.kernel.org/show_bug.cgi?id=3D56881 > > > > Signed-off-by: Jianfeng Tan > > --- > > lib/librte_vhost/vhost_user/virtio-net-user.c | 12 +++++++++--- > > 1 file changed, 9 insertions(+), 3 deletions(-) > > > > diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c > > b/lib/librte_vhost/vhost_user/virtio-net-user.c > > index a998ad8..641561c 100644 > > --- a/lib/librte_vhost/vhost_user/virtio-net-user.c > > +++ b/lib/librte_vhost/vhost_user/virtio-net-user.c > > @@ -147,6 +147,10 @@ user_set_mem_table(struct vhost_device_ctx ctx, > struct VhostUserMsg *pmsg) > > /* This is ugly */ > > mapped_size =3D memory.regions[idx].memory_size + > > memory.regions[idx].mmap_offset; > > + > > + alignment =3D get_blk_size(pmsg->fds[idx]); > > + mapped_size =3D RTE_ALIGN_CEIL(mapped_size, alignment); > Probably we could remove the alignment of mapped size in free_mem_region = as > well. Yes, after aligning mapped_address when mmap(), this address does not need = to be aligned again when munmap(). But this will effect nothing, or incur any performance issue= . I'm prone to take no change to it. > RTE_ALIGN_CEIL( > region[idx].mapped_size, alignment) If we are not sure, leave it = as it is. > > + > > mapped_address =3D (uint64_t)(uintptr_t)mmap(NULL, > > mapped_size, > > PROT_READ | PROT_WRITE, MAP_SHARED, @@ -154,9 > +158,11 @@ > > user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pm= sg) > > 0); > > > > RTE_LOG(INFO, VHOST_CONFIG, > > - "mapped region %d fd:%d to %p sz:0x%"PRIx64" > off:0x%"PRIx64"\n", > > + "mapped region %d fd:%d to:%p sz:0x%"PRIx64" " > > + "off:0x%"PRIx64" align:0x%"PRIx64"\n", > > idx, pmsg->fds[idx], (void *)(uintptr_t)mapped_address, > > - mapped_size, memory.regions[idx].mmap_offset); > > + mapped_size, memory.regions[idx].mmap_offset, > > + alignment); > > > > if (mapped_address =3D=3D (uint64_t)(uintptr_t)MAP_FAILED) { > > RTE_LOG(ERR, VHOST_CONFIG, > > @@ -166,7 +172,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, > > struct VhostUserMsg *pmsg) > > > > pregion_orig[idx].mapped_address =3D mapped_address; > > pregion_orig[idx].mapped_size =3D mapped_size; > > - pregion_orig[idx].blksz =3D get_blk_size(pmsg->fds[idx]); > > + pregion_orig[idx].blksz =3D alignment; > > pregion_orig[idx].fd =3D pmsg->fds[idx]; > > > > mapped_address +=3D memory.regions[idx].mmap_offset;