Skip to contentSkip to conversation

s390: virtio: let arch validate VIRTIO features

PATCH Superseded Pierre Morel 5 participants 14 messages Jul 7, 2020

Subsystems (4)

v4 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v4 cover s390: virtio: let arch validate VIRTIO features

Hi all,

I changed the patch subject to reflect the content, becoming more general.

1) I removed the ack from Christian and Jason even far as
I understand they gave it for the functionality more than for the implementation.
@Jason, @Christian, please can I get back your acked-by with these changes?

2) previous patch had another name:
[PATCH v3 0/1] s390: virtio: let arch choose to accept devices without IOMMU feature
id: Message-Id: <[email protected]>

3) The new version generalize the validation of the features by the architecture, making it not IOMMU_PLATFORM specific anymore inside virtio.c

The architecture specific code for s390 is now testing the virtio features.

4) Since I reworked the patch I also moved the arch specific code from arch/s390/mm/init.c to arch/s390/kernel/to uv.c

5) Finaly, I splitted the patch into generic virtio and arch specific code.

Regards,
Pierre

Pierre Morel (2):
virtio: let arch validate VIRTIO features
s390: virtio: PV needs VIRTIO I/O device protection

 arch/s390/kernel/uv.c         | 25 +++++++++++++++++++++++++
 drivers/virtio/virtio.c       | 19 +++++++++++++++++++
 include/linux/virtio_config.h |  1 +
 3 files changed, 45 insertions(+)
Signature · 39 lines
2.25.1

Changelog

to v4:

- separate virtio and arch code
  (Pierre)

- moved code from arch/s390/mm/init.c to arch/s390/kernel/uv.c
  (Heiko)

- moved validation inside the arch code
  (Connie)

- moved the call to arch validation before VIRTIO_F_1 test
  (Michael)

to v3:

- add warning
  (Connie, Christian)

- add comment
  (Connie)

- change hook name
  (Halil, Connie)

to v2:

- put the test in virtio_finalize_features()
  (Connie)

- put the test inside VIRTIO core
  (Jason)

- pass a virtio device as parameter
  (Halil)
#1 lore raw

PATCH v4 1/2 virtio: let arch validate VIRTIO features

An architecture may need to validate the VIRTIO devices features based on architecture specificities.

---
 drivers/virtio/virtio.c       | 19 +++++++++++++++++++
 include/linux/virtio_config.h |  1 +
 2 files changed, 20 insertions(+)
drivers/virtio/virtio.c +19 -0
index a977e32a88f2..3179a8aa76f5 100644
@@ -167,6 +167,21 @@ void virtio_add_status(struct virtio_device *dev, unsigned int status)
 }
 EXPORT_SYMBOL_GPL(virtio_add_status);
 
+/*
+ * arch_needs_virtio_iommu_platform - provide arch specific hook when finalizing
+ *				      features for VIRTIO device dev
+ * @dev: the VIRTIO device being added
+ *
+ * Permits the platform to provide architecture specific functionality when
+ * devices features are finalized. This is the default implementation.
+ * Architecture implementations can override this.
+ */
+
+int __weak arch_validate_virtio_features(struct virtio_device *dev)
+{
+	return 0;
+}
+
 int virtio_finalize_features(struct virtio_device *dev)
 {
 	int ret = dev->config->finalize_features(dev);
@@ -176,6 +191,10 @@ int virtio_finalize_features(struct virtio_device *dev)
 	if (ret)
 		return ret;
 
+	ret = arch_validate_virtio_features(dev);
+	if (ret)
+		return ret;
+
 	if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1))
 		return 0;
 
include/linux/virtio_config.h +1 -0
index bb4cc4910750..3f4117adf311 100644
@@ -459,4 +459,5 @@ static inline void virtio_cwrite64(struct virtio_device *vdev,
 		_r;							\
 	})
 
+int arch_validate_virtio_features(struct virtio_device *dev);
 #endif /* _LINUX_VIRTIO_CONFIG_H */
Signature · 1 line
2.25.1
#6 lore raw

PATCH v4 2/2 s390: virtio: PV needs VIRTIO I/O device protection

In reply to Pierre Morel

S390, protecting the guest memory against unauthorized host access needs to enforce VIRTIO I/O device protection through the use of VIRTIO_F_VERSION_1 and VIRTIO_F_IOMMU_PLATFORM.

---
 arch/s390/kernel/uv.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
arch/s390/kernel/uv.c +25 -0
index c296e5c8dbf9..106330f6eda1 100644
@@ -14,6 +14,7 @@
 #include <linux/memblock.h>
 #include <linux/pagemap.h>
 #include <linux/swap.h>
+#include <linux/virtio_config.h>
 #include <asm/facility.h>
 #include <asm/sections.h>
 #include <asm/uv.h>
@@ -413,3 +414,27 @@ static int __init uv_info_init(void)
 }
 device_initcall(uv_info_init);
 #endif
+
+/*
+ * arch_validate_virtio_iommu_platform
+ * @dev: the VIRTIO device being added
+ *
+ * Return value: returns -ENODEV if any features of the
+ *               device breaks the protected virtualization
+ *               0 otherwise.
+ */
+int arch_validate_virtio_features(struct virtio_device *dev)
+{
+	if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
+		dev_warn(&dev->dev, "device must provide VIRTIO_F_VERSION_1\n");
+		return is_prot_virt_guest() ? -ENODEV : 0;
+	}
+
+	if (!virtio_has_feature(dev, VIRTIO_F_IOMMU_PLATFORM)) {
+		dev_warn(&dev->dev,
+			 "device must provide VIRTIO_F_IOMMU_PLATFORM\n");
+		return is_prot_virt_guest() ? -ENODEV : 0;
+	}
+
+	return 0;
+}
Signature · 1 line
2.25.1
Reviewed-by on v4 1/2
#2 lore raw

Re: [PATCH v4 1/2] virtio: let arch validate VIRTIO features

In reply to Pierre Morel
Quoted 2 lines · On Tue, 7 Jul 2020 10:44:36 +0200 Pierre Morel <[email protected]> wrote:

An architecture may need to validate the VIRTIO devices features based on architecture specificities.

s/specifities/specifics/

Quoted 12 lines
---
 drivers/virtio/virtio.c       | 19 +++++++++++++++++++
 include/linux/virtio_config.h |  1 +
 2 files changed, 20 insertions(+)
drivers/virtio/virtio.c +0 -0
index a977e32a88f2..3179a8aa76f5 100644

drivers/virtio/virtio.c void virtio_add_status(struct virtio_device *dev, unsigned int status) · line 171

Quoted 5 lines
drivers/virtio/virtio.c +2 -0
@@ -167,6 +167,21 @@ void virtio_add_status(struct virtio_device *dev, unsigned int status)
 }
 EXPORT_SYMBOL_GPL(virtio_add_status);
 
+/*
+ * arch_needs_virtio_iommu_platform - provide arch specific hook when finalizing

s/arch_needs_virtio_iommu_platform/arch_validate_virtio_features/

:)

drivers/virtio/virtio.c void virtio_add_status(struct virtio_device *dev, unsigned int status) · line 175

Quoted 4 lines
drivers/virtio/virtio.c +4 -0
+ *				      features for VIRTIO device dev
+ * @dev: the VIRTIO device being added
+ *
+ * Permits the platform to provide architecture specific functionality when

s/provide architecture specific functionality/handle architecture-specific requirements/

?

drivers/virtio/virtio.c void virtio_add_status(struct virtio_device *dev, unsigned int status) · line 176

Quoted 1 line
drivers/virtio/virtio.c +1 -0
+ * devices features are finalized. This is the default implementation.

s/devices/device/

Quoted 27 lines
drivers/virtio/virtio.c +12 -0
+ * Architecture implementations can override this.
+ */
+
+int __weak arch_validate_virtio_features(struct virtio_device *dev)
+{
+	return 0;
+}
+
 int virtio_finalize_features(struct virtio_device *dev)
 {
 	int ret = dev->config->finalize_features(dev);
@@ -176,6 +191,10 @@ int virtio_finalize_features(struct virtio_device *dev)
 	if (ret)
 		return ret;
 
+	ret = arch_validate_virtio_features(dev);
+	if (ret)
+		return ret;
+
 	if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1))
 		return 0;
 
include/linux/virtio_config.h +0 -0
index bb4cc4910750..3f4117adf311 100644

include/linux/virtio_config.h static inline void virtio_cwrite64(struct virtio_device *vdev, · line 463

Quoted 5 lines
include/linux/virtio_config.h +1 -0
@@ -459,4 +459,5 @@ static inline void virtio_cwrite64(struct virtio_device *vdev,
 		_r;							\
 	})
 
+int arch_validate_virtio_features(struct virtio_device *dev);
 #endif /* _LINUX_VIRTIO_CONFIG_H */

With the wording fixed,

#7 lore raw

Re: [PATCH v4 2/2] s390: virtio: PV needs VIRTIO I/O device protection

In reply to Pierre Morel
Quoted 3 lines · On Tue, 7 Jul 2020 10:44:37 +0200 Pierre Morel <[email protected]> wrote:

S390, protecting the guest memory against unauthorized host access needs to enforce VIRTIO I/O device protection through the use of VIRTIO_F_VERSION_1 and VIRTIO_F_IOMMU_PLATFORM.

Hm... what about:

"If protected virtualization is active on s390, the virtio queues are not accessible to the host, unless VIRTIO_F_IOMMU_PLATFORM has been negotiated. Use the new arch_validate_virtio_features() interface to enforce this."

Quoted 19 lines
---
 arch/s390/kernel/uv.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
arch/s390/kernel/uv.c +1 -0
index c296e5c8dbf9..106330f6eda1 100644
@@ -14,6 +14,7 @@
 #include <linux/memblock.h>
 #include <linux/pagemap.h>
 #include <linux/swap.h>
+#include <linux/virtio_config.h>
 #include <asm/facility.h>
 #include <asm/sections.h>
 #include <asm/uv.h>

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 419

Quoted 6 lines
arch/s390/kernel/uv.c +3 -0
@@ -413,3 +414,27 @@ static int __init uv_info_init(void)
 }
 device_initcall(uv_info_init);
 #endif
+
+/*
+ * arch_validate_virtio_iommu_platform

s/arch_validate_virtio_iommu_platform/arch_validate_virtio_features/

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 424

Quoted 5 lines
arch/s390/kernel/uv.c +5 -0
+ * @dev: the VIRTIO device being added
+ *
+ * Return value: returns -ENODEV if any features of the
+ *               device breaks the protected virtualization
+ *               0 otherwise.

I don't think you need to specify the contract here: that belongs to the definition in the virtio core. What about simply adding a sentence "Return an error if required features are missing on a guest running with protected virtualization." ?

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 427

Quoted 3 lines
arch/s390/kernel/uv.c +3 -0
+ */
+int arch_validate_virtio_features(struct virtio_device *dev)
+{

Maybe jump out immediately if the guest is not protected?

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 437

Quoted 10 lines
arch/s390/kernel/uv.c +10 -0
+	if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
+		dev_warn(&dev->dev, "device must provide VIRTIO_F_VERSION_1\n");
+		return is_prot_virt_guest() ? -ENODEV : 0;
+	}
+
+	if (!virtio_has_feature(dev, VIRTIO_F_IOMMU_PLATFORM)) {
+		dev_warn(&dev->dev,
+			 "device must provide VIRTIO_F_IOMMU_PLATFORM\n");
+		return is_prot_virt_guest() ? -ENODEV : 0;
+	}

if (!is_prot_virt_guest())

	return 0;
if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
	dev_warn(&dev->dev,
                 "legacy virtio is incompatible with protected guests");
	return -ENODEV;
}
if (!virtio_has_feature(dev, VIRTIO_F_IOMMU_PLATFORM)) {
	dev_warn(&dev->dev,
		 "device does not work with limited memory access in protected guests");
	return -ENODEV;
}
Quoted 3 lines
arch/s390/kernel/uv.c +3 -0
+
+	return 0;
+}
#8 lore raw

Re: [PATCH v4 2/2] s390: virtio: PV needs VIRTIO I/O device protection

Quoted 7 lines · Cornelia Huck
Quoted 3 lines · On Tue, 7 Jul 2020 10:44:37 +0200 Pierre Morel <[email protected]> wrote:

S390, protecting the guest memory against unauthorized host access needs to enforce VIRTIO I/O device protection through the use of VIRTIO_F_VERSION_1 and VIRTIO_F_IOMMU_PLATFORM.

Quoted 6 lines

Hm... what about:

"If protected virtualization is active on s390, the virtio queues are not accessible to the host, unless VIRTIO_F_IOMMU_PLATFORM has been negotiated. Use the new arch_validate_virtio_features() interface to enforce this."

Yes, thanks.

Quoted 35 lines
Quoted 20 lines
---
  arch/s390/kernel/uv.c | 25 +++++++++++++++++++++++++
  1 file changed, 25 insertions(+)
arch/s390/kernel/uv.c +1 -0
index c296e5c8dbf9..106330f6eda1 100644
@@ -14,6 +14,7 @@
  #include <linux/memblock.h>
  #include <linux/pagemap.h>
  #include <linux/swap.h>
+#include <linux/virtio_config.h>
  #include <asm/facility.h>
  #include <asm/sections.h>
  #include <asm/uv.h>

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 419

Quoted 6 lines
arch/s390/kernel/uv.c +3 -0
@@ -413,3 +414,27 @@ static int __init uv_info_init(void)
  }
  device_initcall(uv_info_init);
  #endif
+
+/*
+ * arch_validate_virtio_iommu_platform

s/arch_validate_virtio_iommu_platform/arch_validate_virtio_features/

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 424

Quoted 5 lines
arch/s390/kernel/uv.c +5 -0
+ * @dev: the VIRTIO device being added
+ *
+ * Return value: returns -ENODEV if any features of the
+ *               device breaks the protected virtualization
+ *               0 otherwise.
Quoted 4 lines

I don't think you need to specify the contract here: that belongs to the definition in the virtio core. What about simply adding a sentence "Return an error if required features are missing on a guest running with protected virtualization." ?

OK, right.

Quoted 27 lines

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 427

Quoted 4 lines
arch/s390/kernel/uv.c +3 -0
+ */
+int arch_validate_virtio_features(struct virtio_device *dev)
+{

Maybe jump out immediately if the guest is not protected?

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 437

Quoted 10 lines
arch/s390/kernel/uv.c +10 -0
+	if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
+		dev_warn(&dev->dev, "device must provide VIRTIO_F_VERSION_1\n");
+		return is_prot_virt_guest() ? -ENODEV : 0;
+	}
+
+	if (!virtio_has_feature(dev, VIRTIO_F_IOMMU_PLATFORM)) {
+		dev_warn(&dev->dev,
+			 "device must provide VIRTIO_F_IOMMU_PLATFORM\n");
+		return is_prot_virt_guest() ? -ENODEV : 0;
+	}

if (!is_prot_virt_guest())

	return 0;
if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
	dev_warn(&dev->dev,
                  "legacy virtio is incompatible with protected guests");
	return -ENODEV;
}
Quoted 5 lines
if (!virtio_has_feature(dev, VIRTIO_F_IOMMU_PLATFORM)) {
	dev_warn(&dev->dev,
		 "device does not work with limited memory access in protected guests");
	return -ENODEV;
}

Yes, easier to read.

Thanks,
Pierre

Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
#3 lore raw

Re: [PATCH v4 1/2] virtio: let arch validate VIRTIO features

In reply to Cornelia Huck
Quoted 7 lines · Cornelia Huck
Quoted 2 lines · On Tue, 7 Jul 2020 10:44:36 +0200 Pierre Morel <[email protected]> wrote:

An architecture may need to validate the VIRTIO devices features based on architecture specificities.

s/specifities/specifics/

OK

Quoted 16 lines
Quoted 16 lines
---
  drivers/virtio/virtio.c       | 19 +++++++++++++++++++
  include/linux/virtio_config.h |  1 +
  2 files changed, 20 insertions(+)
drivers/virtio/virtio.c +0 -0
index a977e32a88f2..3179a8aa76f5 100644
@@ -167,6 +167,21 @@ void virtio_add_status(struct virtio_device *dev, unsigned int status)
  }
  EXPORT_SYMBOL_GPL(virtio_add_status);
 
Quoted 6 lines

drivers/virtio/virtio.c void virtio_add_status(struct virtio_device *dev, unsigned int status) · line 171

Quoted 2 lines
drivers/virtio/virtio.c +2 -0
+/*
+ * arch_needs_virtio_iommu_platform - provide arch specific hook when finalizing

s/arch_needs_virtio_iommu_platform/arch_validate_virtio_features/

:)

grrr... yes.

Quoted 9 lines

drivers/virtio/virtio.c void virtio_add_status(struct virtio_device *dev, unsigned int status) · line 175

Quoted 5 lines
drivers/virtio/virtio.c +4 -0
+ *				      features for VIRTIO device dev
+ * @dev: the VIRTIO device being added
+ *
+ * Permits the platform to provide architecture specific functionality when

s/provide architecture specific functionality/handle architecture-specific requirements/

?

better, thanks.

Quoted 4 lines

drivers/virtio/virtio.c void virtio_add_status(struct virtio_device *dev, unsigned int status) · line 176

Quoted 2 lines
drivers/virtio/virtio.c +1 -0
+ * devices features are finalized. This is the default implementation.

s/devices/device/

yes.

Quoted 31 lines
Quoted 31 lines
drivers/virtio/virtio.c +12 -0
+ * Architecture implementations can override this.
+ */
+
+int __weak arch_validate_virtio_features(struct virtio_device *dev)
+{
+	return 0;
+}
+
  int virtio_finalize_features(struct virtio_device *dev)
  {
  	int ret = dev->config->finalize_features(dev);
@@ -176,6 +191,10 @@ int virtio_finalize_features(struct virtio_device *dev)
  	if (ret)
  		return ret;
 
+	ret = arch_validate_virtio_features(dev);
+	if (ret)
+		return ret;
+
  	if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1))
  		return 0;
 
include/linux/virtio_config.h +0 -0
index bb4cc4910750..3f4117adf311 100644
@@ -459,4 +459,5 @@ static inline void virtio_cwrite64(struct virtio_device *vdev,
  		_r;							\
  	})
 
Quoted 7 lines

include/linux/virtio_config.h static inline void virtio_cwrite64(struct virtio_device *vdev, · line 463

Quoted 2 lines
include/linux/virtio_config.h +1 -0
+int arch_validate_virtio_features(struct virtio_device *dev);
  #endif /* _LINUX_VIRTIO_CONFIG_H */

With the wording fixed,

Thanks for the review.

regards,
Pierre

Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
#4 lore raw

Re: [PATCH v4 1/2] virtio: let arch validate VIRTIO features

In reply to Cornelia Huck
Quoted 23 lines · Cornelia Huck
Quoted 2 lines · On Tue, 7 Jul 2020 10:44:36 +0200 Pierre Morel <[email protected]> wrote:

An architecture may need to validate the VIRTIO devices features based on architecture specificities.

s/specifities/specifics/

Quoted 15 lines
---
 drivers/virtio/virtio.c       | 19 +++++++++++++++++++
 include/linux/virtio_config.h |  1 +
 2 files changed, 20 insertions(+)
drivers/virtio/virtio.c +0 -0
index a977e32a88f2..3179a8aa76f5 100644
@@ -167,6 +167,21 @@ void virtio_add_status(struct virtio_device *dev, unsigned int status)
 }
 EXPORT_SYMBOL_GPL(virtio_add_status);
 
Quoted 4 lines

drivers/virtio/virtio.c void virtio_add_status(struct virtio_device *dev, unsigned int status) · line 171

Quoted 2 lines
drivers/virtio/virtio.c +2 -0
+/*
+ * arch_needs_virtio_iommu_platform - provide arch specific hook when finalizing

s/arch_needs_virtio_iommu_platform/arch_validate_virtio_features/

With the things from Conny fixed,

#12 lore raw

Re: [PATCH v4 2/2] s390: virtio: PV needs VIRTIO I/O device protection

In reply to Pierre Morel
Quoted 28 lines · Pierre Morel

S390, protecting the guest memory against unauthorized host access needs to enforce VIRTIO I/O device protection through the use of VIRTIO_F_VERSION_1 and VIRTIO_F_IOMMU_PLATFORM.

---
 arch/s390/kernel/uv.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
arch/s390/kernel/uv.c +4 -0
index c296e5c8dbf9..106330f6eda1 100644
@@ -14,6 +14,7 @@
 #include <linux/memblock.h>
 #include <linux/pagemap.h>
 #include <linux/swap.h>
+#include <linux/virtio_config.h>
 #include <asm/facility.h>
 #include <asm/sections.h>
 #include <asm/uv.h>
@@ -413,3 +414,27 @@ static int __init uv_info_init(void)
 }
 device_initcall(uv_info_init);
 #endif
+
+/*
+ * arch_validate_virtio_iommu_platform

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 429

Quoted 10 lines
arch/s390/kernel/uv.c +10 -0
+ * @dev: the VIRTIO device being added
+ *
+ * Return value: returns -ENODEV if any features of the
+ *               device breaks the protected virtualization
+ *               0 otherwise.
+ */
+int arch_validate_virtio_features(struct virtio_device *dev)
+{
+	if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
+		dev_warn(&dev->dev, "device must provide VIRTIO_F_VERSION_1\n");

I think you only want to warn if is_prot_virt_guest is true? We certainly want to be able to run as a guest of older hypervisors with virtio 0.95, no?

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 435

Quoted 6 lines
arch/s390/kernel/uv.c +6 -0
+		return is_prot_virt_guest() ? -ENODEV : 0;
+	}
+
+	if (!virtio_has_feature(dev, VIRTIO_F_IOMMU_PLATFORM)) {
+		dev_warn(&dev->dev,
+			 "device must provide VIRTIO_F_IOMMU_PLATFORM\n");

same here.

Quoted 6 lines
arch/s390/kernel/uv.c +5 -0
+		return is_prot_virt_guest() ? -ENODEV : 0;
+	}
+
+	return 0;
+}
#10 lore raw

Re: [PATCH v4 2/2] s390: virtio: PV needs VIRTIO I/O device protection

In reply to Cornelia Huck
Quoted 7 lines · Cornelia Huck
Quoted 3 lines · On Tue, 7 Jul 2020 10:44:37 +0200 Pierre Morel <[email protected]> wrote:

S390, protecting the guest memory against unauthorized host access needs to enforce VIRTIO I/O device protection through the use of VIRTIO_F_VERSION_1 and VIRTIO_F_IOMMU_PLATFORM.

Quoted 6 lines

Hm... what about:

"If protected virtualization is active on s390, the virtio queues are not accessible to the host, unless VIRTIO_F_IOMMU_PLATFORM has been negotiated. Use the new arch_validate_virtio_features() interface to enforce this."

s/enforce this/fail probe if that's not the case, preventing a host error on access attempt/

Quoted 74 lines
Quoted 19 lines
---
 arch/s390/kernel/uv.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
arch/s390/kernel/uv.c +1 -0
index c296e5c8dbf9..106330f6eda1 100644
@@ -14,6 +14,7 @@
 #include <linux/memblock.h>
 #include <linux/pagemap.h>
 #include <linux/swap.h>
+#include <linux/virtio_config.h>
 #include <asm/facility.h>
 #include <asm/sections.h>
 #include <asm/uv.h>

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 419

Quoted 6 lines
arch/s390/kernel/uv.c +3 -0
@@ -413,3 +414,27 @@ static int __init uv_info_init(void)
 }
 device_initcall(uv_info_init);
 #endif
+
+/*
+ * arch_validate_virtio_iommu_platform

s/arch_validate_virtio_iommu_platform/arch_validate_virtio_features/

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 424

Quoted 5 lines
arch/s390/kernel/uv.c +5 -0
+ * @dev: the VIRTIO device being added
+ *
+ * Return value: returns -ENODEV if any features of the
+ *               device breaks the protected virtualization
+ *               0 otherwise.

I don't think you need to specify the contract here: that belongs to the definition in the virtio core. What about simply adding a sentence "Return an error if required features are missing on a guest running with protected virtualization." ?

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 427

Quoted 3 lines
arch/s390/kernel/uv.c +3 -0
+ */
+int arch_validate_virtio_features(struct virtio_device *dev)
+{

Maybe jump out immediately if the guest is not protected?

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 437

Quoted 10 lines
arch/s390/kernel/uv.c +10 -0
+	if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
+		dev_warn(&dev->dev, "device must provide VIRTIO_F_VERSION_1\n");
+		return is_prot_virt_guest() ? -ENODEV : 0;
+	}
+
+	if (!virtio_has_feature(dev, VIRTIO_F_IOMMU_PLATFORM)) {
+		dev_warn(&dev->dev,
+			 "device must provide VIRTIO_F_IOMMU_PLATFORM\n");
+		return is_prot_virt_guest() ? -ENODEV : 0;
+	}

if (!is_prot_virt_guest())

	return 0;
if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
	dev_warn(&dev->dev,
                 "legacy virtio is incompatible with protected guests");
	return -ENODEV;
}
if (!virtio_has_feature(dev, VIRTIO_F_IOMMU_PLATFORM)) {
	dev_warn(&dev->dev,
		 "device does not work with limited memory access in protected guests");
	return -ENODEV;
}
Quoted 3 lines
arch/s390/kernel/uv.c +3 -0
+
+	return 0;
+}
#13 lore raw

Re: [PATCH v4 2/2] s390: virtio: PV needs VIRTIO I/O device protection

In reply to Christian Borntraeger
Quoted 36 lines · Christian Borntraeger
Quoted 33 lines · Pierre Morel

S390, protecting the guest memory against unauthorized host access needs to enforce VIRTIO I/O device protection through the use of VIRTIO_F_VERSION_1 and VIRTIO_F_IOMMU_PLATFORM.

---
  arch/s390/kernel/uv.c | 25 +++++++++++++++++++++++++
  1 file changed, 25 insertions(+)
arch/s390/kernel/uv.c +9 -0
index c296e5c8dbf9..106330f6eda1 100644
@@ -14,6 +14,7 @@
  #include <linux/memblock.h>
  #include <linux/pagemap.h>
  #include <linux/swap.h>
+#include <linux/virtio_config.h>
  #include <asm/facility.h>
  #include <asm/sections.h>
  #include <asm/uv.h>
@@ -413,3 +414,27 @@ static int __init uv_info_init(void)
  }
  device_initcall(uv_info_init);
  #endif
+
+/*
+ * arch_validate_virtio_iommu_platform
+ * @dev: the VIRTIO device being added
+ *
+ * Return value: returns -ENODEV if any features of the
+ *               device breaks the protected virtualization
+ *               0 otherwise.
Quoted 8 lines

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 429

Quoted 5 lines
arch/s390/kernel/uv.c +5 -0
+ */
+int arch_validate_virtio_features(struct virtio_device *dev)
+{
+	if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
+		dev_warn(&dev->dev, "device must provide VIRTIO_F_VERSION_1\n");

I think you only want to warn if is_prot_virt_guest is true? We certainly want to be able to run as a guest of older hypervisors with virtio 0.95, no?

clear, yes.
I will first check for PV as Connie sugested.

Quoted 10 lines

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 435

Quoted 8 lines
arch/s390/kernel/uv.c +6 -0
+		return is_prot_virt_guest() ? -ENODEV : 0;
+	}
+
+	if (!virtio_has_feature(dev, VIRTIO_F_IOMMU_PLATFORM)) {
+		dev_warn(&dev->dev,
+			 "device must provide VIRTIO_F_IOMMU_PLATFORM\n");

same here.

Yes,
Thanks,

Pierre

Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
#5 lore raw

Re: [PATCH v4 1/2] virtio: let arch validate VIRTIO features

In reply to Christian Borntraeger
Quoted 10 lines · Christian Borntraeger
Quoted 7 lines · Cornelia Huck
Quoted 2 lines · On Tue, 7 Jul 2020 10:44:36 +0200 Pierre Morel <[email protected]> wrote:

An architecture may need to validate the VIRTIO devices features based on architecture specificities.

s/specifities/specifics/

yes

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
---
  drivers/virtio/virtio.c       | 19 +++++++++++++++++++
  include/linux/virtio_config.h |  1 +
  2 files changed, 20 insertions(+)
drivers/virtio/virtio.c +0 -0
index a977e32a88f2..3179a8aa76f5 100644
@@ -167,6 +167,21 @@ void virtio_add_status(struct virtio_device *dev, unsigned int status)
  }
  EXPORT_SYMBOL_GPL(virtio_add_status);
 
Quoted 9 lines
Quoted 4 lines

drivers/virtio/virtio.c void virtio_add_status(struct virtio_device *dev, unsigned int status) · line 171

Quoted 2 lines
drivers/virtio/virtio.c +2 -0
+/*
+ * arch_needs_virtio_iommu_platform - provide arch specific hook when finalizing

s/arch_needs_virtio_iommu_platform/arch_validate_virtio_features/

With the things from Conny fixed,

Thanks,
Pierre

Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
#9 lore raw

Re: [PATCH v4 2/2] s390: virtio: PV needs VIRTIO I/O device protection

In reply to Pierre Morel
Quoted 10 lines · On Tue, 7 Jul 2020 12:38:17 +0200 Pierre Morel <[email protected]> wrote:
Quoted 7 lines · Cornelia Huck
Quoted 3 lines · On Tue, 7 Jul 2020 10:44:37 +0200 Pierre Morel <[email protected]> wrote:

S390, protecting the guest memory against unauthorized host access needs to enforce VIRTIO I/O device protection through the use of VIRTIO_F_VERSION_1 and VIRTIO_F_IOMMU_PLATFORM.

Quoted 15 lines
Quoted 6 lines

Hm... what about:

"If protected virtualization is active on s390, the virtio queues are not accessible to the host, unless VIRTIO_F_IOMMU_PLATFORM has been negotiated. Use the new arch_validate_virtio_features() interface to enforce this."

Yes, thanks.

Quoted 5 lines
Quoted 5 lines
---
  arch/s390/kernel/uv.c | 25 +++++++++++++++++++++++++

Is this the right place to put this stuff? This file seems to be about implementing the interface for interacting with the ultravisor. I would rather expect something like arch/s390/kernel/virtio.c

Should we ever get arch hooks for balloon those could go in arch/s390/kernel/virtio.c as well.

Quoted 64 lines
Quoted 30 lines
Quoted 15 lines
  1 file changed, 25 insertions(+)
arch/s390/kernel/uv.c +1 -0
index c296e5c8dbf9..106330f6eda1 100644
@@ -14,6 +14,7 @@
  #include <linux/memblock.h>
  #include <linux/pagemap.h>
  #include <linux/swap.h>
+#include <linux/virtio_config.h>
  #include <asm/facility.h>
  #include <asm/sections.h>
  #include <asm/uv.h>

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 419

Quoted 6 lines
arch/s390/kernel/uv.c +3 -0
@@ -413,3 +414,27 @@ static int __init uv_info_init(void)
  }
  device_initcall(uv_info_init);
  #endif
+
+/*
+ * arch_validate_virtio_iommu_platform

s/arch_validate_virtio_iommu_platform/arch_validate_virtio_features/

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 424

Quoted 5 lines
arch/s390/kernel/uv.c +5 -0
+ * @dev: the VIRTIO device being added
+ *
+ * Return value: returns -ENODEV if any features of the
+ *               device breaks the protected virtualization
+ *               0 otherwise.
Quoted 4 lines

I don't think you need to specify the contract here: that belongs to the definition in the virtio core. What about simply adding a sentence "Return an error if required features are missing on a guest running with protected virtualization." ?

OK, right.

Quoted 27 lines

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 427

Quoted 4 lines
arch/s390/kernel/uv.c +3 -0
+ */
+int arch_validate_virtio_features(struct virtio_device *dev)
+{

Maybe jump out immediately if the guest is not protected?

arch/s390/kernel/uv.c static int __init uv_info_init(void) · line 437

Quoted 10 lines
arch/s390/kernel/uv.c +10 -0
+	if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
+		dev_warn(&dev->dev, "device must provide VIRTIO_F_VERSION_1\n");
+		return is_prot_virt_guest() ? -ENODEV : 0;
+	}
+
+	if (!virtio_has_feature(dev, VIRTIO_F_IOMMU_PLATFORM)) {
+		dev_warn(&dev->dev,
+			 "device must provide VIRTIO_F_IOMMU_PLATFORM\n");
+		return is_prot_virt_guest() ? -ENODEV : 0;
+	}

if (!is_prot_virt_guest())

	return 0;
if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
	dev_warn(&dev->dev,
                  "legacy virtio is incompatible with protected guests");
	return -ENODEV;
}
Quoted 8 lines
Quoted 5 lines
if (!virtio_has_feature(dev, VIRTIO_F_IOMMU_PLATFORM)) {
	dev_warn(&dev->dev,
		 "device does not work with limited memory access in protected guests");
	return -ENODEV;
}

Yes, easier to read.

Not only easier to read but does not produce warnings
if !is_prot_virt_guest(). I strongly prefer the variant proposed by Connie.

Otherwise LGTM.

Regards,
Halil

#11 lore raw

Re: [PATCH v4 2/2] s390: virtio: PV needs VIRTIO I/O device protection

In reply to Michael S. Tsirkin
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Cornelia Huck
Quoted 3 lines · On Tue, 7 Jul 2020 10:44:37 +0200 Pierre Morel <[email protected]> wrote:

S390, protecting the guest memory against unauthorized host access needs to enforce VIRTIO I/O device protection through the use of VIRTIO_F_VERSION_1 and VIRTIO_F_IOMMU_PLATFORM.

Quoted 9 lines
Quoted 6 lines

Hm... what about:

"If protected virtualization is active on s390, the virtio queues are not accessible to the host, unless VIRTIO_F_IOMMU_PLATFORM has been negotiated. Use the new arch_validate_virtio_features() interface to enforce this."

s/enforce this/fail probe if that's not the case, preventing a host error on access attempt/

yes, more complete, thanks.

regards,
Pierre

Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen