Skip to content

Commit

Permalink
xen/virtio: Enable restricted memory access using Xen grant mappings
Browse files Browse the repository at this point in the history
In order to support virtio in Xen guests add a config option XEN_VIRTIO
enabling the user to specify whether in all Xen guests virtio should
be able to access memory via Xen grant mappings only on the host side.

Also set PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS feature from the guest
initialization code on Arm and x86 if CONFIG_XEN_VIRTIO is enabled.

Signed-off-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Link: https://lore.kernel.org/r/1654197833-25362-5-git-send-email-olekstysh@gmail.com
Signed-off-by: Juergen Gross <jgross@suse.com>
  • Loading branch information
Juergen Gross committed Jun 6, 2022
1 parent d6aca35 commit fa1f574
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions arch/arm/xen/enlighten.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ static int __init xen_guest_init(void)
if (!xen_domain())
return 0;

xen_set_restricted_virtio_memory_access();

if (!acpi_disabled)
xen_acpi_guest_init();
else
Expand Down
2 changes: 2 additions & 0 deletions arch/x86/xen/enlighten_hvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ static void __init xen_hvm_guest_init(void)
if (xen_pv_domain())
return;

xen_set_restricted_virtio_memory_access();

init_hvm_pv_info();

reserve_shared_info();
Expand Down
2 changes: 2 additions & 0 deletions arch/x86/xen/enlighten_pv.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ static DEFINE_PER_CPU(struct tls_descs, shadow_tls_desc);

static void __init xen_pv_init_platform(void)
{
xen_set_restricted_virtio_memory_access();

populate_extra_pte(fix_to_virt(FIX_PARAVIRT_BOOTMAP));

set_fixmap(FIX_PARAVIRT_BOOTMAP, xen_start_info->shared_info);
Expand Down
11 changes: 11 additions & 0 deletions drivers/xen/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,15 @@ config XEN_GRANT_DMA_OPS
bool
select DMA_OPS

config XEN_VIRTIO
bool "Xen virtio support"
depends on VIRTIO
select XEN_GRANT_DMA_OPS
help
Enable virtio support for running as Xen guest. Depending on the
guest type this will require special support on the backend side
(qemu or kernel, depending on the virtio device types used).

If in doubt, say n.

endmenu
8 changes: 8 additions & 0 deletions include/xen/xen.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ bool xen_biovec_phys_mergeable(const struct bio_vec *vec1,
extern u64 xen_saved_max_mem_size;
#endif

#include <linux/platform-feature.h>

static inline void xen_set_restricted_virtio_memory_access(void)
{
if (IS_ENABLED(CONFIG_XEN_VIRTIO) && xen_domain())
platform_set(PLATFORM_VIRTIO_RESTRICTED_MEM_ACCESS);
}

#ifdef CONFIG_XEN_UNPOPULATED_ALLOC
int xen_alloc_unpopulated_pages(unsigned int nr_pages, struct page **pages);
void xen_free_unpopulated_pages(unsigned int nr_pages, struct page **pages);
Expand Down

0 comments on commit fa1f574

Please sign in to comment.