On Fri, 12 Mar 2021 at 11:20, Andrew Scull <ascull@xxxxxxxxxx> wrote: > > On Thu, 11 Mar 2021 at 10:35, Quentin Perret <qperret@xxxxxxxxxx> wrote: > > > > On Thursday 04 Mar 2021 at 11:54:47 (+0000), 'Andrew Scull' via kernel-team wrote: > > > smp_procesor_id() works off of the cpu_number per-cpu variable. Create > > > an nVHE hyp version of cpu_number and initialize it to the same value as > > > the host when creating the hyp per-cpu regions. > > > > > > Signed-off-by: Andrew Scull <ascull@xxxxxxxxxx> > > > --- > > > arch/arm64/kvm/arm.c | 2 ++ > > > arch/arm64/kvm/hyp/nvhe/hyp-smp.c | 2 ++ > > > 2 files changed, 4 insertions(+) > > > > > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > > > index 26ccc369cf11..e3edea8379f3 100644 > > > --- a/arch/arm64/kvm/arm.c > > > +++ b/arch/arm64/kvm/arm.c > > > @@ -54,6 +54,7 @@ DECLARE_KVM_HYP_PER_CPU(unsigned long, kvm_hyp_vector); > > > static DEFINE_PER_CPU(unsigned long, kvm_arm_hyp_stack_page); > > > unsigned long kvm_arm_hyp_percpu_base[NR_CPUS]; > > > DECLARE_KVM_NVHE_PER_CPU(struct kvm_nvhe_init_params, kvm_init_params); > > > +DECLARE_KVM_NVHE_PER_CPU(int, cpu_number); > > > > > > /* The VMID used in the VTTBR */ > > > static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1); > > > @@ -1740,6 +1741,7 @@ static int init_hyp_mode(void) > > > page_addr = page_address(page); > > > memcpy(page_addr, CHOOSE_NVHE_SYM(__per_cpu_start), nvhe_percpu_size()); > > > kvm_arm_hyp_percpu_base[cpu] = (unsigned long)page_addr; > > > + *per_cpu_ptr_nvhe_sym(cpu_number, cpu) = cpu; > > > } > > > > > > /* > > > diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-smp.c b/arch/arm64/kvm/hyp/nvhe/hyp-smp.c > > > index 879559057dee..86f952b1de18 100644 > > > --- a/arch/arm64/kvm/hyp/nvhe/hyp-smp.c > > > +++ b/arch/arm64/kvm/hyp/nvhe/hyp-smp.c > > > @@ -8,6 +8,8 @@ > > > #include <asm/kvm_hyp.h> > > > #include <asm/kvm_mmu.h> > > > > > > +DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number); > > > > Is smp_processor_id() going to work at EL2 with CONFIG_DEBUG_PREEMPT=y ? > > If not, then maybe we should have out own hyp_smp_processor_id() macro? > > It's not, preempt_count() won't work,= at a minimum. I got far too > drawn into the other branch of that #ifdef. > > We only use __smp_processor_id() in hyp, but that might not play too > nicely with VHE and forgetting the leading underscores will just lead > to nVHE issues that might not be caught in the build. > > So you might be right that this is a case where we need to break from > standard APIs. And we can define `raw_smp_processor_id()` to something > that will give a compile time error when used in hyp to try and > prevent accidental misuse. Having just read the build error again: :236: undefined reference to `__kvm_nvhe_debug_smp_processor_id' Another option could be to define `debug_smp_processor_id()` for nvhe, which is easy since preemption is always disabled, IIRC. _______________________________________________ kvmarm mailing list kvmarm@xxxxxxxxxxxxxxxxxxxxx https://lists.cs.columbia.edu/mailman/listinfo/kvmarm