DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] vhost: fix mmap failure as len not aligned with hugepage size
@ 2015-10-29 23:51 Jianfeng Tan
  2015-11-06  1:23 ` Changchun Ouyang
  2015-11-11  3:57 ` Xie, Huawei
  0 siblings, 2 replies; 5+ messages in thread
From: Jianfeng Tan @ 2015-10-29 23:51 UTC (permalink / raw)
  To: dev

This patch fixes a bug under lower version linux kernel, mmap() fails when
length is not aligned with hugepage size.

Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
---
 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 = memory.regions[idx].memory_size +
 			memory.regions[idx].mmap_offset;
+
+		alignment = get_blk_size(pmsg->fds[idx]);
+		mapped_size = RTE_ALIGN_CEIL(mapped_size, alignment);
+
 		mapped_address = (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 *pmsg)
 			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 == (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 = mapped_address;
 		pregion_orig[idx].mapped_size = mapped_size;
-		pregion_orig[idx].blksz = get_blk_size(pmsg->fds[idx]);
+		pregion_orig[idx].blksz = alignment;
 		pregion_orig[idx].fd = pmsg->fds[idx];
 
 		mapped_address +=  memory.regions[idx].mmap_offset;
-- 
2.1.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-11-12  2:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-29 23:51 [dpdk-dev] [PATCH] vhost: fix mmap failure as len not aligned with hugepage size Jianfeng Tan
2015-11-06  1:23 ` Changchun Ouyang
2015-11-11  3:57 ` Xie, Huawei
2015-11-12  2:35   ` Tan, Jianfeng
2015-11-12  2:46     ` Xie, Huawei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).