virtio: make sure legacy pci device gain 32bit-pfn vq
RFC PATCH 1/1 virtio: make sure legacy pci device gain 32bit-pfn vq
We observed issues like:
virtio-pci 0000:14:00.0: platform bug: legacy virtio-mmio must not be used with RAM above 0x4000GB
when we have a legacy pci device which desired 32bit-pfn vq but gain 64bit-pfn instead, lead into the failure of probe.
vring_use_dma_api() is playing the key role in here, to help the allocation process understand which kind of vq it should alloc, however, it failed to take care the legacy pci device, which only have 32bit feature flag and can never have VIRTIO_F_ACCESS_PLATFORM setted.
This patch introduce force_dma flag to help vring_use_dma_api() understanding the requirement better, to avoid the failing.
--- drivers/virtio/virtio_pci_legacy.c | 10 ++++++++++ drivers/virtio/virtio_ring.c | 3 +++ include/linux/virtio.h | 1 + 3 files changed, 14 insertions(+)
drivers/virtio/virtio_pci_legacy.c +10 -0
@@ -263,6 +263,16 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev) vp_dev->setup_vq = setup_vq; vp_dev->del_vq = del_vq; +/* +* The legacy pci device requre 32bit-pfn vq, +* or setup_vq() will failed. +* +* Thus we make sure vring_use_dma_api() will +* return true during the allocation by marking +* force_dma here. +*/ + vp_dev->vdev.force_dma = true; +return 0 ; err_iomap:
drivers/virtio/virtio_ring.c +3 -0
@@ -245,6 +245,9 @@ static inline bool virtqueue_use_indirect(struct virtqueue *_vq,static bool vring_use_dma_api (struct virtio_device *vdev) { +if (vdev->force_dma) +return true; +if (!virtio_has_dma_quirk (vdev))return true;
include/linux/virtio.h +1 -0
@@ -109,6 +109,7 @@ struct virtio_device {bool failed;bool config_enabled;bool config_change_pending; +bool force_dma;spinlock_t config_lock;spinlock_t vqs_list_lock;/* Protects VQs list access */ struct device dev;
Signature · 1 line
1.8.3.1
Michael S. Tsirkin
maintainerQuoted 13 lines · 王贇
We observed issues like:
virtio-pci 0000:14:00.0: platform bug: legacy virtio-mmio must not be used with RAM above 0x4000GBwhen we have a legacy pci device which desired 32bit-pfn vq but gain 64bit-pfn instead, lead into the failure of probe.
vring_use_dma_api()is playing the key role in here, to help the allocation process understand which kind of vq it should alloc, however, it failed to take care the legacy pci device, which only have 32bit feature flag and can never haveVIRTIO_F_ACCESS_PLATFORMsetted.
Quoted 4 lines
This patch introduce
force_dmaflag to helpvring_use_dma_api()understanding the requirement better, to avoid the failing.Signed-off-by Michael Wang <[email protected]>
This will break configs where the device appears behind a virtual iommu, so this won't fly.
Just make your device support 1.0, eh?
Quoted 58 lines
--- drivers/virtio/virtio_pci_legacy.c | 10 ++++++++++ drivers/virtio/virtio_ring.c | 3 +++ include/linux/virtio.h | 1 + 3 files changed, 14 insertions(+)drivers/virtio/virtio_pci_legacy.c +10
-0@@ -263,6 +263,16 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev) vp_dev->setup_vq = setup_vq; vp_dev->del_vq = del_vq; +/* +* The legacy pci device requre 32bit-pfn vq, +* or setup_vq() will failed. +* +* Thus we make sure vring_use_dma_api() will +* return true during the allocation by marking +* force_dma here. +*/ + vp_dev->vdev.force_dma = true; +return 0 ;
err_iomap:drivers/virtio/virtio_ring.c +3
-0@@ -245,6 +245,9 @@ static inline bool virtqueue_use_indirect(struct virtqueue *_vq, static bool vring_use_dma_api(struct virtio_device *vdev) { +if (vdev->force_dma) +return true; +if (!virtio_has_dma_quirk (vdev))return true;include/linux/virtio.h +1
-0@@ -109,6 +109,7 @@ struct virtio_device {bool failed;bool config_enabled;bool config_change_pending; +bool force_dma;spinlock_t config_lock;spinlock_t vqs_list_lock;/* Protects VQs list access */ struct device dev;Signature · 1 line
1.8.3.1
Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · 王贇
We observed issues like:
virtio-pci 0000:14:00.0: platform bug: legacy virtio-mmio must not be used with RAM above 0x4000GBwhen we have a legacy pci device which desired 32bit-pfn vq but gain 64bit-pfn instead, lead into the failure of probe.
vring_use_dma_api()is playing the key role in here, to help the allocation process understand which kind of vq it should alloc, however, it failed to take care the legacy pci device, which only have 32bit feature flag and can never haveVIRTIO_F_ACCESS_PLATFORMsetted.
Quoted 8 lines
Quoted 4 lines
This patch introduce
force_dmaflag to helpvring_use_dma_api()understanding the requirement better, to avoid the failing.Signed-off-by Michael Wang <[email protected]>This will break configs where the device appears behind a virtual iommu, so this won't fly.
Just make your device support 1.0, eh?
Hi, Michael
Thanks for the comment, unfortunately modify device is not an option for us :-(
Is there any idea on how to solve this issue properly?
Regards,
Michael Wang
Quoted 59 lines
Quoted 59 lines
--- drivers/virtio/virtio_pci_legacy.c | 10 ++++++++++ drivers/virtio/virtio_ring.c | 3 +++ include/linux/virtio.h | 1 + 3 files changed, 14 insertions(+)drivers/virtio/virtio_pci_legacy.c +10
-0@@ -263,6 +263,16 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev) vp_dev->setup_vq = setup_vq; vp_dev->del_vq = del_vq; +/* +* The legacy pci device requre 32bit-pfn vq, +* or setup_vq() will failed. +* +* Thus we make sure vring_use_dma_api() will +* return true during the allocation by marking +* force_dma here. +*/ + vp_dev->vdev.force_dma = true; +return 0 ;
err_iomap:drivers/virtio/virtio_ring.c +3
-0@@ -245,6 +245,9 @@ static inline bool virtqueue_use_indirect(struct virtqueue *_vq, static bool vring_use_dma_api(struct virtio_device *vdev) { +if (vdev->force_dma) +return true; +if (!virtio_has_dma_quirk (vdev))return true;include/linux/virtio.h +1
-0@@ -109,6 +109,7 @@ struct virtio_device {bool failed;bool config_enabled;bool config_change_pending; +bool force_dma;spinlock_t config_lock;spinlock_t vqs_list_lock;/* Protects VQs list access */ struct device dev;Signature · 1 line
1.8.3.1
Michael S. Tsirkin
maintainerQuoted 28 lines · 王贇
Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · 王贇
We observed issues like:
virtio-pci 0000:14:00.0: platform bug: legacy virtio-mmio must not be used with RAM above 0x4000GBwhen we have a legacy pci device which desired 32bit-pfn vq but gain 64bit-pfn instead, lead into the failure of probe.
vring_use_dma_api()is playing the key role in here, to help the allocation process understand which kind of vq it should alloc, however, it failed to take care the legacy pci device, which only have 32bit feature flag and can never haveVIRTIO_F_ACCESS_PLATFORMsetted.Quoted 8 lines
Quoted 4 lines
This patch introduce
force_dmaflag to helpvring_use_dma_api()understanding the requirement better, to avoid the failing.Signed-off-by Michael Wang <[email protected]>This will break configs where the device appears behind a virtual iommu, so this won't fly.
Just make your device support 1.0, eh?Hi, Michael
Quoted 7 lines
Thanks for the comment, unfortunately modify device is not an option for us :-(
Is there any idea on how to solve this issue properly?
Regards,
Michael Wang
There's an old idea:
https://www.spinics.net/lists/kernel/msg3248800.html
Quoted 59 lines
Quoted 59 lines
Quoted 59 lines
--- drivers/virtio/virtio_pci_legacy.c | 10 ++++++++++ drivers/virtio/virtio_ring.c | 3 +++ include/linux/virtio.h | 1 + 3 files changed, 14 insertions(+)drivers/virtio/virtio_pci_legacy.c +10
-0@@ -263,6 +263,16 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev) vp_dev->setup_vq = setup_vq; vp_dev->del_vq = del_vq; +/* +* The legacy pci device requre 32bit-pfn vq, +* or setup_vq() will failed. +* +* Thus we make sure vring_use_dma_api() will +* return true during the allocation by marking +* force_dma here. +*/ + vp_dev->vdev.force_dma = true; +return 0 ;
err_iomap:drivers/virtio/virtio_ring.c +3
-0@@ -245,6 +245,9 @@ static inline bool virtqueue_use_indirect(struct virtqueue *_vq, static bool vring_use_dma_api(struct virtio_device *vdev) { +if (vdev->force_dma) +return true; +if (!virtio_has_dma_quirk (vdev))return true;include/linux/virtio.h +1
-0@@ -109,6 +109,7 @@ struct virtio_device {bool failed;bool config_enabled;bool config_change_pending; +bool force_dma;spinlock_t config_lock;spinlock_t vqs_list_lock;/* Protects VQs list access */ struct device dev;Signature · 1 line
1.8.3.1
Michael S. Tsirkin
maintainerQuoted 28 lines · 王贇
Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · 王贇
We observed issues like:
virtio-pci 0000:14:00.0: platform bug: legacy virtio-mmio must not be used with RAM above 0x4000GBwhen we have a legacy pci device which desired 32bit-pfn vq but gain 64bit-pfn instead, lead into the failure of probe.
vring_use_dma_api()is playing the key role in here, to help the allocation process understand which kind of vq it should alloc, however, it failed to take care the legacy pci device, which only have 32bit feature flag and can never haveVIRTIO_F_ACCESS_PLATFORMsetted.Quoted 8 lines
Quoted 4 lines
This patch introduce
force_dmaflag to helpvring_use_dma_api()understanding the requirement better, to avoid the failing.Signed-off-by Michael Wang <[email protected]>This will break configs where the device appears behind a virtual iommu, so this won't fly.
Just make your device support 1.0, eh?Hi, Michael
Quoted 7 lines
Thanks for the comment, unfortunately modify device is not an option for us :-(
Is there any idea on how to solve this issue properly?
Regards,
Michael Wang
By the way, there is a bug in the error message. Want to fix that?
Quoted 59 lines
Quoted 59 lines
Quoted 59 lines
--- drivers/virtio/virtio_pci_legacy.c | 10 ++++++++++ drivers/virtio/virtio_ring.c | 3 +++ include/linux/virtio.h | 1 + 3 files changed, 14 insertions(+)drivers/virtio/virtio_pci_legacy.c +10
-0@@ -263,6 +263,16 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev) vp_dev->setup_vq = setup_vq; vp_dev->del_vq = del_vq; +/* +* The legacy pci device requre 32bit-pfn vq, +* or setup_vq() will failed. +* +* Thus we make sure vring_use_dma_api() will +* return true during the allocation by marking +* force_dma here. +*/ + vp_dev->vdev.force_dma = true; +return 0 ;
err_iomap:drivers/virtio/virtio_ring.c +3
-0@@ -245,6 +245,9 @@ static inline bool virtqueue_use_indirect(struct virtqueue *_vq, static bool vring_use_dma_api(struct virtio_device *vdev) { +if (vdev->force_dma) +return true; +if (!virtio_has_dma_quirk (vdev))return true;include/linux/virtio.h +1
-0@@ -109,6 +109,7 @@ struct virtio_device {bool failed;bool config_enabled;bool config_change_pending; +bool force_dma;spinlock_t config_lock;spinlock_t vqs_list_lock;/* Protects VQs list access */ struct device dev;Signature · 1 line
1.8.3.1
Quoted 32 lines · Michael S. Tsirkin
Quoted 31 lines · 王贇
Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · 王贇
We observed issues like:
virtio-pci 0000:14:00.0: platform bug: legacy virtio-mmio must not be used with RAM above 0x4000GBwhen we have a legacy pci device which desired 32bit-pfn vq but gain 64bit-pfn instead, lead into the failure of probe.
vring_use_dma_api()is playing the key role in here, to help the allocation process understand which kind of vq it should alloc, however, it failed to take care the legacy pci device, which only have 32bit feature flag and can never haveVIRTIO_F_ACCESS_PLATFORMsetted.Quoted 8 lines
Quoted 4 lines
This patch introduce
force_dmaflag to helpvring_use_dma_api()understanding the requirement better, to avoid the failing.Signed-off-by Michael Wang <[email protected]>This will break configs where the device appears behind a virtual iommu, so this won't fly.
Just make your device support 1.0, eh?Hi, Michael
Thanks for the comment, unfortunately modify device is not an option for us :-(
Quoted 6 lines
Quoted 4 lines
Is there any idea on how to solve this issue properly?
Regards,
Michael WangBy the way, there is a bug in the error message. Want to fix that?
Could you please provide more detail about the bug? We'd like to help fixing it :-)
Besides, I've checked that patch but it can't address our issue, we actually have this legacy pci device on arm platform, and the memory layout is unfriendly since allocation rarely providing page-address below 44bit, we understand the virtio-iommu case should not do force dma, while we don't have that so it's just working fine.
Regards,
Michael Wang
Quoted 61 lines
Quoted 61 lines
Quoted 61 lines
Quoted 61 lines
--- drivers/virtio/virtio_pci_legacy.c | 10 ++++++++++ drivers/virtio/virtio_ring.c | 3 +++ include/linux/virtio.h | 1 + 3 files changed, 14 insertions(+)drivers/virtio/virtio_pci_legacy.c +10
-0@@ -263,6 +263,16 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev) vp_dev->setup_vq = setup_vq; vp_dev->del_vq = del_vq; +/* +* The legacy pci device requre 32bit-pfn vq, +* or setup_vq() will failed. +* +* Thus we make sure vring_use_dma_api() will +* return true during the allocation by marking +* force_dma here. +*/ + vp_dev->vdev.force_dma = true; +return 0 ;
err_iomap:drivers/virtio/virtio_ring.c +3
-0@@ -245,6 +245,9 @@ static inline bool virtqueue_use_indirect(struct virtqueue *_vq, static bool vring_use_dma_api(struct virtio_device *vdev) { + if (vdev->force_dma) + return true; +if (!virtio_has_dma_quirk (vdev))return true;include/linux/virtio.h +1
-0@@ -109,6 +109,7 @@ struct virtio_device {bool failed;bool config_enabled;bool config_change_pending; +bool force_dma;spinlock_t config_lock;spinlock_t vqs_list_lock;/* Protects VQs list access */ struct device dev;Signature · 1 line
1.8.3.1
Michael S. Tsirkin
maintainerQuoted 37 lines · 王贇
Quoted 34 lines · Michael S. Tsirkin
Quoted 33 lines · 王贇
Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · 王贇
We observed issues like:
virtio-pci 0000:14:00.0: platform bug: legacy virtio-mmio must not be used with RAM above 0x4000GBwhen we have a legacy pci device which desired 32bit-pfn vq but gain 64bit-pfn instead, lead into the failure of probe.
vring_use_dma_api()is playing the key role in here, to help the allocation process understand which kind of vq it should alloc, however, it failed to take care the legacy pci device, which only have 32bit feature flag and can never haveVIRTIO_F_ACCESS_PLATFORMsetted.Quoted 8 lines
Quoted 4 lines
This patch introduce
force_dmaflag to helpvring_use_dma_api()understanding the requirement better, to avoid the failing.Signed-off-by Michael Wang <[email protected]>This will break configs where the device appears behind a virtual iommu, so this won't fly.
Just make your device support 1.0, eh?Hi, Michael
Thanks for the comment, unfortunately modify device is not an option for us :-(
Is there any idea on how to solve this issue properly?
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Regards,
Michael WangBy the way, there is a bug in the error message. Want to fix that?
Could you please provide more detail about the bug? We'd like to help fixing it :-)
virtio-pci 0000:14:00.0: platform bug: legacy virtio-mmio must ...
should be virtio-pci not virtio-mmio
Quoted 8 lines
Besides, I've checked that patch but it can't address our issue, we actually have this legacy pci device on arm platform, and the memory layout is unfriendly since allocation rarely providing page-address below 44bit, we understand the virtio-iommu case should not do force dma, while we don't have that so it's just working fine.
Regards,
Michael Wang
Hmm wait a sec is it a physical device or a hypervisor? If a physical one then doesn't it need VIRTIO_F_ORDER_PLATFORM on ARM?
Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
--- drivers/virtio/virtio_pci_legacy.c | 10 ++++++++++ drivers/virtio/virtio_ring.c | 3 +++ include/linux/virtio.h | 1 + 3 files changed, 14 insertions(+)drivers/virtio/virtio_pci_legacy.c +10
-0@@ -263,6 +263,16 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev) vp_dev->setup_vq = setup_vq; vp_dev->del_vq = del_vq; +/* +* The legacy pci device requre 32bit-pfn vq, +* or setup_vq() will failed. +* +* Thus we make sure vring_use_dma_api() will +* return true during the allocation by marking +* force_dma here. +*/ + vp_dev->vdev.force_dma = true; +return 0 ;
err_iomap:drivers/virtio/virtio_ring.c +3
-0@@ -245,6 +245,9 @@ static inline bool virtqueue_use_indirect(struct virtqueue *_vq, static bool vring_use_dma_api(struct virtio_device *vdev) { + if (vdev->force_dma) + return true; +if (!virtio_has_dma_quirk (vdev))return true;
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
include/linux/virtio.h +0
-0@@ -109,6 +109,7 @@ struct virtio_device {bool failed;Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/linux/virtio.h +1
-0bool config_enabled;bool config_change_pending; +bool force_dma;spinlock_t config_lock;spinlock_t vqs_list_lock;/* Protects VQs list access */ struct device dev;Signature · 1 line
1.8.3.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
在 2021/12/8 下午7:08, Michael S. Tsirkin 写道:
[snip]
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Hi, Michael
Thanks for the comment, unfortunately modify device is not an option for us :-(
Is there any idea on how to solve this issue properly?
Regards,
Michael Wang
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
By the way, there is a bug in the error message. Want to fix that?
Could you please provide more detail about the bug? We'd like to help fixing it :-)
virtio-pci 0000:14:00.0: platform bug: legacy virtio-mmio must ...
should be virtio-pci not virtio-mmio
Patch on the way~
Quoted 9 lines
Quoted 9 lines
Besides, I've checked that patch but it can't address our issue, we actually have this legacy pci device on arm platform, and the memory layout is unfriendly since allocation rarely providing page-address below 44bit, we understand the virtio-iommu case should not do force dma, while we don't have that so it's just working fine.
Quoted 6 lines
Quoted 2 lines
Regards,
Michael WangHmm wait a sec is it a physical device or a hypervisor? If a physical one then doesn't it need
VIRTIO_F_ORDER_PLATFORMon ARM?
The PCI device is virtual, I can't see how VIRTIO_F_ORDER_PLATFORM help address this issue, legacy pci config is 32bit but it's 36, seems like will never be included?
Regards,
Michael Wang
Quoted 64 lines
Quoted 64 lines
Quoted 64 lines
Quoted 64 lines
Quoted 64 lines
Quoted 64 lines
--- drivers/virtio/virtio_pci_legacy.c | 10 ++++++++++ drivers/virtio/virtio_ring.c | 3 +++ include/linux/virtio.h | 1 + 3 files changed, 14 insertions(+)drivers/virtio/virtio_pci_legacy.c +10
-0@@ -263,6 +263,16 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev) vp_dev->setup_vq = setup_vq; vp_dev->del_vq = del_vq; +/* +* The legacy pci device requre 32bit-pfn vq, +* or setup_vq() will failed. +* +* Thus we make sure vring_use_dma_api() will +* return true during the allocation by marking +* force_dma here. +*/ + vp_dev->vdev.force_dma = true; +return 0 ;
err_iomap:drivers/virtio/virtio_ring.c +3
-0@@ -245,6 +245,9 @@ static inline bool virtqueue_use_indirect(struct virtqueue *_vq, static bool vring_use_dma_api(struct virtio_device *vdev) { + if (vdev->force_dma) + return true; +if (!virtio_has_dma_quirk (vdev))return true;include/linux/virtio.h +1
-0@@ -109,6 +109,7 @@ struct virtio_device {bool failed;bool config_enabled;bool config_change_pending; +bool force_dma;spinlock_t config_lock;spinlock_t vqs_list_lock;/* Protects VQs list access */ struct device dev;Signature · 1 line
1.8.3.1
Michael S. Tsirkin
maintainerQuoted 42 lines · 王贇
在 2021/12/8 下午7:08, Michael S. Tsirkin 写道:
[snip]Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Hi, Michael
Thanks for the comment, unfortunately modify device is not an option for us :-(
Is there any idea on how to solve this issue properly?
Regards,
Michael WangQuoted 8 lines
Quoted 4 lines
Quoted 1 line
By the way, there is a bug in the error message. Want to fix that?
Could you please provide more detail about the bug? We'd like to help fixing it :-)
virtio-pci 0000:14:00.0: platform bug: legacy virtio-mmio must ...
should be virtio-pci not virtio-mmio
Patch on the way~
Quoted 9 lines
Quoted 9 lines
Besides, I've checked that patch but it can't address our issue, we actually have this legacy pci device on arm platform, and the memory layout is unfriendly since allocation rarely providing page-address below 44bit, we understand the virtio-iommu case should not do force dma, while we don't have that so it's just working fine.
Quoted 6 lines
Quoted 2 lines
Regards,
Michael WangHmm wait a sec is it a physical device or a hypervisor? If a physical one then doesn't it need
VIRTIO_F_ORDER_PLATFORMon ARM?
Quoted 6 lines
The PCI device is virtual, I can't see how
VIRTIO_F_ORDER_PLATFORMhelp address this issue, legacy pci config is 32bit but it's 36, seems like will never be included?Regards,
Michael Wang
Oh, if the device is virtual then I think you should just update it please. virtio 0.X is architecturally limited to small VMs,
if your hypervisor supports more it should emulate virtio 1.0.
Quoted 64 lines
Quoted 64 lines
Quoted 64 lines
Quoted 64 lines
Quoted 64 lines
Quoted 64 lines
Quoted 64 lines
--- drivers/virtio/virtio_pci_legacy.c | 10 ++++++++++ drivers/virtio/virtio_ring.c | 3 +++ include/linux/virtio.h | 1 + 3 files changed, 14 insertions(+)drivers/virtio/virtio_pci_legacy.c +10
-0@@ -263,6 +263,16 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev) vp_dev->setup_vq = setup_vq; vp_dev->del_vq = del_vq; +/* +* The legacy pci device requre 32bit-pfn vq, +* or setup_vq() will failed. +* +* Thus we make sure vring_use_dma_api() will +* return true during the allocation by marking +* force_dma here. +*/ + vp_dev->vdev.force_dma = true; +return 0 ;
err_iomap:drivers/virtio/virtio_ring.c +3
-0@@ -245,6 +245,9 @@ static inline bool virtqueue_use_indirect(struct virtqueue *_vq, static bool vring_use_dma_api(struct virtio_device *vdev) { + if (vdev->force_dma) + return true; +if (!virtio_has_dma_quirk (vdev))return true;include/linux/virtio.h +1
-0@@ -109,6 +109,7 @@ struct virtio_device {bool failed;bool config_enabled;bool config_change_pending; +bool force_dma;spinlock_t config_lock;spinlock_t vqs_list_lock;/* Protects VQs list access */ struct device dev;Signature · 1 line
1.8.3.1
在 2021/12/9 下午2:40, Michael S. Tsirkin 写道:
[snip]
Quoted 17 lines
Quoted 17 lines
Quoted 6 lines
Quoted 6 lines
Besides, I've checked that patch but it can't address our issue, we actually have this legacy pci device on arm platform, and the memory layout is unfriendly since allocation rarely providing page-address below 44bit, we understand the virtio-iommu case should not do force dma, while we don't have that so it's just working fine.
Quoted 6 lines
Quoted 2 lines
Regards,
Michael WangHmm wait a sec is it a physical device or a hypervisor? If a physical one then doesn't it need
VIRTIO_F_ORDER_PLATFORMon ARM?The PCI device is virtual, I can't see how
VIRTIO_F_ORDER_PLATFORMhelp address this issue, legacy pci config is 32bit but it's 36, seems like will never be included?
Quoted 6 lines
Quoted 2 lines
Regards,
Michael WangOh, if the device is virtual then I think you should just update it please. virtio 0.X is architecturally limited to small VMs,
if your hypervisor supports more it should emulate virtio 1.0.
I see, nice to confirm the proper approach, although we don't have that option on the desk :-P
So as long as we don't have any iommu enabled, the force dma approach could be safe, is this correct?
Regards,
Michael Wang
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
--- drivers/virtio/virtio_pci_legacy.c | 10 ++++++++++ drivers/virtio/virtio_ring.c | 3 +++ include/linux/virtio.h | 1 + 3 files changed, 14 insertions(+)drivers/virtio/virtio_pci_legacy.c +10
-0@@ -263,6 +263,16 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev) vp_dev->setup_vq = setup_vq; vp_dev->del_vq = del_vq; +/* +* The legacy pci device requre 32bit-pfn vq, +* or setup_vq() will failed. +* +* Thus we make sure vring_use_dma_api() will +* return true during the allocation by marking +* force_dma here. +*/ + vp_dev->vdev.force_dma = true; +return 0 ;
err_iomap:drivers/virtio/virtio_ring.c +3
-0@@ -245,6 +245,9 @@ static inline bool virtqueue_use_indirect(struct virtqueue *_vq, static bool vring_use_dma_api(struct virtio_device *vdev) { + if (vdev->force_dma) + return true; +if (!virtio_has_dma_quirk (vdev))return true;include/linux/virtio.h +1
-0@@ -109,6 +109,7 @@ struct virtio_device {bool failed;bool config_enabled;bool config_change_pending; +bool force_dma;spinlock_t config_lock;spinlock_t vqs_list_lock;/* Protects VQs list access */ struct device dev;Signature · 1 line
1.8.3.1
Michael S. Tsirkin
maintainerQuoted 24 lines · 王贇
在 2021/12/9 下午2:40, Michael S. Tsirkin 写道:
[snip]Quoted 20 lines
Quoted 19 lines
Quoted 6 lines
Quoted 6 lines
Besides, I've checked that patch but it can't address our issue, we actually have this legacy pci device on arm platform, and the memory layout is unfriendly since allocation rarely providing page-address below 44bit, we understand the virtio-iommu case should not do force dma, while we don't have that so it's just working fine.
Quoted 6 lines
Quoted 2 lines
Regards,
Michael WangHmm wait a sec is it a physical device or a hypervisor? If a physical one then doesn't it need
VIRTIO_F_ORDER_PLATFORMon ARM?The PCI device is virtual, I can't see how
VIRTIO_F_ORDER_PLATFORMhelp address this issue, legacy pci config is 32bit but it's 36, seems like will never be included?Regards,
Michael Wang
Quoted 6 lines
Quoted 3 lines
Oh, if the device is virtual then I think you should just update it please. virtio 0.X is architecturally limited to small VMs,
if your hypervisor supports more it should emulate virtio 1.0.I see, nice to confirm the proper approach, although we don't have that option on the desk :-P
Don't see why, a stronger justification will be needed before everyone takes on the maintainance burden of maintaining hacks like this. If we make an exception here this opens floodgates for everyone too lazy to add virtio 1 support to instead push hacks at the linux level.
Quoted 5 lines
So as long as we don't have any iommu enabled, the force dma approach could be safe, is this correct?
Regards,
Michael Wang
Not unless there's an API at the DMA API level that guarantees DMA addresses are physical addresses.
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
--- drivers/virtio/virtio_pci_legacy.c | 10 ++++++++++ drivers/virtio/virtio_ring.c | 3 +++ include/linux/virtio.h | 1 + 3 files changed, 14 insertions(+)drivers/virtio/virtio_pci_legacy.c +10
-0@@ -263,6 +263,16 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev) vp_dev->setup_vq = setup_vq; vp_dev->del_vq = del_vq; +/* +* The legacy pci device requre 32bit-pfn vq, +* or setup_vq() will failed. +* +* Thus we make sure vring_use_dma_api() will +* return true during the allocation by marking +* force_dma here. +*/ + vp_dev->vdev.force_dma = true; +return 0 ;
err_iomap:drivers/virtio/virtio_ring.c +3
-0@@ -245,6 +245,9 @@ static inline bool virtqueue_use_indirect(struct virtqueue *_vq, static bool vring_use_dma_api(struct virtio_device *vdev) { + if (vdev->force_dma) + return true; +if (!virtio_has_dma_quirk (vdev))return true;include/linux/virtio.h +1
-0@@ -109,6 +109,7 @@ struct virtio_device {bool failed;bool config_enabled;bool config_change_pending; +bool force_dma;spinlock_t config_lock;spinlock_t vqs_list_lock;/* Protects VQs list access */ struct device dev;Signature · 1 line
1.8.3.1
Michael S. Tsirkin
maintainerQuoted 45 lines · 王贇
Quoted 32 lines · Michael S. Tsirkin
Quoted 31 lines · 王贇
Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · 王贇
We observed issues like:
virtio-pci 0000:14:00.0: platform bug: legacy virtio-mmio must not be used with RAM above 0x4000GBwhen we have a legacy pci device which desired 32bit-pfn vq but gain 64bit-pfn instead, lead into the failure of probe.
vring_use_dma_api()is playing the key role in here, to help the allocation process understand which kind of vq it should alloc, however, it failed to take care the legacy pci device, which only have 32bit feature flag and can never haveVIRTIO_F_ACCESS_PLATFORMsetted.Quoted 8 lines
Quoted 4 lines
This patch introduce
force_dmaflag to helpvring_use_dma_api()understanding the requirement better, to avoid the failing.Signed-off-by Michael Wang <[email protected]>This will break configs where the device appears behind a virtual iommu, so this won't fly.
Just make your device support 1.0, eh?Hi, Michael
Thanks for the comment, unfortunately modify device is not an option for us :-(
Quoted 6 lines
Quoted 4 lines
Is there any idea on how to solve this issue properly?
Regards,
Michael WangBy the way, there is a bug in the error message. Want to fix that?
Could you please provide more detail about the bug? We'd like to help fixing it :-)
Quoted 8 lines
Besides, I've checked that patch but it can't address our issue, we actually have this legacy pci device on arm platform, and the memory layout is unfriendly since allocation rarely providing page-address below 44bit, we understand the virtio-iommu case should not do force dma, while we don't have that so it's just working fine.
Regards,
Michael Wang
BTW is it just the ring that's at issue?
Figuring out we have this problematic config and then allocating just the ring from coherent memory seems more palatable.
But please note we still need to detect config with a virtual iommu (can be any kind not just virtio-iommu, smmu, vtd are all affected) and disable the hacks. This is what the new DMA API I suggested would do.
Quoted 61 lines
Quoted 61 lines
Quoted 61 lines
Quoted 61 lines
Quoted 61 lines
--- drivers/virtio/virtio_pci_legacy.c | 10 ++++++++++ drivers/virtio/virtio_ring.c | 3 +++ include/linux/virtio.h | 1 + 3 files changed, 14 insertions(+)drivers/virtio/virtio_pci_legacy.c +10
-0@@ -263,6 +263,16 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev) vp_dev->setup_vq = setup_vq; vp_dev->del_vq = del_vq; +/* +* The legacy pci device requre 32bit-pfn vq, +* or setup_vq() will failed. +* +* Thus we make sure vring_use_dma_api() will +* return true during the allocation by marking +* force_dma here. +*/ + vp_dev->vdev.force_dma = true; +return 0 ;
err_iomap:drivers/virtio/virtio_ring.c +3
-0@@ -245,6 +245,9 @@ static inline bool virtqueue_use_indirect(struct virtqueue *_vq, static bool vring_use_dma_api(struct virtio_device *vdev) { + if (vdev->force_dma) + return true; +if (!virtio_has_dma_quirk (vdev))return true;include/linux/virtio.h +1
-0@@ -109,6 +109,7 @@ struct virtio_device {bool failed;bool config_enabled;bool config_change_pending; +bool force_dma;spinlock_t config_lock;spinlock_t vqs_list_lock;/* Protects VQs list access */ struct device dev;Signature · 1 line
1.8.3.1
在 2021/12/9 上午8:19, Michael S. Tsirkin 写道:
[snip]
Quoted 22 lines
Quoted 22 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Hi, Michael
Thanks for the comment, unfortunately modify device is not an option for us :-(
Quoted 6 lines
Quoted 4 lines
Is there any idea on how to solve this issue properly?
Regards,
Michael WangBy the way, there is a bug in the error message. Want to fix that?
Could you please provide more detail about the bug? We'd like to help fixing it :-)
Besides, I've checked that patch but it can't address our issue, we actually have this legacy pci device on arm platform, and the memory layout is unfriendly since allocation rarely providing page-address below 44bit, we understand the virtio-iommu case should not do force dma, while we don't have that so it's just working fine.
Quoted 4 lines
Quoted 2 lines
Regards,
Michael WangBTW is it just the ring that's at issue?
Yes, the dma address for ring allocated as page can't fit the requirement.
Quoted 2 lines
Figuring out we have this problematic config and then allocating just the ring from coherent memory seems more palatable.
Agree, I'm also wondering why can't we force alloc 44bit-pfn page to fit the requirement? I mean if there are such pages, we should use them firstly as dma address for legacy devices, and only fail when there are no such pages at all, but can't find existing API to alloc page with such requirement... anyway.
Quoted 4 lines
But please note we still need to detect config with a virtual iommu (can be any kind not just virtio-iommu, smmu, vtd are all affected) and disable the hacks. This is what the new DMA API I suggested would do.
Fair enough, any more details about the design of new API?
Regards,
Michael Wang
Quoted 63 lines
Quoted 63 lines
Quoted 63 lines
Quoted 63 lines
Quoted 63 lines
Quoted 63 lines
--- drivers/virtio/virtio_pci_legacy.c | 10 ++++++++++ drivers/virtio/virtio_ring.c | 3 +++ include/linux/virtio.h | 1 + 3 files changed, 14 insertions(+)drivers/virtio/virtio_pci_legacy.c +10
-0@@ -263,6 +263,16 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev) vp_dev->setup_vq = setup_vq; vp_dev->del_vq = del_vq; +/* +* The legacy pci device requre 32bit-pfn vq, +* or setup_vq() will failed. +* +* Thus we make sure vring_use_dma_api() will +* return true during the allocation by marking +* force_dma here. +*/ + vp_dev->vdev.force_dma = true; +return 0 ;
err_iomap:drivers/virtio/virtio_ring.c +3
-0@@ -245,6 +245,9 @@ static inline bool virtqueue_use_indirect(struct virtqueue *_vq, static bool vring_use_dma_api(struct virtio_device *vdev) { + if (vdev->force_dma) + return true; +if (!virtio_has_dma_quirk (vdev))return true;include/linux/virtio.h +1
-0@@ -109,6 +109,7 @@ struct virtio_device {bool failed;bool config_enabled;bool config_change_pending; +bool force_dma;spinlock_t config_lock;spinlock_t vqs_list_lock;/* Protects VQs list access */ struct device dev;Signature · 1 line
1.8.3.1
Michael S. Tsirkin
maintainerQuoted 43 lines · 王贇
在 2021/12/9 上午8:19, Michael S. Tsirkin 写道:
[snip]Quoted 22 lines
Quoted 22 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Hi, Michael
Thanks for the comment, unfortunately modify device is not an option for us :-(
Quoted 6 lines
Quoted 4 lines
Is there any idea on how to solve this issue properly?
Regards,
Michael WangBy the way, there is a bug in the error message. Want to fix that?
Could you please provide more detail about the bug? We'd like to help fixing it :-)
Besides, I've checked that patch but it can't address our issue, we actually have this legacy pci device on arm platform, and the memory layout is unfriendly since allocation rarely providing page-address below 44bit, we understand the virtio-iommu case should not do force dma, while we don't have that so it's just working fine.
Quoted 4 lines
Quoted 2 lines
Regards,
Michael WangBTW is it just the ring that's at issue?
Yes, the dma address for ring allocated as page can't fit the requirement.
Quoted 2 lines
Figuring out we have this problematic config and then allocating just the ring from coherent memory seems more palatable.
Agree, I'm also wondering why can't we force alloc 44bit-pfn page to fit the requirement? I mean if there are such pages, we should use them firstly as dma address for legacy devices, and only fail when there are no such pages at all, but can't find existing API to alloc page with such requirement... anyway.
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
But please note we still need to detect config with a virtual iommu (can be any kind not just virtio-iommu, smmu, vtd are all affected) and disable the hacks. This is what the new DMA API I suggested would do.
Fair enough, any more details about the design of new API?
Regards,
Michael Wang
The idea was that on some systems any DMA address is also a physical address (as in the case of e.g. bounce buffers) and then it can be used without VIRTIO_F_ACCESS_PLATFORM.
Quoted 64 lines
Quoted 64 lines
Quoted 64 lines
Quoted 64 lines
Quoted 64 lines
Quoted 64 lines
Quoted 64 lines
--- drivers/virtio/virtio_pci_legacy.c | 10 ++++++++++ drivers/virtio/virtio_ring.c | 3 +++ include/linux/virtio.h | 1 + 3 files changed, 14 insertions(+)drivers/virtio/virtio_pci_legacy.c +10
-0@@ -263,6 +263,16 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev) vp_dev->setup_vq = setup_vq; vp_dev->del_vq = del_vq; +/* +* The legacy pci device requre 32bit-pfn vq, +* or setup_vq() will failed. +* +* Thus we make sure vring_use_dma_api() will +* return true during the allocation by marking +* force_dma here. +*/ + vp_dev->vdev.force_dma = true; +return 0 ;
err_iomap:drivers/virtio/virtio_ring.c +3
-0@@ -245,6 +245,9 @@ static inline bool virtqueue_use_indirect(struct virtqueue *_vq, static bool vring_use_dma_api(struct virtio_device *vdev) { + if (vdev->force_dma) + return true; +if (!virtio_has_dma_quirk (vdev))return true;include/linux/virtio.h +1
-0@@ -109,6 +109,7 @@ struct virtio_device {bool failed;bool config_enabled;bool config_change_pending; +bool force_dma;spinlock_t config_lock;spinlock_t vqs_list_lock;/* Protects VQs list access */ struct device dev;Signature · 1 line
1.8.3.1