From: Ackerley Tng Remove the addr and len module parameters from the sample memory provider. The prototype doesn't require pre-carved out memory ranges, since MPS_NEW_CHILD already allows carving out memory on the fly. Being able to carve out memory on the fly makes testing easier. Signed-off-by: Ackerley Tng --- samples/Kconfig | 12 +++------ samples/kvm/mem_provider_sample.c | 53 +++++++++------------------------------ 2 files changed, 15 insertions(+), 50 deletions(-) diff --git a/samples/Kconfig b/samples/Kconfig index 3c870bca076af..a06eafb5d7ba4 100644 --- a/samples/Kconfig +++ b/samples/Kconfig @@ -331,15 +331,9 @@ config SAMPLE_KVM_MEM_PROVIDER depends on MEM_PROVIDER && CONTIG_ALLOC && X86_64 && m help This builds a sample memory provider (include/linux/mem_provider.h). - Its files can back a guest_memfd and be mapped by iommufd. Loaded - with addr= and len=, it lends a fixed physical range that has no - struct page, for example memory hidden with memmap= on the command - line. Without them, it allocates a contiguous region with - alloc_contig_pages(). - - It shows how a memory owner moves pages between VMs, takes them - back or makes them read only, and how guest_memfd and iommufd - follow each change. + Its files can back a guest_memfd and be mapped by iommufd. + It allocates a contiguous region with alloc_contig_pages() + and carves out child provider files on the fly. If unsure, say N. diff --git a/samples/kvm/mem_provider_sample.c b/samples/kvm/mem_provider_sample.c index f7ecb2ea1d75d..574c712a11389 100644 --- a/samples/kvm/mem_provider_sample.c +++ b/samples/kvm/mem_provider_sample.c @@ -8,17 +8,9 @@ * guest's devices. The module calls neither KVM nor iommufd: it answers * "what is page N" and revokes a range when the answer changes. * - * The region is either: - * - * - a fixed range given with addr= and len=, which has no struct page, for - * example memory hidden from the kernel with memmap= on the command line; - * - or, without those parameters, a range from alloc_contig_pages(). - * * The control device /dev/mem_provider_sample creates provider files. - * SETUP makes one file over the whole region. NEW_CHILD carves part of the - * region into a child file, and MOVE, DONATE and RECLAIM change which child - * has which page. A page can also be taken away or made read only. See - * mem_provider_sample.h. + * NEW_CHILD carves part of the region into a child file. A page can also + * be taken away. See mem_provider_sample.h. * * Confidential VMs are not supported. */ @@ -38,15 +30,6 @@ #include "mem_provider_sample.h" -static unsigned long long addr; -module_param(addr, ullong, 0444); -MODULE_PARM_DESC(addr, - "Physical base of a region with no struct page (optional)"); - -static unsigned long long len; -module_param(len, ullong, 0444); -MODULE_PARM_DESC(len, "Size in bytes of that region (optional)"); - /* * One provider file. * @@ -314,32 +297,26 @@ static struct page *mps_alloc_region(unsigned long npages) /* ---- Root and children -------------------------------------------------- */ -/* Create the root on the first NEW_CHILD, from addr=/len= or of @size. */ +/* Create the root on the first NEW_CHILD of @size. */ static int mps_root_ensure(u64 size) { - struct page *pages = NULL; + struct page *pages; unsigned long npages; lockdep_assert_held(&mps_root.lock); if (mps_root.npages) return 0; - if (addr && len) { - mps_root.base_pfn = addr >> PAGE_SHIFT; - npages = len >> PAGE_SHIFT; - } else { - if (!size || !PAGE_ALIGNED(size)) - return -EINVAL; - npages = size >> PAGE_SHIFT; - pages = mps_alloc_region(npages); - if (!pages) - return -ENOMEM; - mps_root.base_pfn = page_to_pfn(pages); - } + if (!size || !PAGE_ALIGNED(size)) + return -EINVAL; + npages = size >> PAGE_SHIFT; + pages = mps_alloc_region(npages); + if (!pages) + return -ENOMEM; + mps_root.base_pfn = page_to_pfn(pages); mps_root.allocated = bitmap_zalloc(npages, GFP_KERNEL); if (!mps_root.allocated) { - if (pages) - free_contig_range(page_to_pfn(pages), npages); + free_contig_range(page_to_pfn(pages), npages); return -ENOMEM; } mps_root.cma_pages = pages; @@ -489,12 +466,6 @@ static int __init mps_init(void) { int ret; - if ((addr || len) && - (!addr || !len || !PAGE_ALIGNED(addr) || !PAGE_ALIGNED(len))) { - pr_err("mem_provider_sample: addr= and len= must both be set and page aligned\n"); - return -EINVAL; - } - mutex_init(&mps_root.lock); INIT_LIST_HEAD(&mps_root.children); -- 2.56.0.257.gf7497c7d27-goog