2023-01-11 06:50:15

by Jason Wang

[permalink] [raw]
Subject: [PATCH 5/5] vdpa: mlx5: support per virtqueue dma device

This patch implements per virtqueue dma device for mlx5_vdpa. This is
needed for virtio_vdpa to work for CVQ which is backed by vringh but
not DMA. We simply advertise the vDPA device itself as the DMA device
for CVQ then DMA API can simply use PA so the identical mapping for
CVQ can still be used. Otherwise the identical (1:1) mapping won't
work when platform IOMMU is enabled since the IOVA is allocated on
demand which is not necessarily the PA.

This fixes the following crash when mlx5 vDPA device is bound to
virtio-vdpa with platform IOMMU enabled but not in passthrough mode:

BUG: unable to handle page fault for address: ff2fb3063deb1002
#PF: supervisor read access in kernel mode
#PF: error_code(0x0000) - not-present page
PGD 1393001067 P4D 1393002067 PUD 0
Oops: 0000 [#1] PREEMPT SMP NOPTI
CPU: 55 PID: 8923 Comm: kworker/u112:3 Kdump: loaded Not tainted 6.1.0+ #7
Hardware name: Dell Inc. PowerEdge R750/0PJ80M, BIOS 1.5.4 12/17/2021
Workqueue: mlx5_vdpa_wq mlx5_cvq_kick_handler [mlx5_vdpa]
RIP: 0010:vringh_getdesc_iotlb+0x93/0x1d0 [vringh]
Code: 14 25 40 ef 01 00 83 82 c0 0a 00 00 01 48 2b 05 93 5a 1b ea 8b 4c 24 14 48 c1 f8 06 48 c1 e0 0c 48 03 05 90 5a 1b ea 48 01 c8 <0f> b7 00 83 aa c0 0a 00 00 01 65 ff 0d bc e4 41 3f 0f 84 05 01 00
RSP: 0018:ff46821ba664fdf8 EFLAGS: 00010282
RAX: ff2fb3063deb1002 RBX: 0000000000000a20 RCX: 0000000000000002
RDX: ff2fb318d2f94380 RSI: 0000000000000002 RDI: 0000000000000001
RBP: ff2fb3065e832410 R08: ff46821ba664fe00 R09: 0000000000000001
R10: 0000000000000000 R11: 000000000000000d R12: ff2fb3065e832488
R13: ff2fb3065e8324a8 R14: ff2fb3065e8324c8 R15: ff2fb3065e8324a8
FS: 0000000000000000(0000) GS:ff2fb3257fac0000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ff2fb3063deb1002 CR3: 0000001392010006 CR4: 0000000000771ee0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
PKRU: 55555554
Call Trace:
<TASK>
mlx5_cvq_kick_handler+0x89/0x2b0 [mlx5_vdpa]
process_one_work+0x1e2/0x3b0
? rescuer_thread+0x390/0x390
worker_thread+0x50/0x3a0
? rescuer_thread+0x390/0x390
kthread+0xd6/0x100
? kthread_complete_and_exit+0x20/0x20
ret_from_fork+0x1f/0x30
</TASK>

Signed-off-by: Jason Wang <[email protected]>
---
drivers/vdpa/mlx5/net/mlx5_vnet.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index 6632651b1e54..b0e74c25bf48 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -2682,6 +2682,16 @@ static int mlx5_vdpa_set_map(struct vdpa_device *vdev, unsigned int asid,
return err;
}

+struct device *mlx5_get_vq_dma_dev(struct vdpa_device *vdev, u16 idx)
+{
+ struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
+
+ if (is_ctrl_vq_idx(mvdev, idx))
+ return &vdev->dev;
+
+ return mvdev->vdev.dma_dev;
+}
+
static void mlx5_vdpa_free(struct vdpa_device *vdev)
{
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
@@ -2897,6 +2907,7 @@ static const struct vdpa_config_ops mlx5_vdpa_ops = {
.get_generation = mlx5_vdpa_get_generation,
.set_map = mlx5_vdpa_set_map,
.set_group_asid = mlx5_set_group_asid,
+ .get_vq_dma_dev = mlx5_get_vq_dma_dev,
.free = mlx5_vdpa_free,
.suspend = mlx5_vdpa_suspend,
};
--
2.25.1


2023-01-11 12:56:53

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 5/5] vdpa: mlx5: support per virtqueue dma device

Hi Jason,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.2-rc3 next-20230111]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Jason-Wang/virtio_ring-per-virtqueue-dma-device/20230111-143052
patch link: https://lore.kernel.org/r/20230111062809.25020-6-jasowang%40redhat.com
patch subject: [PATCH 5/5] vdpa: mlx5: support per virtqueue dma device
config: s390-allyesconfig
compiler: s390-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/b7278272b70c83d953ebb0e5334dfc15c0b5c385
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jason-Wang/virtio_ring-per-virtqueue-dma-device/20230111-143052
git checkout b7278272b70c83d953ebb0e5334dfc15c0b5c385
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=s390 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=s390 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

>> drivers/vdpa/mlx5/net/mlx5_vnet.c:2658:16: warning: no previous prototype for 'mlx5_get_vq_dma_dev' [-Wmissing-prototypes]
2658 | struct device *mlx5_get_vq_dma_dev(struct vdpa_device *vdev, u16 idx)
| ^~~~~~~~~~~~~~~~~~~


vim +/mlx5_get_vq_dma_dev +2658 drivers/vdpa/mlx5/net/mlx5_vnet.c

2657
> 2658 struct device *mlx5_get_vq_dma_dev(struct vdpa_device *vdev, u16 idx)
2659 {
2660 struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
2661
2662 if (is_ctrl_vq_idx(mvdev, idx))
2663 return &vdev->dev;
2664
2665 return mvdev->vdev.dma_dev;
2666 }
2667

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests


Attachments:
(No filename) (2.36 kB)
config (318.08 kB)
Download all attachments

2023-01-12 02:25:07

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 5/5] vdpa: mlx5: support per virtqueue dma device

Hi Jason,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.2-rc3 next-20230111]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Jason-Wang/virtio_ring-per-virtqueue-dma-device/20230111-143052
patch link: https://lore.kernel.org/r/20230111062809.25020-6-jasowang%40redhat.com
patch subject: [PATCH 5/5] vdpa: mlx5: support per virtqueue dma device
config: x86_64-allmodconfig
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/b7278272b70c83d953ebb0e5334dfc15c0b5c385
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jason-Wang/virtio_ring-per-virtqueue-dma-device/20230111-143052
git checkout b7278272b70c83d953ebb0e5334dfc15c0b5c385
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/gpu/drm/i915/ drivers/vdpa/mlx5/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

>> drivers/vdpa/mlx5/net/mlx5_vnet.c:2658:16: warning: no previous prototype for function 'mlx5_get_vq_dma_dev' [-Wmissing-prototypes]
struct device *mlx5_get_vq_dma_dev(struct vdpa_device *vdev, u16 idx)
^
drivers/vdpa/mlx5/net/mlx5_vnet.c:2658:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
struct device *mlx5_get_vq_dma_dev(struct vdpa_device *vdev, u16 idx)
^
static
1 warning generated.


vim +/mlx5_get_vq_dma_dev +2658 drivers/vdpa/mlx5/net/mlx5_vnet.c

2657
> 2658 struct device *mlx5_get_vq_dma_dev(struct vdpa_device *vdev, u16 idx)
2659 {
2660 struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
2661
2662 if (is_ctrl_vq_idx(mvdev, idx))
2663 return &vdev->dev;
2664
2665 return mvdev->vdev.dma_dev;
2666 }
2667

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests


Attachments:
(No filename) (2.70 kB)
config (292.51 kB)
Download all attachments

2023-01-15 12:07:19

by Eli Cohen

[permalink] [raw]
Subject: RE: [PATCH 5/5] vdpa: mlx5: support per virtqueue dma device

> From: Jason Wang <[email protected]>
> Sent: Wednesday, 11 January 2023 8:28
> To: [email protected]; [email protected]
> Cc: Eli Cohen <[email protected]>; [email protected];
> [email protected]; [email protected];
> [email protected]
> Subject: [PATCH 5/5] vdpa: mlx5: support per virtqueue dma device
>
> This patch implements per virtqueue dma device for mlx5_vdpa. This is
> needed for virtio_vdpa to work for CVQ which is backed by vringh but
> not DMA. We simply advertise the vDPA device itself as the DMA device
> for CVQ then DMA API can simply use PA so the identical mapping for
> CVQ can still be used. Otherwise the identical (1:1) mapping won't
> work when platform IOMMU is enabled since the IOVA is allocated on
> demand which is not necessarily the PA.
>
> This fixes the following crash when mlx5 vDPA device is bound to
> virtio-vdpa with platform IOMMU enabled but not in passthrough mode:
>
> BUG: unable to handle page fault for address: ff2fb3063deb1002
> #PF: supervisor read access in kernel mode
> #PF: error_code(0x0000) - not-present page
> PGD 1393001067 P4D 1393002067 PUD 0
> Oops: 0000 [#1] PREEMPT SMP NOPTI
> CPU: 55 PID: 8923 Comm: kworker/u112:3 Kdump: loaded Not tainted 6.1.0+
> #7
> Hardware name: Dell Inc. PowerEdge R750/0PJ80M, BIOS 1.5.4 12/17/2021
> Workqueue: mlx5_vdpa_wq mlx5_cvq_kick_handler [mlx5_vdpa]
> RIP: 0010:vringh_getdesc_iotlb+0x93/0x1d0 [vringh]
> Code: 14 25 40 ef 01 00 83 82 c0 0a 00 00 01 48 2b 05 93 5a 1b ea 8b 4c 24
> 14 48 c1 f8 06 48 c1 e0 0c 48 03 05 90 5a 1b ea 48 01 c8 <0f> b7 00 83 aa c0
> 0a 00 00 01 65 ff 0d bc e4 41 3f 0f 84 05 01 00
> RSP: 0018:ff46821ba664fdf8 EFLAGS: 00010282
> RAX: ff2fb3063deb1002 RBX: 0000000000000a20 RCX: 0000000000000002
> RDX: ff2fb318d2f94380 RSI: 0000000000000002 RDI: 0000000000000001
> RBP: ff2fb3065e832410 R08: ff46821ba664fe00 R09: 0000000000000001
> R10: 0000000000000000 R11: 000000000000000d R12: ff2fb3065e832488
> R13: ff2fb3065e8324a8 R14: ff2fb3065e8324c8 R15: ff2fb3065e8324a8
> FS: 0000000000000000(0000) GS:ff2fb3257fac0000(0000)
> knlGS:0000000000000000
> CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: ff2fb3063deb1002 CR3: 0000001392010006 CR4: 0000000000771ee0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2:
> 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> PKRU: 55555554
> Call Trace:
> <TASK>
> mlx5_cvq_kick_handler+0x89/0x2b0 [mlx5_vdpa]
> process_one_work+0x1e2/0x3b0
> ? rescuer_thread+0x390/0x390
> worker_thread+0x50/0x3a0
> ? rescuer_thread+0x390/0x390
> kthread+0xd6/0x100
> ? kthread_complete_and_exit+0x20/0x20
> ret_from_fork+0x1f/0x30
> </TASK>
>
> Signed-off-by: Jason Wang <[email protected]>

mlx5_get_vq_dma_dev needs to made static. Other than that:
Reviewed-by: Eli Cohen <[email protected]>
Tested-by: <[email protected]>

Reviewed-by: Eli Cohen <[email protected]>
Tested-by: <[email protected]>
> ---
> drivers/vdpa/mlx5/net/mlx5_vnet.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index 6632651b1e54..b0e74c25bf48 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -2682,6 +2682,16 @@ static int mlx5_vdpa_set_map(struct vdpa_device
> *vdev, unsigned int asid,
> return err;
> }
>
> +struct device *mlx5_get_vq_dma_dev(struct vdpa_device *vdev, u16 idx)
> +{
> + struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
> +
> + if (is_ctrl_vq_idx(mvdev, idx))
> + return &vdev->dev;
> +
> + return mvdev->vdev.dma_dev;
> +}
> +
> static void mlx5_vdpa_free(struct vdpa_device *vdev)
> {
> struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
> @@ -2897,6 +2907,7 @@ static const struct vdpa_config_ops mlx5_vdpa_ops
> = {
> .get_generation = mlx5_vdpa_get_generation,
> .set_map = mlx5_vdpa_set_map,
> .set_group_asid = mlx5_set_group_asid,
> + .get_vq_dma_dev = mlx5_get_vq_dma_dev,
> .free = mlx5_vdpa_free,
> .suspend = mlx5_vdpa_suspend,
> };
> --
> 2.25.1

2023-01-16 03:13:07

by Jason Wang

[permalink] [raw]
Subject: Re: [PATCH 5/5] vdpa: mlx5: support per virtqueue dma device

On Sun, Jan 15, 2023 at 7:08 PM Eli Cohen <[email protected]> wrote:
>
> > From: Jason Wang <[email protected]>
> > Sent: Wednesday, 11 January 2023 8:28
> > To: [email protected]; [email protected]
> > Cc: Eli Cohen <[email protected]>; [email protected];
> > [email protected]; [email protected];
> > [email protected]
> > Subject: [PATCH 5/5] vdpa: mlx5: support per virtqueue dma device
> >
> > This patch implements per virtqueue dma device for mlx5_vdpa. This is
> > needed for virtio_vdpa to work for CVQ which is backed by vringh but
> > not DMA. We simply advertise the vDPA device itself as the DMA device
> > for CVQ then DMA API can simply use PA so the identical mapping for
> > CVQ can still be used. Otherwise the identical (1:1) mapping won't
> > work when platform IOMMU is enabled since the IOVA is allocated on
> > demand which is not necessarily the PA.
> >
> > This fixes the following crash when mlx5 vDPA device is bound to
> > virtio-vdpa with platform IOMMU enabled but not in passthrough mode:
> >
> > BUG: unable to handle page fault for address: ff2fb3063deb1002
> > #PF: supervisor read access in kernel mode
> > #PF: error_code(0x0000) - not-present page
> > PGD 1393001067 P4D 1393002067 PUD 0
> > Oops: 0000 [#1] PREEMPT SMP NOPTI
> > CPU: 55 PID: 8923 Comm: kworker/u112:3 Kdump: loaded Not tainted 6.1.0+
> > #7
> > Hardware name: Dell Inc. PowerEdge R750/0PJ80M, BIOS 1.5.4 12/17/2021
> > Workqueue: mlx5_vdpa_wq mlx5_cvq_kick_handler [mlx5_vdpa]
> > RIP: 0010:vringh_getdesc_iotlb+0x93/0x1d0 [vringh]
> > Code: 14 25 40 ef 01 00 83 82 c0 0a 00 00 01 48 2b 05 93 5a 1b ea 8b 4c 24
> > 14 48 c1 f8 06 48 c1 e0 0c 48 03 05 90 5a 1b ea 48 01 c8 <0f> b7 00 83 aa c0
> > 0a 00 00 01 65 ff 0d bc e4 41 3f 0f 84 05 01 00
> > RSP: 0018:ff46821ba664fdf8 EFLAGS: 00010282
> > RAX: ff2fb3063deb1002 RBX: 0000000000000a20 RCX: 0000000000000002
> > RDX: ff2fb318d2f94380 RSI: 0000000000000002 RDI: 0000000000000001
> > RBP: ff2fb3065e832410 R08: ff46821ba664fe00 R09: 0000000000000001
> > R10: 0000000000000000 R11: 000000000000000d R12: ff2fb3065e832488
> > R13: ff2fb3065e8324a8 R14: ff2fb3065e8324c8 R15: ff2fb3065e8324a8
> > FS: 0000000000000000(0000) GS:ff2fb3257fac0000(0000)
> > knlGS:0000000000000000
> > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> > CR2: ff2fb3063deb1002 CR3: 0000001392010006 CR4: 0000000000771ee0
> > DR0: 0000000000000000 DR1: 0000000000000000 DR2:
> > 0000000000000000
> > DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> > PKRU: 55555554
> > Call Trace:
> > <TASK>
> > mlx5_cvq_kick_handler+0x89/0x2b0 [mlx5_vdpa]
> > process_one_work+0x1e2/0x3b0
> > ? rescuer_thread+0x390/0x390
> > worker_thread+0x50/0x3a0
> > ? rescuer_thread+0x390/0x390
> > kthread+0xd6/0x100
> > ? kthread_complete_and_exit+0x20/0x20
> > ret_from_fork+0x1f/0x30
> > </TASK>
> >
> > Signed-off-by: Jason Wang <[email protected]>
>
> mlx5_get_vq_dma_dev needs to made static.

Right, I will fix it in v2.

> Other than that:
> Reviewed-by: Eli Cohen <[email protected]>
> Tested-by: <[email protected]>

Thanks

>
> Reviewed-by: Eli Cohen <[email protected]>
> Tested-by: <[email protected]>
> > ---
> > drivers/vdpa/mlx5/net/mlx5_vnet.c | 11 +++++++++++
> > 1 file changed, 11 insertions(+)
> >
> > diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > index 6632651b1e54..b0e74c25bf48 100644
> > --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > @@ -2682,6 +2682,16 @@ static int mlx5_vdpa_set_map(struct vdpa_device
> > *vdev, unsigned int asid,
> > return err;
> > }
> >
> > +struct device *mlx5_get_vq_dma_dev(struct vdpa_device *vdev, u16 idx)
> > +{
> > + struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
> > +
> > + if (is_ctrl_vq_idx(mvdev, idx))
> > + return &vdev->dev;
> > +
> > + return mvdev->vdev.dma_dev;
> > +}
> > +
> > static void mlx5_vdpa_free(struct vdpa_device *vdev)
> > {
> > struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
> > @@ -2897,6 +2907,7 @@ static const struct vdpa_config_ops mlx5_vdpa_ops
> > = {
> > .get_generation = mlx5_vdpa_get_generation,
> > .set_map = mlx5_vdpa_set_map,
> > .set_group_asid = mlx5_set_group_asid,
> > + .get_vq_dma_dev = mlx5_get_vq_dma_dev,
> > .free = mlx5_vdpa_free,
> > .suspend = mlx5_vdpa_suspend,
> > };
> > --
> > 2.25.1
>