public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Erdem Aktas <erdemaktas@google.com>
Cc: linux-kernel@vger.kernel.org,
	virtualization@lists.linux-foundation.org,
	Jason Wang <jasowang@redhat.com>
Subject: Re: [RFC] Add DMA_API support for Virtio devices earlier than VirtIO 1.0
Date: Thu, 28 Oct 2021 01:40:16 -0400	[thread overview]
Message-ID: <20211028013901-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20211027232828.2043569-1-erdemaktas@google.com>

On Wed, Oct 27, 2021 at 04:28:28PM -0700, Erdem Aktas wrote:
> Enable DMA_API for any VirtIO device earlier than Virtio 1.0 which
> is the only way for those devices to be configured correctly when
> memory access is retricted.
> 
> Virtio devices can use DMA_API to translate guest phsical addresses to
> device physical addresses if VIRTIO_F_ACCESS_PLATFORM feature is set
> while the device is being initialized. VIRTIO_F_ACCESS_PLATFORM
> feature is only supported in VirtIO 1.0 and later devices. This prevents
> any device using an earlier VirtIO version than Virtio 1.0 to be
> attached when memory access is restricted ie memory encryption features
> (AMD SEV [ES/SNP], Intel TDX, etc..) are enabled.
> 
> Signed-off-by: Erdem Aktas <erdemaktas@google.com>


Sorry .. NACK.

Virtio before 1.0 is on life support. No new features. Just use 1.0
please.


> ---
> I have tested the this patch using linux-stable.git head, 5.15.0-rc6
> kernel and scsi disk with virtio 0.95 version with legacy VM and
> Confidential VM (AMD SEV). I want to get feedback if
> there is any risk or downside of enabling DMA_API on older virtio
> drivers when memory encrytion is enabled.
> 
>  drivers/virtio/virtio.c       |  7 ++-----
>  include/linux/virtio_config.h | 22 ++++++++++++++--------
>  2 files changed, 16 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
> index 236081afe9a2..71115ba85d07 100644
> --- a/drivers/virtio/virtio.c
> +++ b/drivers/virtio/virtio.c
> @@ -179,11 +179,8 @@ int virtio_finalize_features(struct virtio_device *dev)
>  	if (ret) {
>  		if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
>  			dev_warn(&dev->dev,
> -				 "device must provide VIRTIO_F_VERSION_1\n");
> -			return -ENODEV;
> -		}
> -
> -		if (!virtio_has_feature(dev, VIRTIO_F_ACCESS_PLATFORM)) {
> +				 "device does not provide VIRTIO_F_VERSION_1 while restricted memory access is enabled!.\n");
> +		} else if (!virtio_has_feature(dev, VIRTIO_F_ACCESS_PLATFORM)) {
>  			dev_warn(&dev->dev,
>  				 "device must provide VIRTIO_F_ACCESS_PLATFORM\n");
>  			return -ENODEV;
> diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
> index 8519b3ae5d52..6eacb4d43318 100644
> --- a/include/linux/virtio_config.h
> +++ b/include/linux/virtio_config.h
> @@ -170,6 +170,15 @@ static inline bool virtio_has_feature(const struct virtio_device *vdev,
>  	return __virtio_test_bit(vdev, fbit);
>  }
>  
> +#ifdef CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
> +int arch_has_restricted_virtio_memory_access(void);
> +#else
> +static inline int arch_has_restricted_virtio_memory_access(void)
> +{
> +	return 0;
> +}
> +#endif /* CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS */
> +
>  /**
>   * virtio_has_dma_quirk - determine whether this device has the DMA quirk
>   * @vdev: the device
> @@ -180,6 +189,11 @@ static inline bool virtio_has_dma_quirk(const struct virtio_device *vdev)
>  	 * Note the reverse polarity of the quirk feature (compared to most
>  	 * other features), this is for compatibility with legacy systems.
>  	 */
> +	if (!virtio_has_feature(vdev, VIRTIO_F_VERSION_1) &&
> +	   arch_has_restricted_virtio_memory_access())
> +		return false;
> +
> +
>  	return !virtio_has_feature(vdev, VIRTIO_F_ACCESS_PLATFORM);
>  }
>  
> @@ -558,13 +572,5 @@ static inline void virtio_cwrite64(struct virtio_device *vdev,
>  		_r;							\
>  	})
>  
> -#ifdef CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
> -int arch_has_restricted_virtio_memory_access(void);
> -#else
> -static inline int arch_has_restricted_virtio_memory_access(void)
> -{
> -	return 0;
> -}
> -#endif /* CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS */
>  
>  #endif /* _LINUX_VIRTIO_CONFIG_H */
> -- 
> 2.30.2


      reply	other threads:[~2021-10-28  5:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-27 23:28 [RFC] Add DMA_API support for Virtio devices earlier than VirtIO 1.0 Erdem Aktas
2021-10-28  5:40 ` Michael S. Tsirkin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211028013901-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=erdemaktas@google.com \
    --cc=jasowang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox