vhost: fix offset while mmaping log base address

Message ID 20240708065749.1131-1-xiangwencheng@dayudpu.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series vhost: fix offset while mmaping log base address |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS

Commit Message

BillXiang July 8, 2024, 6:57 a.m. UTC
From: BillXiang <xiangwencheng@dayudpu.com>

For sanity the offset should be the last parameter of mmap.

Fixes: fbc4d24 ("vhost: fix offset while mmaping log base address")
Signed-off-by: BillXiang <xiangwencheng@dayudpu.com>
---
 lib/vhost/vhost_user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Chenbo Xia July 9, 2024, 12:42 p.m. UTC | #1
> On Jul 8, 2024, at 14:57, BillXiang <xiangwencheng@dayudpu.com> wrote:
> 
> External email: Use caution opening links or attachments
> 
> 
> From: BillXiang <xiangwencheng@dayudpu.com>
> 
> For sanity the offset should be the last parameter of mmap.
> 
> Fixes: fbc4d24 ("vhost: fix offset while mmaping log base address")

The commit id length should be 12.

Since QEMU always send offset 0, I think it’s no need to backport the
patch, so no cc-stable is fine.

With above fixed:

Reviewed-by: Chenbo Xia <chenbox@nvidia.com>

> Signed-off-by: BillXiang <xiangwencheng@dayudpu.com>
> ---
> lib/vhost/vhost_user.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
> index 5f470da38a..0893ae80bb 100644
> --- a/lib/vhost/vhost_user.c
> +++ b/lib/vhost/vhost_user.c
> @@ -2399,7 +2399,7 @@ vhost_user_set_log_base(struct virtio_net **pdev,
>         * mmap from 0 to workaround a hugepage mmap bug: mmap will
>         * fail when offset is not page size aligned.
>         */
> -       addr = mmap(0, size + off, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
> +       addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, off);
>        alignment = get_blk_size(fd);
>        close(fd);
>        if (addr == MAP_FAILED) {
> --
> 2.30.0
  
BillXiang July 10, 2024, 3:22 a.m. UTC | #2
From: BillXiang <xiangwencheng@dayudpu.com>

> From: "Chenbo Xia"<chenbox@nvidia.com>
> Date: Tue, Jul 9, 2024, 20:42
> Subject: Re: [PATCH] vhost: fix offset while mmaping log base address
> To: "BillXiang"<xiangwencheng@dayudpu.com>
> Cc: "Maxime Coquelin"<maxime.coquelin@redhat.com>, "Jianfeng Tan"<jianfeng.tan@intel.com>, "Tomasz Kulasek"<tomaszx.kulasek@intel.com>, "Pawel Wodkowski"<pawelx.wodkowski@intel.com>, "dev@dpdk.org"<dev@dpdk.org>
> > On Jul 8, 2024, at 14:57, BillXiang <xiangwencheng@dayudpu.com> wrote:
> >
> > External email: Use caution opening links or attachments
> >
> >
> > From: BillXiang <xiangwencheng@dayudpu.com>
> >
> > For sanity the offset should be the last parameter of mmap.
> >
> > Fixes: fbc4d24 ("vhost: fix offset while mmaping log base address")
>
> The commit id length should be 12.
>

Thanks, I will mind it.

> Since QEMU always send offset 0, I think it's no need to backport the
> patch, so no cc-stable is fine.
>

I just think the code is confusing and I'm wondering whether the offset 
sent by QEMU or maybe other VM can be non-zero.

If it's a mistake just fix it.

> With above fixed:
>
> Reviewed-by: Chenbo Xia <chenbox@nvidia.com>
>
> > Signed-off-by: BillXiang <xiangwencheng@dayudpu.com>
> > ---
> > lib/vhost/vhost_user.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
> > index 5f470da38a..0893ae80bb 100644
> > --- a/lib/vhost/vhost_user.c
> > +++ b/lib/vhost/vhost_user.c
> > @@ -2399,7 +2399,7 @@ vhost_user_set_log_base(struct virtio_net **pdev,
> >     * mmap from 0 to workaround a hugepage mmap bug: mmap will
> >     * fail when offset is not page size aligned.
> >     */
> > -    addr = mmap(0, size + off, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
> > +    addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, off);
> >    alignment = get_blk_size(fd);
> >    close(fd);
> >    if (addr == MAP_FAILED) {
> > --
> > 2.30.0
  
Maxime Coquelin Sept. 19, 2024, 12:03 p.m. UTC | #3
On 7/8/24 08:57, BillXiang wrote:
> From: BillXiang <xiangwencheng@dayudpu.com>
> 
> For sanity the offset should be the last parameter of mmap.
> 
> Fixes: fbc4d24 ("vhost: fix offset while mmaping log base address")
> Signed-off-by: BillXiang <xiangwencheng@dayudpu.com>
> ---
>   lib/vhost/vhost_user.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
> index 5f470da38a..0893ae80bb 100644
> --- a/lib/vhost/vhost_user.c
> +++ b/lib/vhost/vhost_user.c
> @@ -2399,7 +2399,7 @@ vhost_user_set_log_base(struct virtio_net **pdev,
>   	 * mmap from 0 to workaround a hugepage mmap bug: mmap will
>   	 * fail when offset is not page size aligned.
>   	 */
> -	addr = mmap(0, size + off, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
> +	addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, off);
>   	alignment = get_blk_size(fd);
>   	close(fd);
>   	if (addr == MAP_FAILED) {

Fixed the fixes tag and Cc'ed stable.

Applied to next-virtio/for-next-net.

Thanks,
Maxime
  
Maxime Coquelin Sept. 19, 2024, 12:04 p.m. UTC | #4
On 7/8/24 08:57, BillXiang wrote:
> From: BillXiang <xiangwencheng@dayudpu.com>
> 
> For sanity the offset should be the last parameter of mmap.
> 
> Fixes: fbc4d24 ("vhost: fix offset while mmaping log base address")
> Signed-off-by: BillXiang <xiangwencheng@dayudpu.com>
> ---
>   lib/vhost/vhost_user.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 

Applied to next-virtio/for-next-net.

Thanks,
Maxime
  

Patch

diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
index 5f470da38a..0893ae80bb 100644
--- a/lib/vhost/vhost_user.c
+++ b/lib/vhost/vhost_user.c
@@ -2399,7 +2399,7 @@  vhost_user_set_log_base(struct virtio_net **pdev,
 	 * mmap from 0 to workaround a hugepage mmap bug: mmap will
 	 * fail when offset is not page size aligned.
 	 */
-	addr = mmap(0, size + off, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+	addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, off);
 	alignment = get_blk_size(fd);
 	close(fd);
 	if (addr == MAP_FAILED) {