All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 2/5] perf kvm: Introduce guest interfaces for sampling callchains
  2023-10-08 14:48 [PATCH v2 0/5] perf: KVM: Enable callchains for guests Tianyi Liu
@ 2023-10-08 14:53   ` Tianyi Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Tianyi Liu @ 2023-10-08 14:53 UTC (permalink / raw)
  To: seanjc, pbonzini, peterz, mingo, acme
  Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-perf-users, kvm,
	x86, mark.rutland, alexander.shishkin, jolsa, namhyung, irogers,
	adrian.hunter, Tianyi Liu

This patch introduces two callback interfaces used between perf and KVM:

- get_frame_pointer: Return the frame pointer of the running vm.

- read_virt: Read data from a virtual address of the running vm,
  used for reading the stack frames from the guest.

This also introduces a new flag, `PERF_GUEST_64BIT`, to the `.state`
callback interface, which indicates whether the vm is running in
64-bit mode.

Signed-off-by: Tianyi Liu <i.pear@outlook.com>
---
 include/linux/perf_event.h | 15 +++++++++++++++
 kernel/events/core.c       | 10 ++++++++++
 2 files changed, 25 insertions(+)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index e85cd1c0e..d0f937a62 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -28,10 +28,13 @@
 
 #define PERF_GUEST_ACTIVE	0x01
 #define PERF_GUEST_USER	0x02
+#define PERF_GUEST_64BIT 0x04
 
 struct perf_guest_info_callbacks {
 	unsigned int			(*state)(void);
 	unsigned long			(*get_ip)(void);
+	unsigned long			(*get_frame_pointer)(void);
+	bool				(*read_virt)(void *addr, void *dest, unsigned int len);
 	unsigned int			(*handle_intel_pt_intr)(void);
 };
 
@@ -1495,6 +1498,8 @@ extern struct perf_guest_info_callbacks __rcu *perf_guest_cbs;
 
 DECLARE_STATIC_CALL(__perf_guest_state, *perf_guest_cbs->state);
 DECLARE_STATIC_CALL(__perf_guest_get_ip, *perf_guest_cbs->get_ip);
+DECLARE_STATIC_CALL(__perf_guest_get_frame_pointer, *perf_guest_cbs->get_frame_pointer);
+DECLARE_STATIC_CALL(__perf_guest_read_virt, *perf_guest_cbs->read_virt);
 DECLARE_STATIC_CALL(__perf_guest_handle_intel_pt_intr, *perf_guest_cbs->handle_intel_pt_intr);
 
 static inline unsigned int perf_guest_state(void)
@@ -1505,6 +1510,14 @@ static inline unsigned long perf_guest_get_ip(void)
 {
 	return static_call(__perf_guest_get_ip)();
 }
+static inline unsigned long perf_guest_get_frame_pointer(void)
+{
+	return static_call(__perf_guest_get_frame_pointer)();
+}
+static inline bool perf_guest_read_virt(void *addr, void *dest, unsigned int length)
+{
+	return static_call(__perf_guest_read_virt)(addr, dest, length);
+}
 static inline unsigned int perf_guest_handle_intel_pt_intr(void)
 {
 	return static_call(__perf_guest_handle_intel_pt_intr)();
@@ -1514,6 +1527,8 @@ extern void perf_unregister_guest_info_callbacks(struct perf_guest_info_callback
 #else
 static inline unsigned int perf_guest_state(void)		 { return 0; }
 static inline unsigned long perf_guest_get_ip(void)		 { return 0; }
+static inline unsigned long perf_guest_get_frame_pointer(void)	{ return 0; }
+static inline bool perf_guest_read_virt(void*, void*, unsigned int)	{ return 0; }
 static inline unsigned int perf_guest_handle_intel_pt_intr(void) { return 0; }
 #endif /* CONFIG_GUEST_PERF_EVENTS */
 
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4c72a41f1..eaba00ec2 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6759,6 +6759,8 @@ struct perf_guest_info_callbacks __rcu *perf_guest_cbs;
 
 DEFINE_STATIC_CALL_RET0(__perf_guest_state, *perf_guest_cbs->state);
 DEFINE_STATIC_CALL_RET0(__perf_guest_get_ip, *perf_guest_cbs->get_ip);
+DEFINE_STATIC_CALL_RET0(__perf_guest_get_frame_pointer, *perf_guest_cbs->get_frame_pointer);
+DEFINE_STATIC_CALL_RET0(__perf_guest_read_virt, *perf_guest_cbs->read_virt);
 DEFINE_STATIC_CALL_RET0(__perf_guest_handle_intel_pt_intr, *perf_guest_cbs->handle_intel_pt_intr);
 
 void perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
@@ -6770,6 +6772,12 @@ void perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
 	static_call_update(__perf_guest_state, cbs->state);
 	static_call_update(__perf_guest_get_ip, cbs->get_ip);
 
+	if (cbs->get_frame_pointer)
+		static_call_update(__perf_guest_get_frame_pointer, cbs->get_frame_pointer);
+
+	if (cbs->read_virt)
+		static_call_update(__perf_guest_read_virt, cbs->read_virt);
+
 	/* Implementing ->handle_intel_pt_intr is optional. */
 	if (cbs->handle_intel_pt_intr)
 		static_call_update(__perf_guest_handle_intel_pt_intr,
@@ -6785,6 +6793,8 @@ void perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
 	rcu_assign_pointer(perf_guest_cbs, NULL);
 	static_call_update(__perf_guest_state, (void *)&__static_call_return0);
 	static_call_update(__perf_guest_get_ip, (void *)&__static_call_return0);
+	static_call_update(__perf_guest_get_frame_pointer, (void *)&__static_call_return0);
+	static_call_update(__perf_guest_read_virt, (void *)&__static_call_return0);
 	static_call_update(__perf_guest_handle_intel_pt_intr,
 			   (void *)&__static_call_return0);
 	synchronize_rcu();
-- 
2.42.0


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

* [PATCH v2 2/5] perf kvm: Introduce guest interfaces for sampling callchains
@ 2023-10-08 14:53   ` Tianyi Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Tianyi Liu @ 2023-10-08 14:53 UTC (permalink / raw)
  To: seanjc, pbonzini, peterz, mingo, acme
  Cc: linux-arm-kernel, kvmarm, linux-kernel, linux-perf-users, kvm,
	x86, mark.rutland, alexander.shishkin, jolsa, namhyung, irogers,
	adrian.hunter, Tianyi Liu

This patch introduces two callback interfaces used between perf and KVM:

- get_frame_pointer: Return the frame pointer of the running vm.

- read_virt: Read data from a virtual address of the running vm,
  used for reading the stack frames from the guest.

This also introduces a new flag, `PERF_GUEST_64BIT`, to the `.state`
callback interface, which indicates whether the vm is running in
64-bit mode.

Signed-off-by: Tianyi Liu <i.pear@outlook.com>
---
 include/linux/perf_event.h | 15 +++++++++++++++
 kernel/events/core.c       | 10 ++++++++++
 2 files changed, 25 insertions(+)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index e85cd1c0e..d0f937a62 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -28,10 +28,13 @@
 
 #define PERF_GUEST_ACTIVE	0x01
 #define PERF_GUEST_USER	0x02
+#define PERF_GUEST_64BIT 0x04
 
 struct perf_guest_info_callbacks {
 	unsigned int			(*state)(void);
 	unsigned long			(*get_ip)(void);
+	unsigned long			(*get_frame_pointer)(void);
+	bool				(*read_virt)(void *addr, void *dest, unsigned int len);
 	unsigned int			(*handle_intel_pt_intr)(void);
 };
 
@@ -1495,6 +1498,8 @@ extern struct perf_guest_info_callbacks __rcu *perf_guest_cbs;
 
 DECLARE_STATIC_CALL(__perf_guest_state, *perf_guest_cbs->state);
 DECLARE_STATIC_CALL(__perf_guest_get_ip, *perf_guest_cbs->get_ip);
+DECLARE_STATIC_CALL(__perf_guest_get_frame_pointer, *perf_guest_cbs->get_frame_pointer);
+DECLARE_STATIC_CALL(__perf_guest_read_virt, *perf_guest_cbs->read_virt);
 DECLARE_STATIC_CALL(__perf_guest_handle_intel_pt_intr, *perf_guest_cbs->handle_intel_pt_intr);
 
 static inline unsigned int perf_guest_state(void)
@@ -1505,6 +1510,14 @@ static inline unsigned long perf_guest_get_ip(void)
 {
 	return static_call(__perf_guest_get_ip)();
 }
+static inline unsigned long perf_guest_get_frame_pointer(void)
+{
+	return static_call(__perf_guest_get_frame_pointer)();
+}
+static inline bool perf_guest_read_virt(void *addr, void *dest, unsigned int length)
+{
+	return static_call(__perf_guest_read_virt)(addr, dest, length);
+}
 static inline unsigned int perf_guest_handle_intel_pt_intr(void)
 {
 	return static_call(__perf_guest_handle_intel_pt_intr)();
@@ -1514,6 +1527,8 @@ extern void perf_unregister_guest_info_callbacks(struct perf_guest_info_callback
 #else
 static inline unsigned int perf_guest_state(void)		 { return 0; }
 static inline unsigned long perf_guest_get_ip(void)		 { return 0; }
+static inline unsigned long perf_guest_get_frame_pointer(void)	{ return 0; }
+static inline bool perf_guest_read_virt(void*, void*, unsigned int)	{ return 0; }
 static inline unsigned int perf_guest_handle_intel_pt_intr(void) { return 0; }
 #endif /* CONFIG_GUEST_PERF_EVENTS */
 
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4c72a41f1..eaba00ec2 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6759,6 +6759,8 @@ struct perf_guest_info_callbacks __rcu *perf_guest_cbs;
 
 DEFINE_STATIC_CALL_RET0(__perf_guest_state, *perf_guest_cbs->state);
 DEFINE_STATIC_CALL_RET0(__perf_guest_get_ip, *perf_guest_cbs->get_ip);
+DEFINE_STATIC_CALL_RET0(__perf_guest_get_frame_pointer, *perf_guest_cbs->get_frame_pointer);
+DEFINE_STATIC_CALL_RET0(__perf_guest_read_virt, *perf_guest_cbs->read_virt);
 DEFINE_STATIC_CALL_RET0(__perf_guest_handle_intel_pt_intr, *perf_guest_cbs->handle_intel_pt_intr);
 
 void perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
@@ -6770,6 +6772,12 @@ void perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
 	static_call_update(__perf_guest_state, cbs->state);
 	static_call_update(__perf_guest_get_ip, cbs->get_ip);
 
+	if (cbs->get_frame_pointer)
+		static_call_update(__perf_guest_get_frame_pointer, cbs->get_frame_pointer);
+
+	if (cbs->read_virt)
+		static_call_update(__perf_guest_read_virt, cbs->read_virt);
+
 	/* Implementing ->handle_intel_pt_intr is optional. */
 	if (cbs->handle_intel_pt_intr)
 		static_call_update(__perf_guest_handle_intel_pt_intr,
@@ -6785,6 +6793,8 @@ void perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
 	rcu_assign_pointer(perf_guest_cbs, NULL);
 	static_call_update(__perf_guest_state, (void *)&__static_call_return0);
 	static_call_update(__perf_guest_get_ip, (void *)&__static_call_return0);
+	static_call_update(__perf_guest_get_frame_pointer, (void *)&__static_call_return0);
+	static_call_update(__perf_guest_read_virt, (void *)&__static_call_return0);
 	static_call_update(__perf_guest_handle_intel_pt_intr,
 			   (void *)&__static_call_return0);
 	synchronize_rcu();
-- 
2.42.0


_______________________________________________
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] 3+ messages in thread

* Re: [PATCH v2 2/5] perf kvm: Introduce guest interfaces for sampling callchains
@ 2023-10-12 22:07 kernel test robot
  0 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2023-10-12 22:07 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp

:::::: 
:::::: Manual check reason: "low confidence static check warning: include/linux/perf_event.h:1531:41: sparse: sparse: no identifier for function argument"
:::::: 

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <SY4P282MB10842B9353422CD2C86DCB929DCFA@SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM>
References: <SY4P282MB10842B9353422CD2C86DCB929DCFA@SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM>
TO: Tianyi Liu <i.pear@outlook.com>
TO: seanjc@google.com
TO: pbonzini@redhat.com
TO: peterz@infradead.org
TO: mingo@redhat.com
TO: acme@kernel.org
CC: linux-arm-kernel@lists.infradead.org
CC: kvmarm@lists.linux.dev
CC: linux-kernel@vger.kernel.org
CC: linux-perf-users@vger.kernel.org
CC: kvm@vger.kernel.org
CC: x86@kernel.org
CC: mark.rutland@arm.com
CC: alexander.shishkin@linux.intel.com
CC: jolsa@kernel.org
CC: namhyung@kernel.org
CC: irogers@google.com
CC: adrian.hunter@intel.com
CC: Tianyi Liu <i.pear@outlook.com>

Hi Tianyi,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 8a749fd1a8720d4619c91c8b6e7528c0a355c0aa]

url:    https://github.com/intel-lab-lkp/linux/commits/Tianyi-Liu/KVM-Add-arch-specific-interfaces-for-sampling-guest-callchains/20231008-230042
base:   8a749fd1a8720d4619c91c8b6e7528c0a355c0aa
patch link:    https://lore.kernel.org/r/SY4P282MB10842B9353422CD2C86DCB929DCFA%40SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM
patch subject: [PATCH v2 2/5] perf kvm: Introduce guest interfaces for sampling callchains
:::::: branch date: 4 days ago
:::::: commit date: 4 days ago
config: i386-randconfig-062-20231012 (https://download.01.org/0day-ci/archive/20231013/202310130614.KeOsd089-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231013/202310130614.KeOsd089-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/r/202310130614.KeOsd089-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
   fs/netfs/main.c: note: in included file (through include/linux/trace_events.h, include/trace/trace_events.h, include/trace/define_trace.h, ...):
>> include/linux/perf_event.h:1531:41: sparse: sparse: no identifier for function argument
   include/linux/perf_event.h:1531:48: sparse: sparse: no identifier for function argument
   include/linux/perf_event.h:1531:55: sparse: sparse: no identifier for function argument

vim +1531 include/linux/perf_event.h

87b940a0675e25 Sean Christopherson 2021-11-11  1504  
1c3430516b0732 Sean Christopherson 2021-11-11  1505  static inline unsigned int perf_guest_state(void)
1c3430516b0732 Sean Christopherson 2021-11-11  1506  {
87b940a0675e25 Sean Christopherson 2021-11-11  1507  	return static_call(__perf_guest_state)();
1c3430516b0732 Sean Christopherson 2021-11-11  1508  }
1c3430516b0732 Sean Christopherson 2021-11-11  1509  static inline unsigned long perf_guest_get_ip(void)
1c3430516b0732 Sean Christopherson 2021-11-11  1510  {
87b940a0675e25 Sean Christopherson 2021-11-11  1511  	return static_call(__perf_guest_get_ip)();
1c3430516b0732 Sean Christopherson 2021-11-11  1512  }
7b615fa3e48fd3 Tianyi Liu          2023-10-08  1513  static inline unsigned long perf_guest_get_frame_pointer(void)
7b615fa3e48fd3 Tianyi Liu          2023-10-08  1514  {
7b615fa3e48fd3 Tianyi Liu          2023-10-08  1515  	return static_call(__perf_guest_get_frame_pointer)();
7b615fa3e48fd3 Tianyi Liu          2023-10-08  1516  }
7b615fa3e48fd3 Tianyi Liu          2023-10-08  1517  static inline bool perf_guest_read_virt(void *addr, void *dest, unsigned int length)
7b615fa3e48fd3 Tianyi Liu          2023-10-08  1518  {
7b615fa3e48fd3 Tianyi Liu          2023-10-08  1519  	return static_call(__perf_guest_read_virt)(addr, dest, length);
7b615fa3e48fd3 Tianyi Liu          2023-10-08  1520  }
1c3430516b0732 Sean Christopherson 2021-11-11  1521  static inline unsigned int perf_guest_handle_intel_pt_intr(void)
1c3430516b0732 Sean Christopherson 2021-11-11  1522  {
87b940a0675e25 Sean Christopherson 2021-11-11  1523  	return static_call(__perf_guest_handle_intel_pt_intr)();
1c3430516b0732 Sean Christopherson 2021-11-11  1524  }
2934e3d09350c1 Sean Christopherson 2021-11-11  1525  extern void perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs);
2934e3d09350c1 Sean Christopherson 2021-11-11  1526  extern void perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs);
2aef6f306b39bb Sean Christopherson 2021-11-11  1527  #else
2aef6f306b39bb Sean Christopherson 2021-11-11  1528  static inline unsigned int perf_guest_state(void)		 { return 0; }
2aef6f306b39bb Sean Christopherson 2021-11-11  1529  static inline unsigned long perf_guest_get_ip(void)		 { return 0; }
7b615fa3e48fd3 Tianyi Liu          2023-10-08  1530  static inline unsigned long perf_guest_get_frame_pointer(void)	{ return 0; }
7b615fa3e48fd3 Tianyi Liu          2023-10-08 @1531  static inline bool perf_guest_read_virt(void*, void*, unsigned int)	{ return 0; }
2aef6f306b39bb Sean Christopherson 2021-11-11  1532  static inline unsigned int perf_guest_handle_intel_pt_intr(void) { return 0; }
2aef6f306b39bb Sean Christopherson 2021-11-11  1533  #endif /* CONFIG_GUEST_PERF_EVENTS */
39447b386c846b Zhang, Yanmin       2010-04-19  1534  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

end of thread, other threads:[~2023-10-12 22:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-12 22:07 [PATCH v2 2/5] perf kvm: Introduce guest interfaces for sampling callchains kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2023-10-08 14:48 [PATCH v2 0/5] perf: KVM: Enable callchains for guests Tianyi Liu
2023-10-08 14:53 ` [PATCH v2 2/5] perf kvm: Introduce guest interfaces for sampling callchains Tianyi Liu
2023-10-08 14:53   ` Tianyi Liu

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.