All of lore.kernel.org
 help / color / mirror / Atom feed
* [arm-platforms:kvm-arm64/per-vcpu-host-pmu-data 3/4] arch/arm64/kvm/arm.c:764:23: error: 'struct kvm_pmu' has no member named 'events'
@ 2022-05-16 10:42 kernel test robot
  2022-05-16 12:25   ` Marc Zyngier
  0 siblings, 1 reply; 5+ messages in thread
From: kernel test robot @ 2022-05-16 10:42 UTC (permalink / raw)
  To: Fuad Tabba; +Cc: kbuild-all, linux-arm-kernel, Marc Zyngier, Oliver Upton

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git kvm-arm64/per-vcpu-host-pmu-data
head:   722625c6f4c5b6a9953d6af04c7bb1a6e12830b3
commit: 84d751a019a9792f5b4884e1d598b603c360ec22 [3/4] KVM: arm64: Pass pmu events to hyp via vcpu
config: arm64-randconfig-r022-20220516 (https://download.01.org/0day-ci/archive/20220516/202205161814.KQHpOzsJ-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/commit/?id=84d751a019a9792f5b4884e1d598b603c360ec22
        git remote add arm-platforms https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git
        git fetch --no-tags arm-platforms kvm-arm64/per-vcpu-host-pmu-data
        git checkout 84d751a019a9792f5b4884e1d598b603c360ec22
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash arch/arm64/kvm/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   arch/arm64/kvm/arm.c: In function 'kvm_pmu_update_vcpu_events':
>> arch/arm64/kvm/arm.c:764:23: error: 'struct kvm_pmu' has no member named 'events'
     764 |         vcpu->arch.pmu.events = *kvm_get_pmu_events();
         |                       ^
>> arch/arm64/kvm/arm.c:764:33: error: invalid use of undefined type 'struct kvm_pmu_events'
     764 |         vcpu->arch.pmu.events = *kvm_get_pmu_events();
         |                                 ^
--
   In file included from include/asm-generic/percpu.h:7,
                    from arch/arm64/include/asm/percpu.h:248,
                    from arch/arm64/include/asm/smp.h:28,
                    from include/linux/smp.h:113,
                    from include/linux/percpu.h:7,
                    from include/linux/context_tracking_state.h:5,
                    from include/linux/hardirq.h:5,
                    from include/linux/kvm_host.h:7,
                    from arch/arm64/kvm/pmu.c:6:
   arch/arm64/kvm/pmu.c: In function 'kvm_get_pmu_events':
>> include/linux/percpu-defs.h:219:59: error: invalid use of undefined type 'struct kvm_pmu_events'
     219 |         const void __percpu *__vpp_verify = (typeof((ptr) + 0))NULL;    \
         |                                                           ^
   include/linux/percpu-defs.h:241:9: note: in expansion of macro '__verify_pcpu_ptr'
     241 |         __verify_pcpu_ptr(ptr);                                         \
         |         ^~~~~~~~~~~~~~~~~
   include/linux/percpu-defs.h:252:27: note: in expansion of macro 'raw_cpu_ptr'
     252 | #define this_cpu_ptr(ptr) raw_cpu_ptr(ptr)
         |                           ^~~~~~~~~~~
   arch/arm64/kvm/pmu.c:31:16: note: in expansion of macro 'this_cpu_ptr'
      31 |         return this_cpu_ptr(&kvm_pmu_events);
         |                ^~~~~~~~~~~~
   arch/arm64/kvm/pmu.c: In function 'kvm_set_pmu_events':
>> arch/arm64/kvm/pmu.c:46:20: error: invalid use of undefined type 'struct kvm_pmu_events'
      46 |                 pmu->events_host |= set;
         |                    ^~
   arch/arm64/kvm/pmu.c:48:20: error: invalid use of undefined type 'struct kvm_pmu_events'
      48 |                 pmu->events_guest |= set;
         |                    ^~
   arch/arm64/kvm/pmu.c: In function 'kvm_clr_pmu_events':
   arch/arm64/kvm/pmu.c:61:12: error: invalid use of undefined type 'struct kvm_pmu_events'
      61 |         pmu->events_host &= ~clr;
         |            ^~
   arch/arm64/kvm/pmu.c:62:12: error: invalid use of undefined type 'struct kvm_pmu_events'
      62 |         pmu->events_guest &= ~clr;
         |            ^~
   arch/arm64/kvm/pmu.c: In function 'kvm_vcpu_pmu_restore_guest':
   arch/arm64/kvm/pmu.c:186:27: error: invalid use of undefined type 'struct kvm_pmu_events'
     186 |         events_guest = pmu->events_guest;
         |                           ^~
   arch/arm64/kvm/pmu.c:187:26: error: invalid use of undefined type 'struct kvm_pmu_events'
     187 |         events_host = pmu->events_host;
         |                          ^~
   arch/arm64/kvm/pmu.c: In function 'kvm_vcpu_pmu_restore_host':
   arch/arm64/kvm/pmu.c:206:27: error: invalid use of undefined type 'struct kvm_pmu_events'
     206 |         events_guest = pmu->events_guest;
         |                           ^~
   arch/arm64/kvm/pmu.c:207:26: error: invalid use of undefined type 'struct kvm_pmu_events'
     207 |         events_host = pmu->events_host;
         |                          ^~
   In file included from include/asm-generic/percpu.h:7,
                    from arch/arm64/include/asm/percpu.h:248,
                    from arch/arm64/include/asm/smp.h:28,
                    from include/linux/smp.h:113,
                    from include/linux/percpu.h:7,
                    from include/linux/context_tracking_state.h:5,
                    from include/linux/hardirq.h:5,
                    from include/linux/kvm_host.h:7,
                    from arch/arm64/kvm/pmu.c:6:
   arch/arm64/kvm/pmu.c: At top level:
>> arch/arm64/kvm/pmu.c:9:46: error: storage size of 'kvm_pmu_events' isn't known
       9 | static DEFINE_PER_CPU(struct kvm_pmu_events, kvm_pmu_events);
         |                                              ^~~~~~~~~~~~~~
   include/linux/percpu-defs.h:104:44: note: in definition of macro 'DEFINE_PER_CPU_SECTION'
     104 |         __PCPU_ATTRS(sec) __typeof__(type) name
         |                                            ^~~~
   arch/arm64/kvm/pmu.c:9:8: note: in expansion of macro 'DEFINE_PER_CPU'
       9 | static DEFINE_PER_CPU(struct kvm_pmu_events, kvm_pmu_events);
         |        ^~~~~~~~~~~~~~
--
   arch/arm64/kvm/hyp/nvhe/switch.c: In function '__pmu_switch_to_guest':
>> arch/arm64/kvm/hyp/nvhe/switch.c:128:53: error: 'struct kvm_pmu' has no member named 'events'
     128 |         struct kvm_pmu_events *pmu = &vcpu->arch.pmu.events;
         |                                                     ^
>> arch/arm64/kvm/hyp/nvhe/switch.c:130:16: error: invalid use of undefined type 'struct kvm_pmu_events'
     130 |         if (pmu->events_host)
         |                ^~
   In file included from arch/arm64/include/asm/cputype.h:175,
                    from arch/arm64/include/asm/cache.h:8,
                    from include/linux/cache.h:6,
                    from include/linux/printk.h:9,
                    from include/asm-generic/bug.h:22,
                    from arch/arm64/include/asm/bug.h:26,
                    from include/linux/bug.h:5,
                    from include/linux/mmdebug.h:5,
                    from include/linux/percpu.h:5,
                    from include/linux/context_tracking_state.h:5,
                    from include/linux/hardirq.h:5,
                    from include/linux/kvm_host.h:7,
                    from arch/arm64/include/asm/kvm_emulate.h:14,
                    from arch/arm64/kvm/hyp/include/hyp/adjust_pc.h:13,
                    from arch/arm64/kvm/hyp/include/hyp/switch.h:10,
                    from arch/arm64/kvm/hyp/nvhe/switch.c:7:
   arch/arm64/kvm/hyp/nvhe/switch.c:131:33: error: invalid use of undefined type 'struct kvm_pmu_events'
     131 |                 write_sysreg(pmu->events_host, pmcntenclr_el0);
         |                                 ^~
   arch/arm64/include/asm/sysreg.h:1300:27: note: in definition of macro 'write_sysreg'
    1300 |         u64 __val = (u64)(v);                                   \
         |                           ^
   arch/arm64/kvm/hyp/nvhe/switch.c:133:16: error: invalid use of undefined type 'struct kvm_pmu_events'
     133 |         if (pmu->events_guest)
         |                ^~
   In file included from arch/arm64/include/asm/cputype.h:175,
                    from arch/arm64/include/asm/cache.h:8,
                    from include/linux/cache.h:6,
                    from include/linux/printk.h:9,
                    from include/asm-generic/bug.h:22,
                    from arch/arm64/include/asm/bug.h:26,
                    from include/linux/bug.h:5,
                    from include/linux/mmdebug.h:5,
                    from include/linux/percpu.h:5,
                    from include/linux/context_tracking_state.h:5,
                    from include/linux/hardirq.h:5,
                    from include/linux/kvm_host.h:7,
                    from arch/arm64/include/asm/kvm_emulate.h:14,
                    from arch/arm64/kvm/hyp/include/hyp/adjust_pc.h:13,
                    from arch/arm64/kvm/hyp/include/hyp/switch.h:10,
                    from arch/arm64/kvm/hyp/nvhe/switch.c:7:
   arch/arm64/kvm/hyp/nvhe/switch.c:134:33: error: invalid use of undefined type 'struct kvm_pmu_events'
     134 |                 write_sysreg(pmu->events_guest, pmcntenset_el0);
         |                                 ^~
   arch/arm64/include/asm/sysreg.h:1300:27: note: in definition of macro 'write_sysreg'
    1300 |         u64 __val = (u64)(v);                                   \
         |                           ^
   arch/arm64/kvm/hyp/nvhe/switch.c:136:20: error: invalid use of undefined type 'struct kvm_pmu_events'
     136 |         return (pmu->events_host || pmu->events_guest);
         |                    ^~
   arch/arm64/kvm/hyp/nvhe/switch.c:136:40: error: invalid use of undefined type 'struct kvm_pmu_events'
     136 |         return (pmu->events_host || pmu->events_guest);
         |                                        ^~
   arch/arm64/kvm/hyp/nvhe/switch.c: In function '__pmu_switch_to_host':
   arch/arm64/kvm/hyp/nvhe/switch.c:144:53: error: 'struct kvm_pmu' has no member named 'events'
     144 |         struct kvm_pmu_events *pmu = &vcpu->arch.pmu.events;
         |                                                     ^
   arch/arm64/kvm/hyp/nvhe/switch.c:146:16: error: invalid use of undefined type 'struct kvm_pmu_events'
     146 |         if (pmu->events_guest)
         |                ^~
   In file included from arch/arm64/include/asm/cputype.h:175,
                    from arch/arm64/include/asm/cache.h:8,
                    from include/linux/cache.h:6,
                    from include/linux/printk.h:9,
                    from include/asm-generic/bug.h:22,
                    from arch/arm64/include/asm/bug.h:26,
                    from include/linux/bug.h:5,
                    from include/linux/mmdebug.h:5,
                    from include/linux/percpu.h:5,
                    from include/linux/context_tracking_state.h:5,
                    from include/linux/hardirq.h:5,
                    from include/linux/kvm_host.h:7,
                    from arch/arm64/include/asm/kvm_emulate.h:14,
                    from arch/arm64/kvm/hyp/include/hyp/adjust_pc.h:13,
                    from arch/arm64/kvm/hyp/include/hyp/switch.h:10,
                    from arch/arm64/kvm/hyp/nvhe/switch.c:7:
   arch/arm64/kvm/hyp/nvhe/switch.c:147:33: error: invalid use of undefined type 'struct kvm_pmu_events'
     147 |                 write_sysreg(pmu->events_guest, pmcntenclr_el0);
         |                                 ^~
   arch/arm64/include/asm/sysreg.h:1300:27: note: in definition of macro 'write_sysreg'
    1300 |         u64 __val = (u64)(v);                                   \
         |                           ^
   arch/arm64/kvm/hyp/nvhe/switch.c:149:16: error: invalid use of undefined type 'struct kvm_pmu_events'
     149 |         if (pmu->events_host)
         |                ^~
   In file included from arch/arm64/include/asm/cputype.h:175,
                    from arch/arm64/include/asm/cache.h:8,
                    from include/linux/cache.h:6,
                    from include/linux/printk.h:9,
                    from include/asm-generic/bug.h:22,
                    from arch/arm64/include/asm/bug.h:26,
                    from include/linux/bug.h:5,
                    from include/linux/mmdebug.h:5,
                    from include/linux/percpu.h:5,
                    from include/linux/context_tracking_state.h:5,
                    from include/linux/hardirq.h:5,
                    from include/linux/kvm_host.h:7,
                    from arch/arm64/include/asm/kvm_emulate.h:14,


vim +764 arch/arm64/kvm/arm.c

   753	
   754	/*
   755	 * Updates the vcpu's view of the pmu events for this cpu.
   756	 * Must be called before every vcpu run after disabling interrupts, to ensure
   757	 * that an interrupt cannot fire and update the structure.
   758	 */
   759	static void kvm_pmu_update_vcpu_events(struct kvm_vcpu *vcpu)
   760	{
   761		if (has_vhe() || !kvm_vcpu_has_pmu(vcpu))
   762			return;
   763	
 > 764		vcpu->arch.pmu.events = *kvm_get_pmu_events();
   765	}
   766	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [arm-platforms:kvm-arm64/per-vcpu-host-pmu-data 3/4] arch/arm64/kvm/arm.c:764:23: error: 'struct kvm_pmu' has no member named 'events'
  2022-05-16 10:42 [arm-platforms:kvm-arm64/per-vcpu-host-pmu-data 3/4] arch/arm64/kvm/arm.c:764:23: error: 'struct kvm_pmu' has no member named 'events' kernel test robot
@ 2022-05-16 12:25   ` Marc Zyngier
  0 siblings, 0 replies; 5+ messages in thread
From: Marc Zyngier @ 2022-05-16 12:25 UTC (permalink / raw)
  To: kernel test robot; +Cc: Fuad Tabba, kbuild-all, linux-arm-kernel, Oliver Upton

On Mon, 16 May 2022 11:42:33 +0100,
kernel test robot <lkp@intel.com> wrote:
> 
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git kvm-arm64/per-vcpu-host-pmu-data
> head:   722625c6f4c5b6a9953d6af04c7bb1a6e12830b3
> commit: 84d751a019a9792f5b4884e1d598b603c360ec22 [3/4] KVM: arm64: Pass pmu events to hyp via vcpu
> config: arm64-randconfig-r022-20220516 (https://download.01.org/0day-ci/archive/20220516/202205161814.KQHpOzsJ-lkp@intel.com/config)
> compiler: aarch64-linux-gcc (GCC) 11.3.0
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/commit/?id=84d751a019a9792f5b4884e1d598b603c360ec22
>         git remote add arm-platforms https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git
>         git fetch --no-tags arm-platforms kvm-arm64/per-vcpu-host-pmu-data
>         git checkout 84d751a019a9792f5b4884e1d598b603c360ec22
>         # save the config file
>         mkdir build_dir && cp config build_dir/.config
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash arch/arm64/kvm/
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All errors (new ones prefixed by >>):
> 
>    arch/arm64/kvm/arm.c: In function 'kvm_pmu_update_vcpu_events':
> >> arch/arm64/kvm/arm.c:764:23: error: 'struct kvm_pmu' has no member named 'events'
>      764 |         vcpu->arch.pmu.events = *kvm_get_pmu_events();
>          |                       ^
> >> arch/arm64/kvm/arm.c:764:33: error: invalid use of undefined type 'struct kvm_pmu_events'
>      764 |         vcpu->arch.pmu.events = *kvm_get_pmu_events();
>          |                                 ^

[...]

Thanks for the heads up. That's the result of ARM_PMU not being
selected, which results in HW_PERF_EVENTS not being selected
either. From there, everything falls apart.

That's the result of really bad hygiene that has been going on
since... almost forever, with bits of code accessing the internals of
the PMU structures without much care. Let's pull things together and
allow the whole of the PMU code (with the exception of the sysreg
accessors) to be compiled out.

Fuad, can you please eyeball the patch below? If you're OK with it,
I'll slap that onto the branch.

Thanks,

	M.

From b25d64c6f4c9d266706a45dcd0a14ee4ca2d7d16 Mon Sep 17 00:00:00 2001
From: Marc Zyngier <maz@kernel.org>
Date: Mon, 16 May 2022 13:02:24 +0100
Subject: [PATCH] KVM: arm64: pmu: Restore compilation when HW_PERF_EVENTS
 isn't selected

Moving kvm_pmu_events into the vcpu (and refering to it) broke the
somewhat unusual case where the kernel has no support for a PMU
at all.

In order to solve this, move things around a bit so that we can
easily avoid refering to the pmu structure outside of PMU-aware
code. As a bonus, pmu.c isn't compiled in when HW_PERF_EVENTS
isn't selected.

Cc: Fuad Tabba <tabba@google.com>
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/202205161814.KQHpOzsJ-lkp@intel.com
---
 arch/arm64/include/asm/kvm_host.h |  6 ------
 arch/arm64/kvm/Makefile           |  4 ++--
 arch/arm64/kvm/arm.c              | 13 -------------
 arch/arm64/kvm/hyp/nvhe/switch.c  |  5 +++++
 include/kvm/arm_pmu.h             | 24 ++++++++++++++++++++++++
 5 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index efca5a63bdaf..ef774b8955bc 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -789,10 +789,6 @@ void kvm_arch_vcpu_put_debug_state_flags(struct kvm_vcpu *vcpu);
 #ifdef CONFIG_KVM
 void kvm_set_pmu_events(u32 set, struct perf_event_attr *attr);
 void kvm_clr_pmu_events(u32 clr);
-
-struct kvm_pmu_events *kvm_get_pmu_events(void);
-void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu);
-void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu);
 #else
 static inline void kvm_set_pmu_events(u32 set, struct perf_event_attr *attr) {}
 static inline void kvm_clr_pmu_events(u32 clr) {}
@@ -824,8 +820,6 @@ bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu);
 #define kvm_has_mte(kvm)					\
 	(system_supports_mte() &&				\
 	 test_bit(KVM_ARCH_FLAG_MTE_ENABLED, &(kvm)->arch.flags))
-#define kvm_vcpu_has_pmu(vcpu)					\
-	(test_bit(KVM_ARM_VCPU_PMU_V3, (vcpu)->arch.features))
 
 int kvm_trng_call(struct kvm_vcpu *vcpu);
 #ifdef CONFIG_KVM
diff --git a/arch/arm64/kvm/Makefile b/arch/arm64/kvm/Makefile
index 261644b1a6bb..aa127ae9f675 100644
--- a/arch/arm64/kvm/Makefile
+++ b/arch/arm64/kvm/Makefile
@@ -13,7 +13,7 @@ obj-$(CONFIG_KVM) += hyp/
 kvm-y += arm.o mmu.o mmio.o psci.o hypercalls.o pvtime.o \
 	 inject_fault.o va_layout.o handle_exit.o \
 	 guest.o debug.o reset.o sys_regs.o \
-	 vgic-sys-reg-v3.o fpsimd.o pmu.o pkvm.o \
+	 vgic-sys-reg-v3.o fpsimd.o pkvm.o \
 	 arch_timer.o trng.o vmid.o \
 	 vgic/vgic.o vgic/vgic-init.o \
 	 vgic/vgic-irqfd.o vgic/vgic-v2.o \
@@ -22,7 +22,7 @@ kvm-y += arm.o mmu.o mmio.o psci.o hypercalls.o pvtime.o \
 	 vgic/vgic-mmio-v3.o vgic/vgic-kvm-device.o \
 	 vgic/vgic-its.o vgic/vgic-debug.o
 
-kvm-$(CONFIG_HW_PERF_EVENTS)  += pmu-emul.o
+kvm-$(CONFIG_HW_PERF_EVENTS)  += pmu-emul.o pmu.o
 
 always-y := hyp_constants.h hyp-constants.s
 
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index aa1b15e9d5d9..b3821c430ec9 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -751,19 +751,6 @@ static int noinstr kvm_arm_vcpu_enter_exit(struct kvm_vcpu *vcpu)
 	return ret;
 }
 
-/*
- * Updates the vcpu's view of the pmu events for this cpu.
- * Must be called before every vcpu run after disabling interrupts, to ensure
- * that an interrupt cannot fire and update the structure.
- */
-static void kvm_pmu_update_vcpu_events(struct kvm_vcpu *vcpu)
-{
-	if (has_vhe() || !kvm_vcpu_has_pmu(vcpu))
-		return;
-
-	vcpu->arch.pmu.events = *kvm_get_pmu_events();
-}
-
 /**
  * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code
  * @vcpu:	The VCPU pointer
diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c
index ff7b29fb9787..c7cd2036a75e 100644
--- a/arch/arm64/kvm/hyp/nvhe/switch.c
+++ b/arch/arm64/kvm/hyp/nvhe/switch.c
@@ -123,6 +123,7 @@ static void __hyp_vgic_restore_state(struct kvm_vcpu *vcpu)
 /**
  * Disable host events, enable guest events
  */
+#ifdef CONFIG_HW_PERF_EVENTS
 static bool __pmu_switch_to_guest(struct kvm_vcpu *vcpu)
 {
 	struct kvm_pmu_events *pmu = &vcpu->arch.pmu.events;
@@ -149,6 +150,10 @@ static void __pmu_switch_to_host(struct kvm_vcpu *vcpu)
 	if (pmu->events_host)
 		write_sysreg(pmu->events_host, pmcntenset_el0);
 }
+#else
+#define __pmu_switch_to_guest(v)	({ false; })
+#define __pmu_switch_to_host(v)		do {} while (0)
+#endif
 
 /**
  * Handler for protected VM MSR, MRS or System instruction execution in AArch64.
diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h
index 35a0903cae32..c0b868ce6a8f 100644
--- a/include/kvm/arm_pmu.h
+++ b/include/kvm/arm_pmu.h
@@ -72,6 +72,25 @@ int kvm_arm_pmu_v3_get_attr(struct kvm_vcpu *vcpu,
 int kvm_arm_pmu_v3_has_attr(struct kvm_vcpu *vcpu,
 			    struct kvm_device_attr *attr);
 int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu);
+
+struct kvm_pmu_events *kvm_get_pmu_events(void);
+void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu);
+void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu);
+
+#define kvm_vcpu_has_pmu(vcpu)					\
+	(test_bit(KVM_ARM_VCPU_PMU_V3, (vcpu)->arch.features))
+
+/*
+ * Updates the vcpu's view of the pmu events for this cpu.
+ * Must be called before every vcpu run after disabling interrupts, to ensure
+ * that an interrupt cannot fire and update the structure.
+ */
+#define kvm_pmu_update_vcpu_events(vcpu)				\
+	do {								\
+		if (!has_vhe() && kvm_vcpu_has_pmu(vcpu))		\
+			vcpu->arch.pmu.events = *kvm_get_pmu_events();	\
+	} while (0)
+
 #else
 struct kvm_pmu {
 };
@@ -133,6 +152,11 @@ static inline u64 kvm_pmu_get_pmceid(struct kvm_vcpu *vcpu, bool pmceid1)
 	return 0;
 }
 
+#define kvm_vcpu_has_pmu(vcpu)		({ false; })
+static inline void kvm_pmu_update_vcpu_events(struct kvm_vcpu *vcpu) {}
+static inline void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu) {}
+static inline void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu) {}
+
 #endif
 
 #endif
-- 
2.34.1


-- 
Without deviation from the norm, progress is not possible.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [arm-platforms:kvm-arm64/per-vcpu-host-pmu-data 3/4] arch/arm64/kvm/arm.c:764:23: error: 'struct kvm_pmu' has no member named 'events'
@ 2022-05-16 12:25   ` Marc Zyngier
  0 siblings, 0 replies; 5+ messages in thread
From: Marc Zyngier @ 2022-05-16 12:25 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 8879 bytes --]

On Mon, 16 May 2022 11:42:33 +0100,
kernel test robot <lkp@intel.com> wrote:
> 
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git kvm-arm64/per-vcpu-host-pmu-data
> head:   722625c6f4c5b6a9953d6af04c7bb1a6e12830b3
> commit: 84d751a019a9792f5b4884e1d598b603c360ec22 [3/4] KVM: arm64: Pass pmu events to hyp via vcpu
> config: arm64-randconfig-r022-20220516 (https://download.01.org/0day-ci/archive/20220516/202205161814.KQHpOzsJ-lkp(a)intel.com/config)
> compiler: aarch64-linux-gcc (GCC) 11.3.0
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/commit/?id=84d751a019a9792f5b4884e1d598b603c360ec22
>         git remote add arm-platforms https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git
>         git fetch --no-tags arm-platforms kvm-arm64/per-vcpu-host-pmu-data
>         git checkout 84d751a019a9792f5b4884e1d598b603c360ec22
>         # save the config file
>         mkdir build_dir && cp config build_dir/.config
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash arch/arm64/kvm/
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All errors (new ones prefixed by >>):
> 
>    arch/arm64/kvm/arm.c: In function 'kvm_pmu_update_vcpu_events':
> >> arch/arm64/kvm/arm.c:764:23: error: 'struct kvm_pmu' has no member named 'events'
>      764 |         vcpu->arch.pmu.events = *kvm_get_pmu_events();
>          |                       ^
> >> arch/arm64/kvm/arm.c:764:33: error: invalid use of undefined type 'struct kvm_pmu_events'
>      764 |         vcpu->arch.pmu.events = *kvm_get_pmu_events();
>          |                                 ^

[...]

Thanks for the heads up. That's the result of ARM_PMU not being
selected, which results in HW_PERF_EVENTS not being selected
either. From there, everything falls apart.

That's the result of really bad hygiene that has been going on
since... almost forever, with bits of code accessing the internals of
the PMU structures without much care. Let's pull things together and
allow the whole of the PMU code (with the exception of the sysreg
accessors) to be compiled out.

Fuad, can you please eyeball the patch below? If you're OK with it,
I'll slap that onto the branch.

Thanks,

	M.

>From b25d64c6f4c9d266706a45dcd0a14ee4ca2d7d16 Mon Sep 17 00:00:00 2001
From: Marc Zyngier <maz@kernel.org>
Date: Mon, 16 May 2022 13:02:24 +0100
Subject: [PATCH] KVM: arm64: pmu: Restore compilation when HW_PERF_EVENTS
 isn't selected

Moving kvm_pmu_events into the vcpu (and refering to it) broke the
somewhat unusual case where the kernel has no support for a PMU
at all.

In order to solve this, move things around a bit so that we can
easily avoid refering to the pmu structure outside of PMU-aware
code. As a bonus, pmu.c isn't compiled in when HW_PERF_EVENTS
isn't selected.

Cc: Fuad Tabba <tabba@google.com>
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/202205161814.KQHpOzsJ-lkp(a)intel.com
---
 arch/arm64/include/asm/kvm_host.h |  6 ------
 arch/arm64/kvm/Makefile           |  4 ++--
 arch/arm64/kvm/arm.c              | 13 -------------
 arch/arm64/kvm/hyp/nvhe/switch.c  |  5 +++++
 include/kvm/arm_pmu.h             | 24 ++++++++++++++++++++++++
 5 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index efca5a63bdaf..ef774b8955bc 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -789,10 +789,6 @@ void kvm_arch_vcpu_put_debug_state_flags(struct kvm_vcpu *vcpu);
 #ifdef CONFIG_KVM
 void kvm_set_pmu_events(u32 set, struct perf_event_attr *attr);
 void kvm_clr_pmu_events(u32 clr);
-
-struct kvm_pmu_events *kvm_get_pmu_events(void);
-void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu);
-void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu);
 #else
 static inline void kvm_set_pmu_events(u32 set, struct perf_event_attr *attr) {}
 static inline void kvm_clr_pmu_events(u32 clr) {}
@@ -824,8 +820,6 @@ bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu);
 #define kvm_has_mte(kvm)					\
 	(system_supports_mte() &&				\
 	 test_bit(KVM_ARCH_FLAG_MTE_ENABLED, &(kvm)->arch.flags))
-#define kvm_vcpu_has_pmu(vcpu)					\
-	(test_bit(KVM_ARM_VCPU_PMU_V3, (vcpu)->arch.features))
 
 int kvm_trng_call(struct kvm_vcpu *vcpu);
 #ifdef CONFIG_KVM
diff --git a/arch/arm64/kvm/Makefile b/arch/arm64/kvm/Makefile
index 261644b1a6bb..aa127ae9f675 100644
--- a/arch/arm64/kvm/Makefile
+++ b/arch/arm64/kvm/Makefile
@@ -13,7 +13,7 @@ obj-$(CONFIG_KVM) += hyp/
 kvm-y += arm.o mmu.o mmio.o psci.o hypercalls.o pvtime.o \
 	 inject_fault.o va_layout.o handle_exit.o \
 	 guest.o debug.o reset.o sys_regs.o \
-	 vgic-sys-reg-v3.o fpsimd.o pmu.o pkvm.o \
+	 vgic-sys-reg-v3.o fpsimd.o pkvm.o \
 	 arch_timer.o trng.o vmid.o \
 	 vgic/vgic.o vgic/vgic-init.o \
 	 vgic/vgic-irqfd.o vgic/vgic-v2.o \
@@ -22,7 +22,7 @@ kvm-y += arm.o mmu.o mmio.o psci.o hypercalls.o pvtime.o \
 	 vgic/vgic-mmio-v3.o vgic/vgic-kvm-device.o \
 	 vgic/vgic-its.o vgic/vgic-debug.o
 
-kvm-$(CONFIG_HW_PERF_EVENTS)  += pmu-emul.o
+kvm-$(CONFIG_HW_PERF_EVENTS)  += pmu-emul.o pmu.o
 
 always-y := hyp_constants.h hyp-constants.s
 
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index aa1b15e9d5d9..b3821c430ec9 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -751,19 +751,6 @@ static int noinstr kvm_arm_vcpu_enter_exit(struct kvm_vcpu *vcpu)
 	return ret;
 }
 
-/*
- * Updates the vcpu's view of the pmu events for this cpu.
- * Must be called before every vcpu run after disabling interrupts, to ensure
- * that an interrupt cannot fire and update the structure.
- */
-static void kvm_pmu_update_vcpu_events(struct kvm_vcpu *vcpu)
-{
-	if (has_vhe() || !kvm_vcpu_has_pmu(vcpu))
-		return;
-
-	vcpu->arch.pmu.events = *kvm_get_pmu_events();
-}
-
 /**
  * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code
  * @vcpu:	The VCPU pointer
diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c
index ff7b29fb9787..c7cd2036a75e 100644
--- a/arch/arm64/kvm/hyp/nvhe/switch.c
+++ b/arch/arm64/kvm/hyp/nvhe/switch.c
@@ -123,6 +123,7 @@ static void __hyp_vgic_restore_state(struct kvm_vcpu *vcpu)
 /**
  * Disable host events, enable guest events
  */
+#ifdef CONFIG_HW_PERF_EVENTS
 static bool __pmu_switch_to_guest(struct kvm_vcpu *vcpu)
 {
 	struct kvm_pmu_events *pmu = &vcpu->arch.pmu.events;
@@ -149,6 +150,10 @@ static void __pmu_switch_to_host(struct kvm_vcpu *vcpu)
 	if (pmu->events_host)
 		write_sysreg(pmu->events_host, pmcntenset_el0);
 }
+#else
+#define __pmu_switch_to_guest(v)	({ false; })
+#define __pmu_switch_to_host(v)		do {} while (0)
+#endif
 
 /**
  * Handler for protected VM MSR, MRS or System instruction execution in AArch64.
diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h
index 35a0903cae32..c0b868ce6a8f 100644
--- a/include/kvm/arm_pmu.h
+++ b/include/kvm/arm_pmu.h
@@ -72,6 +72,25 @@ int kvm_arm_pmu_v3_get_attr(struct kvm_vcpu *vcpu,
 int kvm_arm_pmu_v3_has_attr(struct kvm_vcpu *vcpu,
 			    struct kvm_device_attr *attr);
 int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu);
+
+struct kvm_pmu_events *kvm_get_pmu_events(void);
+void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu);
+void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu);
+
+#define kvm_vcpu_has_pmu(vcpu)					\
+	(test_bit(KVM_ARM_VCPU_PMU_V3, (vcpu)->arch.features))
+
+/*
+ * Updates the vcpu's view of the pmu events for this cpu.
+ * Must be called before every vcpu run after disabling interrupts, to ensure
+ * that an interrupt cannot fire and update the structure.
+ */
+#define kvm_pmu_update_vcpu_events(vcpu)				\
+	do {								\
+		if (!has_vhe() && kvm_vcpu_has_pmu(vcpu))		\
+			vcpu->arch.pmu.events = *kvm_get_pmu_events();	\
+	} while (0)
+
 #else
 struct kvm_pmu {
 };
@@ -133,6 +152,11 @@ static inline u64 kvm_pmu_get_pmceid(struct kvm_vcpu *vcpu, bool pmceid1)
 	return 0;
 }
 
+#define kvm_vcpu_has_pmu(vcpu)		({ false; })
+static inline void kvm_pmu_update_vcpu_events(struct kvm_vcpu *vcpu) {}
+static inline void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu) {}
+static inline void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu) {}
+
 #endif
 
 #endif
-- 
2.34.1


-- 
Without deviation from the norm, progress is not possible.

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [arm-platforms:kvm-arm64/per-vcpu-host-pmu-data 3/4] arch/arm64/kvm/arm.c:764:23: error: 'struct kvm_pmu' has no member named 'events'
  2022-05-16 12:25   ` Marc Zyngier
@ 2022-05-16 12:37     ` Fuad Tabba
  -1 siblings, 0 replies; 5+ messages in thread
From: Fuad Tabba @ 2022-05-16 12:37 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: kernel test robot, kbuild-all, linux-arm-kernel, Oliver Upton

Hi Marc,



On Mon, May 16, 2022 at 1:25 PM Marc Zyngier <maz@kernel.org> wrote:
>
> On Mon, 16 May 2022 11:42:33 +0100,
> kernel test robot <lkp@intel.com> wrote:
> >
> > tree:   https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git kvm-arm64/per-vcpu-host-pmu-data
> > head:   722625c6f4c5b6a9953d6af04c7bb1a6e12830b3
> > commit: 84d751a019a9792f5b4884e1d598b603c360ec22 [3/4] KVM: arm64: Pass pmu events to hyp via vcpu
> > config: arm64-randconfig-r022-20220516 (https://download.01.org/0day-ci/archive/20220516/202205161814.KQHpOzsJ-lkp@intel.com/config)
> > compiler: aarch64-linux-gcc (GCC) 11.3.0
> > reproduce (this is a W=1 build):
> >         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> >         chmod +x ~/bin/make.cross
> >         # https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/commit/?id=84d751a019a9792f5b4884e1d598b603c360ec22
> >         git remote add arm-platforms https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git
> >         git fetch --no-tags arm-platforms kvm-arm64/per-vcpu-host-pmu-data
> >         git checkout 84d751a019a9792f5b4884e1d598b603c360ec22
> >         # save the config file
> >         mkdir build_dir && cp config build_dir/.config
> >         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash arch/arm64/kvm/
> >
> > If you fix the issue, kindly add following tag as appropriate
> > Reported-by: kernel test robot <lkp@intel.com>
> >
> > All errors (new ones prefixed by >>):
> >
> >    arch/arm64/kvm/arm.c: In function 'kvm_pmu_update_vcpu_events':
> > >> arch/arm64/kvm/arm.c:764:23: error: 'struct kvm_pmu' has no member named 'events'
> >      764 |         vcpu->arch.pmu.events = *kvm_get_pmu_events();
> >          |                       ^
> > >> arch/arm64/kvm/arm.c:764:33: error: invalid use of undefined type 'struct kvm_pmu_events'
> >      764 |         vcpu->arch.pmu.events = *kvm_get_pmu_events();
> >          |                                 ^
>
> [...]
>
> Thanks for the heads up. That's the result of ARM_PMU not being
> selected, which results in HW_PERF_EVENTS not being selected
> either. From there, everything falls apart.
>
> That's the result of really bad hygiene that has been going on
> since... almost forever, with bits of code accessing the internals of
> the PMU structures without much care. Let's pull things together and
> allow the whole of the PMU code (with the exception of the sysreg
> accessors) to be compiled out.
>
> Fuad, can you please eyeball the patch below? If you're OK with it,
> I'll slap that onto the branch.

LGTM. Thanks for fixing that.

Reviewed-by: Fuad Tabba <tabba@google.com>

Cheers,
/fuad

>
> Thanks,
>
>         M.
>
> From b25d64c6f4c9d266706a45dcd0a14ee4ca2d7d16 Mon Sep 17 00:00:00 2001
> From: Marc Zyngier <maz@kernel.org>
> Date: Mon, 16 May 2022 13:02:24 +0100
> Subject: [PATCH] KVM: arm64: pmu: Restore compilation when HW_PERF_EVENTS
>  isn't selected
>
> Moving kvm_pmu_events into the vcpu (and refering to it) broke the
> somewhat unusual case where the kernel has no support for a PMU
> at all.
>
> In order to solve this, move things around a bit so that we can
> easily avoid refering to the pmu structure outside of PMU-aware
> code. As a bonus, pmu.c isn't compiled in when HW_PERF_EVENTS
> isn't selected.
>
> Cc: Fuad Tabba <tabba@google.com>
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> Link: https://lore.kernel.org/r/202205161814.KQHpOzsJ-lkp@intel.com
> ---
>  arch/arm64/include/asm/kvm_host.h |  6 ------
>  arch/arm64/kvm/Makefile           |  4 ++--
>  arch/arm64/kvm/arm.c              | 13 -------------
>  arch/arm64/kvm/hyp/nvhe/switch.c  |  5 +++++
>  include/kvm/arm_pmu.h             | 24 ++++++++++++++++++++++++
>  5 files changed, 31 insertions(+), 21 deletions(-)
>
> diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
> index efca5a63bdaf..ef774b8955bc 100644
> --- a/arch/arm64/include/asm/kvm_host.h
> +++ b/arch/arm64/include/asm/kvm_host.h
> @@ -789,10 +789,6 @@ void kvm_arch_vcpu_put_debug_state_flags(struct kvm_vcpu *vcpu);
>  #ifdef CONFIG_KVM
>  void kvm_set_pmu_events(u32 set, struct perf_event_attr *attr);
>  void kvm_clr_pmu_events(u32 clr);
> -
> -struct kvm_pmu_events *kvm_get_pmu_events(void);
> -void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu);
> -void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu);
>  #else
>  static inline void kvm_set_pmu_events(u32 set, struct perf_event_attr *attr) {}
>  static inline void kvm_clr_pmu_events(u32 clr) {}
> @@ -824,8 +820,6 @@ bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu);
>  #define kvm_has_mte(kvm)                                       \
>         (system_supports_mte() &&                               \
>          test_bit(KVM_ARCH_FLAG_MTE_ENABLED, &(kvm)->arch.flags))
> -#define kvm_vcpu_has_pmu(vcpu)                                 \
> -       (test_bit(KVM_ARM_VCPU_PMU_V3, (vcpu)->arch.features))
>
>  int kvm_trng_call(struct kvm_vcpu *vcpu);
>  #ifdef CONFIG_KVM
> diff --git a/arch/arm64/kvm/Makefile b/arch/arm64/kvm/Makefile
> index 261644b1a6bb..aa127ae9f675 100644
> --- a/arch/arm64/kvm/Makefile
> +++ b/arch/arm64/kvm/Makefile
> @@ -13,7 +13,7 @@ obj-$(CONFIG_KVM) += hyp/
>  kvm-y += arm.o mmu.o mmio.o psci.o hypercalls.o pvtime.o \
>          inject_fault.o va_layout.o handle_exit.o \
>          guest.o debug.o reset.o sys_regs.o \
> -        vgic-sys-reg-v3.o fpsimd.o pmu.o pkvm.o \
> +        vgic-sys-reg-v3.o fpsimd.o pkvm.o \
>          arch_timer.o trng.o vmid.o \
>          vgic/vgic.o vgic/vgic-init.o \
>          vgic/vgic-irqfd.o vgic/vgic-v2.o \
> @@ -22,7 +22,7 @@ kvm-y += arm.o mmu.o mmio.o psci.o hypercalls.o pvtime.o \
>          vgic/vgic-mmio-v3.o vgic/vgic-kvm-device.o \
>          vgic/vgic-its.o vgic/vgic-debug.o
>
> -kvm-$(CONFIG_HW_PERF_EVENTS)  += pmu-emul.o
> +kvm-$(CONFIG_HW_PERF_EVENTS)  += pmu-emul.o pmu.o
>
>  always-y := hyp_constants.h hyp-constants.s
>
> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> index aa1b15e9d5d9..b3821c430ec9 100644
> --- a/arch/arm64/kvm/arm.c
> +++ b/arch/arm64/kvm/arm.c
> @@ -751,19 +751,6 @@ static int noinstr kvm_arm_vcpu_enter_exit(struct kvm_vcpu *vcpu)
>         return ret;
>  }
>
> -/*
> - * Updates the vcpu's view of the pmu events for this cpu.
> - * Must be called before every vcpu run after disabling interrupts, to ensure
> - * that an interrupt cannot fire and update the structure.
> - */
> -static void kvm_pmu_update_vcpu_events(struct kvm_vcpu *vcpu)
> -{
> -       if (has_vhe() || !kvm_vcpu_has_pmu(vcpu))
> -               return;
> -
> -       vcpu->arch.pmu.events = *kvm_get_pmu_events();
> -}
> -
>  /**
>   * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code
>   * @vcpu:      The VCPU pointer
> diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c
> index ff7b29fb9787..c7cd2036a75e 100644
> --- a/arch/arm64/kvm/hyp/nvhe/switch.c
> +++ b/arch/arm64/kvm/hyp/nvhe/switch.c
> @@ -123,6 +123,7 @@ static void __hyp_vgic_restore_state(struct kvm_vcpu *vcpu)
>  /**
>   * Disable host events, enable guest events
>   */
> +#ifdef CONFIG_HW_PERF_EVENTS
>  static bool __pmu_switch_to_guest(struct kvm_vcpu *vcpu)
>  {
>         struct kvm_pmu_events *pmu = &vcpu->arch.pmu.events;
> @@ -149,6 +150,10 @@ static void __pmu_switch_to_host(struct kvm_vcpu *vcpu)
>         if (pmu->events_host)
>                 write_sysreg(pmu->events_host, pmcntenset_el0);
>  }
> +#else
> +#define __pmu_switch_to_guest(v)       ({ false; })
> +#define __pmu_switch_to_host(v)                do {} while (0)
> +#endif
>
>  /**
>   * Handler for protected VM MSR, MRS or System instruction execution in AArch64.
> diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h
> index 35a0903cae32..c0b868ce6a8f 100644
> --- a/include/kvm/arm_pmu.h
> +++ b/include/kvm/arm_pmu.h
> @@ -72,6 +72,25 @@ int kvm_arm_pmu_v3_get_attr(struct kvm_vcpu *vcpu,
>  int kvm_arm_pmu_v3_has_attr(struct kvm_vcpu *vcpu,
>                             struct kvm_device_attr *attr);
>  int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu);
> +
> +struct kvm_pmu_events *kvm_get_pmu_events(void);
> +void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu);
> +void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu);
> +
> +#define kvm_vcpu_has_pmu(vcpu)                                 \
> +       (test_bit(KVM_ARM_VCPU_PMU_V3, (vcpu)->arch.features))
> +
> +/*
> + * Updates the vcpu's view of the pmu events for this cpu.
> + * Must be called before every vcpu run after disabling interrupts, to ensure
> + * that an interrupt cannot fire and update the structure.
> + */
> +#define kvm_pmu_update_vcpu_events(vcpu)                               \
> +       do {                                                            \
> +               if (!has_vhe() && kvm_vcpu_has_pmu(vcpu))               \
> +                       vcpu->arch.pmu.events = *kvm_get_pmu_events();  \
> +       } while (0)
> +
>  #else
>  struct kvm_pmu {
>  };
> @@ -133,6 +152,11 @@ static inline u64 kvm_pmu_get_pmceid(struct kvm_vcpu *vcpu, bool pmceid1)
>         return 0;
>  }
>
> +#define kvm_vcpu_has_pmu(vcpu)         ({ false; })
> +static inline void kvm_pmu_update_vcpu_events(struct kvm_vcpu *vcpu) {}
> +static inline void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu) {}
> +static inline void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu) {}
> +
>  #endif
>
>  #endif
> --
> 2.34.1
>
>
> --
> Without deviation from the norm, progress is not possible.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [arm-platforms:kvm-arm64/per-vcpu-host-pmu-data 3/4] arch/arm64/kvm/arm.c:764:23: error: 'struct kvm_pmu' has no member named 'events'
@ 2022-05-16 12:37     ` Fuad Tabba
  0 siblings, 0 replies; 5+ messages in thread
From: Fuad Tabba @ 2022-05-16 12:37 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 9923 bytes --]

Hi Marc,



On Mon, May 16, 2022 at 1:25 PM Marc Zyngier <maz@kernel.org> wrote:
>
> On Mon, 16 May 2022 11:42:33 +0100,
> kernel test robot <lkp@intel.com> wrote:
> >
> > tree:   https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git kvm-arm64/per-vcpu-host-pmu-data
> > head:   722625c6f4c5b6a9953d6af04c7bb1a6e12830b3
> > commit: 84d751a019a9792f5b4884e1d598b603c360ec22 [3/4] KVM: arm64: Pass pmu events to hyp via vcpu
> > config: arm64-randconfig-r022-20220516 (https://download.01.org/0day-ci/archive/20220516/202205161814.KQHpOzsJ-lkp(a)intel.com/config)
> > compiler: aarch64-linux-gcc (GCC) 11.3.0
> > reproduce (this is a W=1 build):
> >         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> >         chmod +x ~/bin/make.cross
> >         # https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/commit/?id=84d751a019a9792f5b4884e1d598b603c360ec22
> >         git remote add arm-platforms https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git
> >         git fetch --no-tags arm-platforms kvm-arm64/per-vcpu-host-pmu-data
> >         git checkout 84d751a019a9792f5b4884e1d598b603c360ec22
> >         # save the config file
> >         mkdir build_dir && cp config build_dir/.config
> >         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash arch/arm64/kvm/
> >
> > If you fix the issue, kindly add following tag as appropriate
> > Reported-by: kernel test robot <lkp@intel.com>
> >
> > All errors (new ones prefixed by >>):
> >
> >    arch/arm64/kvm/arm.c: In function 'kvm_pmu_update_vcpu_events':
> > >> arch/arm64/kvm/arm.c:764:23: error: 'struct kvm_pmu' has no member named 'events'
> >      764 |         vcpu->arch.pmu.events = *kvm_get_pmu_events();
> >          |                       ^
> > >> arch/arm64/kvm/arm.c:764:33: error: invalid use of undefined type 'struct kvm_pmu_events'
> >      764 |         vcpu->arch.pmu.events = *kvm_get_pmu_events();
> >          |                                 ^
>
> [...]
>
> Thanks for the heads up. That's the result of ARM_PMU not being
> selected, which results in HW_PERF_EVENTS not being selected
> either. From there, everything falls apart.
>
> That's the result of really bad hygiene that has been going on
> since... almost forever, with bits of code accessing the internals of
> the PMU structures without much care. Let's pull things together and
> allow the whole of the PMU code (with the exception of the sysreg
> accessors) to be compiled out.
>
> Fuad, can you please eyeball the patch below? If you're OK with it,
> I'll slap that onto the branch.

LGTM. Thanks for fixing that.

Reviewed-by: Fuad Tabba <tabba@google.com>

Cheers,
/fuad

>
> Thanks,
>
>         M.
>
> From b25d64c6f4c9d266706a45dcd0a14ee4ca2d7d16 Mon Sep 17 00:00:00 2001
> From: Marc Zyngier <maz@kernel.org>
> Date: Mon, 16 May 2022 13:02:24 +0100
> Subject: [PATCH] KVM: arm64: pmu: Restore compilation when HW_PERF_EVENTS
>  isn't selected
>
> Moving kvm_pmu_events into the vcpu (and refering to it) broke the
> somewhat unusual case where the kernel has no support for a PMU
> at all.
>
> In order to solve this, move things around a bit so that we can
> easily avoid refering to the pmu structure outside of PMU-aware
> code. As a bonus, pmu.c isn't compiled in when HW_PERF_EVENTS
> isn't selected.
>
> Cc: Fuad Tabba <tabba@google.com>
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> Link: https://lore.kernel.org/r/202205161814.KQHpOzsJ-lkp(a)intel.com
> ---
>  arch/arm64/include/asm/kvm_host.h |  6 ------
>  arch/arm64/kvm/Makefile           |  4 ++--
>  arch/arm64/kvm/arm.c              | 13 -------------
>  arch/arm64/kvm/hyp/nvhe/switch.c  |  5 +++++
>  include/kvm/arm_pmu.h             | 24 ++++++++++++++++++++++++
>  5 files changed, 31 insertions(+), 21 deletions(-)
>
> diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
> index efca5a63bdaf..ef774b8955bc 100644
> --- a/arch/arm64/include/asm/kvm_host.h
> +++ b/arch/arm64/include/asm/kvm_host.h
> @@ -789,10 +789,6 @@ void kvm_arch_vcpu_put_debug_state_flags(struct kvm_vcpu *vcpu);
>  #ifdef CONFIG_KVM
>  void kvm_set_pmu_events(u32 set, struct perf_event_attr *attr);
>  void kvm_clr_pmu_events(u32 clr);
> -
> -struct kvm_pmu_events *kvm_get_pmu_events(void);
> -void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu);
> -void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu);
>  #else
>  static inline void kvm_set_pmu_events(u32 set, struct perf_event_attr *attr) {}
>  static inline void kvm_clr_pmu_events(u32 clr) {}
> @@ -824,8 +820,6 @@ bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu);
>  #define kvm_has_mte(kvm)                                       \
>         (system_supports_mte() &&                               \
>          test_bit(KVM_ARCH_FLAG_MTE_ENABLED, &(kvm)->arch.flags))
> -#define kvm_vcpu_has_pmu(vcpu)                                 \
> -       (test_bit(KVM_ARM_VCPU_PMU_V3, (vcpu)->arch.features))
>
>  int kvm_trng_call(struct kvm_vcpu *vcpu);
>  #ifdef CONFIG_KVM
> diff --git a/arch/arm64/kvm/Makefile b/arch/arm64/kvm/Makefile
> index 261644b1a6bb..aa127ae9f675 100644
> --- a/arch/arm64/kvm/Makefile
> +++ b/arch/arm64/kvm/Makefile
> @@ -13,7 +13,7 @@ obj-$(CONFIG_KVM) += hyp/
>  kvm-y += arm.o mmu.o mmio.o psci.o hypercalls.o pvtime.o \
>          inject_fault.o va_layout.o handle_exit.o \
>          guest.o debug.o reset.o sys_regs.o \
> -        vgic-sys-reg-v3.o fpsimd.o pmu.o pkvm.o \
> +        vgic-sys-reg-v3.o fpsimd.o pkvm.o \
>          arch_timer.o trng.o vmid.o \
>          vgic/vgic.o vgic/vgic-init.o \
>          vgic/vgic-irqfd.o vgic/vgic-v2.o \
> @@ -22,7 +22,7 @@ kvm-y += arm.o mmu.o mmio.o psci.o hypercalls.o pvtime.o \
>          vgic/vgic-mmio-v3.o vgic/vgic-kvm-device.o \
>          vgic/vgic-its.o vgic/vgic-debug.o
>
> -kvm-$(CONFIG_HW_PERF_EVENTS)  += pmu-emul.o
> +kvm-$(CONFIG_HW_PERF_EVENTS)  += pmu-emul.o pmu.o
>
>  always-y := hyp_constants.h hyp-constants.s
>
> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> index aa1b15e9d5d9..b3821c430ec9 100644
> --- a/arch/arm64/kvm/arm.c
> +++ b/arch/arm64/kvm/arm.c
> @@ -751,19 +751,6 @@ static int noinstr kvm_arm_vcpu_enter_exit(struct kvm_vcpu *vcpu)
>         return ret;
>  }
>
> -/*
> - * Updates the vcpu's view of the pmu events for this cpu.
> - * Must be called before every vcpu run after disabling interrupts, to ensure
> - * that an interrupt cannot fire and update the structure.
> - */
> -static void kvm_pmu_update_vcpu_events(struct kvm_vcpu *vcpu)
> -{
> -       if (has_vhe() || !kvm_vcpu_has_pmu(vcpu))
> -               return;
> -
> -       vcpu->arch.pmu.events = *kvm_get_pmu_events();
> -}
> -
>  /**
>   * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code
>   * @vcpu:      The VCPU pointer
> diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c
> index ff7b29fb9787..c7cd2036a75e 100644
> --- a/arch/arm64/kvm/hyp/nvhe/switch.c
> +++ b/arch/arm64/kvm/hyp/nvhe/switch.c
> @@ -123,6 +123,7 @@ static void __hyp_vgic_restore_state(struct kvm_vcpu *vcpu)
>  /**
>   * Disable host events, enable guest events
>   */
> +#ifdef CONFIG_HW_PERF_EVENTS
>  static bool __pmu_switch_to_guest(struct kvm_vcpu *vcpu)
>  {
>         struct kvm_pmu_events *pmu = &vcpu->arch.pmu.events;
> @@ -149,6 +150,10 @@ static void __pmu_switch_to_host(struct kvm_vcpu *vcpu)
>         if (pmu->events_host)
>                 write_sysreg(pmu->events_host, pmcntenset_el0);
>  }
> +#else
> +#define __pmu_switch_to_guest(v)       ({ false; })
> +#define __pmu_switch_to_host(v)                do {} while (0)
> +#endif
>
>  /**
>   * Handler for protected VM MSR, MRS or System instruction execution in AArch64.
> diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h
> index 35a0903cae32..c0b868ce6a8f 100644
> --- a/include/kvm/arm_pmu.h
> +++ b/include/kvm/arm_pmu.h
> @@ -72,6 +72,25 @@ int kvm_arm_pmu_v3_get_attr(struct kvm_vcpu *vcpu,
>  int kvm_arm_pmu_v3_has_attr(struct kvm_vcpu *vcpu,
>                             struct kvm_device_attr *attr);
>  int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu);
> +
> +struct kvm_pmu_events *kvm_get_pmu_events(void);
> +void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu);
> +void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu);
> +
> +#define kvm_vcpu_has_pmu(vcpu)                                 \
> +       (test_bit(KVM_ARM_VCPU_PMU_V3, (vcpu)->arch.features))
> +
> +/*
> + * Updates the vcpu's view of the pmu events for this cpu.
> + * Must be called before every vcpu run after disabling interrupts, to ensure
> + * that an interrupt cannot fire and update the structure.
> + */
> +#define kvm_pmu_update_vcpu_events(vcpu)                               \
> +       do {                                                            \
> +               if (!has_vhe() && kvm_vcpu_has_pmu(vcpu))               \
> +                       vcpu->arch.pmu.events = *kvm_get_pmu_events();  \
> +       } while (0)
> +
>  #else
>  struct kvm_pmu {
>  };
> @@ -133,6 +152,11 @@ static inline u64 kvm_pmu_get_pmceid(struct kvm_vcpu *vcpu, bool pmceid1)
>         return 0;
>  }
>
> +#define kvm_vcpu_has_pmu(vcpu)         ({ false; })
> +static inline void kvm_pmu_update_vcpu_events(struct kvm_vcpu *vcpu) {}
> +static inline void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu) {}
> +static inline void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu) {}
> +
>  #endif
>
>  #endif
> --
> 2.34.1
>
>
> --
> Without deviation from the norm, progress is not possible.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-05-16 12:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-16 10:42 [arm-platforms:kvm-arm64/per-vcpu-host-pmu-data 3/4] arch/arm64/kvm/arm.c:764:23: error: 'struct kvm_pmu' has no member named 'events' kernel test robot
2022-05-16 12:25 ` Marc Zyngier
2022-05-16 12:25   ` Marc Zyngier
2022-05-16 12:37   ` Fuad Tabba
2022-05-16 12:37     ` Fuad Tabba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.