From 266ad81e21b4809c8c43ca100f783f046ec8f2c1 Mon Sep 17 00:00:00 2001 From: gcc_2023 Date: Mon, 4 Mar 2024 14:43:09 +0800 Subject: [PATCH] virtio_ring: force use dma api when AMD SEV is actived anolis inclusion from anolis-devel-5.10 commit cd0806839d0e33589964fbcb652fed198f4f9cba category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/ID6HJJ CVE: NA Reference: https://gitee.com/anolis/cloud-kernel/commit/cd0806839d0e33589964fbcb652fed198f4f9cba -------------------------------- 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. Signed-off-by: gcc_2023 Reviewed-by: Kun(llfl) Acked-by: Zelin Deng Link: https://gitee.com/anolis/cloud-kernel/pulls/2811 Singed-off-by: Zhiguang Ni --- 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 5b905ba6fe6e..a0a61f90cfbf 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -12,6 +12,7 @@ #include #include #include +#include #ifdef DEBUG /* For development, we want to crash whenever the ring is screwed. */ @@ -214,6 +215,13 @@ static inline bool virtqueue_use_indirect(struct virtqueue *_vq, return (vq->indirect && total_sg > 1 && vq->vq.num_free); } +static inline bool should_force_dma(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. @@ -257,6 +265,9 @@ static bool vring_use_dma_api(struct virtio_device *vdev) if (xen_domain()) return true; + if (should_force_dma(vdev)) + return true; + return false; } -- Gitee