diff mbox series

[v4] eal: fix create user mem map repeatedly when it exists

Message ID 1607339329-624-1-git-send-email-wangyunjian@huawei.com (mailing list archive)
State New
Delegated to: David Marchand
Headers show
Series [v4] eal: fix create user mem map repeatedly when it exists | expand

Checks

Context Check Description
ci/travis-robot warning Travis build: failed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/checkpatch success coding style OK

Commit Message

wangyunjian Dec. 7, 2020, 11:08 a.m. UTC
From: Yunjian Wang <wangyunjian@huawei.com>

Currently, user mem maps will check if the newly mapped area is adjacent
to any existing mapping, but will not check if the mapping is identical
because it assumes that the API will never get called with the same
mapping twice. This will result in duplicate entries in the user mem
maps list.

Fix it by also checking for duplicate mappings, and skipping them if
they are found.

Fixes: 0cbce3a167f1 ("vfio: skip DMA map failure if already mapped")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
v4:
  Update commit log suggested by Anatoly Burakov
---
 lib/librte_eal/linux/eal_vfio.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

wangyunjian March 25, 2021, 1:38 p.m. UTC | #1
Friendly ping.

> -----Original Message-----
> From: wangyunjian
> Sent: Monday, December 7, 2020 7:09 PM
> To: dev@dpdk.org
> Cc: david.marchand@redhat.com; thomas@monjalon.net;
> anatoly.burakov@intel.com; Lilijun (Jerry) <jerry.lilijun@huawei.com>; xudingke
> <xudingke@huawei.com>; wangyunjian <wangyunjian@huawei.com>;
> stable@dpdk.org
> Subject: [dpdk-dev] [PATCH v4] eal: fix create user mem map repeatedly when it
> exists
> 
> From: Yunjian Wang <wangyunjian@huawei.com>
> 
> Currently, user mem maps will check if the newly mapped area is adjacent to
> any existing mapping, but will not check if the mapping is identical because it
> assumes that the API will never get called with the same mapping twice. This
> will result in duplicate entries in the user mem maps list.
> 
> Fix it by also checking for duplicate mappings, and skipping them if they are
> found.
> 
> Fixes: 0cbce3a167f1 ("vfio: skip DMA map failure if already mapped")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
> ---
> v4:
>   Update commit log suggested by Anatoly Burakov
> ---
>  lib/librte_eal/linux/eal_vfio.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/lib/librte_eal/linux/eal_vfio.c b/lib/librte_eal/linux/eal_vfio.c index
> 050082444e..0967215783 100644
> --- a/lib/librte_eal/linux/eal_vfio.c
> +++ b/lib/librte_eal/linux/eal_vfio.c
> @@ -168,6 +168,10 @@ adjust_map(struct user_mem_map *src, struct
> user_mem_map *end,  static int  merge_map(struct user_mem_map *left,
> struct user_mem_map *right)  {
> +	/* merge the same maps into one */
> +	if (memcmp(left, right, sizeof(struct user_mem_map)) == 0)
> +		goto out;
> +
>  	if (left->addr + left->len != right->addr)
>  		return 0;
>  	if (left->iova + left->len != right->iova) @@ -175,6 +179,7 @@
> merge_map(struct user_mem_map *left, struct user_mem_map *right)
> 
>  	left->len += right->len;
> 
> +out:
>  	memset(right, 0, sizeof(*right));
> 
>  	return 1;
> --
> 2.23.0
Thomas Monjalon March 25, 2021, 2:30 p.m. UTC | #2
07/12/2020 12:08, wangyunjian:
> From: Yunjian Wang <wangyunjian@huawei.com>
> 
> Currently, user mem maps will check if the newly mapped area is adjacent
> to any existing mapping, but will not check if the mapping is identical
> because it assumes that the API will never get called with the same
> mapping twice. This will result in duplicate entries in the user mem
> maps list.
> 
> Fix it by also checking for duplicate mappings, and skipping them if
> they are found.

Sorry, that's still difficult to read,
and it is not clear what is the impact of the bug.

+Cc some english native speakers for help.

> Fixes: 0cbce3a167f1 ("vfio: skip DMA map failure if already mapped")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
Kevin Traynor March 25, 2021, 4:45 p.m. UTC | #3
On 25/03/2021 14:30, Thomas Monjalon wrote:
> 07/12/2020 12:08, wangyunjian:
>> From: Yunjian Wang <wangyunjian@huawei.com>
>>
>> Currently, user mem maps will check if the newly mapped area is adjacent
>> to any existing mapping, but will not check if the mapping is identical
>> because it assumes that the API will never get called with the same
>> mapping twice. This will result in duplicate entries in the user mem
>> maps list.
>>
>> Fix it by also checking for duplicate mappings, and skipping them if
>> they are found.
> 
> Sorry, that's still difficult to read,
> and it is not clear what is the impact of the bug.
> 

I agree the impact of the bug is not clear from the description. It
seems to be explained at a low level in
http://inbox.dpdk.org/dev/34EFBCA9F01B0748BEB6B629CE643AE60DB32BD6@DGGEMM533-MBX.china.huawei.com/
that the array size is 256 (VFIO_MAX_USER_MEM_MAPS) and it may fill up
due to duplicate mem maps.

How about something like:
--
New user mem maps are checked if they are adjacent to an existing mem
map and if so, the mem map entries are merged.

It did not check for duplicate mem maps, so if the API is called with
the same mem map multiple times, they will occupy multiple mem map
entries. This will reduce the amount of entries available for unique mem
maps.

Check for duplicate mem maps and merge them into one mem map entry if
any found.
--

You might want to add something about the possible impact for
applications that is being fixed here too.

> +Cc some english native speakers for help.

(Probably the worst people to ask)

> 
>> Fixes: 0cbce3a167f1 ("vfio: skip DMA map failure if already mapped")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
>> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
> 
> 
>
diff mbox series

Patch

diff --git a/lib/librte_eal/linux/eal_vfio.c b/lib/librte_eal/linux/eal_vfio.c
index 050082444e..0967215783 100644
--- a/lib/librte_eal/linux/eal_vfio.c
+++ b/lib/librte_eal/linux/eal_vfio.c
@@ -168,6 +168,10 @@  adjust_map(struct user_mem_map *src, struct user_mem_map *end,
 static int
 merge_map(struct user_mem_map *left, struct user_mem_map *right)
 {
+	/* merge the same maps into one */
+	if (memcmp(left, right, sizeof(struct user_mem_map)) == 0)
+		goto out;
+
 	if (left->addr + left->len != right->addr)
 		return 0;
 	if (left->iova + left->len != right->iova)
@@ -175,6 +179,7 @@  merge_map(struct user_mem_map *left, struct user_mem_map *right)
 
 	left->len += right->len;
 
+out:
 	memset(right, 0, sizeof(*right));
 
 	return 1;