Instead of using arch_has_restricted_virtio_memory_access() together with CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS, replace those with platform_has() and a new platform feature PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS.
Unified · Split
| @@ -768,7 +768,6 @@ menu "Virtualization" · 767 unmodified lines | |||
| 768 | config PROTECTED_VIRTUALIZATION_GUEST | 768 | config PROTECTED_VIRTUALIZATION_GUEST |
| 769 | def_bool n | 769 | def_bool n |
| 770 | prompt "Protected virtualization guest support" | 770 | prompt "Protected virtualization guest support" |
| 771 | select ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS | ||
| 772 | help | 771 | help |
| 773 | Select this option, if you want to be able to run this | 772 | Select this option, if you want to be able to run this |
| 774 | kernel as a protected virtualization KVM guest. | 773 | kernel as a protected virtualization KVM guest. |
| @@ -31,6 +31,7 @@ · 30 unmodified lines | |||
| 31 | #include <linux/cma.h> | 31 | #include <linux/cma.h> |
| 32 | #include <linux/gfp.h> | 32 | #include <linux/gfp.h> |
| 33 | #include <linux/dma-direct.h> | 33 | #include <linux/dma-direct.h> |
| 34 | #include <linux/platform-feature.h> | ||
| 34 | #include <asm/processor.h> | 35 | #include <asm/processor.h> |
| 35 | #include <linux/uaccess.h> | 36 | #include <linux/uaccess.h> |
| 36 | #include <asm/pgalloc.h> | 37 | #include <asm/pgalloc.h> |
| @@ -168,22 +169,14 @@ bool force_dma_unencrypted(struct device *dev) · 131 unmodified lines | |||
| 168 | return is_prot_virt_guest(); | 169 | return is_prot_virt_guest(); |
| 169 | } | 170 | } |
| 170 | 171 | ||
| 171 | #ifdef CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS | ||
| 172 | |||
| 173 | int arch_has_restricted_virtio_memory_access(void) | ||
| 174 | { | ||
| 175 | return is_prot_virt_guest(); | ||
| 176 | } | ||
| 177 | EXPORT_SYMBOL(arch_has_restricted_virtio_memory_access); | ||
| 178 | |||
| 179 | #endif | ||
| 180 | |||
| 181 | /* protected virtualization */ | 172 | /* protected virtualization */ |
| 182 | static void pv_init(void) | 173 | static void pv_init(void) |
| 183 | { | 174 | { |
| 184 | if (!is_prot_virt_guest()) | 175 | if (!is_prot_virt_guest()) |
| 185 | return; | 176 | return; |
| 186 | 177 | ||
| 178 | platform_set(PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS); | ||
| 179 | |||
| 187 | /* make sure bounce buffers are shared */ | 180 | /* make sure bounce buffers are shared */ |
| 188 | swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE); | 181 | swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE); |
| 189 | swiotlb_update_mem_attributes(); | 182 | swiotlb_update_mem_attributes(); |
| @@ -1542,7 +1542,6 @@ config X86_CPA_STATISTICS · 1541 unmodified lines | |||
| 1542 | config X86_MEM_ENCRYPT | 1542 | config X86_MEM_ENCRYPT |
| 1543 | select ARCH_HAS_FORCE_DMA_UNENCRYPTED | 1543 | select ARCH_HAS_FORCE_DMA_UNENCRYPTED |
| 1544 | select DYNAMIC_PHYSICAL_MASK | 1544 | select DYNAMIC_PHYSICAL_MASK |
| 1545 | select ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS | ||
| 1546 | def_bool n | 1545 | def_bool n |
| 1547 | 1546 | ||
| 1548 | config AMD_MEM_ENCRYPT | 1547 | config AMD_MEM_ENCRYPT |
| @@ -12,7 +12,6 @@ · 11 unmodified lines | |||
| 12 | #include <linux/swiotlb.h> | 12 | #include <linux/swiotlb.h> |
| 13 | #include <linux/cc_platform.h> | 13 | #include <linux/cc_platform.h> |
| 14 | #include <linux/mem_encrypt.h> | 14 | #include <linux/mem_encrypt.h> |
| 15 | #include <linux/virtio_config.h> | ||
| 16 | 15 | ||
| 17 | /* Override for DMA direct allocation check - ARCH_HAS_FORCE_DMA_UNENCRYPTED */ | 16 | /* Override for DMA direct allocation check - ARCH_HAS_FORCE_DMA_UNENCRYPTED */ |
| 18 | bool force_dma_unencrypted(struct device *dev) | 17 | bool force_dma_unencrypted(struct device *dev) |
| @@ -87,9 +86,3 @@ void __init mem_encrypt_init(void) · 68 unmodified lines | |||
| 87 | 86 | ||
| 88 | print_mem_encrypt_feature_info(); | 87 | print_mem_encrypt_feature_info(); |
| 89 | } | 88 | } |
| 90 | |||
| 91 | int arch_has_restricted_virtio_memory_access(void) | ||
| 92 | { | ||
| 93 | return cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT); | ||
| 94 | } | ||
| 95 | EXPORT_SYMBOL_GPL(arch_has_restricted_virtio_memory_access); | ||
| @@ -21,6 +21,7 @@ · 20 unmodified lines | |||
| 21 | #include <linux/dma-mapping.h> | 21 | #include <linux/dma-mapping.h> |
| 22 | #include <linux/virtio_config.h> | 22 | #include <linux/virtio_config.h> |
| 23 | #include <linux/cc_platform.h> | 23 | #include <linux/cc_platform.h> |
| 24 | #include <linux/platform-feature.h> | ||
| 24 | 25 | ||
| 25 | #include <asm/tlbflush.h> | 26 | #include <asm/tlbflush.h> |
| 26 | #include <asm/fixmap.h> | 27 | #include <asm/fixmap.h> |
| @@ -242,6 +243,9 @@ void __init sev_setup_arch(void) · 215 unmodified lines | |||
| 242 | size = total_mem * 6 / 100; | 243 | size = total_mem * 6 / 100; |
| 243 | size = clamp_val(size, IO_TLB_DEFAULT_SIZE, SZ_1G); | 244 | size = clamp_val(size, IO_TLB_DEFAULT_SIZE, SZ_1G); |
| 244 | swiotlb_adjust_size(size); | 245 | swiotlb_adjust_size(size); |
| 246 | |||
| 247 | /* Set restricted memory access for virtio. */ | ||
| 248 | platform_set(PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS); | ||
| 245 | } | 249 | } |
| 246 | 250 | ||
| 247 | static unsigned long pg_level_to_pfn(int level, pte_t *kpte, pgprot_t *ret_prot) | 251 | static unsigned long pg_level_to_pfn(int level, pte_t *kpte, pgprot_t *ret_prot) |
| @@ -6,12 +6,6 @@ config VIRTIO · 5 unmodified lines | |||
| 6 | bus, such as CONFIG_VIRTIO_PCI, CONFIG_VIRTIO_MMIO, CONFIG_RPMSG | 6 | bus, such as CONFIG_VIRTIO_PCI, CONFIG_VIRTIO_MMIO, CONFIG_RPMSG |
| 7 | or CONFIG_S390_GUEST. | 7 | or CONFIG_S390_GUEST. |
| 8 | 8 | ||
| 9 | config ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS | ||
| 10 | bool | ||
| 11 | help | ||
| 12 | This option is selected if the architecture may need to enforce | ||
| 13 | VIRTIO_F_ACCESS_PLATFORM | ||
| 14 | |||
| 15 | config VIRTIO_PCI_LIB | 9 | config VIRTIO_PCI_LIB |
| 16 | tristate | 10 | tristate |
| 17 | help | 11 | help |
| @@ -5,6 +5,7 @@ · 4 unmodified lines | |||
| 5 | #include <linux/module.h> | 5 | #include <linux/module.h> |
| 6 | #include <linux/idr.h> | 6 | #include <linux/idr.h> |
| 7 | #include <linux/of.h> | 7 | #include <linux/of.h> |
| 8 | #include <linux/platform-feature.h> | ||
| 8 | #include <uapi/linux/virtio_ids.h> | 9 | #include <uapi/linux/virtio_ids.h> |
| 9 | 10 | ||
| 10 | /* Unique numbering for virtio devices. */ | 11 | /* Unique numbering for virtio devices. */ |
| @@ -170,12 +171,10 @@ EXPORT_SYMBOL_GPL(virtio_add_status); · 159 unmodified lines | |||
| 170 | static int virtio_features_ok(struct virtio_device *dev) | 171 | static int virtio_features_ok(struct virtio_device *dev) |
| 171 | { | 172 | { |
| 172 | unsigned int status; | 173 | unsigned int status; |
| 173 | int ret; | ||
| 174 | 174 | ||
| 175 | might_sleep(); | 175 | might_sleep(); |
| 176 | 176 | ||
| 177 | ret = arch_has_restricted_virtio_memory_access(); | 177 | if (platform_has(PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS)) { |
| 178 | if (ret) { | ||
| 179 | if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) { | 178 | if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) { |
| 180 | dev_warn(&dev->dev, | 179 | dev_warn(&dev->dev, |
| 181 | "device must provide VIRTIO_F_VERSION_1\n"); | 180 | "device must provide VIRTIO_F_VERSION_1\n"); |
| @@ -6,7 +6,11 @@ · 5 unmodified lines | |||
| 6 | #include <asm/platform-feature.h> | 6 | #include <asm/platform-feature.h> |
| 7 | 7 | ||
| 8 | /* The platform features are starting with the architecture specific ones. */ | 8 | /* The platform features are starting with the architecture specific ones. */ |
| 9 | #define PLATFORM_FEAT_N (0 + PLATFORM_ARCH_FEAT_N) | 9 | |
| 10 | /* Used to enable platform specific DMA handling for virtio devices. */ | ||
| 11 | #define PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS (0 + PLATFORM_ARCH_FEAT_N) | ||
| 12 | |||
| 13 | #define PLATFORM_FEAT_N (1 + PLATFORM_ARCH_FEAT_N) | ||
| 10 | 14 | ||
| 11 | void platform_set(unsigned int feature); | 15 | void platform_set(unsigned int feature); |
| 12 | void platform_clear(unsigned int feature); | 16 | void platform_clear(unsigned int feature); |
| @@ -604,13 +604,4 @@ static inline void virtio_cwrite64(struct virtio_device *vdev, · 603 unmodified lines | |||
| 604 | _r; \ | 604 | _r; \ |
| 605 | }) | 605 | }) |
| 606 | 606 | ||
| 607 | #ifdef CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS | ||
| 608 | int arch_has_restricted_virtio_memory_access(void); | ||
| 609 | #else | ||
| 610 | static inline int arch_has_restricted_virtio_memory_access(void) | ||
| 611 | { | ||
| 612 | return 0; | ||
| 613 | } | ||
| 614 | #endif /* CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS */ | ||
| 615 | |||
| 616 | #endif /* _LINUX_VIRTIO_CONFIG_H */ | 607 | #endif /* _LINUX_VIRTIO_CONFIG_H */ |