s390: virtio: let arch validate VIRTIO features
Subsystems (4)
v5 cover s390: virtio: let arch validate VIRTIO features
Hi all,
The goal of the series is to give a chance to the architecture to validate VIRTIO device features.
in this respin:
1) I kept removed the ack from Jason as I reworked the patch @Jason, the nature and goal of the patch did not really changed please can I get back your acked-by with these changes?
2) I suppressed the unnecessary verbosity of the architecture specific patch
3) put back the arch specific code inside arch/s390/mm/init.c after offline discussion with Christian.
Regards,
Pierre
Pierre Morel (2):
virtio: let arch validate VIRTIO features
s390: virtio: PV needs VIRTIO I/O device protection
arch/s390/mm/init.c | 27 +++++++++++++++++++++++++++ drivers/virtio/virtio.c | 19 +++++++++++++++++++ include/linux/virtio_config.h | 1 + 3 files changed, 47 insertions(+)
Signature · 51 lines
2.25.1 Changelog to v5: - return directly from S390 arch_validate_virtio_features() when the guest is not protected. (Connie) - Somme rewording (Connie, Michael) - moved back code from arch/s390/ ...kernel/uv.c to ...mm/init.c (Christian) to v4: - separate virtio and arch code (Pierre) - moved code from arch/s390/mm/init.c to arch/s390/kernel/uv.c (as interpreted from Heiko's comment) - 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)
PATCH v5 1/2 virtio: let arch validate VIRTIO features
An architecture may need to validate the VIRTIO devices features based on architecture specifics.
--- drivers/virtio/virtio.c | 19 +++++++++++++++++++ include/linux/virtio_config.h | 1 + 2 files changed, 20 insertions(+)
drivers/virtio/virtio.c +19 -0
@@ -167,6 +167,21 @@ void virtio_add_status(struct virtio_device *dev, unsigned int status) }EXPORT_SYMBOL_GPL (virtio_add_status); +/* +* arch_validate_virtio_features - provide arch specific hook when finalizing +* features for VIRTIO device dev +* @dev: the VIRTIO device being added +* +* Permits the platform to handle architecture-specific requirements when +* device 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
@@ -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
Re: [PATCH v5 1/2] virtio: let arch validate VIRTIO features
Quoted 6 lines · On Thu, 9 Jul 2020 10:39:18 +0200 Pierre Morel <[email protected]> wrote:
An architecture may need to validate the VIRTIO devices features based on architecture specifics.
Signed-off-by Pierre Morel <[email protected]>Reviewed-by Cornelia Huck <[email protected]>
Quoted 52 lines
--- drivers/virtio/virtio.c | 19 +++++++++++++++++++ include/linux/virtio_config.h | 1 + 2 files changed, 20 insertions(+)drivers/virtio/virtio.c +19
-0@@ -167,6 +167,21 @@ void virtio_add_status(struct virtio_device *dev, unsigned int status) }EXPORT_SYMBOL_GPL (virtio_add_status); +/* +* arch_validate_virtio_features - provide arch specific hook when finalizing +* features for VIRTIO device dev +* @dev: the VIRTIO device being added +* +* Permits the platform to handle architecture-specific requirements when +* device 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@@ -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 */
Re: [PATCH v5 1/2] virtio: let arch validate VIRTIO features
Quoted 11 lines · Halil Pasic
Quoted 6 lines · On Thu, 9 Jul 2020 10:39:18 +0200 Pierre Morel <[email protected]> wrote:
An architecture may need to validate the VIRTIO devices features based on architecture specifics.
Signed-off-by Pierre Morel <[email protected]>Reviewed-by Cornelia Huck <[email protected]>Acked-by Halil Pasic <[email protected]>
Thanks,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
PATCH v5 2/2 s390: virtio: PV needs VIRTIO I/O device protection
In reply to Pierre MorelIf 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 fail probe if that's not the case, preventing a host error on access attempt
--- arch/s390/mm/init.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
arch/s390/mm/init.c +27 -0
@@ -45,6 +45,7 @@#include <asm/kasan.h> #include <asm/dma-mapping.h> #include <asm/uv.h> +#include <linux/virtio_config.h> pgd_t swapper_pg_dir[PTRS_PER_PGD] __section(.bss..swapper_pg_dir);
@@ -161,6 +162,32 @@ bool force_dma_unencrypted(struct device *dev)return is_prot_virt_guest (); } +/* +* arch_validate_virtio_features +* @dev: the VIRTIO device being added +* +* Return an error if required features are missing on a guest running +* with protected virtualization. +*/ +int arch_validate_virtio_features (struct virtio_device *dev) +{ +if (!is_prot_virt_guest ()) +return 0 ; + +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_IOMMU_PLATFORM )) { +dev_warn (&dev->dev, +"device must provide VIRTIO_F_IOMMU_PLATFORM\n" ); +return -ENODEV ; + } + +return 0 ; +} +/* protected virtualization */ static void pv_init (void ) {
Signature · 1 line
2.25.1
Re: [PATCH v5 2/2] s390: virtio: PV needs VIRTIO I/O device protection
Quoted 31 lines · On Thu, 9 Jul 2020 10:39:19 +0200 Pierre Morel <[email protected]> wrote:
If protected virtualization is active on s390, the virtio queues are not accessible to the host, unless
VIRTIO_F_IOMMU_PLATFORMhas been negotiated. Use the newarch_validate_virtio_features()interface to fail probe if that's not the case, preventing a host error on access attemptSigned-off-by Pierre Morel <[email protected]>--- arch/s390/mm/init.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)arch/s390/mm/init.c +5
-0@@ -45,6 +45,7 @@#include <asm/kasan.h> #include <asm/dma-mapping.h> #include <asm/uv.h> +#include <linux/virtio_config.h> pgd_t swapper_pg_dir[PTRS_PER_PGD] __section(.bss..swapper_pg_dir);@@ -161,6 +162,32 @@ bool force_dma_unencrypted(struct device *dev)return is_prot_virt_guest (); } +/* +* arch_validate_virtio_features +* @dev: the VIRTIO device being added +*
arch/s390/mm/init.c bool force_dma_unencrypted(struct device *dev) · line 178
Quoted 10 lines
arch/s390/mm/init.c +10
-0+* Return an error if required features are missing on a guest running +* with protected virtualization. +*/ +int arch_validate_virtio_features (struct virtio_device *dev) +{ +if (!is_prot_virt_guest ()) +return 0 ; + +if (!virtio_has_feature (dev,VIRTIO_F_VERSION_1 )) { +dev_warn (&dev->dev,"device must provide VIRTIO_F_VERSION_1\n" );
I'd probably use "legacy virtio not supported with protected virtualization".
arch/s390/mm/init.c bool force_dma_unencrypted(struct device *dev) · line 184
Quoted 6 lines
arch/s390/mm/init.c +6
-0+return -ENODEV ; + } + +if (!virtio_has_feature (dev,VIRTIO_F_IOMMU_PLATFORM )) { +dev_warn (&dev->dev, +"device must provide VIRTIO_F_IOMMU_PLATFORM\n" );
"support for limited memory access required for protected virtualization"
?
Mentioning the feature flag is shorter in both cases, though.
arch/s390/mm/init.c bool force_dma_unencrypted(struct device *dev) · line 193
Quoted 9 lines
arch/s390/mm/init.c +6
-0+return -ENODEV ; + } + +return 0 ; +} +/* protected virtualization */ static void pv_init (void ) {
Either way,
Halil Pasic
Acked-byRe: [PATCH v5 2/2] s390: virtio: PV needs VIRTIO I/O device protection
Quoted 8 lines · On Thu, 9 Jul 2020 10:57:33 +0200 Cornelia Huck <[email protected]> wrote:
Quoted 5 lines · On Thu, 9 Jul 2020 10:39:19 +0200 Pierre Morel <[email protected]> wrote:
If protected virtualization is active on s390, the virtio queues are not accessible to the host, unless
VIRTIO_F_IOMMU_PLATFORMhas been negotiated. Use the newarch_validate_virtio_features()interface to fail probe if that's not the case, preventing a host error on access attempt
Punctuation at the end?
Also 'that's not the case' refers to the negation 'VIRTIO_F_IOMMU_PLATFORM has been negotiated', arch_validate_virtio_features() is however part of virtio_finalize_features(), which is in turn part of the feature negotiation. But that is details. I'm fine with keeping the message as is.
Quoted 50 lines
Quoted 26 lines
Signed-off-by Pierre Morel <[email protected]>--- arch/s390/mm/init.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)arch/s390/mm/init.c +5
-0@@ -45,6 +45,7 @@#include <asm/kasan.h> #include <asm/dma-mapping.h> #include <asm/uv.h> +#include <linux/virtio_config.h> pgd_t swapper_pg_dir[PTRS_PER_PGD] __section(.bss..swapper_pg_dir);@@ -161,6 +162,32 @@ bool force_dma_unencrypted(struct device *dev)return is_prot_virt_guest (); } +/* +* arch_validate_virtio_features +* @dev: the VIRTIO device being added +* arch/s390/mm/init.c bool force_dma_unencrypted(struct device *dev) · line 178
Quoted 10 lines
arch/s390/mm/init.c +10
-0+* Return an error if required features are missing on a guest running +* with protected virtualization. +*/ +int arch_validate_virtio_features (struct virtio_device *dev) +{ +if (!is_prot_virt_guest ()) +return 0 ; + +if (!virtio_has_feature (dev,VIRTIO_F_VERSION_1 )) { +dev_warn (&dev->dev,"device must provide VIRTIO_F_VERSION_1\n" );I'd probably use "legacy virtio not supported with protected virtualization".
arch/s390/mm/init.c bool force_dma_unencrypted(struct device *dev) · line 184
Quoted 6 lines
arch/s390/mm/init.c +6
-0+return -ENODEV ; + } + +if (!virtio_has_feature (dev,VIRTIO_F_IOMMU_PLATFORM )) { +dev_warn (&dev->dev, +"device must provide VIRTIO_F_IOMMU_PLATFORM\n" );"support for limited memory access required for protected virtualization"
Quoted 3 lines
?
Mentioning the feature flag is shorter in both cases, though.
I liked the messages in v4. Why did we change those? Did somebody complain?
I prefer the old ones, but it any case:
Quoted 15 lines
arch/s390/mm/init.c bool force_dma_unencrypted(struct device *dev) · line 193
Quoted 10 lines
arch/s390/mm/init.c +6
-0+return -ENODEV ; + } + +return 0 ; +} +/* protected virtualization */ static void pv_init (void ) {Either way,
Reviewed-by Cornelia Huck <[email protected]>
Re: [PATCH v5 2/2] s390: virtio: PV needs VIRTIO I/O device protection
Quoted 73 lines · Halil Pasic
Quoted 8 lines · On Thu, 9 Jul 2020 10:57:33 +0200 Cornelia Huck <[email protected]> wrote:
Quoted 5 lines · On Thu, 9 Jul 2020 10:39:19 +0200 Pierre Morel <[email protected]> wrote:
If protected virtualization is active on s390, the virtio queues are not accessible to the host, unless
VIRTIO_F_IOMMU_PLATFORMhas been negotiated. Use the newarch_validate_virtio_features()interface to fail probe if that's not the case, preventing a host error on access attemptPunctuation at the end?
Also 'that's not the case' refers to the negation '
VIRTIO_F_IOMMU_PLATFORMhas been negotiated',arch_validate_virtio_features()is however part ofvirtio_finalize_features(), which is in turn part of the feature negotiation. But that is details. I'm fine with keeping the message as is.Quoted 52 lines
Quoted 26 lines
Signed-off-by Pierre Morel <[email protected]>--- arch/s390/mm/init.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)arch/s390/mm/init.c +5
-0@@ -45,6 +45,7 @@#include <asm/kasan.h> #include <asm/dma-mapping.h> #include <asm/uv.h> +#include <linux/virtio_config.h> pgd_t swapper_pg_dir[PTRS_PER_PGD] __section(.bss..swapper_pg_dir);@@ -161,6 +162,32 @@ bool force_dma_unencrypted(struct device *dev)return is_prot_virt_guest (); } +/* +* arch_validate_virtio_features +* @dev: the VIRTIO device being added +* arch/s390/mm/init.c bool force_dma_unencrypted(struct device *dev) · line 178
Quoted 10 lines
arch/s390/mm/init.c +10
-0+* Return an error if required features are missing on a guest running +* with protected virtualization. +*/ +int arch_validate_virtio_features (struct virtio_device *dev) +{ +if (!is_prot_virt_guest ()) +return 0 ; + +if (!virtio_has_feature (dev,VIRTIO_F_VERSION_1 )) { +dev_warn (&dev->dev,"device must provide VIRTIO_F_VERSION_1\n" );I'd probably use "legacy virtio not supported with protected virtualization".
arch/s390/mm/init.c bool force_dma_unencrypted(struct device *dev) · line 184
Quoted 6 lines
arch/s390/mm/init.c +6
-0+return -ENODEV ; + } + +if (!virtio_has_feature (dev,VIRTIO_F_IOMMU_PLATFORM )) { +dev_warn (&dev->dev, +"device must provide VIRTIO_F_IOMMU_PLATFORM\n" );"support for limited memory access required for protected virtualization"
?
Quoted 8 lines
Quoted 1 line
Mentioning the feature flag is shorter in both cases, though.
I liked the messages in v4. Why did we change those? Did somebody complain?
I prefer the old ones, but it any case:
Acked-by Halil Pasic <[email protected]>
Thanks,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v5 2/2] s390: virtio: PV needs VIRTIO I/O device protection
In reply to Cornelia HuckQuoted 58 lines · Cornelia Huck
Quoted 31 lines · On Thu, 9 Jul 2020 10:39:19 +0200 Pierre Morel <[email protected]> wrote:
If protected virtualization is active on s390, the virtio queues are not accessible to the host, unless
VIRTIO_F_IOMMU_PLATFORMhas been negotiated. Use the newarch_validate_virtio_features()interface to fail probe if that's not the case, preventing a host error on access attemptSigned-off-by Pierre Morel <[email protected]>--- arch/s390/mm/init.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)arch/s390/mm/init.c +5
-0@@ -45,6 +45,7 @@#include <asm/kasan.h> #include <asm/dma-mapping.h> #include <asm/uv.h> +#include <linux/virtio_config.h> pgd_t swapper_pg_dir[PTRS_PER_PGD] __section(.bss..swapper_pg_dir);@@ -161,6 +162,32 @@ bool force_dma_unencrypted(struct device *dev)return is_prot_virt_guest (); } +/* +* arch_validate_virtio_features +* @dev: the VIRTIO device being added +* arch/s390/mm/init.c bool force_dma_unencrypted(struct device *dev) · line 178
Quoted 10 lines
arch/s390/mm/init.c +10
-0+* Return an error if required features are missing on a guest running +* with protected virtualization. +*/ +int arch_validate_virtio_features (struct virtio_device *dev) +{ +if (!is_prot_virt_guest ()) +return 0 ; + +if (!virtio_has_feature (dev,VIRTIO_F_VERSION_1 )) { +dev_warn (&dev->dev,"device must provide VIRTIO_F_VERSION_1\n" );I'd probably use "legacy virtio not supported with protected virtualization".
arch/s390/mm/init.c bool force_dma_unencrypted(struct device *dev) · line 184
Quoted 6 lines
arch/s390/mm/init.c +6
-0+return -ENODEV ; + } + +if (!virtio_has_feature (dev,VIRTIO_F_IOMMU_PLATFORM )) { +dev_warn (&dev->dev, +"device must provide VIRTIO_F_IOMMU_PLATFORM\n" );"support for limited memory access required for protected virtualization"
Quoted 3 lines
?
Mentioning the feature flag is shorter in both cases, though.
And I think easier to look for in case of debugging purpose. I change it if there is more demands.
Quoted 13 lines
arch/s390/mm/init.c bool force_dma_unencrypted(struct device *dev) · line 193
Quoted 10 lines
arch/s390/mm/init.c +6
-0+return -ENODEV ; + } + +return 0 ; +} +/* protected virtualization */ static void pv_init (void ) {Either way,
Quoted 2 lines
Reviewed-by Cornelia Huck <[email protected]>
Thanks,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v5 2/2] s390: virtio: PV needs VIRTIO I/O device protection
Quoted 21 lines · On Thu, 9 Jul 2020 12:51:58 +0200 Pierre Morel <[email protected]> wrote:
Quoted 21 lines
arch/s390/mm/init.c bool force_dma_unencrypted(struct device *dev) · line 178
Quoted 7 lines
arch/s390/mm/init.c +7
-0+int arch_validate_virtio_features (struct virtio_device *dev) +{ +if (!is_prot_virt_guest ()) +return 0 ; + +if (!virtio_has_feature (dev,VIRTIO_F_VERSION_1 )) { +dev_warn (&dev->dev,"device must provide VIRTIO_F_VERSION_1\n" );I'd probably use "legacy virtio not supported with protected virtualization".
arch/s390/mm/init.c bool force_dma_unencrypted(struct device *dev) · line 184
Quoted 6 lines
arch/s390/mm/init.c +6
-0+return -ENODEV ; + } + +if (!virtio_has_feature (dev,VIRTIO_F_IOMMU_PLATFORM )) { +dev_warn (&dev->dev, +"device must provide VIRTIO_F_IOMMU_PLATFORM\n" );"support for limited memory access required for protected virtualization"
Quoted 6 lines
Quoted 3 lines
?
Mentioning the feature flag is shorter in both cases, though.
And I think easier to look for in case of debugging purpose. I change it if there is more demands.
Not all our end users are kernel and/or qemu developers. I find the messages from v4 less technical, more informative, and way better.
Regards,
Halil
Re: [PATCH v5 2/2] s390: virtio: PV needs VIRTIO I/O device protection
Quoted 28 lines · Halil Pasic
Quoted 25 lines · On Thu, 9 Jul 2020 12:51:58 +0200 Pierre Morel <[email protected]> wrote:
Quoted 24 lines
arch/s390/mm/init.c bool force_dma_unencrypted(struct device *dev) · line 178
Quoted 7 lines
arch/s390/mm/init.c +7
-0+int arch_validate_virtio_features (struct virtio_device *dev) +{ +if (!is_prot_virt_guest ()) +return 0 ; + +if (!virtio_has_feature (dev,VIRTIO_F_VERSION_1 )) { +dev_warn (&dev->dev,"device must provide VIRTIO_F_VERSION_1\n" );I'd probably use "legacy virtio not supported with protected virtualization".
arch/s390/mm/init.c bool force_dma_unencrypted(struct device *dev) · line 184
Quoted 6 lines
arch/s390/mm/init.c +6
-0+return -ENODEV ; + } + +if (!virtio_has_feature (dev,VIRTIO_F_IOMMU_PLATFORM )) { +dev_warn (&dev->dev, +"device must provide VIRTIO_F_IOMMU_PLATFORM\n" );"support for limited memory access required for protected virtualization"
?
Mentioning the feature flag is shorter in both cases, though.
Quoted 9 lines
Quoted 2 lines
And I think easier to look for in case of debugging purpose. I change it if there is more demands.
Not all our end users are kernel and/or qemu developers. I find the messages from v4 less technical, more informative, and way better.
Regards,
Halil
Can you please tell me the messages you are speaking of, because for me the warning's messages are exactly the same in v4 and v5!?
I checked many times, but may be I still missed something.
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v5 2/2] s390: virtio: PV needs VIRTIO I/O device protection
Quoted 37 lines · On Thu, 9 Jul 2020 16:51:04 +0200 Pierre Morel <[email protected]> wrote:
Quoted 34 lines · Halil Pasic
Quoted 21 lines · On Thu, 9 Jul 2020 12:51:58 +0200 Pierre Morel <[email protected]> wrote:
Quoted 21 lines
arch/s390/mm/init.c bool force_dma_unencrypted(struct device *dev) · line 178
Quoted 7 lines
arch/s390/mm/init.c +7
-0+int arch_validate_virtio_features (struct virtio_device *dev) +{ +if (!is_prot_virt_guest ()) +return 0 ; + +if (!virtio_has_feature (dev,VIRTIO_F_VERSION_1 )) { +dev_warn (&dev->dev,"device must provide VIRTIO_F_VERSION_1\n" );I'd probably use "legacy virtio not supported with protected virtualization".
arch/s390/mm/init.c bool force_dma_unencrypted(struct device *dev) · line 184
Quoted 6 lines
arch/s390/mm/init.c +6
-0+return -ENODEV ; + } + +if (!virtio_has_feature (dev,VIRTIO_F_IOMMU_PLATFORM )) { +dev_warn (&dev->dev, +"device must provide VIRTIO_F_IOMMU_PLATFORM\n" );"support for limited memory access required for protected virtualization"
Quoted 6 lines
Quoted 3 lines
?
Mentioning the feature flag is shorter in both cases, though.
And I think easier to look for in case of debugging purpose. I change it if there is more demands.
Not all our end users are kernel and/or qemu developers. I find the messages from v4 less technical, more informative, and way better.
Quoted 9 lines
Quoted 3 lines
Regards,
HalilCan you please tell me the messages you are speaking of, because for me the warning's messages are exactly the same in v4 and v5!?
I checked many times, but may be I still missed something.
Sorry, my bad. My brain is over-generating. The messages where discussed at v3 and Connie made a very similar proposal to the one above which I seconded (for reference look at Message-ID:
<[email protected]>). I was under the impression that it got implemented in v4, but it was not. That's why I ended up talking bs.
Regards,
Halil