Commit 3f9dfbeb authored by Juergen Gross's avatar Juergen Gross

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: default avatarJuergen Gross <jgross@suse.com>
Reviewed-by: default avatarOleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Tested-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com> # Arm64 only
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarBorislav Petkov <bp@suse.de>
parent 2130a790
...@@ -768,7 +768,6 @@ menu "Virtualization" ...@@ -768,7 +768,6 @@ menu "Virtualization"
config PROTECTED_VIRTUALIZATION_GUEST config PROTECTED_VIRTUALIZATION_GUEST
def_bool n def_bool n
prompt "Protected virtualization guest support" prompt "Protected virtualization guest support"
select ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
help help
Select this option, if you want to be able to run this Select this option, if you want to be able to run this
kernel as a protected virtualization KVM guest. kernel as a protected virtualization KVM guest.
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <linux/cma.h> #include <linux/cma.h>
#include <linux/gfp.h> #include <linux/gfp.h>
#include <linux/dma-direct.h> #include <linux/dma-direct.h>
#include <linux/platform-feature.h>
#include <asm/processor.h> #include <asm/processor.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <asm/pgalloc.h> #include <asm/pgalloc.h>
...@@ -168,22 +169,14 @@ bool force_dma_unencrypted(struct device *dev) ...@@ -168,22 +169,14 @@ bool force_dma_unencrypted(struct device *dev)
return is_prot_virt_guest(); return is_prot_virt_guest();
} }
#ifdef CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
int arch_has_restricted_virtio_memory_access(void)
{
return is_prot_virt_guest();
}
EXPORT_SYMBOL(arch_has_restricted_virtio_memory_access);
#endif
/* protected virtualization */ /* protected virtualization */
static void pv_init(void) static void pv_init(void)
{ {
if (!is_prot_virt_guest()) if (!is_prot_virt_guest())
return; return;
platform_set(PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS);
/* make sure bounce buffers are shared */ /* make sure bounce buffers are shared */
swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE); swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE);
swiotlb_update_mem_attributes(); swiotlb_update_mem_attributes();
......
...@@ -1542,7 +1542,6 @@ config X86_CPA_STATISTICS ...@@ -1542,7 +1542,6 @@ config X86_CPA_STATISTICS
config X86_MEM_ENCRYPT config X86_MEM_ENCRYPT
select ARCH_HAS_FORCE_DMA_UNENCRYPTED select ARCH_HAS_FORCE_DMA_UNENCRYPTED
select DYNAMIC_PHYSICAL_MASK select DYNAMIC_PHYSICAL_MASK
select ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
def_bool n def_bool n
config AMD_MEM_ENCRYPT config AMD_MEM_ENCRYPT
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include <linux/swiotlb.h> #include <linux/swiotlb.h>
#include <linux/cc_platform.h> #include <linux/cc_platform.h>
#include <linux/mem_encrypt.h> #include <linux/mem_encrypt.h>
#include <linux/virtio_config.h>
/* Override for DMA direct allocation check - ARCH_HAS_FORCE_DMA_UNENCRYPTED */ /* Override for DMA direct allocation check - ARCH_HAS_FORCE_DMA_UNENCRYPTED */
bool force_dma_unencrypted(struct device *dev) bool force_dma_unencrypted(struct device *dev)
...@@ -87,9 +86,3 @@ void __init mem_encrypt_init(void) ...@@ -87,9 +86,3 @@ void __init mem_encrypt_init(void)
print_mem_encrypt_feature_info(); print_mem_encrypt_feature_info();
} }
int arch_has_restricted_virtio_memory_access(void)
{
return cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT);
}
EXPORT_SYMBOL_GPL(arch_has_restricted_virtio_memory_access);
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/virtio_config.h> #include <linux/virtio_config.h>
#include <linux/cc_platform.h> #include <linux/cc_platform.h>
#include <linux/platform-feature.h>
#include <asm/tlbflush.h> #include <asm/tlbflush.h>
#include <asm/fixmap.h> #include <asm/fixmap.h>
...@@ -242,6 +243,9 @@ void __init sev_setup_arch(void) ...@@ -242,6 +243,9 @@ void __init sev_setup_arch(void)
size = total_mem * 6 / 100; size = total_mem * 6 / 100;
size = clamp_val(size, IO_TLB_DEFAULT_SIZE, SZ_1G); size = clamp_val(size, IO_TLB_DEFAULT_SIZE, SZ_1G);
swiotlb_adjust_size(size); swiotlb_adjust_size(size);
/* Set restricted memory access for virtio. */
platform_set(PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS);
} }
static unsigned long pg_level_to_pfn(int level, pte_t *kpte, pgprot_t *ret_prot) static unsigned long pg_level_to_pfn(int level, pte_t *kpte, pgprot_t *ret_prot)
......
...@@ -6,12 +6,6 @@ config VIRTIO ...@@ -6,12 +6,6 @@ config VIRTIO
bus, such as CONFIG_VIRTIO_PCI, CONFIG_VIRTIO_MMIO, CONFIG_RPMSG bus, such as CONFIG_VIRTIO_PCI, CONFIG_VIRTIO_MMIO, CONFIG_RPMSG
or CONFIG_S390_GUEST. or CONFIG_S390_GUEST.
config ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
bool
help
This option is selected if the architecture may need to enforce
VIRTIO_F_ACCESS_PLATFORM
config VIRTIO_PCI_LIB config VIRTIO_PCI_LIB
tristate tristate
help help
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/platform-feature.h>
#include <uapi/linux/virtio_ids.h> #include <uapi/linux/virtio_ids.h>
/* Unique numbering for virtio devices. */ /* Unique numbering for virtio devices. */
...@@ -170,12 +171,10 @@ EXPORT_SYMBOL_GPL(virtio_add_status); ...@@ -170,12 +171,10 @@ EXPORT_SYMBOL_GPL(virtio_add_status);
static int virtio_features_ok(struct virtio_device *dev) static int virtio_features_ok(struct virtio_device *dev)
{ {
unsigned int status; unsigned int status;
int ret;
might_sleep(); might_sleep();
ret = arch_has_restricted_virtio_memory_access(); if (platform_has(PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS)) {
if (ret) {
if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) { if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
dev_warn(&dev->dev, dev_warn(&dev->dev,
"device must provide VIRTIO_F_VERSION_1\n"); "device must provide VIRTIO_F_VERSION_1\n");
......
...@@ -6,7 +6,11 @@ ...@@ -6,7 +6,11 @@
#include <asm/platform-feature.h> #include <asm/platform-feature.h>
/* The platform features are starting with the architecture specific ones. */ /* The platform features are starting with the architecture specific ones. */
#define PLATFORM_FEAT_N (0 + PLATFORM_ARCH_FEAT_N)
/* Used to enable platform specific DMA handling for virtio devices. */
#define PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS (0 + PLATFORM_ARCH_FEAT_N)
#define PLATFORM_FEAT_N (1 + PLATFORM_ARCH_FEAT_N)
void platform_set(unsigned int feature); void platform_set(unsigned int feature);
void platform_clear(unsigned int feature); void platform_clear(unsigned int feature);
......
...@@ -604,13 +604,4 @@ static inline void virtio_cwrite64(struct virtio_device *vdev, ...@@ -604,13 +604,4 @@ static inline void virtio_cwrite64(struct virtio_device *vdev,
_r; \ _r; \
}) })
#ifdef CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
int arch_has_restricted_virtio_memory_access(void);
#else
static inline int arch_has_restricted_virtio_memory_access(void)
{
return 0;
}
#endif /* CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS */
#endif /* _LINUX_VIRTIO_CONFIG_H */ #endif /* _LINUX_VIRTIO_CONFIG_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment