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
768config PROTECTED_VIRTUALIZATION_GUEST768config PROTECTED_VIRTUALIZATION_GUEST
769 def_bool n769 def_bool n
770 prompt "Protected virtualization guest support"770 prompt "Protected virtualization guest support"
771 select ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
772 help771 help
773 Select this option, if you want to be able to run this772 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.
arch/s390/mm/init.c+3−10
@@ -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
173int arch_has_restricted_virtio_memory_access(void)
174{
175 return is_prot_virt_guest();
176}
177EXPORT_SYMBOL(arch_has_restricted_virtio_memory_access);
178
179#endif
180
181/* protected virtualization */172/* protected virtualization */
182static void pv_init(void)173static 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();
arch/x86/Kconfig+0−1
@@ -1542,7 +1542,6 @@ config X86_CPA_STATISTICS · 1541 unmodified lines
1542config X86_MEM_ENCRYPT1542config X86_MEM_ENCRYPT
1543 select ARCH_HAS_FORCE_DMA_UNENCRYPTED1543 select ARCH_HAS_FORCE_DMA_UNENCRYPTED
1544 select DYNAMIC_PHYSICAL_MASK1544 select DYNAMIC_PHYSICAL_MASK
1545 select ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
1546 def_bool n1545 def_bool n
1547 1546
1548config AMD_MEM_ENCRYPT1547config AMD_MEM_ENCRYPT
arch/x86/mm/mem_encrypt.c+0−7
@@ -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 */
18bool force_dma_unencrypted(struct device *dev)17bool 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
91int arch_has_restricted_virtio_memory_access(void)
92{
93 return cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT);
94}
95EXPORT_SYMBOL_GPL(arch_has_restricted_virtio_memory_access);
arch/x86/mm/mem_encrypt_amd.c+4−0
@@ -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
247static unsigned long pg_level_to_pfn(int level, pte_t *kpte, pgprot_t *ret_prot)251static 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
6 bus, such as CONFIG_VIRTIO_PCI, CONFIG_VIRTIO_MMIO, CONFIG_RPMSG6 bus, such as CONFIG_VIRTIO_PCI, CONFIG_VIRTIO_MMIO, CONFIG_RPMSG
7 or CONFIG_S390_GUEST.7 or CONFIG_S390_GUEST.
8 8
9config 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
15config VIRTIO_PCI_LIB9config VIRTIO_PCI_LIB
16 tristate10 tristate
17 help11 help
drivers/virtio/virtio.c+2−3
@@ -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
170static int virtio_features_ok(struct virtio_device *dev)171static 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");
include/linux/platform-feature.h+5−1
@@ -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
11void platform_set(unsigned int feature);15void platform_set(unsigned int feature);
12void platform_clear(unsigned int feature);16void 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
604 _r; \604 _r; \
605 })605 })
606 606
607#ifdef CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
608int arch_has_restricted_virtio_memory_access(void);
609#else
610static 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 */

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