Skip to contentSkip to conversation

tools headers UAPI: Sync linux/kvm.h with the kernel sources

PATCH In review Arnaldo Carvalho de Melo 1 participant 2 messages Dec 20, 2022 – Dec 21, 2022 3 messages not in the archive KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools headers UAPI: Sync linux/kvm.h with the kernel sources

tldr; Just FYI, I'm carrying this on the perf tools tree.

- Arnaldo

Full explanation:

There used to be no copies, with tools/ code using kernel headers directly. From time to time tools/perf/ broke due to legitimate kernel hacking. At some point Linus complained about such direct usage. Then we adopted the current model.

The way these headers are used in perf are not restricted to just including them to compile something.

There are sometimes used in scripts that convert defines into string tables, etc, so some change may break one of these scripts, or new MSRs may use some different #define pattern, etc.

E.g.:

  $ ls -1 tools/perf/trace/beauty/*.sh | head -5
  tools/perf/trace/beauty/arch_errno_names.sh
  tools/perf/trace/beauty/drm_ioctl.sh
  tools/perf/trace/beauty/fadvise.sh
  tools/perf/trace/beauty/fsconfig.sh
  tools/perf/trace/beauty/fsmount.sh
  $
  $ tools/perf/trace/beauty/fadvise.sh
  static const char *fadvise_advices[] = {
  	[0] = "NORMAL",
  	[1] = "RANDOM",
  	[2] = "SEQUENTIAL",
  	[3] = "WILLNEED",
  	[4] = "DONTNEED",
  	[5] = "NOREUSE",
  };
  $

The tools/perf/check-headers.sh script, part of the tools/ build process, points out changes in the original files.

So its important not to touch the copies in tools/ when doing changes in the original kernel headers, that will be done later, when check-headers.sh inform about the change to the perf tools hackers.

---

To pick the changes in:

86bdf3ebcfe1ded0 ("KVM: Support dirty ring in conjunction with bitmap")

That just rebuilds perf, as these patches don't add any new KVM ioctl to be harvested for the the 'perf trace' ioctl syscall argument beautifiers.

This is also by now used by tools/testing/selftests/kvm/, a simple test build didn't succeed, but for another reason:

lib/kvm_util.c: In function ‘vm_enable_dirty_ring’:
lib/kvm_util.c:125:30: error: ‘KVM_CAP_DIRTY_LOG_RING_ACQ_REL’ undeclared (first use in this function); did you mean ‘KVM_CAP_DIRTY_LOG_RING’?

    125 |         if (vm_check_cap(vm, KVM_CAP_DIRTY_LOG_RING_ACQ_REL))
        |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        |                              KVM_CAP_DIRTY_LOG_RING

I'll send a separate patch for that.

This silences this perf build warning:

Warning: Kernel ABI header at 'tools/include/uapi/linux/kvm.h' differs from latest version at 'include/uapi/linux/kvm.h' diff -u tools/include/uapi/linux/kvm.h include/uapi/linux/kvm.h

Cc Adrian Hunter <[email protected]>
Cc Gavin Shan <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paolo Bonzini <[email protected]>
---
 tools/include/uapi/linux/kvm.h | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
tools/include/uapi/linux/kvm.h +12 -1
index 21d6d29502e486ad..20522d4ba1e0d8b0 100644
@@ -98,7 +98,7 @@ struct kvm_userspace_memory_region {
 /*
  * The bit 0 ~ bit 15 of kvm_userspace_memory_region::flags are visible for
  * userspace, other bits are reserved for kvm internal use which are defined
- *in include/linux/kvm_host.h.
+ * in include/linux/kvm_host.h.
  */
 #define KVM_MEM_LOG_DIRTY_PAGES	(1UL << 0)
 #define KVM_MEM_READONLY	(1UL << 1)
@@ -477,6 +477,9 @@ struct kvm_run {
 #define KVM_MSR_EXIT_REASON_INVAL	(1 << 0)
 #define KVM_MSR_EXIT_REASON_UNKNOWN	(1 << 1)
 #define KVM_MSR_EXIT_REASON_FILTER	(1 << 2)
+#define KVM_MSR_EXIT_REASON_VALID_MASK	(KVM_MSR_EXIT_REASON_INVAL   |	\
+					 KVM_MSR_EXIT_REASON_UNKNOWN |	\
+					 KVM_MSR_EXIT_REASON_FILTER)
 			__u32 reason; /* kernel -> user */
 			__u32 index; /* kernel -> user */
 			__u64 data; /* kernel <-> user */
@@ -1170,6 +1173,8 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_S390_ZPCI_OP 221
 #define KVM_CAP_S390_CPU_TOPOLOGY 222
 #define KVM_CAP_DIRTY_LOG_RING_ACQ_REL 223
+#define KVM_CAP_S390_PROTECTED_ASYNC_DISABLE 224
+#define KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP 225
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -1259,6 +1264,7 @@ struct kvm_x86_mce {
 #define KVM_XEN_HVM_CONFIG_RUNSTATE		(1 << 3)
 #define KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL	(1 << 4)
 #define KVM_XEN_HVM_CONFIG_EVTCHN_SEND		(1 << 5)
+#define KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG	(1 << 6)
 
 struct kvm_xen_hvm_config {
 	__u32 flags;
@@ -1726,6 +1732,8 @@ enum pv_cmd_id {
 	KVM_PV_UNSHARE_ALL,
 	KVM_PV_INFO,
 	KVM_PV_DUMP,
+	KVM_PV_ASYNC_CLEANUP_PREPARE,
+	KVM_PV_ASYNC_CLEANUP_PERFORM,
 };
 
 struct kvm_pv_cmd {
@@ -1756,6 +1764,7 @@ struct kvm_xen_hvm_attr {
 	union {
 		__u8 long_mode;
 		__u8 vector;
+		__u8 runstate_update_flag;
 		struct {
 			__u64 gfn;
 		} shared_info;
@@ -1796,6 +1805,8 @@ struct kvm_xen_hvm_attr {
 /* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_EVTCHN_SEND */
 #define KVM_XEN_ATTR_TYPE_EVTCHN		0x3
 #define KVM_XEN_ATTR_TYPE_XEN_VERSION		0x4
+/* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG */
+#define KVM_XEN_ATTR_TYPE_RUNSTATE_UPDATE_FLAG	0x5
 
 /* Per-vCPU Xen attributes */
 #define KVM_XEN_VCPU_GET_ATTR	_IOWR(KVMIO, 0xca, struct kvm_xen_vcpu_attr)
Signature · 1 line
2.38.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Re: [PATCH 1/1] kvm selftests: Add conditional KVM_CAP_DIRTY_LOG_RING_ACQ_REL define kernel sources

Em Wed, Dec 21, 2022 at 08:57:11AM +0000, Marc Zyngier escreveu:

Quoted 15 lines · Gavin Shan
Quoted 13 lines · Arnaldo Carvalho de Melo
Quoted 12 lines

I tried to build make -C tools/testing/selftests/kvm/ to check that an update I made to the tools/include/uapi/linux/kvm.h file wouldn't break the KVM selftests, but I stumbled on an unrelated build failure where it tries to use a define that isn't available in the system headers (fedora 36), so add it conditionally.

Shouldn't this use the tools/ headers? Anyway, see if this is something useful.

---

Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/kvm/include/kvm_util.h +0 -0
index c9286811a4cb88e0..4ab76fd22efd951d 100644
@@ -10,4 +10,8 @@
  #include "kvm_util_base.h"
  #include "ucall_common.h"
  +#ifndef KVM_CAP_DIRTY_LOG_RING_ACQ_REL
Quoted 8 lines

tools/testing/selftests/kvm/include/kvm_util.h line 16

Quoted 4 lines
tools/testing/selftests/kvm/include/kvm_util.h +3 -0
+#define KVM_CAP_DIRTY_LOG_RING_ACQ_REL 223
+#endif
+
  #endif /* SELFTEST_KVM_UTIL_H */

I don't think it's necessary because KVM_CAP_DIRTY_LOG_RING_ACQ_REL has been defined in include/uapi/linux/kvm.h, which needs to be synchronized to /usr/include/linux/kvm.h, included by tools/testing/selftests/kvm/include/kvm_util_base.h

Until that happens, I can't test build it, and:

⬢[acme@toolbox perf]$ rpm -qf /usr/include/linux/kvm.h kernel-headers-6.0.5-200.fc36.x86_64

is in a distro package.

- Arnaldo

Quoted 13 lines
Quoted 2 lines

By the way, you forgot to copy the correct maillist, [email protected] or [email protected].

Actually, the latter is now deprecated, and will be turned off early next year. [email protected] is the new kid on the block (I just need to get Konstantin to turn on the archiving process).

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Signature · 1 line
- Arnaldo