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 | 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. |
| @@ -31,6 +31,7 @@ · 30 unmodified lines | ||
| 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> |
| @@ -168,22 +169,14 @@ bool force_dma_unencrypted(struct device *dev) · 131 unmodified lines | ||
| 168 | 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 | 172 | /* protected virtualization */ |
| 182 | 173 | static void pv_init(void) |
| 183 | 174 | { |
| 184 | 175 | if (!is_prot_virt_guest()) |
| 185 | 176 | return; |
| 186 | 177 | |
| 178 | + platform_set(PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS); | |
| 179 | + | |
| 187 | 180 | /* make sure bounce buffers are shared */ |
| 188 | 181 | swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE); |
| 189 | 182 | swiotlb_update_mem_attributes(); |
| @@ -1542,7 +1542,6 @@ config X86_CPA_STATISTICS · 1541 unmodified lines | ||
| 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 |
| @@ -12,7 +12,6 @@ · 11 unmodified lines | ||
| 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) |
| @@ -87,9 +86,3 @@ void __init mem_encrypt_init(void) · 68 unmodified lines | ||
| 87 | 86 | |
| 88 | 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 | 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> |
| @@ -242,6 +243,9 @@ void __init sev_setup_arch(void) · 215 unmodified lines | ||
| 242 | 243 | size = total_mem * 6 / 100; |
| 243 | 244 | size = clamp_val(size, IO_TLB_DEFAULT_SIZE, SZ_1G); |
| 244 | 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 | 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 | 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 |
| @@ -5,6 +5,7 @@ · 4 unmodified lines | ||
| 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. */ |
| @@ -170,12 +171,10 @@ EXPORT_SYMBOL_GPL(virtio_add_status); · 159 unmodified lines | ||
| 170 | 171 | static int virtio_features_ok(struct virtio_device *dev) |
| 171 | 172 | { |
| 172 | 173 | unsigned int status; |
| 173 | − int ret; | |
| 174 | 174 | |
| 175 | 175 | might_sleep(); |
| 176 | 176 | |
| 177 | − ret = arch_has_restricted_virtio_memory_access(); | |
| 178 | − if (ret) { | |
| 177 | + if (platform_has(PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS)) { | |
| 179 | 178 | if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) { |
| 180 | 179 | dev_warn(&dev->dev, |
| 181 | 180 | "device must provide VIRTIO_F_VERSION_1\n"); |
| @@ -6,7 +6,11 @@ · 5 unmodified lines | ||
| 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); |
| @@ -604,13 +604,4 @@ static inline void virtio_cwrite64(struct virtio_device *vdev, · 603 unmodified lines | ||
| 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 */ |