From f8961012bbece17f4840a8691577ac53f9e12e8e Mon Sep 17 00:00:00 2001 From: gcc_2023 Date: Mon, 4 Mar 2024 14:43:09 +0800 Subject: [PATCH] anolis: virtio_ring: force use dma api when AMD SEV is actived Upstream: no ANBZ: #8424 The guest using virtio must use unencrypted memory for interacting with the virtio backend. Therefore, virtio_ring must use dma api to initialize vqs. Hygon-SIG: commit cd0806839d0e anolis anolis: virtio_ring: force use dma api when AMD SEV is actived Signed-off-by: gcc_2023 Reviewed-by: Kun(llfl) Acked-by: Zelin Deng Link: https://gitee.com/anolis/cloud-kernel/pulls/2811 [ hly: qualify the param as const in should_force_dma(). ] Signed-off-by: hanliyang --- drivers/virtio/virtio_ring.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index db4582687b95..51fcdb31e5fb 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -14,6 +14,7 @@ #include #include #include +#include #ifdef DEBUG /* For development, we want to crash whenever the ring is screwed. */ @@ -251,6 +252,13 @@ static bool virtqueue_use_indirect(const struct vring_virtqueue *vq, return (vq->indirect && total_sg > 1 && vq->vq.num_free); } +static inline bool should_force_dma(const struct virtio_device *dev) +{ + return (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT) && + (!virtio_has_feature(dev, VIRTIO_F_VERSION_1) || + !virtio_has_feature(dev, VIRTIO_F_ACCESS_PLATFORM))); +} + /* * Modern virtio devices have feature bits to specify whether they need a * quirk and bypass the IOMMU. If not there, just use the DMA API. @@ -294,6 +302,9 @@ static bool vring_use_dma_api(const struct virtio_device *vdev) if (xen_domain()) return true; + if (should_force_dma(vdev)) + return true; + return false; } -- Gitee