Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

virtio: replace arch_has_restricted_virtio_memory_access()

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.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Tested-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com> # Arm64 only
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Borislav Petkov <bp@suse.de>

+14 -38
-1
arch/s390/Kconfig
··· 768 768 config PROTECTED_VIRTUALIZATION_GUEST 769 769 def_bool n 770 770 prompt "Protected virtualization guest support" 771 - select ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS 772 771 help 773 772 Select this option, if you want to be able to run this 774 773 kernel as a protected virtualization KVM guest.
+3 -10
arch/s390/mm/init.c
··· 31 31 #include <linux/cma.h> 32 32 #include <linux/gfp.h> 33 33 #include <linux/dma-direct.h> 34 + #include <linux/platform-feature.h> 34 35 #include <asm/processor.h> 35 36 #include <linux/uaccess.h> 36 37 #include <asm/pgalloc.h> ··· 169 168 return is_prot_virt_guest(); 170 169 } 171 170 172 - #ifdef CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS 173 - 174 - int arch_has_restricted_virtio_memory_access(void) 175 - { 176 - return is_prot_virt_guest(); 177 - } 178 - EXPORT_SYMBOL(arch_has_restricted_virtio_memory_access); 179 - 180 - #endif 181 - 182 171 /* protected virtualization */ 183 172 static void pv_init(void) 184 173 { 185 174 if (!is_prot_virt_guest()) 186 175 return; 176 + 177 + platform_set(PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS); 187 178 188 179 /* make sure bounce buffers are shared */ 189 180 swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
-1
arch/x86/Kconfig
··· 1542 1542 config X86_MEM_ENCRYPT 1543 1543 select ARCH_HAS_FORCE_DMA_UNENCRYPTED 1544 1544 select DYNAMIC_PHYSICAL_MASK 1545 - select ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS 1546 1545 def_bool n 1547 1546 1548 1547 config AMD_MEM_ENCRYPT
-7
arch/x86/mm/mem_encrypt.c
··· 12 12 #include <linux/swiotlb.h> 13 13 #include <linux/cc_platform.h> 14 14 #include <linux/mem_encrypt.h> 15 - #include <linux/virtio_config.h> 16 15 17 16 /* Override for DMA direct allocation check - ARCH_HAS_FORCE_DMA_UNENCRYPTED */ 18 17 bool force_dma_unencrypted(struct device *dev) ··· 86 87 87 88 print_mem_encrypt_feature_info(); 88 89 } 89 - 90 - int arch_has_restricted_virtio_memory_access(void) 91 - { 92 - return cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT); 93 - } 94 - EXPORT_SYMBOL_GPL(arch_has_restricted_virtio_memory_access);
+4
arch/x86/mm/mem_encrypt_amd.c
··· 21 21 #include <linux/dma-mapping.h> 22 22 #include <linux/virtio_config.h> 23 23 #include <linux/cc_platform.h> 24 + #include <linux/platform-feature.h> 24 25 25 26 #include <asm/tlbflush.h> 26 27 #include <asm/fixmap.h> ··· 243 242 size = total_mem * 6 / 100; 244 243 size = clamp_val(size, IO_TLB_DEFAULT_SIZE, SZ_1G); 245 244 swiotlb_adjust_size(size); 245 + 246 + /* Set restricted memory access for virtio. */ 247 + platform_set(PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS); 246 248 } 247 249 248 250 static unsigned long pg_level_to_pfn(int level, pte_t *kpte, pgprot_t *ret_prot)
-6
drivers/virtio/Kconfig
··· 6 6 bus, such as CONFIG_VIRTIO_PCI, CONFIG_VIRTIO_MMIO, CONFIG_RPMSG 7 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 9 config VIRTIO_PCI_LIB 16 10 tristate 17 11 help
+2 -3
drivers/virtio/virtio.c
··· 5 5 #include <linux/module.h> 6 6 #include <linux/idr.h> 7 7 #include <linux/of.h> 8 + #include <linux/platform-feature.h> 8 9 #include <uapi/linux/virtio_ids.h> 9 10 10 11 /* Unique numbering for virtio devices. */ ··· 171 170 static int virtio_features_ok(struct virtio_device *dev) 172 171 { 173 172 unsigned int status; 174 - int ret; 175 173 176 174 might_sleep(); 177 175 178 - ret = arch_has_restricted_virtio_memory_access(); 179 - if (ret) { 176 + if (platform_has(PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS)) { 180 177 if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) { 181 178 dev_warn(&dev->dev, 182 179 "device must provide VIRTIO_F_VERSION_1\n");
+5 -1
include/linux/platform-feature.h
··· 6 6 #include <asm/platform-feature.h> 7 7 8 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 15 void platform_set(unsigned int feature); 12 16 void platform_clear(unsigned int feature);
-9
include/linux/virtio_config.h
··· 604 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 607 #endif /* _LINUX_VIRTIO_CONFIG_H */