arm/arm64: target-efi prep
Subsystems (2)
The patches mostly prepare kvm-unit-tests/arm for targeting EFI platforms. The actually EFI support will come in another series, but these patches are good for removing assumptions from our memory maps and about our PSCI conduit, even if we never merged EFI support.
Thanks,
drew
The following changes since commit 9e7a5929569d61414feefcb1d8024e7685cb7eb3:
arm: add eabi version of 64-bit division functions (2021-05-12 15:52:24 +0200)
are available in the Git repository at:
https://gitlab.com/rhdrjones/kvm-unit-tests.git arm/queue
for you to fetch changes up to bd5bd1577dcc298cafaf0e26d318a628e650b2a7:
arm/arm64: psci: Don't assume method is hvc (2021-05-17 16:08:24 +0200)
----------------------------------------------------------------
Alexandru Elisei (1):
configure: arm: Replace --vmm with --target
Andrew Jones (9):
arm/arm64: Reorganize cstart assembler arm/arm64: Move setup_vm into setup
pci-testdev: ioremap regions
arm64: micro-bench: ioremap userspace_emulated_addr arm/arm64: mmu: Stop mapping an assumed IO region arm/arm64: mmu: Remove memory layout assumptions arm/arm64: setup: Consolidate memory layout assumptions
chr-testdev: Silently fail init
arm/arm64: psci: Don't assume method is hvc
arm/cstart.S | 92 +++++++++++++++-------- arm/cstart64.S | 45 ++++++++--- arm/flat.lds | 23 ++++++ arm/micro-bench.c | 26 ++++--- arm/selftest.c | 34 ++------- configure | 30 +++++--- lib/arm/asm/io.h | 6 ++ lib/arm/asm/mmu.h | 3 + lib/arm/asm/page.h | 2 + lib/arm/asm/pgtable-hwdef.h | 1 + lib/arm/asm/psci.h | 10 ++- lib/arm/asm/setup.h | 7 +- lib/arm/mmu.c | 53 ++++++++----- lib/arm/psci.c | 35 +++++++-- lib/arm/setup.c | 177 ++++++++++++++++++++++++++------------------ lib/arm64/asm/io.h | 6 ++ lib/arm64/asm/mmu.h | 1 + lib/arm64/asm/page.h | 2 + lib/chr-testdev.c | 5 +- lib/pci-host-generic.c | 5 +- lib/pci-host-generic.h | 4 +- lib/pci-testdev.c | 4 + 22 files changed, 372 insertions(+), 199 deletions(-)
[PULL kvm-unit-tests 04/10] pci-testdev: ioremap regions
Don't assume the physical addresses used with PCI have already been identity mapped.
--- lib/pci-host-generic.c | 5 ++--- lib/pci-host-generic.h | 4 ++-- lib/pci-testdev.c | 4 ++++ 3 files changed, 8 insertions(+), 5 deletions(-)
lib/pci-host-generic.c +2 -3
@@ -122,7 +122,7 @@ static struct pci_host_bridge *pci_dt_probe(void) sizeof(host->addr_space[0]) * nr_addr_spaces);assert (host !=NULL ); - host->start = base.addr; + host->start =ioremap (base.addr, base.size); host->size = base.size; host->bus = bus; host->bus_max = bus_max;
@@ -279,8 +279,7 @@ phys_addr_t pci_host_bridge_get_paddr(u64 pci_addr)static void __iomem *pci_get_dev_conf (struct pci_host_bridge *host,int devfn) { -return (void __iomem *)(unsigned long ) - host->start + (devfn <<PCI_ECAM_DEVFN_SHIFT ); +return host->start + (devfn <<PCI_ECAM_DEVFN_SHIFT ); }u8 pci_config_readb (pcidevaddr_t dev,u8 off)
lib/pci-host-generic.h +2 -2
@@ -18,8 +18,8 @@ struct pci_addr_space { };struct pci_host_bridge { -phys_addr_t start; -phys_addr_t size; +void __iomem *start; +size_t size;int bus;int bus_max;int nr_addr_spaces;
lib/pci-testdev.c +4 -0
@@ -185,7 +185,11 @@ int pci_testdev(void) mem =ioremap (addr,PAGE_SIZE ); addr =pci_bar_get_addr (&pci_dev,1 ); +#if defined(__i386__) || defined(__x86_64__) io = (void *)(unsigned long )addr; +#else + io =ioremap (addr,PAGE_SIZE ); +#endif nr_tests +=pci_testdev_all (mem, &pci_testdev_mem_ops); nr_tests +=pci_testdev_all (io, &pci_testdev_io_ops);
Signature · 1 line
2.30.2
[PULL kvm-unit-tests 07/10] arm/arm64: mmu: Remove memory layout assumptions
In reply to Andrew JonesRather than making too many assumptions about the memory layout in mmu code, just set up the page tables per the memory regions (which means putting all the memory layout assumptions in setup). To ensure we get the right default flags set we need to split the primary region into two regions for code and data.
We still only expect the primary regions to be present, but the next patch will remove that assumption too.
(Unfortunately we still have an assumption in setup_mmu. We assume
the range 3G-4G is available for the virtual memory allocator. We'll need to remove that assumption as well with another patch in order to support arbitrary memory maps.)
--- lib/arm/asm/setup.h | 1 + lib/arm/mmu.c | 26 +++++++++++++++----------- lib/arm/setup.c | 29 +++++++++++++++++++++-------- 3 files changed, 37 insertions(+), 19 deletions(-)
lib/arm/asm/setup.h +1 -0
@@ -15,6 +15,7 @@ extern int nr_cpus;#define MR_F_PRIMARY (1U << 0)#define MR_F_IO (1U << 1) +#define MR_F_CODE (1U << 2)#define MR_F_UNKNOWN (1U << 31)struct mem_region {
lib/arm/mmu.c +15 -11
@@ -20,8 +20,6 @@#include <linux/compiler.h> -extern unsigned long etext; -pgd_t *mmu_idmap;/* CPU 0 starts with disabled MMU */
@@ -157,7 +155,7 @@ void mmu_set_range_sect(pgd_t *pgtable, uintptr_t virt_offset,void *setup_mmu (phys_addr_t phys_end) { -uintptr_t code_end = (uintptr_t )&etext; +struct mem_region *r;/* 3G-4G region is reserved for vmalloc, cap phys_end at 3G */ if (phys_end > (3ul <<30 ))
@@ -173,14 +171,20 @@ void *setup_mmu(phys_addr_t phys_end)if (!mmu_idmap) mmu_idmap =alloc_page (); -/* armv8 requires code shared between EL1 and EL0 to be read-only */ -mmu_set_range_ptes (mmu_idmap,PHYS_OFFSET , -PHYS_OFFSET , code_end, -__pgprot (PTE_WBWA |PTE_RDONLY |PTE_USER )); - -mmu_set_range_ptes (mmu_idmap, code_end, - code_end, phys_end, -__pgprot (PTE_WBWA |PTE_USER )); +for (r = mem_regions; r->end; ++r) { +if (r->flags &MR_F_IO ) { +continue ; + }else if (r->flags &MR_F_CODE ) { +assert_msg (r->flags &MR_F_PRIMARY ,"Unexpected code region" ); +/* armv8 requires code shared between EL1 and EL0 to be read-only */ +mmu_set_range_ptes (mmu_idmap, r->start, r->start, r->end, +__pgprot (PTE_WBWA |PTE_USER |PTE_RDONLY )); + }else { +assert_msg (r->flags &MR_F_PRIMARY ,"Unexpected data region" ); +mmu_set_range_ptes (mmu_idmap, r->start, r->start, r->end, +__pgprot (PTE_WBWA |PTE_USER )); + } + }mmu_enable (mmu_idmap);return mmu_idmap;
lib/arm/setup.c +21 -8
@@ -31,6 +31,7 @@#define NR_INITIAL_MEM_REGIONS 16extern unsigned long stacktop; +extern unsigned long etext;struct timer_state __timer_state;
@@ -88,10 +89,12 @@ unsigned int mem_region_get_flags(phys_addr_t paddr)static void mem_init (phys_addr_t freemem_start) { +phys_addr_t code_end = (phys_addr_t )(unsigned long )&etext;struct dt_pbus_reg regs[NR_INITIAL_MEM_REGIONS ]; -struct mem_region primary, mem = { +struct mem_region mem = { .start = (phys_addr_t)-1 , }; +struct mem_region *primary =NULL ;phys_addr_t base, top;int nr_regs, nr_io =0 , i;
@@ -110,8 +113,6 @@ static void mem_init(phys_addr_t freemem_start) nr_regs =dt_get_memory_params (regs,NR_INITIAL_MEM_REGIONS - nr_io);assert (nr_regs >0 ); - primary = (struct mem_region ){0 }; -for (i =0 ; i < nr_regs; ++i) {struct mem_region *r = &mem_regions[nr_io + i];
@@ -123,7 +124,7 @@ static void mem_init(phys_addr_t freemem_start)*/ if (freemem_start >= r->start && freemem_start < r->end) { r->flags |=MR_F_PRIMARY ; - primary = *r; + primary = r; }/*
@@ -135,13 +136,25 @@ static void mem_init(phys_addr_t freemem_start)if (r->end > mem.end) mem.end = r->end; } -assert (primary.end !=0 ); +assert (primary);assert (!(mem.start & ~PHYS_MASK ) && !((mem.end -1 ) & ~PHYS_MASK )); - __phys_offset = primary.start;/* PHYS_OFFSET */ - __phys_end = primary.end;/* PHYS_END */ + __phys_offset = primary->start;/* PHYS_OFFSET */ + __phys_end = primary->end;/* PHYS_END */ + +/* Split the primary region into two regions; code and data */ + mem_regions[nr_io + i] = (struct mem_region ){ + .start = code_end, + .end = primary->end, + .flags =MR_F_PRIMARY , + }; + *primary = (struct mem_region ){ + .start = primary->start, + .end = code_end, + .flags =MR_F_PRIMARY |MR_F_CODE , + }; -phys_alloc_init (freemem_start, primary.end - freemem_start); +phys_alloc_init (freemem_start, __phys_end - freemem_start);phys_alloc_set_minimum_alignment (SMP_CACHE_BYTES );phys_alloc_get_unused (&base, &top);
Signature · 1 line
2.30.2
[PULL kvm-unit-tests 10/10] arm/arm64: psci: Don't assume method is hvc
In reply to Andrew JonesThe method can be smc in addition to hvc, and it will be when running on bare metal. Additionally, we move the invocations to assembly so we don't have to rely on compiler assumptions. We also fix the prototype of psci_invoke. function_id should be an unsigned int, not an unsigned long.
--- arm/cstart.S | 22 ++++++++++++++++++++++ arm/cstart64.S | 22 ++++++++++++++++++++++ arm/selftest.c | 34 +++++++--------------------------- lib/arm/asm/psci.h | 10 ++++++++-- lib/arm/psci.c | 35 +++++++++++++++++++++++++++-------- lib/arm/setup.c | 2 ++ 6 files changed, 88 insertions(+), 37 deletions(-)
arm/cstart.S +22 -0
@@ -95,6 +95,28 @@ start: .text +/* + * psci_invoke_hvc / psci_invoke_smc + * + * Inputs: + * r0 -- function_id + * r1 -- arg0 + * r2 -- arg1 + * r3 -- arg2 + * + * Outputs: + * r0 -- return code + */ +.globl psci_invoke_hvc +psci_invoke_hvc: + hvc #0 + mov pc, lr + +.globl psci_invoke_smc +psci_invoke_smc: + smc #0 + mov pc, lr + enable_vfp: /* Enable full access to CP10 and CP11: */ mov r0, #(3 << 22 | 3 << 20)
arm/cstart64.S +22 -0
@@ -109,6 +109,28 @@ start: .text +/* + * psci_invoke_hvc / psci_invoke_smc + * + * Inputs: + * w0 -- function_id + * x1 -- arg0 + * x2 -- arg1 + * x3 -- arg2 + * + * Outputs: + * x0 -- return code + */ +.globl psci_invoke_hvc +psci_invoke_hvc: + hvc #0 + ret + +.globl psci_invoke_smc +psci_invoke_smc: + smc #0 + ret + get_mmu_off: adrp x0, auxinfo ldr x0, [x0, :lo12:auxinfo + 8]
arm/selftest.c +7 -27
@@ -400,33 +400,13 @@ static void check_vectors(void *arg __unused)exit (report_summary ()); } -static bool psci_check (void ) +static void psci_print (void ) { -const struct fdt_property *method; -int node, len, ver; - - node =fdt_node_offset_by_compatible (dt_fdt (),-1 ,"arm,psci-0.2" ); -if (node <0 ) { -printf ("PSCI v0.2 compatibility required\n" ); -return false; - } - - method =fdt_get_property (dt_fdt (), node,"method" , &len); -if (method ==NULL ) { -printf ("bad psci device tree node\n" ); -return false; - } - -if (len <4 ||strcmp (method->data,"hvc" ) !=0 ) { -printf ("psci method must be hvc\n" ); -return false; - } - - ver =psci_invoke (PSCI_0_2_FN_PSCI_VERSION ,0 ,0 ,0 ); -printf ("PSCI version %d.%d\n" ,PSCI_VERSION_MAJOR (ver), -PSCI_VERSION_MINOR (ver)); - -return true; +int ver =psci_invoke (PSCI_0_2_FN_PSCI_VERSION ,0 ,0 ,0 ); +report_info ("PSCI version: %d.%d" ,PSCI_VERSION_MAJOR (ver), +PSCI_VERSION_MINOR (ver)); +report_info ("PSCI method: %s" , psci_invoke == psci_invoke_hvc ? +"hvc" :"smc" ); } static void cpu_report(void *data __unused)
@@ -465,7 +445,7 @@ int main(int argc, char **argv) }else if (strcmp (argv[1 ],"smp" ) ==0 ) { -report (psci_check (),"PSCI version" ); +psci_print ();on_cpus (cpu_report,NULL );while (!cpumask_full (&ready))cpu_relax ();
lib/arm/asm/psci.h +8 -2
@@ -3,8 +3,14 @@#include <libcflat.h> #include <linux/psci.h> -extern int psci_invoke (unsigned long function_id,unsigned long arg0, -unsigned long arg1,unsigned long arg2); +typedef int (*psci_invoke_fn )(unsigned int function_id,unsigned long arg0, +unsigned long arg1,unsigned long arg2); +extern psci_invoke_fn psci_invoke; +extern int psci_invoke_hvc (unsigned int function_id,unsigned long arg0, +unsigned long arg1,unsigned long arg2); +extern int psci_invoke_smc (unsigned int function_id,unsigned long arg0, +unsigned long arg1,unsigned long arg2); +extern void psci_set_conduit (void );extern int psci_cpu_on (unsigned long cpuid,unsigned long entry_point);extern void psci_system_reset (void );extern int cpu_psci_cpu_boot (unsigned int cpu);
lib/arm/psci.c +27 -8
@@ -6,22 +6,21 @@* * This work is licensed under the terms of the GNU LGPL, version 2. */ +#include <devicetree.h> #include <asm/psci.h> #include <asm/setup.h> #include <asm/page.h> #include <asm/smp.h> -__attribute__((noinline)) -int psci_invoke (unsigned long function_id,unsigned long arg0, -unsigned long arg1,unsigned long arg2) +static int psci_invoke_none (unsigned int function_id,unsigned long arg0, +unsigned long arg1,unsigned long arg2) { - asmvolatile ( -"hvc #0" - :"+r" (function_id) - :"r" (arg0),"r" (arg1),"r" (arg2)); -return function_id; +printf ("No PSCI method configured! Can't invoke...\n" ); +return PSCI_RET_NOT_PRESENT ; } +psci_invoke_fn psci_invoke = psci_invoke_none; +int psci_cpu_on (unsigned long cpuid,unsigned long entry_point) {#ifdef __arm__
@@ -56,3 +55,23 @@ void psci_system_off(void)int err =psci_invoke (PSCI_0_2_FN_SYSTEM_OFF ,0 ,0 ,0 );printf ("CPU%d unable to do system off (error = %d)\n" ,smp_processor_id (), err); } + +void psci_set_conduit (void ) +{ +const void *fdt =dt_fdt (); +const struct fdt_property *method; +int node, len; + + node =fdt_node_offset_by_compatible (fdt,-1 ,"arm,psci-0.2" ); +assert_msg (node >=0 ,"PSCI v0.2 compatibility required" ); + + method =fdt_get_property (fdt, node,"method" , &len); +assert (method !=NULL && len ==4 ); + +if (strcmp (method->data,"hvc" ) ==0 ) + psci_invoke = psci_invoke_hvc; +else if (strcmp (method->data,"smc" ) ==0 ) + psci_invoke = psci_invoke_smc; +else +assert_msg (false,"Unknown PSCI conduit: %s" , method->data); +}
lib/arm/setup.c +2 -0
@@ -25,6 +25,7 @@#include <asm/processor.h> #include <asm/smp.h> #include <asm/timer.h> +#include <asm/psci.h> #include "io.h"
@@ -266,6 +267,7 @@ void setup(const void *fdt, phys_addr_t freemem_start)mem_regions_add_assumed ();mem_init (PAGE_ALIGN ((unsigned long )freemem)); +psci_set_conduit ();cpu_init ();/* cpu_init must be called before thread_info_init */
Signature · 1 line
2.30.2
[PULL kvm-unit-tests 02/10] arm/arm64: Reorganize cstart assembler
In reply to Andrew JonesMove secondary_entry helper functions out of .init and into .text, since secondary_entry isn't run at at "init" time. Actually, anything that is used after init time should be in .text, as we may not include .init in some build configurations.
Reviewed-by Nikos Nikoleris <[email protected]>
--- arm/cstart.S | 66 +++++++++++++++++++++++++++++--------------------- arm/cstart64.S | 18 ++++++++------ 2 files changed, 49 insertions(+), 35 deletions(-)
arm/cstart.S +38 -28
@@ -96,32 +96,7 @@ start: bl exit b halt - -.macro set_mode_stack mode, stack - add \stack, #S_FRAME_SIZE - msr cpsr_c, #(\mode | PSR_I_BIT | PSR_F_BIT) - isb - mov sp, \stack -.endm - -exceptions_init: - mrc p15, 0, r2, c1, c0, 0 @ read SCTLR - bic r2, #CR_V @ SCTLR.V := 0 - mcr p15, 0, r2, c1, c0, 0 @ write SCTLR - ldr r2, =vector_table - mcr p15, 0, r2, c12, c0, 0 @ write VBAR - - mrs r2, cpsr - - /* first frame reserved for svc mode */ - set_mode_stack UND_MODE, r0 - set_mode_stack ABT_MODE, r0 - set_mode_stack IRQ_MODE, r0 - set_mode_stack FIQ_MODE, r0 - - msr cpsr_cxsf, r2 @ back to svc mode - isb - mov pc, lr +.text enable_vfp: /* Enable full access to CP10 and CP11: */
@@ -133,8 +108,6 @@ enable_vfp: vmsr fpexc, r0 mov pc, lr -.text - .global get_mmu_off get_mmu_off: ldr r0, =auxinfo
@@ -235,6 +208,43 @@ asm_mmu_disable: mov pc, lr +/* + * Vectors + */ + +.macro set_mode_stack mode, stack + add \stack, #S_FRAME_SIZE + msr cpsr_c, #(\mode | PSR_I_BIT | PSR_F_BIT) + isb + mov sp, \stack +.endm + +/* + * exceptions_init + * + * Input r0 is the stack top, which is the exception stacks base + */ +exceptions_init: + mrc p15, 0, r2, c1, c0, 0 @ read SCTLR + bic r2, #CR_V @ SCTLR.V := 0 + mcr p15, 0, r2, c1, c0, 0 @ write SCTLR + ldr r2, =vector_table + mcr p15, 0, r2, c12, c0, 0 @ write VBAR + + mrs r2, cpsr + + /* + * The first frame is reserved for svc mode + */ + set_mode_stack UND_MODE, r0 + set_mode_stack ABT_MODE, r0 + set_mode_stack IRQ_MODE, r0 + set_mode_stack FIQ_MODE, r0 + + msr cpsr_cxsf, r2 @ back to svc mode + isb + mov pc, lr + /* * Vector stubs * Simplified version of the Linux kernel implementation
arm/cstart64.S +11 -7
@@ -109,13 +109,6 @@ start: bl exit b halt -exceptions_init: - adrp x4, vector_table - add x4, x4, :lo12:vector_table - msr vbar_el1, x4 - isb - ret - .text .globl get_mmu_off
@@ -251,6 +244,17 @@ asm_mmu_disable: /* * Vectors + */ + +exceptions_init: + adrp x4, vector_table + add x4, x4, :lo12:vector_table + msr vbar_el1, x4 + isb + ret + +/* + * Vector stubs * Adapted from arch/arm64/kernel/entry.S */ .macro vector_stub, name, vec
Signature · 1 line
2.30.2
[PULL kvm-unit-tests 08/10] arm/arm64: setup: Consolidate memory layout assumptions
In reply to Andrew JonesKeep as much memory layout assumptions as possible in init::start and a single setup function. This prepares us for calling setup() from different start functions which have been linked with different linker scripts. To do this, stacktop is only referenced from init::start, making freemem_start a parameter to setup(). We also split mem_init() into three parts, one that populates the mem regions per the DT, one that populates the mem regions per assumptions, and one that does the mem init. The concept of a primary region is dropped, but we add a sanity check for the absence of memory holes, because we don't know how to deal with them yet.
--- arm/cstart.S | 4 +- arm/cstart64.S | 2 + arm/flat.lds | 23 ++++++ lib/arm/asm/setup.h | 8 +- lib/arm/mmu.c | 2 - lib/arm/setup.c | 175 ++++++++++++++++++++++++-------------------- 6 files changed, 128 insertions(+), 86 deletions(-)
arm/cstart.S +3 -1
@@ -80,7 +80,9 @@ start: /* complete setup */ pop {r0-r1} - bl setup + mov r3, #0 + ldr r2, =stacktop @ r2,r3 is the base of free memory + bl setup @ r0 is the addr of the dtb /* run the test */ ldr r0, =__argc
arm/cstart64.S +2 -0
@@ -92,6 +92,8 @@ start: bl exceptions_init /* complete setup */ + adrp x1, stacktop + add x1, x1, :lo12:stacktop // x1 is the base of free memory bl setup // x0 is the addr of the dtb /* run the test */
arm/flat.lds +23 -0
@@ -1,3 +1,26 @@ +/* + * init::start will pass stacktop to setup() as the base of free memory. + * setup() will then move the FDT and initrd to that base before calling + * mem_init(). With those movements and this linker script, we'll end up + * having the following memory layout: + * + * +----------------------+ <-- top of physical memory + * | | + * ~ ~ + * | | + * +----------------------+ <-- top of initrd + * | | + * +----------------------+ <-- top of FDT + * | | + * +----------------------+ <-- top of cpu0's stack + * | | + * +----------------------+ <-- top of text/data/bss sections + * | | + * | | + * +----------------------+ <-- load address + * | | + * +----------------------+ <-- physical address 0x0 + */ SECTIONS {
lib/arm/asm/setup.h +4 -4
@@ -13,9 +13,8 @@extern u64 cpus[NR_CPUS ];/* per-cpu IDs (MPIDRs) */ extern int nr_cpus; -#define MR_F_PRIMARY (1U << 0) -#define MR_F_IO (1U << 1) -#define MR_F_CODE (1U << 2) +#define MR_F_IO (1U << 0) +#define MR_F_CODE (1U << 1)#define MR_F_UNKNOWN (1U << 31)struct mem_region {
@@ -26,6 +25,7 @@ struct mem_region {extern struct mem_region *mem_regions;extern phys_addr_t __phys_offset, __phys_end; +extern struct mem_region *mem_region_find (phys_addr_t paddr);extern unsigned int mem_region_get_flags (phys_addr_t paddr);#define PHYS_OFFSET (__phys_offset)
@@ -35,6 +35,6 @@ extern unsigned int mem_region_get_flags(phys_addr_t paddr);#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)#define SMP_CACHE_BYTES L1_CACHE_BYTES -void setup (const void *fdt); +void setup (const void *fdt,phys_addr_t freemem_start);#endif /* _ASMARM_SETUP_H_ */
lib/arm/mmu.c +0 -2
@@ -175,12 +175,10 @@ void *setup_mmu(phys_addr_t phys_end)if (r->flags &MR_F_IO ) {continue ; }else if (r->flags &MR_F_CODE ) { -assert_msg (r->flags &MR_F_PRIMARY ,"Unexpected code region" );/* armv8 requires code shared between EL1 and EL0 to be read-only */ mmu_set_range_ptes (mmu_idmap, r->start, r->start, r->end,__pgprot (PTE_WBWA |PTE_USER |PTE_RDONLY )); }else { -assert_msg (r->flags &MR_F_PRIMARY ,"Unexpected data region" );mmu_set_range_ptes (mmu_idmap, r->start, r->start, r->end,__pgprot (PTE_WBWA |PTE_USER )); }
lib/arm/setup.c +96 -79
238 lines not on this page · raw message
Signature · 1 line
2.30.2
[PULL kvm-unit-tests 06/10] arm/arm64: mmu: Stop mapping an assumed IO region
In reply to Andrew JonesBy providing a proper ioremap function, we can just rely on devices calling it for each region they need (as they already do) instead of mapping a big assumed I/O range. We don't require the MMU to be enabled at the time of the ioremap. In that case, we add the mapping to the identity map anyway. This allows us to call setup_vm after io_init. Why don't we just call setup_vm before io_init, I hear you ask? Well, that's because tests like sieve want to start with the MMU off, later call setup_vm, and all the while have working I/O. Some unit tests are just really demanding...
While at it, ensure we map the I/O regions with XN (execute never), as suggested by Alexandru Elisei.
--- lib/arm/asm/io.h | 6 ++++++ lib/arm/asm/mmu.h | 3 +++ lib/arm/asm/page.h | 2 ++ lib/arm/asm/pgtable-hwdef.h | 1 + lib/arm/mmu.c | 37 +++++++++++++++++++++++++++---------- lib/arm64/asm/io.h | 6 ++++++ lib/arm64/asm/mmu.h | 1 + lib/arm64/asm/page.h | 2 ++ 8 files changed, 48 insertions(+), 10 deletions(-)
lib/arm/asm/io.h +6 -0
@@ -77,6 +77,12 @@ static inline void __raw_writel(u32 val, volatile void __iomem *addr) : "r" (val)); } +#define ioremap ioremap +static inline void __iomem *ioremap (phys_addr_t phys_addr,size_t size) +{ +return __ioremap (phys_addr, size); +} +#define virt_to_phys virt_to_physstatic inline phys_addr_t virt_to_phys (const volatile void *x) {
lib/arm/asm/mmu.h +3 -0
@@ -8,10 +8,13 @@#include <asm/barrier.h> #define PTE_USER L_PTE_USER +#define PTE_UXN L_PTE_XN +#define PTE_PXN L_PTE_PXN#define PTE_RDONLY PTE_AP2#define PTE_SHARED L_PTE_SHARED#define PTE_AF PTE_EXT_AF#define PTE_WBWA L_PTE_MT_WRITEALLOC +#define PTE_UNCACHED L_PTE_MT_UNCACHED/* See B3.18.7 TLB maintenance operations */
lib/arm/asm/page.h +2 -0
@@ -47,5 +47,7 @@ typedef struct { pteval_t pgprot; } pgprot_t;extern phys_addr_t __virt_to_phys (unsigned long addr);extern unsigned long __phys_to_virt (phys_addr_t addr); +extern void *__ioremap (phys_addr_t phys_addr,size_t size); +#endif /* !__ASSEMBLY__ */ #endif /* _ASMARM_PAGE_H_ */
lib/arm/asm/pgtable-hwdef.h +1 -0
@@ -34,6 +34,7 @@#define L_PTE_USER (_AT(pteval_t, 1) << 6)/* AP[1] */ #define L_PTE_SHARED (_AT(pteval_t, 3) << 8)/* SH[1:0], inner shareable */ #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10)/* AF */ +#define L_PTE_PXN (_AT(pteval_t, 1) << 53)/* PXN */ #define L_PTE_XN (_AT(pteval_t, 1) << 54)/* XN */ /*
lib/arm/mmu.c +27 -10
@@ -11,6 +11,7 @@#include <asm/mmu.h> #include <asm/setup.h> #include <asm/page.h> +#include <asm/io.h> #include "alloc_page.h" #include "vmalloc.h"
@@ -157,9 +158,8 @@ void mmu_set_range_sect(pgd_t *pgtable, uintptr_t virt_offset,void *setup_mmu (phys_addr_t phys_end) {uintptr_t code_end = (uintptr_t )&etext; -struct mem_region *r; -/* 0G-1G = I/O, 1G-3G = identity, 3G-4G = vmalloc */ +/* 3G-4G region is reserved for vmalloc, cap phys_end at 3G */ if (phys_end > (3ul <<30 )) phys_end =3ul <<30 ;
@@ -170,14 +170,8 @@ void *setup_mmu(phys_addr_t phys_end) "Unsupported translation granule %ld\n", PAGE_SIZE);#endif - mmu_idmap =alloc_page (); - -for (r = mem_regions; r->end; ++r) { -if (!(r->flags &MR_F_IO )) -continue ; -mmu_set_range_sect (mmu_idmap, r->start, r->start, r->end, -__pgprot (PMD_SECT_UNCACHED |PMD_SECT_USER )); - } +if (!mmu_idmap) + mmu_idmap =alloc_page ();/* armv8 requires code shared between EL1 and EL0 to be read-only */ mmu_set_range_ptes(mmu_idmap, PHYS_OFFSET,
@@ -192,6 +186,29 @@ void *setup_mmu(phys_addr_t phys_end)return mmu_idmap; } +void __iomem *__ioremap (phys_addr_t phys_addr,size_t size) +{ +phys_addr_t paddr_aligned = phys_addr &PAGE_MASK ; +phys_addr_t paddr_end =PAGE_ALIGN (phys_addr + size); +pgprot_t prot =__pgprot (PTE_UNCACHED |PTE_USER |PTE_UXN |PTE_PXN ); +pgd_t *pgtable; + +assert (sizeof (long ) ==8 || !(phys_addr >>32 )); + +if (mmu_enabled ()) { + pgtable =current_thread_info ()->pgtable; + }else { +if (!mmu_idmap) + mmu_idmap =alloc_page (); + pgtable = mmu_idmap; + } + +mmu_set_range_ptes (pgtable, paddr_aligned, paddr_aligned, + paddr_end, prot); + +return (void __iomem *)(unsigned long )phys_addr; +} +phys_addr_t __virt_to_phys (unsigned long addr) {if (mmu_enabled ()) {
lib/arm64/asm/io.h +6 -0
@@ -71,6 +71,12 @@ static inline u64 __raw_readq(const volatile void __iomem *addr)return val; } +#define ioremap ioremap +static inline void __iomem *ioremap (phys_addr_t phys_addr,size_t size) +{ +return __ioremap (phys_addr, size); +} +#define virt_to_phys virt_to_physstatic inline phys_addr_t virt_to_phys (const volatile void *x) {
lib/arm64/asm/mmu.h +1 -0
@@ -8,6 +8,7 @@#include <asm/barrier.h> #define PMD_SECT_UNCACHED PMD_ATTRINDX(MT_DEVICE_nGnRE) +#define PTE_UNCACHED PTE_ATTRINDX(MT_DEVICE_nGnRE)#define PTE_WBWA PTE_ATTRINDX(MT_NORMAL)static inline void flush_tlb_all (void )
lib/arm64/asm/page.h +2 -0
@@ -72,5 +72,7 @@ typedef struct { pteval_t pgprot; } pgprot_t;extern phys_addr_t __virt_to_phys (unsigned long addr);extern unsigned long __phys_to_virt (phys_addr_t addr); +extern void *__ioremap (phys_addr_t phys_addr,size_t size); +#endif /* !__ASSEMBLY__ */ #endif /* _ASMARM64_PAGE_H_ */
Signature · 1 line
2.30.2
[PULL kvm-unit-tests 09/10] chr-testdev: Silently fail init
In reply to Andrew JonesIf there's no virtio-console / chr-testdev configured, then the user probably didn't want them. Just silently fail rather than stating the obvious.
--- lib/chr-testdev.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
lib/chr-testdev.c +1 -4
@@ -54,11 +54,8 @@ void chr_testdev_init(void)int ret; vcon =virtio_bind (VIRTIO_ID_CONSOLE ); -if (vcon ==NULL ) { -printf ("%s: %s: can't find a virtio-console\n" , - __func__,TESTDEV_NAME ); +if (vcon ==NULL )return ; - } ret = vcon->config->find_vqs (vcon,2 , vqs,NULL , io_names);if (ret <0 ) {
Signature · 1 line
2.30.2
[PULL kvm-unit-tests 01/10] configure: arm: Replace --vmm with --target
In reply to Andrew JonesFrom: Alexandru Elisei <[email protected]>
The --vmm configure option was added to distinguish between the two virtual machine managers that kvm-unit-tests supports for the arm and arm64 architectures, qemu or kvmtool. There are plans to make kvm-unit-tests work as an EFI app, which will require changes to the way tests are compiled. Instead of adding a new configure option specifically for EFI and have it coexist with --vmm, or overloading the semantics of the existing --vmm option, let's replace --vmm with the more generic name --target.
Since --target is only valid for arm and arm64, reject the option when it's specified for another architecture, which is how --vmm should have behaved from the start.
--- configure | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-)
configure +21 -9
@@ -21,7 +21,7 @@ pretty_print_stacks=yes environ_default=yes u32_long= wa_divide= -vmm="qemu" +target= errata_force=0 erratatxt="$srcdir/errata.txt" host_key_document=
@@ -35,8 +35,8 @@ usage() { Options include: --arch=ARCH architecture to compile for ($arch) --processor=PROCESSOR processor to compile for ($arch) - --vmm=VMM virtual machine monitor to compile for (qemu - or kvmtool, default is qemu) (arm/arm64 only) + --target=TARGET target platform that the tests will be running on (qemu or + kvmtool, default is qemu) (arm/arm64 only) --cross-prefix=PREFIX cross compiler prefix --cc=CC c compiler to use ($cc) --ld=LD ld linker to use ($ld)
@@ -58,7 +58,7 @@ usage() { --earlycon=EARLYCON Specify the UART name, type and address (optional, arm and arm64 only). The specified address will overwrite the UART - address set by the --vmm option. EARLYCON can be one of + address set by the --target option. EARLYCON can be one of (case sensitive): uart[8250],mmio,ADDR Specify an 8250 compatible UART at address ADDR. Supported
@@ -88,8 +88,8 @@ while [[ "$1" = -* ]]; do --processor) processor="$arg" ;; - --vmm) - vmm="$arg" + --target) + target="$arg" ;; --cross-prefix) cross_prefix="$arg"
@@ -146,6 +146,15 @@ arch_name=$arch [ "$arch" = "aarch64" ] && arch="arm64" [ "$arch_name" = "arm64" ] && arch_name="aarch64" +if [ -z "$target" ]; then + target="qemu" +else + if [ "$arch" != "arm64" ] && [ "$arch" != "arm" ]; then + echo "--target is not supported for $arch" + usage + fi +fi + if [ -z "$page_size" ]; then [ "$arch" = "arm64" ] && page_size="65536" [ "$arch" = "arm" ] && page_size="4096"
@@ -177,13 +186,13 @@ if [ "$arch" = "i386" ] || [ "$arch" = "x86_64" ]; then testdir=x86 elif [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then testdir=arm - if [ "$vmm" = "qemu" ]; then + if [ "$target" = "qemu" ]; then arm_uart_early_addr=0x09000000 - elif [ "$vmm" = "kvmtool" ]; then + elif [ "$target" = "kvmtool" ]; then arm_uart_early_addr=0x3f8 errata_force=1 else - echo '--vmm must be one of "qemu" or "kvmtool"!' + echo "--target must be one of 'qemu' or 'kvmtool'!" usage fi
@@ -318,6 +327,9 @@ WA_DIVIDE=$wa_divide GENPROTIMG=${GENPROTIMG-genprotimg} HOST_KEY_DOCUMENT=$host_key_document EOF +if [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then + echo "TARGET=$target" >> config.mak +fi cat <<EOF > lib/config.h #ifndef CONFIG_H
Signature · 1 line
2.30.2
[PULL kvm-unit-tests 05/10] arm64: micro-bench: ioremap userspace_emulated_addr
In reply to Andrew JonesWe should explicitly ioremap the userspace emulated address used in the benchmark.
--- arm/micro-bench.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
arm/micro-bench.c +16 -10
@@ -273,7 +273,9 @@ static void hvc_exec(void) asmvolatile ("mov w0, #0x4b000000; hvc #0" :::"w0" ); } -static void mmio_read_user_exec (void ) +static void *userspace_emulated_addr; + +static bool mmio_read_user_prep (void ) {/* * FIXME: Read device-id in virtio mmio here in order to
@@ -281,8 +283,12 @@ static void mmio_read_user_exec(void)* updated in the future if any relevant changes in QEMU * test-dev are made. */ -void *userspace_emulated_addr = (void *)0x0a000008 ; + userspace_emulated_addr = (void *)ioremap (0x0a000008 ,sizeof (u32)); +return true; +} +static void mmio_read_user_exec (void ) +{readl (userspace_emulated_addr); }
@@ -309,14 +315,14 @@ struct exit_test { };static struct exit_test tests[] = { - {"hvc" ,NULL , hvc_exec,NULL ,65536 , true}, - {"mmio_read_user" ,NULL , mmio_read_user_exec,NULL ,65536 , true}, - {"mmio_read_vgic" ,NULL , mmio_read_vgic_exec,NULL ,65536 , true}, - {"eoi" ,NULL , eoi_exec,NULL ,65536 , true}, - {"ipi" , ipi_prep, ipi_exec,NULL ,65536 , true}, - {"ipi_hw" , ipi_hw_prep, ipi_exec,NULL ,65536 , true}, - {"lpi" , lpi_prep, lpi_exec,NULL ,65536 , true}, - {"timer_10ms" , timer_prep, timer_exec, timer_post,256 , true}, + {"hvc" ,NULL , hvc_exec,NULL ,65536 , true}, + {"mmio_read_user" , mmio_read_user_prep, mmio_read_user_exec,NULL ,65536 , true}, + {"mmio_read_vgic" ,NULL , mmio_read_vgic_exec,NULL ,65536 , true}, + {"eoi" ,NULL , eoi_exec,NULL ,65536 , true}, + {"ipi" , ipi_prep, ipi_exec,NULL ,65536 , true}, + {"ipi_hw" , ipi_hw_prep, ipi_exec,NULL ,65536 , true}, + {"lpi" , lpi_prep, lpi_exec,NULL ,65536 , true}, + {"timer_10ms" , timer_prep, timer_exec, timer_post,256 , true}, };struct ns_time {
Signature · 1 line
2.30.2
[PULL kvm-unit-tests 03/10] arm/arm64: Move setup_vm into setup
In reply to Andrew JonesConsolidate our setup calls to reduce the amount we need to do from init::start. Also remove a couple of pointless comments from setup().
--- arm/cstart.S | 6 ------ arm/cstart64.S | 5 ----- lib/arm/setup.c | 7 +++++-- 3 files changed, 5 insertions(+), 13 deletions(-)
arm/cstart.S +0 -6
@@ -81,12 +81,7 @@ start: /* complete setup */ pop {r0-r1} bl setup - bl get_mmu_off - cmp r0, #0 - bne 1f - bl setup_vm -1: /* run the test */ ldr r0, =__argc ldr r0, [r0]
@@ -108,7 +103,6 @@ enable_vfp: vmsr fpexc, r0 mov pc, lr -.global get_mmu_off get_mmu_off: ldr r0, =auxinfo ldr r0, [r0, #4]
arm/cstart64.S +0 -5
@@ -93,11 +93,7 @@ start: /* complete setup */ bl setup // x0 is the addr of the dtb - bl get_mmu_off - cbnz x0, 1f - bl setup_vm -1: /* run the test */ adrp x0, __argc ldr w0, [x0, :lo12:__argc]
@@ -111,7 +107,6 @@ start: .text -.globl get_mmu_off get_mmu_off: adrp x0, auxinfo ldr x0, [x0, :lo12:auxinfo + 8]
lib/arm/setup.c +5 -2
@@ -16,6 +16,8 @@#include <alloc.h> #include <alloc_phys.h> #include <alloc_page.h> +#include <vmalloc.h> +#include <auxinfo.h> #include <argv.h> #include <asm/thread_info.h> #include <asm/setup.h>
@@ -233,7 +235,6 @@ void setup(const void *fdt) freemem += initrd_size; } -/* call init functions */ mem_init (PAGE_ALIGN ((unsigned long )freemem));cpu_init ();
@@ -243,7 +244,6 @@ void setup(const void *fdt)/* mem_init must be called before io_init */ io_init (); -/* finish setup */ timer_save_state (); ret =dt_get_bootargs (&bootargs);
@@ -256,4 +256,7 @@ void setup(const void *fdt)memcpy (env, initrd, initrd_size);setup_env (env, initrd_size); } + +if (!(auxinfo.flags &AUXINFO_MMU_OFF )) +setup_vm (); }
Signature · 1 line
2.30.2
Quoted 25 lines · Andrew Jones
The patches mostly prepare kvm-unit-tests/arm for targeting EFI platforms. The actually EFI support will come in another series, but these patches are good for removing assumptions from our memory maps and about our PSCI conduit, even if we never merged EFI support.
Thanks,
drewThe following changes since commit
9e7a5929569d61414feefcb1d8024e7685cb7eb3:arm: add eabi version of 64-bit division functions (2021-05-12 15:52:24 +0200)
are available in the Git repository at:
https://gitlab.com/rhdrjones/kvm-unit-tests.git arm/queue
for you to fetch changes up to
bd5bd1577dcc298cafaf0e26d318a628e650b2a7:arm/arm64: psci: Don't assume method is hvc (2021-05-17 16:08:24 +0200)
----------------------------------------------------------------
Alexandru Elisei (1):configure: arm: Replace --vmm with --target
Quoted 11 lines
Andrew Jones (9):
arm/arm64: Reorganize cstart assembler arm/arm64: Movesetup_vminto setup
pci-testdev: ioremap regions
arm64: micro-bench: ioremapuserspace_emulated_addrarm/arm64: mmu: Stop mapping an assumed IO region arm/arm64: mmu: Remove memory layout assumptions arm/arm64: setup: Consolidate memory layout assumptions
chr-testdev: Silently fail init
arm/arm64: psci: Don't assume method is hvc
I see these patches have now been merged. Thanks Paolo!
Thanks,
drew