History

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.

Juergen Gross committed 4 years ago

Commit 3f9dfbe1 parent 2130a799 files · +14 −38Browse files

Unified · Split

9 files
  1. arch/s390/Kconfig +0 −1
  2. arch/s390/mm/init.c +3 −10
  3. arch/x86/Kconfig +0 −1
  4. arch/x86/mm/mem_encrypt.c +0 −7
  5. arch/x86/mm/mem_encrypt_amd.c +4 −0
  6. drivers/virtio/Kconfig +0 −6
  7. drivers/virtio/virtio.c +2 −3
  8. include/linux/platform-feature.h +5 −1
  9. include/linux/virtio_config.h +0 −9
arch/s390/Kconfig+0−1
@@ -768,7 +768,6 @@ menu "Virtualization" · 767 unmodified lines
768768 config PROTECTED_VIRTUALIZATION_GUEST
769769 def_bool n
770770 prompt "Protected virtualization guest support"
771− select ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
772771 help
773772 Select this option, if you want to be able to run this
774773 kernel as a protected virtualization KVM guest.
arch/s390/mm/init.c+3−10
@@ -31,6 +31,7 @@ · 30 unmodified lines
3131 #include <linux/cma.h>
3232 #include <linux/gfp.h>
3333 #include <linux/dma-direct.h>
34+#include <linux/platform-feature.h>
3435 #include <asm/processor.h>
3536 #include <linux/uaccess.h>
3637 #include <asm/pgalloc.h>
@@ -168,22 +169,14 @@ bool force_dma_unencrypted(struct device *dev) · 131 unmodified lines
168169 return is_prot_virt_guest();
169170 }
170171
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−
181172 /* protected virtualization */
182173 static void pv_init(void)
183174 {
184175 if (!is_prot_virt_guest())
185176 return;
186177
178+ platform_set(PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS);
179+
187180 /* make sure bounce buffers are shared */
188181 swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
189182 swiotlb_update_mem_attributes();
arch/x86/Kconfig+0−1
@@ -1542,7 +1542,6 @@ config X86_CPA_STATISTICS · 1541 unmodified lines
15421542 config X86_MEM_ENCRYPT
15431543 select ARCH_HAS_FORCE_DMA_UNENCRYPTED
15441544 select DYNAMIC_PHYSICAL_MASK
1545− select ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
15461545 def_bool n
15471546
15481547 config AMD_MEM_ENCRYPT
arch/x86/mm/mem_encrypt.c+0−7
@@ -12,7 +12,6 @@ · 11 unmodified lines
1212 #include <linux/swiotlb.h>
1313 #include <linux/cc_platform.h>
1414 #include <linux/mem_encrypt.h>
15−#include <linux/virtio_config.h>
1615
1716 /* Override for DMA direct allocation check - ARCH_HAS_FORCE_DMA_UNENCRYPTED */
1817 bool force_dma_unencrypted(struct device *dev)
@@ -87,9 +86,3 @@ void __init mem_encrypt_init(void) · 68 unmodified lines
8786
8887 print_mem_encrypt_feature_info();
8988 }
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);
arch/x86/mm/mem_encrypt_amd.c+4−0
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121 #include <linux/dma-mapping.h>
2222 #include <linux/virtio_config.h>
2323 #include <linux/cc_platform.h>
24+#include <linux/platform-feature.h>
2425
2526 #include <asm/tlbflush.h>
2627 #include <asm/fixmap.h>
@@ -242,6 +243,9 @@ void __init sev_setup_arch(void) · 215 unmodified lines
242243 size = total_mem * 6 / 100;
243244 size = clamp_val(size, IO_TLB_DEFAULT_SIZE, SZ_1G);
244245 swiotlb_adjust_size(size);
246+
247+ /* Set restricted memory access for virtio. */
248+ platform_set(PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS);
245249 }
246250
247251 static unsigned long pg_level_to_pfn(int level, pte_t *kpte, pgprot_t *ret_prot)
drivers/virtio/Kconfig+0−6
@@ -6,12 +6,6 @@ config VIRTIO · 5 unmodified lines
66 bus, such as CONFIG_VIRTIO_PCI, CONFIG_VIRTIO_MMIO, CONFIG_RPMSG
77 or CONFIG_S390_GUEST.
88
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−
159 config VIRTIO_PCI_LIB
1610 tristate
1711 help
drivers/virtio/virtio.c+2−3
@@ -5,6 +5,7 @@ · 4 unmodified lines
55 #include <linux/module.h>
66 #include <linux/idr.h>
77 #include <linux/of.h>
8+#include <linux/platform-feature.h>
89 #include <uapi/linux/virtio_ids.h>
910
1011 /* Unique numbering for virtio devices. */
@@ -170,12 +171,10 @@ EXPORT_SYMBOL_GPL(virtio_add_status); · 159 unmodified lines
170171 static int virtio_features_ok(struct virtio_device *dev)
171172 {
172173 unsigned int status;
173− int ret;
174174
175175 might_sleep();
176176
177− ret = arch_has_restricted_virtio_memory_access();
178− if (ret) {
177+ if (platform_has(PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS)) {
179178 if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
180179 dev_warn(&dev->dev,
181180 "device must provide VIRTIO_F_VERSION_1\n");
include/linux/platform-feature.h+5−1
@@ -6,7 +6,11 @@ · 5 unmodified lines
66 #include <asm/platform-feature.h>
77
88 /* 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)
1014
1115 void platform_set(unsigned int feature);
1216 void platform_clear(unsigned int feature);
include/linux/virtio_config.h+0−9
@@ -604,13 +604,4 @@ static inline void virtio_cwrite64(struct virtio_device *vdev, · 603 unmodified lines
604604 _r; \
605605 })
606606
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−
616607 #endif /* _LINUX_VIRTIO_CONFIG_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t