[PATCH] kvm: decode the argument of KVM_CHECK_EXTENSION

Pierre Marsais pierre.marsais at epita.fr
Thu Aug 16 10:26:48 UTC 2018


From: Pierre Marsais <pmarsais at arista.com>

* xlat/kvm_cap.in: New file.
* kvm.c: Include "xlat/kvm_cap.h".
(kvm_ioctl_decode_check_extension): New function.
(kvm_ioctl): Use kvm_ioctl_decode_check_extension.
* tests/ioctl_kvm_run_common.c:
(main) Add tests for KVM_CHECK_EXTENSION ioctl.

Signed-off-by: Pierre Marsais <pierre.marsais at lse.epita.fr>
---
 kvm.c                        |  13 +++
 tests/ioctl_kvm_run_common.c |   4 +
 xlat/kvm_cap.in              | 151 +++++++++++++++++++++++++++++++++++
 3 files changed, 168 insertions(+)
 create mode 100644 xlat/kvm_cap.in

xlat/kvm_cap.in have been generated with the following command line:
grep '#define\s\+KVM_CAP' $linux/include/uapi/linux/kvm.h  | \
sed -E -e 's/^#define\s+([^ \t]+)\s*([0-9]+).*$/printf "%-40s%s\n" \1 \2/e' \
       -e 's/ {8}/\t/g; s/ +/\t/g'

diff --git a/kvm.c b/kvm.c
index c284e838..a518af90 100644
--- a/kvm.c
+++ b/kvm.c
@@ -323,6 +323,16 @@ kvm_ioctl_decode_sregs(struct tcb *const tcp, const unsigned int code,
 }
 # endif /* HAVE_STRUCT_KVM_SREGS */
 
+# include "xlat/kvm_cap.h"
+static int
+kvm_ioctl_decode_check_extension(struct tcb *const tcp, const unsigned int code,
+				 const kernel_ulong_t arg)
+{
+	tprints(", ");
+	printxval(kvm_cap, arg, "KVM_CAP_???");
+	return RVAL_IOCTL_DECODED;
+}
+
 # include "xlat/kvm_exit_reason.h"
 static void
 kvm_ioctl_run_attach_auxstr(struct tcb *const tcp,
@@ -403,6 +413,9 @@ kvm_ioctl(struct tcb *const tcp, const unsigned int code, const kernel_ulong_t a
                return kvm_ioctl_decode_cpuid2(tcp, code, arg);
 # endif
 
+	case KVM_CHECK_EXTENSION:
+		return kvm_ioctl_decode_check_extension(tcp, code, arg);
+
 	case KVM_CREATE_VM:
 		return RVAL_DECODED | RVAL_FD;
 
diff --git a/tests/ioctl_kvm_run_common.c b/tests/ioctl_kvm_run_common.c
index 522935a5..8b8b1779 100644
--- a/tests/ioctl_kvm_run_common.c
+++ b/tests/ioctl_kvm_run_common.c
@@ -306,6 +306,10 @@ main(void)
 	printf("ioctl(%d<%s>, KVM_GET_API_VERSION, 0) = %d\n",
 	       kvm, dev, ret);
 
+	ret = KVM_IOCTL(kvm, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY);
+	printf("ioctl(%d<%s>, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY) = %d\n",
+	       kvm, dev, ret);
+
 	int vm_fd = KVM_IOCTL(kvm, KVM_CREATE_VM, 0);
 	printf("ioctl(%d<%s>, KVM_CREATE_VM, 0) = %d<%s>\n",
 	       kvm, dev, vm_fd, vm_dev);
diff --git a/xlat/kvm_cap.in b/xlat/kvm_cap.in
new file mode 100644
index 00000000..4444664d
--- /dev/null
+++ b/xlat/kvm_cap.in
@@ -0,0 +1,151 @@
+KVM_CAP_IRQCHIP				0
+KVM_CAP_HLT				1
+KVM_CAP_MMU_SHADOW_CACHE_CONTROL	2
+KVM_CAP_USER_MEMORY			3
+KVM_CAP_SET_TSS_ADDR			4
+KVM_CAP_VAPIC				6
+KVM_CAP_EXT_CPUID			7
+KVM_CAP_CLOCKSOURCE			8
+KVM_CAP_NR_VCPUS			9
+KVM_CAP_NR_MEMSLOTS			10
+KVM_CAP_PIT				11
+KVM_CAP_NOP_IO_DELAY			12
+KVM_CAP_PV_MMU				13
+KVM_CAP_MP_STATE			14
+KVM_CAP_COALESCED_MMIO			15
+KVM_CAP_SYNC_MMU			16
+KVM_CAP_IOMMU				18
+KVM_CAP_DESTROY_MEMORY_REGION_WORKS	21
+KVM_CAP_USER_NMI			22
+KVM_CAP_SET_GUEST_DEBUG			23
+KVM_CAP_REINJECT_CONTROL		24
+KVM_CAP_IRQ_ROUTING			25
+KVM_CAP_IRQ_INJECT_STATUS		26
+KVM_CAP_ASSIGN_DEV_IRQ			29
+KVM_CAP_JOIN_MEMORY_REGIONS_WORKS	30
+KVM_CAP_MCE				31
+KVM_CAP_IRQFD				32
+KVM_CAP_PIT2				33
+KVM_CAP_SET_BOOT_CPU_ID			34
+KVM_CAP_PIT_STATE2			35
+KVM_CAP_IOEVENTFD			36
+KVM_CAP_SET_IDENTITY_MAP_ADDR		37
+KVM_CAP_XEN_HVM				38
+KVM_CAP_ADJUST_CLOCK			39
+KVM_CAP_INTERNAL_ERROR_DATA		40
+KVM_CAP_VCPU_EVENTS			41
+KVM_CAP_S390_PSW			42
+KVM_CAP_PPC_SEGSTATE			43
+KVM_CAP_HYPERV				44
+KVM_CAP_HYPERV_VAPIC			45
+KVM_CAP_HYPERV_SPIN			46
+KVM_CAP_PCI_SEGMENT			47
+KVM_CAP_PPC_PAIRED_SINGLES		48
+KVM_CAP_INTR_SHADOW			49
+KVM_CAP_DEBUGREGS			50
+KVM_CAP_X86_ROBUST_SINGLESTEP		51
+KVM_CAP_PPC_OSI				52
+KVM_CAP_PPC_UNSET_IRQ			53
+KVM_CAP_ENABLE_CAP			54
+KVM_CAP_XSAVE				55
+KVM_CAP_XCRS				56
+KVM_CAP_PPC_GET_PVINFO			57
+KVM_CAP_PPC_IRQ_LEVEL			58
+KVM_CAP_ASYNC_PF			59
+KVM_CAP_TSC_CONTROL			60
+KVM_CAP_GET_TSC_KHZ			61
+KVM_CAP_PPC_BOOKE_SREGS			62
+KVM_CAP_SPAPR_TCE			63
+KVM_CAP_PPC_SMT				64
+KVM_CAP_PPC_RMA				65
+KVM_CAP_MAX_VCPUS			66
+KVM_CAP_PPC_HIOR			67
+KVM_CAP_PPC_PAPR			68
+KVM_CAP_SW_TLB				69
+KVM_CAP_ONE_REG				70
+KVM_CAP_S390_GMAP			71
+KVM_CAP_TSC_DEADLINE_TIMER		72
+KVM_CAP_S390_UCONTROL			73
+KVM_CAP_SYNC_REGS			74
+KVM_CAP_PCI_2_3				75
+KVM_CAP_KVMCLOCK_CTRL			76
+KVM_CAP_SIGNAL_MSI			77
+KVM_CAP_PPC_GET_SMMU_INFO		78
+KVM_CAP_S390_COW			79
+KVM_CAP_PPC_ALLOC_HTAB			80
+KVM_CAP_READONLY_MEM			81
+KVM_CAP_IRQFD_RESAMPLE			82
+KVM_CAP_PPC_BOOKE_WATCHDOG		83
+KVM_CAP_PPC_HTAB_FD			84
+KVM_CAP_S390_CSS_SUPPORT		85
+KVM_CAP_PPC_EPR				86
+KVM_CAP_ARM_PSCI			87
+KVM_CAP_ARM_SET_DEVICE_ADDR		88
+KVM_CAP_DEVICE_CTRL			89
+KVM_CAP_IRQ_MPIC			90
+KVM_CAP_PPC_RTAS			91
+KVM_CAP_IRQ_XICS			92
+KVM_CAP_ARM_EL1_32BIT			93
+KVM_CAP_SPAPR_MULTITCE			94
+KVM_CAP_EXT_EMUL_CPUID			95
+KVM_CAP_HYPERV_TIME			96
+KVM_CAP_IOAPIC_POLARITY_IGNORED		97
+KVM_CAP_ENABLE_CAP_VM			98
+KVM_CAP_S390_IRQCHIP			99
+KVM_CAP_IOEVENTFD_NO_LENGTH		100
+KVM_CAP_VM_ATTRIBUTES			101
+KVM_CAP_ARM_PSCI_0_2			102
+KVM_CAP_PPC_FIXUP_HCALL			103
+KVM_CAP_PPC_ENABLE_HCALL		104
+KVM_CAP_CHECK_EXTENSION_VM		105
+KVM_CAP_S390_USER_SIGP			106
+KVM_CAP_S390_VECTOR_REGISTERS		107
+KVM_CAP_S390_MEM_OP			108
+KVM_CAP_S390_USER_STSI			109
+KVM_CAP_S390_SKEYS			110
+KVM_CAP_MIPS_FPU			111
+KVM_CAP_MIPS_MSA			112
+KVM_CAP_S390_INJECT_IRQ			113
+KVM_CAP_S390_IRQ_STATE			114
+KVM_CAP_PPC_HWRNG			115
+KVM_CAP_DISABLE_QUIRKS			116
+KVM_CAP_X86_SMM				117
+KVM_CAP_MULTI_ADDRESS_SPACE		118
+KVM_CAP_GUEST_DEBUG_HW_BPS		119
+KVM_CAP_GUEST_DEBUG_HW_WPS		120
+KVM_CAP_SPLIT_IRQCHIP			121
+KVM_CAP_IOEVENTFD_ANY_LENGTH		122
+KVM_CAP_HYPERV_SYNIC			123
+KVM_CAP_S390_RI				124
+KVM_CAP_SPAPR_TCE_64			125
+KVM_CAP_ARM_PMU_V3			126
+KVM_CAP_VCPU_ATTRIBUTES			127
+KVM_CAP_MAX_VCPU_ID			128
+KVM_CAP_X2APIC_API			129
+KVM_CAP_S390_USER_INSTR0		130
+KVM_CAP_MSI_DEVID			131
+KVM_CAP_PPC_HTM				132
+KVM_CAP_SPAPR_RESIZE_HPT		133
+KVM_CAP_PPC_MMU_RADIX			134
+KVM_CAP_PPC_MMU_HASH_V3			135
+KVM_CAP_IMMEDIATE_EXIT			136
+KVM_CAP_MIPS_VZ				137
+KVM_CAP_MIPS_TE				138
+KVM_CAP_MIPS_64BIT			139
+KVM_CAP_S390_GS				140
+KVM_CAP_S390_AIS			141
+KVM_CAP_SPAPR_TCE_VFIO			142
+KVM_CAP_X86_DISABLE_EXITS		143
+KVM_CAP_ARM_USER_IRQ			144
+KVM_CAP_S390_CMMA_MIGRATION		145
+KVM_CAP_PPC_FWNMI			146
+KVM_CAP_PPC_SMT_POSSIBLE		147
+KVM_CAP_HYPERV_SYNIC2			148
+KVM_CAP_HYPERV_VP_INDEX			149
+KVM_CAP_S390_AIS_MIGRATION		150
+KVM_CAP_PPC_GET_CPU_CHAR		151
+KVM_CAP_S390_BPB			152
+KVM_CAP_GET_MSR_FEATURES		153
+KVM_CAP_HYPERV_EVENTFD			154
+KVM_CAP_HYPERV_TLBFLUSH			155
+KVM_CAP_S390_HPAGE_1M			156
-- 
2.18.0



More information about the Strace-devel mailing list