* [RFC PATCH] KVM: x86: add kvm per-vCPU exits disable capability
@ 2021-12-14 3:32 Kechen Lu
2021-12-14 7:23 ` kernel test robot
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Kechen Lu @ 2021-12-14 3:32 UTC (permalink / raw)
To: kvm, pbonzini
Cc: seanjc, wanpengli, rkrcmar, vkuznets, somduttar, kechenl, linux-kernel
Introduce new bit KVM_X86_DISABLE_EXITS_PER_VCPU and second arg of
KVM_CAP_X86_DISABLE_EXITS cap as vCPU mask for disabling exits to
enable finer-grained VM exits disabling on per vCPU scales instead
of whole guest. This exits_disable_vcpu_mask default is 0, i.e.
disable exits on all vCPUs, if it is 0x5, i.e. enable exits on vCPU0
and vCPU2, disable exits on all other vCPUs. This patch only enabled
this per-vCPU disable on HLT VM-exits.
In use cases like Windows guest running heavy CPU-bound
workloads, disabling HLT VM-exits could mitigate host sched ctx switch
overhead. Simply HLT disabling on all vCPUs could bring
performance benefits, but if no pCPUs reserved for host threads, could
happened to the forced preemption as host does not know the time to do
the schedule for other host threads want to run. With this patch, we
could only disable part of vCPUs HLT exits for one guest, this still
keeps performance benefits, and also shows resiliency to host stressing
workload running at the same time.
In the host stressing workload experiment with Windows guest heavy
CPU-bound workloads, it shows good resiliency and having the ~3%
performance improvement.
Signed-off-by: Kechen Lu <kechenl@nvidia.com>
---
Documentation/virt/kvm/api.rst | 8 +++++++-
arch/x86/include/asm/kvm_host.h | 1 +
arch/x86/kvm/cpuid.c | 2 +-
arch/x86/kvm/svm/svm.c | 2 +-
arch/x86/kvm/vmx/vmx.c | 4 ++--
arch/x86/kvm/x86.c | 5 ++++-
arch/x86/kvm/x86.h | 5 +++--
include/uapi/linux/kvm.h | 4 +++-
8 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index aeeb071c7688..9a44896dc950 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -6580,6 +6580,9 @@ branch to guests' 0x200 interrupt vector.
:Architectures: x86
:Parameters: args[0] defines which exits are disabled
+ args[1] defines vCPU bitmask based on vCPU ID, 1 on
+ corresponding vCPU ID bit would enable exists
+ on that vCPU
:Returns: 0 on success, -EINVAL when args[0] contains invalid exits
Valid bits in args[0] are::
@@ -6588,13 +6591,16 @@ Valid bits in args[0] are::
#define KVM_X86_DISABLE_EXITS_HLT (1 << 1)
#define KVM_X86_DISABLE_EXITS_PAUSE (1 << 2)
#define KVM_X86_DISABLE_EXITS_CSTATE (1 << 3)
+ #define KVM_X86_DISABLE_EXITS_PER_VCPU (1UL << 63)
Enabling this capability on a VM provides userspace with a way to no
longer intercept some instructions for improved latency in some
workloads, and is suggested when vCPUs are associated to dedicated
physical CPUs. More bits can be added in the future; userspace can
just pass the KVM_CHECK_EXTENSION result to KVM_ENABLE_CAP to disable
-all such vmexits.
+all such vmexits. Set KVM_X86_DISABLE_EXITS_PER_VCPU enables per-vCPU
+exits disabling based on the vCPUs bitmask for args[1], currently only
+set for HLT exits.
Do not enable KVM_FEATURE_PV_UNHALT if you disable HLT exits.
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 2164b9f4c7b0..1c65dc500c55 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1085,6 +1085,7 @@ struct kvm_arch {
bool hlt_in_guest;
bool pause_in_guest;
bool cstate_in_guest;
+ u64 exits_disable_vcpu_mask;
unsigned long irq_sources_bitmap;
s64 kvmclock_offset;
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 07e9215e911d..6291e15710ba 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -177,7 +177,7 @@ void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu)
best->ebx = xstate_required_size(vcpu->arch.xcr0, true);
best = kvm_find_kvm_cpuid_features(vcpu);
- if (kvm_hlt_in_guest(vcpu->kvm) && best &&
+ if (kvm_hlt_in_guest(vcpu) && best &&
(best->eax & (1 << KVM_FEATURE_PV_UNHALT)))
best->eax &= ~(1 << KVM_FEATURE_PV_UNHALT);
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index d0f68d11ec70..d24f67b33ae5 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -1276,7 +1276,7 @@ static void init_vmcb(struct kvm_vcpu *vcpu)
svm_set_intercept(svm, INTERCEPT_MWAIT);
}
- if (!kvm_hlt_in_guest(vcpu->kvm))
+ if (!kvm_hlt_in_guest(vcpu))
svm_set_intercept(svm, INTERCEPT_HLT);
control->iopm_base_pa = __sme_set(iopm_base);
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 5aadad3e7367..8694279bb655 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -1585,7 +1585,7 @@ static void vmx_clear_hlt(struct kvm_vcpu *vcpu)
* then the instruction is already executing and RIP has already been
* advanced.
*/
- if (kvm_hlt_in_guest(vcpu->kvm) &&
+ if (kvm_hlt_in_guest(vcpu) &&
vmcs_read32(GUEST_ACTIVITY_STATE) == GUEST_ACTIVITY_HLT)
vmcs_write32(GUEST_ACTIVITY_STATE, GUEST_ACTIVITY_ACTIVE);
}
@@ -4123,7 +4123,7 @@ static u32 vmx_exec_control(struct vcpu_vmx *vmx)
if (kvm_mwait_in_guest(vmx->vcpu.kvm))
exec_control &= ~(CPU_BASED_MWAIT_EXITING |
CPU_BASED_MONITOR_EXITING);
- if (kvm_hlt_in_guest(vmx->vcpu.kvm))
+ if (kvm_hlt_in_guest(&vmx->vcpu))
exec_control &= ~CPU_BASED_HLT_EXITING;
return exec_control;
}
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 0cf1082455df..9432d7c04a98 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5773,6 +5773,9 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
kvm->arch.pause_in_guest = true;
if (cap->args[0] & KVM_X86_DISABLE_EXITS_CSTATE)
kvm->arch.cstate_in_guest = true;
+ if ((cap->args[0] & KVM_X86_DISABLE_EXITS_PER_VCPU) &&
+ cap->args[1])
+ kvm->arch.exits_disable_vcpu_mask = cap->args[1];
r = 0;
break;
case KVM_CAP_MSR_PLATFORM_INFO:
@@ -12080,7 +12083,7 @@ bool kvm_can_do_async_pf(struct kvm_vcpu *vcpu)
vcpu->arch.exception.pending))
return false;
- if (kvm_hlt_in_guest(vcpu->kvm) && !kvm_can_deliver_async_pf(vcpu))
+ if (kvm_hlt_in_guest(vcpu) && !kvm_can_deliver_async_pf(vcpu))
return false;
/*
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index 4abcd8d9836d..449476e13206 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -377,9 +377,10 @@ static inline bool kvm_mwait_in_guest(struct kvm *kvm)
return kvm->arch.mwait_in_guest;
}
-static inline bool kvm_hlt_in_guest(struct kvm *kvm)
+static inline bool kvm_hlt_in_guest(struct kvm_vcpu *vcpu)
{
- return kvm->arch.hlt_in_guest;
+ return vcpu->kvm->arch.hlt_in_guest && (rol64(1UL, vcpu->vcpu_id) &
+ ~vcpu->kvm->arch.exits_disable_vcpu_mask);
}
static inline bool kvm_pause_in_guest(struct kvm *kvm)
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 1daa45268de2..976eb16f7fc0 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -798,10 +798,12 @@ struct kvm_ioeventfd {
#define KVM_X86_DISABLE_EXITS_HLT (1 << 1)
#define KVM_X86_DISABLE_EXITS_PAUSE (1 << 2)
#define KVM_X86_DISABLE_EXITS_CSTATE (1 << 3)
+#define KVM_X86_DISABLE_EXITS_PER_VCPU (1UL << 63)
#define KVM_X86_DISABLE_VALID_EXITS (KVM_X86_DISABLE_EXITS_MWAIT | \
KVM_X86_DISABLE_EXITS_HLT | \
KVM_X86_DISABLE_EXITS_PAUSE | \
- KVM_X86_DISABLE_EXITS_CSTATE)
+ KVM_X86_DISABLE_EXITS_CSTATE| \
+ KVM_X86_DISABLE_EXITS_PER_VCPU)
/* for KVM_ENABLE_CAP */
struct kvm_enable_cap {
--
2.30.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [RFC PATCH] KVM: x86: add kvm per-vCPU exits disable capability
2021-12-14 3:32 [RFC PATCH] KVM: x86: add kvm per-vCPU exits disable capability Kechen Lu
@ 2021-12-14 7:23 ` kernel test robot
2021-12-14 7:54 ` kernel test robot
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2021-12-14 7:23 UTC (permalink / raw)
To: Kechen Lu; +Cc: llvm, kbuild-all
Hi Kechen,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on kvm/queue]
[also build test WARNING on mst-vhost/linux-next tip/master linux/master linus/master v5.16-rc5]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Kechen-Lu/KVM-x86-add-kvm-per-vCPU-exits-disable-capability/20211214-113446
base: https://git.kernel.org/pub/scm/virt/kvm/kvm.git queue
config: i386-buildonly-randconfig-r004-20211213 (https://download.01.org/0day-ci/archive/20211214/202112141509.dBVwl6Ux-lkp@intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project b6a2ddb6c8ac29412b1361810972e15221fa021c)
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://github.com/0day-ci/linux/commit/08f20df47a09e327aee3e73a8d7c77b1ffc01bc0
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Kechen-Lu/KVM-x86-add-kvm-per-vCPU-exits-disable-capability/20211214-113446
git checkout 08f20df47a09e327aee3e73a8d7c77b1ffc01bc0
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash arch/x86/kvm/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
>> arch/x86/kvm/x86.c:5775:23: warning: shift count >= width of type [-Wshift-count-overflow]
if (cap->args[0] & ~KVM_X86_DISABLE_VALID_EXITS)
^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/uapi/linux/kvm.h:806:12: note: expanded from macro 'KVM_X86_DISABLE_VALID_EXITS'
KVM_X86_DISABLE_EXITS_PER_VCPU)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/uapi/linux/kvm.h:801:51: note: expanded from macro 'KVM_X86_DISABLE_EXITS_PER_VCPU'
#define KVM_X86_DISABLE_EXITS_PER_VCPU (1UL << 63)
^ ~~
arch/x86/kvm/x86.c:5787:23: warning: shift count >= width of type [-Wshift-count-overflow]
if ((cap->args[0] & KVM_X86_DISABLE_EXITS_PER_VCPU) &&
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/uapi/linux/kvm.h:801:51: note: expanded from macro 'KVM_X86_DISABLE_EXITS_PER_VCPU'
#define KVM_X86_DISABLE_EXITS_PER_VCPU (1UL << 63)
^ ~~
arch/x86/kvm/x86.c:2335:19: warning: unused function 'gtod_is_based_on_tsc' [-Wunused-function]
static inline int gtod_is_based_on_tsc(int mode)
^
3 warnings generated.
vim +5775 arch/x86/kvm/x86.c
23d43cf998275bc Christoffer Dall 2012-07-24 5724
e5d83c74a5800c2 Paolo Bonzini 2017-02-16 5725 int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
90de4a1875180f8 Nadav Amit 2015-04-13 5726 struct kvm_enable_cap *cap)
90de4a1875180f8 Nadav Amit 2015-04-13 5727 {
90de4a1875180f8 Nadav Amit 2015-04-13 5728 int r;
90de4a1875180f8 Nadav Amit 2015-04-13 5729
90de4a1875180f8 Nadav Amit 2015-04-13 5730 if (cap->flags)
90de4a1875180f8 Nadav Amit 2015-04-13 5731 return -EINVAL;
90de4a1875180f8 Nadav Amit 2015-04-13 5732
90de4a1875180f8 Nadav Amit 2015-04-13 5733 switch (cap->cap) {
90de4a1875180f8 Nadav Amit 2015-04-13 5734 case KVM_CAP_DISABLE_QUIRKS:
90de4a1875180f8 Nadav Amit 2015-04-13 5735 kvm->arch.disabled_quirks = cap->args[0];
90de4a1875180f8 Nadav Amit 2015-04-13 5736 r = 0;
90de4a1875180f8 Nadav Amit 2015-04-13 5737 break;
49df6397edfc5a8 Steve Rutherford 2015-07-29 5738 case KVM_CAP_SPLIT_IRQCHIP: {
49df6397edfc5a8 Steve Rutherford 2015-07-29 5739 mutex_lock(&kvm->lock);
b053b2aef25d007 Steve Rutherford 2015-07-29 5740 r = -EINVAL;
b053b2aef25d007 Steve Rutherford 2015-07-29 5741 if (cap->args[0] > MAX_NR_RESERVED_IOAPIC_PINS)
b053b2aef25d007 Steve Rutherford 2015-07-29 5742 goto split_irqchip_unlock;
49df6397edfc5a8 Steve Rutherford 2015-07-29 5743 r = -EEXIST;
49df6397edfc5a8 Steve Rutherford 2015-07-29 5744 if (irqchip_in_kernel(kvm))
49df6397edfc5a8 Steve Rutherford 2015-07-29 5745 goto split_irqchip_unlock;
557abc40d121358 Paolo Bonzini 2016-06-13 5746 if (kvm->created_vcpus)
49df6397edfc5a8 Steve Rutherford 2015-07-29 5747 goto split_irqchip_unlock;
49df6397edfc5a8 Steve Rutherford 2015-07-29 5748 r = kvm_setup_empty_irq_routing(kvm);
5c0aea0e8d98e38 David Hildenbrand 2017-04-28 5749 if (r)
49df6397edfc5a8 Steve Rutherford 2015-07-29 5750 goto split_irqchip_unlock;
49df6397edfc5a8 Steve Rutherford 2015-07-29 5751 /* Pairs with irqchip_in_kernel. */
49df6397edfc5a8 Steve Rutherford 2015-07-29 5752 smp_wmb();
49776faf93f8074 Radim Krčmář 2016-12-16 5753 kvm->arch.irqchip_mode = KVM_IRQCHIP_SPLIT;
b053b2aef25d007 Steve Rutherford 2015-07-29 5754 kvm->arch.nr_reserved_ioapic_pins = cap->args[0];
ef8b4b7203682cc Paolo Bonzini 2021-11-30 5755 kvm_request_apicv_update(kvm, true, APICV_INHIBIT_REASON_ABSENT);
49df6397edfc5a8 Steve Rutherford 2015-07-29 5756 r = 0;
49df6397edfc5a8 Steve Rutherford 2015-07-29 5757 split_irqchip_unlock:
49df6397edfc5a8 Steve Rutherford 2015-07-29 5758 mutex_unlock(&kvm->lock);
49df6397edfc5a8 Steve Rutherford 2015-07-29 5759 break;
49df6397edfc5a8 Steve Rutherford 2015-07-29 5760 }
3713131345fbea2 Radim Krčmář 2016-07-12 5761 case KVM_CAP_X2APIC_API:
3713131345fbea2 Radim Krčmář 2016-07-12 5762 r = -EINVAL;
3713131345fbea2 Radim Krčmář 2016-07-12 5763 if (cap->args[0] & ~KVM_X2APIC_API_VALID_FLAGS)
3713131345fbea2 Radim Krčmář 2016-07-12 5764 break;
3713131345fbea2 Radim Krčmář 2016-07-12 5765
3713131345fbea2 Radim Krčmář 2016-07-12 5766 if (cap->args[0] & KVM_X2APIC_API_USE_32BIT_IDS)
3713131345fbea2 Radim Krčmář 2016-07-12 5767 kvm->arch.x2apic_format = true;
c519265f2aa348b Radim Krčmář 2016-07-12 5768 if (cap->args[0] & KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK)
c519265f2aa348b Radim Krčmář 2016-07-12 5769 kvm->arch.x2apic_broadcast_quirk_disabled = true;
3713131345fbea2 Radim Krčmář 2016-07-12 5770
3713131345fbea2 Radim Krčmář 2016-07-12 5771 r = 0;
3713131345fbea2 Radim Krčmář 2016-07-12 5772 break;
4d5422cea3b61f1 Wanpeng Li 2018-03-12 5773 case KVM_CAP_X86_DISABLE_EXITS:
4d5422cea3b61f1 Wanpeng Li 2018-03-12 5774 r = -EINVAL;
4d5422cea3b61f1 Wanpeng Li 2018-03-12 @5775 if (cap->args[0] & ~KVM_X86_DISABLE_VALID_EXITS)
4d5422cea3b61f1 Wanpeng Li 2018-03-12 5776 break;
4d5422cea3b61f1 Wanpeng Li 2018-03-12 5777
4d5422cea3b61f1 Wanpeng Li 2018-03-12 5778 if ((cap->args[0] & KVM_X86_DISABLE_EXITS_MWAIT) &&
4d5422cea3b61f1 Wanpeng Li 2018-03-12 5779 kvm_can_mwait_in_guest())
4d5422cea3b61f1 Wanpeng Li 2018-03-12 5780 kvm->arch.mwait_in_guest = true;
766d3571d8e50d3 Michael S. Tsirkin 2018-06-08 5781 if (cap->args[0] & KVM_X86_DISABLE_EXITS_HLT)
caa057a2cad647f Wanpeng Li 2018-03-12 5782 kvm->arch.hlt_in_guest = true;
b31c114b82b2b55 Wanpeng Li 2018-03-12 5783 if (cap->args[0] & KVM_X86_DISABLE_EXITS_PAUSE)
b31c114b82b2b55 Wanpeng Li 2018-03-12 5784 kvm->arch.pause_in_guest = true;
b51700632e0e532 Wanpeng Li 2019-05-21 5785 if (cap->args[0] & KVM_X86_DISABLE_EXITS_CSTATE)
b51700632e0e532 Wanpeng Li 2019-05-21 5786 kvm->arch.cstate_in_guest = true;
08f20df47a09e32 Kechen Lu 2021-12-13 5787 if ((cap->args[0] & KVM_X86_DISABLE_EXITS_PER_VCPU) &&
08f20df47a09e32 Kechen Lu 2021-12-13 5788 cap->args[1])
08f20df47a09e32 Kechen Lu 2021-12-13 5789 kvm->arch.exits_disable_vcpu_mask = cap->args[1];
4d5422cea3b61f1 Wanpeng Li 2018-03-12 5790 r = 0;
4d5422cea3b61f1 Wanpeng Li 2018-03-12 5791 break;
6fbbde9a1969dfb Drew Schmitt 2018-08-20 5792 case KVM_CAP_MSR_PLATFORM_INFO:
6fbbde9a1969dfb Drew Schmitt 2018-08-20 5793 kvm->arch.guest_can_read_msr_platform_info = cap->args[0];
6fbbde9a1969dfb Drew Schmitt 2018-08-20 5794 r = 0;
c4f55198c7c2b87 Jim Mattson 2018-10-16 5795 break;
c4f55198c7c2b87 Jim Mattson 2018-10-16 5796 case KVM_CAP_EXCEPTION_PAYLOAD:
c4f55198c7c2b87 Jim Mattson 2018-10-16 5797 kvm->arch.exception_payload_enabled = cap->args[0];
c4f55198c7c2b87 Jim Mattson 2018-10-16 5798 r = 0;
6fbbde9a1969dfb Drew Schmitt 2018-08-20 5799 break;
1ae099540e8c7f1 Alexander Graf 2020-09-25 5800 case KVM_CAP_X86_USER_SPACE_MSR:
1ae099540e8c7f1 Alexander Graf 2020-09-25 5801 kvm->arch.user_space_msr_mask = cap->args[0];
1ae099540e8c7f1 Alexander Graf 2020-09-25 5802 r = 0;
1ae099540e8c7f1 Alexander Graf 2020-09-25 5803 break;
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5804 case KVM_CAP_X86_BUS_LOCK_EXIT:
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5805 r = -EINVAL;
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5806 if (cap->args[0] & ~KVM_BUS_LOCK_DETECTION_VALID_MODE)
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5807 break;
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5808
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5809 if ((cap->args[0] & KVM_BUS_LOCK_DETECTION_OFF) &&
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5810 (cap->args[0] & KVM_BUS_LOCK_DETECTION_EXIT))
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5811 break;
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5812
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5813 if (kvm_has_bus_lock_exit &&
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5814 cap->args[0] & KVM_BUS_LOCK_DETECTION_EXIT)
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5815 kvm->arch.bus_lock_detection_enabled = true;
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5816 r = 0;
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5817 break;
fe7e948837f312d Sean Christopherson 2021-04-12 5818 #ifdef CONFIG_X86_SGX_KVM
fe7e948837f312d Sean Christopherson 2021-04-12 5819 case KVM_CAP_SGX_ATTRIBUTE: {
fe7e948837f312d Sean Christopherson 2021-04-12 5820 unsigned long allowed_attributes = 0;
fe7e948837f312d Sean Christopherson 2021-04-12 5821
fe7e948837f312d Sean Christopherson 2021-04-12 5822 r = sgx_set_attribute(&allowed_attributes, cap->args[0]);
fe7e948837f312d Sean Christopherson 2021-04-12 5823 if (r)
fe7e948837f312d Sean Christopherson 2021-04-12 5824 break;
fe7e948837f312d Sean Christopherson 2021-04-12 5825
fe7e948837f312d Sean Christopherson 2021-04-12 5826 /* KVM only supports the PROVISIONKEY privileged attribute. */
fe7e948837f312d Sean Christopherson 2021-04-12 5827 if ((allowed_attributes & SGX_ATTR_PROVISIONKEY) &&
fe7e948837f312d Sean Christopherson 2021-04-12 5828 !(allowed_attributes & ~SGX_ATTR_PROVISIONKEY))
fe7e948837f312d Sean Christopherson 2021-04-12 5829 kvm->arch.sgx_provisioning_allowed = true;
fe7e948837f312d Sean Christopherson 2021-04-12 5830 else
fe7e948837f312d Sean Christopherson 2021-04-12 5831 r = -EINVAL;
fe7e948837f312d Sean Christopherson 2021-04-12 5832 break;
fe7e948837f312d Sean Christopherson 2021-04-12 5833 }
fe7e948837f312d Sean Christopherson 2021-04-12 5834 #endif
54526d1fd59338f Nathan Tempelman 2021-04-08 5835 case KVM_CAP_VM_COPY_ENC_CONTEXT_FROM:
54526d1fd59338f Nathan Tempelman 2021-04-08 5836 r = -EINVAL;
54526d1fd59338f Nathan Tempelman 2021-04-08 5837 if (kvm_x86_ops.vm_copy_enc_context_from)
54526d1fd59338f Nathan Tempelman 2021-04-08 5838 r = kvm_x86_ops.vm_copy_enc_context_from(kvm, cap->args[0]);
54526d1fd59338f Nathan Tempelman 2021-04-08 5839 return r;
b56639318bb2be6 Peter Gonda 2021-10-21 5840 case KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM:
b56639318bb2be6 Peter Gonda 2021-10-21 5841 r = -EINVAL;
b56639318bb2be6 Peter Gonda 2021-10-21 5842 if (kvm_x86_ops.vm_move_enc_context_from)
b56639318bb2be6 Peter Gonda 2021-10-21 5843 r = kvm_x86_ops.vm_move_enc_context_from(
b56639318bb2be6 Peter Gonda 2021-10-21 5844 kvm, cap->args[0]);
b56639318bb2be6 Peter Gonda 2021-10-21 5845 return r;
0dbb11230437895 Ashish Kalra 2021-06-08 5846 case KVM_CAP_EXIT_HYPERCALL:
0dbb11230437895 Ashish Kalra 2021-06-08 5847 if (cap->args[0] & ~KVM_EXIT_HYPERCALL_VALID_MASK) {
0dbb11230437895 Ashish Kalra 2021-06-08 5848 r = -EINVAL;
0dbb11230437895 Ashish Kalra 2021-06-08 5849 break;
0dbb11230437895 Ashish Kalra 2021-06-08 5850 }
0dbb11230437895 Ashish Kalra 2021-06-08 5851 kvm->arch.hypercall_exit_enabled = cap->args[0];
0dbb11230437895 Ashish Kalra 2021-06-08 5852 r = 0;
0dbb11230437895 Ashish Kalra 2021-06-08 5853 break;
19238e75bd8ed8f Aaron Lewis 2021-05-10 5854 case KVM_CAP_EXIT_ON_EMULATION_FAILURE:
19238e75bd8ed8f Aaron Lewis 2021-05-10 5855 r = -EINVAL;
19238e75bd8ed8f Aaron Lewis 2021-05-10 5856 if (cap->args[0] & ~1)
19238e75bd8ed8f Aaron Lewis 2021-05-10 5857 break;
19238e75bd8ed8f Aaron Lewis 2021-05-10 5858 kvm->arch.exit_on_emulation_error = cap->args[0];
19238e75bd8ed8f Aaron Lewis 2021-05-10 5859 r = 0;
19238e75bd8ed8f Aaron Lewis 2021-05-10 5860 break;
90de4a1875180f8 Nadav Amit 2015-04-13 5861 default:
90de4a1875180f8 Nadav Amit 2015-04-13 5862 r = -EINVAL;
90de4a1875180f8 Nadav Amit 2015-04-13 5863 break;
90de4a1875180f8 Nadav Amit 2015-04-13 5864 }
90de4a1875180f8 Nadav Amit 2015-04-13 5865 return r;
90de4a1875180f8 Nadav Amit 2015-04-13 5866 }
90de4a1875180f8 Nadav Amit 2015-04-13 5867
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH] KVM: x86: add kvm per-vCPU exits disable capability
@ 2021-12-14 7:23 ` kernel test robot
0 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2021-12-14 7:23 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 14929 bytes --]
Hi Kechen,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on kvm/queue]
[also build test WARNING on mst-vhost/linux-next tip/master linux/master linus/master v5.16-rc5]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Kechen-Lu/KVM-x86-add-kvm-per-vCPU-exits-disable-capability/20211214-113446
base: https://git.kernel.org/pub/scm/virt/kvm/kvm.git queue
config: i386-buildonly-randconfig-r004-20211213 (https://download.01.org/0day-ci/archive/20211214/202112141509.dBVwl6Ux-lkp(a)intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project b6a2ddb6c8ac29412b1361810972e15221fa021c)
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://github.com/0day-ci/linux/commit/08f20df47a09e327aee3e73a8d7c77b1ffc01bc0
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Kechen-Lu/KVM-x86-add-kvm-per-vCPU-exits-disable-capability/20211214-113446
git checkout 08f20df47a09e327aee3e73a8d7c77b1ffc01bc0
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash arch/x86/kvm/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
>> arch/x86/kvm/x86.c:5775:23: warning: shift count >= width of type [-Wshift-count-overflow]
if (cap->args[0] & ~KVM_X86_DISABLE_VALID_EXITS)
^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/uapi/linux/kvm.h:806:12: note: expanded from macro 'KVM_X86_DISABLE_VALID_EXITS'
KVM_X86_DISABLE_EXITS_PER_VCPU)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/uapi/linux/kvm.h:801:51: note: expanded from macro 'KVM_X86_DISABLE_EXITS_PER_VCPU'
#define KVM_X86_DISABLE_EXITS_PER_VCPU (1UL << 63)
^ ~~
arch/x86/kvm/x86.c:5787:23: warning: shift count >= width of type [-Wshift-count-overflow]
if ((cap->args[0] & KVM_X86_DISABLE_EXITS_PER_VCPU) &&
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/uapi/linux/kvm.h:801:51: note: expanded from macro 'KVM_X86_DISABLE_EXITS_PER_VCPU'
#define KVM_X86_DISABLE_EXITS_PER_VCPU (1UL << 63)
^ ~~
arch/x86/kvm/x86.c:2335:19: warning: unused function 'gtod_is_based_on_tsc' [-Wunused-function]
static inline int gtod_is_based_on_tsc(int mode)
^
3 warnings generated.
vim +5775 arch/x86/kvm/x86.c
23d43cf998275bc Christoffer Dall 2012-07-24 5724
e5d83c74a5800c2 Paolo Bonzini 2017-02-16 5725 int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
90de4a1875180f8 Nadav Amit 2015-04-13 5726 struct kvm_enable_cap *cap)
90de4a1875180f8 Nadav Amit 2015-04-13 5727 {
90de4a1875180f8 Nadav Amit 2015-04-13 5728 int r;
90de4a1875180f8 Nadav Amit 2015-04-13 5729
90de4a1875180f8 Nadav Amit 2015-04-13 5730 if (cap->flags)
90de4a1875180f8 Nadav Amit 2015-04-13 5731 return -EINVAL;
90de4a1875180f8 Nadav Amit 2015-04-13 5732
90de4a1875180f8 Nadav Amit 2015-04-13 5733 switch (cap->cap) {
90de4a1875180f8 Nadav Amit 2015-04-13 5734 case KVM_CAP_DISABLE_QUIRKS:
90de4a1875180f8 Nadav Amit 2015-04-13 5735 kvm->arch.disabled_quirks = cap->args[0];
90de4a1875180f8 Nadav Amit 2015-04-13 5736 r = 0;
90de4a1875180f8 Nadav Amit 2015-04-13 5737 break;
49df6397edfc5a8 Steve Rutherford 2015-07-29 5738 case KVM_CAP_SPLIT_IRQCHIP: {
49df6397edfc5a8 Steve Rutherford 2015-07-29 5739 mutex_lock(&kvm->lock);
b053b2aef25d007 Steve Rutherford 2015-07-29 5740 r = -EINVAL;
b053b2aef25d007 Steve Rutherford 2015-07-29 5741 if (cap->args[0] > MAX_NR_RESERVED_IOAPIC_PINS)
b053b2aef25d007 Steve Rutherford 2015-07-29 5742 goto split_irqchip_unlock;
49df6397edfc5a8 Steve Rutherford 2015-07-29 5743 r = -EEXIST;
49df6397edfc5a8 Steve Rutherford 2015-07-29 5744 if (irqchip_in_kernel(kvm))
49df6397edfc5a8 Steve Rutherford 2015-07-29 5745 goto split_irqchip_unlock;
557abc40d121358 Paolo Bonzini 2016-06-13 5746 if (kvm->created_vcpus)
49df6397edfc5a8 Steve Rutherford 2015-07-29 5747 goto split_irqchip_unlock;
49df6397edfc5a8 Steve Rutherford 2015-07-29 5748 r = kvm_setup_empty_irq_routing(kvm);
5c0aea0e8d98e38 David Hildenbrand 2017-04-28 5749 if (r)
49df6397edfc5a8 Steve Rutherford 2015-07-29 5750 goto split_irqchip_unlock;
49df6397edfc5a8 Steve Rutherford 2015-07-29 5751 /* Pairs with irqchip_in_kernel. */
49df6397edfc5a8 Steve Rutherford 2015-07-29 5752 smp_wmb();
49776faf93f8074 Radim Krčmář 2016-12-16 5753 kvm->arch.irqchip_mode = KVM_IRQCHIP_SPLIT;
b053b2aef25d007 Steve Rutherford 2015-07-29 5754 kvm->arch.nr_reserved_ioapic_pins = cap->args[0];
ef8b4b7203682cc Paolo Bonzini 2021-11-30 5755 kvm_request_apicv_update(kvm, true, APICV_INHIBIT_REASON_ABSENT);
49df6397edfc5a8 Steve Rutherford 2015-07-29 5756 r = 0;
49df6397edfc5a8 Steve Rutherford 2015-07-29 5757 split_irqchip_unlock:
49df6397edfc5a8 Steve Rutherford 2015-07-29 5758 mutex_unlock(&kvm->lock);
49df6397edfc5a8 Steve Rutherford 2015-07-29 5759 break;
49df6397edfc5a8 Steve Rutherford 2015-07-29 5760 }
3713131345fbea2 Radim Krčmář 2016-07-12 5761 case KVM_CAP_X2APIC_API:
3713131345fbea2 Radim Krčmář 2016-07-12 5762 r = -EINVAL;
3713131345fbea2 Radim Krčmář 2016-07-12 5763 if (cap->args[0] & ~KVM_X2APIC_API_VALID_FLAGS)
3713131345fbea2 Radim Krčmář 2016-07-12 5764 break;
3713131345fbea2 Radim Krčmář 2016-07-12 5765
3713131345fbea2 Radim Krčmář 2016-07-12 5766 if (cap->args[0] & KVM_X2APIC_API_USE_32BIT_IDS)
3713131345fbea2 Radim Krčmář 2016-07-12 5767 kvm->arch.x2apic_format = true;
c519265f2aa348b Radim Krčmář 2016-07-12 5768 if (cap->args[0] & KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK)
c519265f2aa348b Radim Krčmář 2016-07-12 5769 kvm->arch.x2apic_broadcast_quirk_disabled = true;
3713131345fbea2 Radim Krčmář 2016-07-12 5770
3713131345fbea2 Radim Krčmář 2016-07-12 5771 r = 0;
3713131345fbea2 Radim Krčmář 2016-07-12 5772 break;
4d5422cea3b61f1 Wanpeng Li 2018-03-12 5773 case KVM_CAP_X86_DISABLE_EXITS:
4d5422cea3b61f1 Wanpeng Li 2018-03-12 5774 r = -EINVAL;
4d5422cea3b61f1 Wanpeng Li 2018-03-12 @5775 if (cap->args[0] & ~KVM_X86_DISABLE_VALID_EXITS)
4d5422cea3b61f1 Wanpeng Li 2018-03-12 5776 break;
4d5422cea3b61f1 Wanpeng Li 2018-03-12 5777
4d5422cea3b61f1 Wanpeng Li 2018-03-12 5778 if ((cap->args[0] & KVM_X86_DISABLE_EXITS_MWAIT) &&
4d5422cea3b61f1 Wanpeng Li 2018-03-12 5779 kvm_can_mwait_in_guest())
4d5422cea3b61f1 Wanpeng Li 2018-03-12 5780 kvm->arch.mwait_in_guest = true;
766d3571d8e50d3 Michael S. Tsirkin 2018-06-08 5781 if (cap->args[0] & KVM_X86_DISABLE_EXITS_HLT)
caa057a2cad647f Wanpeng Li 2018-03-12 5782 kvm->arch.hlt_in_guest = true;
b31c114b82b2b55 Wanpeng Li 2018-03-12 5783 if (cap->args[0] & KVM_X86_DISABLE_EXITS_PAUSE)
b31c114b82b2b55 Wanpeng Li 2018-03-12 5784 kvm->arch.pause_in_guest = true;
b51700632e0e532 Wanpeng Li 2019-05-21 5785 if (cap->args[0] & KVM_X86_DISABLE_EXITS_CSTATE)
b51700632e0e532 Wanpeng Li 2019-05-21 5786 kvm->arch.cstate_in_guest = true;
08f20df47a09e32 Kechen Lu 2021-12-13 5787 if ((cap->args[0] & KVM_X86_DISABLE_EXITS_PER_VCPU) &&
08f20df47a09e32 Kechen Lu 2021-12-13 5788 cap->args[1])
08f20df47a09e32 Kechen Lu 2021-12-13 5789 kvm->arch.exits_disable_vcpu_mask = cap->args[1];
4d5422cea3b61f1 Wanpeng Li 2018-03-12 5790 r = 0;
4d5422cea3b61f1 Wanpeng Li 2018-03-12 5791 break;
6fbbde9a1969dfb Drew Schmitt 2018-08-20 5792 case KVM_CAP_MSR_PLATFORM_INFO:
6fbbde9a1969dfb Drew Schmitt 2018-08-20 5793 kvm->arch.guest_can_read_msr_platform_info = cap->args[0];
6fbbde9a1969dfb Drew Schmitt 2018-08-20 5794 r = 0;
c4f55198c7c2b87 Jim Mattson 2018-10-16 5795 break;
c4f55198c7c2b87 Jim Mattson 2018-10-16 5796 case KVM_CAP_EXCEPTION_PAYLOAD:
c4f55198c7c2b87 Jim Mattson 2018-10-16 5797 kvm->arch.exception_payload_enabled = cap->args[0];
c4f55198c7c2b87 Jim Mattson 2018-10-16 5798 r = 0;
6fbbde9a1969dfb Drew Schmitt 2018-08-20 5799 break;
1ae099540e8c7f1 Alexander Graf 2020-09-25 5800 case KVM_CAP_X86_USER_SPACE_MSR:
1ae099540e8c7f1 Alexander Graf 2020-09-25 5801 kvm->arch.user_space_msr_mask = cap->args[0];
1ae099540e8c7f1 Alexander Graf 2020-09-25 5802 r = 0;
1ae099540e8c7f1 Alexander Graf 2020-09-25 5803 break;
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5804 case KVM_CAP_X86_BUS_LOCK_EXIT:
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5805 r = -EINVAL;
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5806 if (cap->args[0] & ~KVM_BUS_LOCK_DETECTION_VALID_MODE)
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5807 break;
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5808
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5809 if ((cap->args[0] & KVM_BUS_LOCK_DETECTION_OFF) &&
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5810 (cap->args[0] & KVM_BUS_LOCK_DETECTION_EXIT))
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5811 break;
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5812
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5813 if (kvm_has_bus_lock_exit &&
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5814 cap->args[0] & KVM_BUS_LOCK_DETECTION_EXIT)
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5815 kvm->arch.bus_lock_detection_enabled = true;
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5816 r = 0;
fe6b6bc802b4008 Chenyi Qiang 2020-11-06 5817 break;
fe7e948837f312d Sean Christopherson 2021-04-12 5818 #ifdef CONFIG_X86_SGX_KVM
fe7e948837f312d Sean Christopherson 2021-04-12 5819 case KVM_CAP_SGX_ATTRIBUTE: {
fe7e948837f312d Sean Christopherson 2021-04-12 5820 unsigned long allowed_attributes = 0;
fe7e948837f312d Sean Christopherson 2021-04-12 5821
fe7e948837f312d Sean Christopherson 2021-04-12 5822 r = sgx_set_attribute(&allowed_attributes, cap->args[0]);
fe7e948837f312d Sean Christopherson 2021-04-12 5823 if (r)
fe7e948837f312d Sean Christopherson 2021-04-12 5824 break;
fe7e948837f312d Sean Christopherson 2021-04-12 5825
fe7e948837f312d Sean Christopherson 2021-04-12 5826 /* KVM only supports the PROVISIONKEY privileged attribute. */
fe7e948837f312d Sean Christopherson 2021-04-12 5827 if ((allowed_attributes & SGX_ATTR_PROVISIONKEY) &&
fe7e948837f312d Sean Christopherson 2021-04-12 5828 !(allowed_attributes & ~SGX_ATTR_PROVISIONKEY))
fe7e948837f312d Sean Christopherson 2021-04-12 5829 kvm->arch.sgx_provisioning_allowed = true;
fe7e948837f312d Sean Christopherson 2021-04-12 5830 else
fe7e948837f312d Sean Christopherson 2021-04-12 5831 r = -EINVAL;
fe7e948837f312d Sean Christopherson 2021-04-12 5832 break;
fe7e948837f312d Sean Christopherson 2021-04-12 5833 }
fe7e948837f312d Sean Christopherson 2021-04-12 5834 #endif
54526d1fd59338f Nathan Tempelman 2021-04-08 5835 case KVM_CAP_VM_COPY_ENC_CONTEXT_FROM:
54526d1fd59338f Nathan Tempelman 2021-04-08 5836 r = -EINVAL;
54526d1fd59338f Nathan Tempelman 2021-04-08 5837 if (kvm_x86_ops.vm_copy_enc_context_from)
54526d1fd59338f Nathan Tempelman 2021-04-08 5838 r = kvm_x86_ops.vm_copy_enc_context_from(kvm, cap->args[0]);
54526d1fd59338f Nathan Tempelman 2021-04-08 5839 return r;
b56639318bb2be6 Peter Gonda 2021-10-21 5840 case KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM:
b56639318bb2be6 Peter Gonda 2021-10-21 5841 r = -EINVAL;
b56639318bb2be6 Peter Gonda 2021-10-21 5842 if (kvm_x86_ops.vm_move_enc_context_from)
b56639318bb2be6 Peter Gonda 2021-10-21 5843 r = kvm_x86_ops.vm_move_enc_context_from(
b56639318bb2be6 Peter Gonda 2021-10-21 5844 kvm, cap->args[0]);
b56639318bb2be6 Peter Gonda 2021-10-21 5845 return r;
0dbb11230437895 Ashish Kalra 2021-06-08 5846 case KVM_CAP_EXIT_HYPERCALL:
0dbb11230437895 Ashish Kalra 2021-06-08 5847 if (cap->args[0] & ~KVM_EXIT_HYPERCALL_VALID_MASK) {
0dbb11230437895 Ashish Kalra 2021-06-08 5848 r = -EINVAL;
0dbb11230437895 Ashish Kalra 2021-06-08 5849 break;
0dbb11230437895 Ashish Kalra 2021-06-08 5850 }
0dbb11230437895 Ashish Kalra 2021-06-08 5851 kvm->arch.hypercall_exit_enabled = cap->args[0];
0dbb11230437895 Ashish Kalra 2021-06-08 5852 r = 0;
0dbb11230437895 Ashish Kalra 2021-06-08 5853 break;
19238e75bd8ed8f Aaron Lewis 2021-05-10 5854 case KVM_CAP_EXIT_ON_EMULATION_FAILURE:
19238e75bd8ed8f Aaron Lewis 2021-05-10 5855 r = -EINVAL;
19238e75bd8ed8f Aaron Lewis 2021-05-10 5856 if (cap->args[0] & ~1)
19238e75bd8ed8f Aaron Lewis 2021-05-10 5857 break;
19238e75bd8ed8f Aaron Lewis 2021-05-10 5858 kvm->arch.exit_on_emulation_error = cap->args[0];
19238e75bd8ed8f Aaron Lewis 2021-05-10 5859 r = 0;
19238e75bd8ed8f Aaron Lewis 2021-05-10 5860 break;
90de4a1875180f8 Nadav Amit 2015-04-13 5861 default:
90de4a1875180f8 Nadav Amit 2015-04-13 5862 r = -EINVAL;
90de4a1875180f8 Nadav Amit 2015-04-13 5863 break;
90de4a1875180f8 Nadav Amit 2015-04-13 5864 }
90de4a1875180f8 Nadav Amit 2015-04-13 5865 return r;
90de4a1875180f8 Nadav Amit 2015-04-13 5866 }
90de4a1875180f8 Nadav Amit 2015-04-13 5867
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH] KVM: x86: add kvm per-vCPU exits disable capability
2021-12-14 3:32 [RFC PATCH] KVM: x86: add kvm per-vCPU exits disable capability Kechen Lu
2021-12-14 7:23 ` kernel test robot
@ 2021-12-14 7:54 ` kernel test robot
2021-12-14 9:58 ` kernel test robot
2021-12-14 18:56 ` Sean Christopherson
3 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2021-12-14 7:54 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 3585 bytes --]
Hi Kechen,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on kvm/queue]
[also build test WARNING on mst-vhost/linux-next tip/master linux/master linus/master v5.16-rc5]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Kechen-Lu/KVM-x86-add-kvm-per-vCPU-exits-disable-capability/20211214-113446
base: https://git.kernel.org/pub/scm/virt/kvm/kvm.git queue
config: i386-randconfig-a014-20211213 (https://download.01.org/0day-ci/archive/20211214/202112141530.ZQIO4PKE-lkp(a)intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/08f20df47a09e327aee3e73a8d7c77b1ffc01bc0
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Kechen-Lu/KVM-x86-add-kvm-per-vCPU-exits-disable-capability/20211214-113446
git checkout 08f20df47a09e327aee3e73a8d7c77b1ffc01bc0
# save the config file to linux build tree
mkdir build_dir
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash arch/x86/kvm/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
In file included from include/linux/kvm_host.h:38,
from arch/x86/kvm/x86.c:19:
arch/x86/kvm/x86.c: In function 'kvm_vm_ioctl_enable_cap':
>> include/uapi/linux/kvm.h:801:51: warning: left shift count >= width of type [-Wshift-count-overflow]
801 | #define KVM_X86_DISABLE_EXITS_PER_VCPU (1UL << 63)
| ^~
include/uapi/linux/kvm.h:806:12: note: in expansion of macro 'KVM_X86_DISABLE_EXITS_PER_VCPU'
806 | KVM_X86_DISABLE_EXITS_PER_VCPU)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/kvm/x86.c:5775:23: note: in expansion of macro 'KVM_X86_DISABLE_VALID_EXITS'
5775 | if (cap->args[0] & ~KVM_X86_DISABLE_VALID_EXITS)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>> include/uapi/linux/kvm.h:801:51: warning: left shift count >= width of type [-Wshift-count-overflow]
801 | #define KVM_X86_DISABLE_EXITS_PER_VCPU (1UL << 63)
| ^~
arch/x86/kvm/x86.c:5787:23: note: in expansion of macro 'KVM_X86_DISABLE_EXITS_PER_VCPU'
5787 | if ((cap->args[0] & KVM_X86_DISABLE_EXITS_PER_VCPU) &&
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +801 include/uapi/linux/kvm.h
796
797 #define KVM_X86_DISABLE_EXITS_MWAIT (1 << 0)
798 #define KVM_X86_DISABLE_EXITS_HLT (1 << 1)
799 #define KVM_X86_DISABLE_EXITS_PAUSE (1 << 2)
800 #define KVM_X86_DISABLE_EXITS_CSTATE (1 << 3)
> 801 #define KVM_X86_DISABLE_EXITS_PER_VCPU (1UL << 63)
802 #define KVM_X86_DISABLE_VALID_EXITS (KVM_X86_DISABLE_EXITS_MWAIT | \
803 KVM_X86_DISABLE_EXITS_HLT | \
804 KVM_X86_DISABLE_EXITS_PAUSE | \
805 KVM_X86_DISABLE_EXITS_CSTATE| \
806 KVM_X86_DISABLE_EXITS_PER_VCPU)
807
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH] KVM: x86: add kvm per-vCPU exits disable capability
2021-12-14 3:32 [RFC PATCH] KVM: x86: add kvm per-vCPU exits disable capability Kechen Lu
2021-12-14 7:23 ` kernel test robot
2021-12-14 7:54 ` kernel test robot
@ 2021-12-14 9:58 ` kernel test robot
2021-12-14 18:56 ` Sean Christopherson
3 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2021-12-14 9:58 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 3619 bytes --]
Hi Kechen,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on kvm/queue]
[also build test ERROR on mst-vhost/linux-next tip/master linux/master linus/master v5.16-rc5]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Kechen-Lu/KVM-x86-add-kvm-per-vCPU-exits-disable-capability/20211214-113446
base: https://git.kernel.org/pub/scm/virt/kvm/kvm.git queue
config: i386-randconfig-a012-20211213 (https://download.01.org/0day-ci/archive/20211214/202112141758.daZ9vc3P-lkp(a)intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/08f20df47a09e327aee3e73a8d7c77b1ffc01bc0
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Kechen-Lu/KVM-x86-add-kvm-per-vCPU-exits-disable-capability/20211214-113446
git checkout 08f20df47a09e327aee3e73a8d7c77b1ffc01bc0
# save the config file to linux build tree
mkdir build_dir
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
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 >>):
In file included from include/linux/kvm_host.h:38,
from arch/x86/kvm/x86.c:19:
arch/x86/kvm/x86.c: In function 'kvm_vm_ioctl_enable_cap':
>> include/uapi/linux/kvm.h:801:51: error: left shift count >= width of type [-Werror=shift-count-overflow]
801 | #define KVM_X86_DISABLE_EXITS_PER_VCPU (1UL << 63)
| ^~
include/uapi/linux/kvm.h:806:12: note: in expansion of macro 'KVM_X86_DISABLE_EXITS_PER_VCPU'
806 | KVM_X86_DISABLE_EXITS_PER_VCPU)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/kvm/x86.c:5775:23: note: in expansion of macro 'KVM_X86_DISABLE_VALID_EXITS'
5775 | if (cap->args[0] & ~KVM_X86_DISABLE_VALID_EXITS)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>> include/uapi/linux/kvm.h:801:51: error: left shift count >= width of type [-Werror=shift-count-overflow]
801 | #define KVM_X86_DISABLE_EXITS_PER_VCPU (1UL << 63)
| ^~
arch/x86/kvm/x86.c:5787:23: note: in expansion of macro 'KVM_X86_DISABLE_EXITS_PER_VCPU'
5787 | if ((cap->args[0] & KVM_X86_DISABLE_EXITS_PER_VCPU) &&
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
vim +801 include/uapi/linux/kvm.h
796
797 #define KVM_X86_DISABLE_EXITS_MWAIT (1 << 0)
798 #define KVM_X86_DISABLE_EXITS_HLT (1 << 1)
799 #define KVM_X86_DISABLE_EXITS_PAUSE (1 << 2)
800 #define KVM_X86_DISABLE_EXITS_CSTATE (1 << 3)
> 801 #define KVM_X86_DISABLE_EXITS_PER_VCPU (1UL << 63)
802 #define KVM_X86_DISABLE_VALID_EXITS (KVM_X86_DISABLE_EXITS_MWAIT | \
803 KVM_X86_DISABLE_EXITS_HLT | \
804 KVM_X86_DISABLE_EXITS_PAUSE | \
805 KVM_X86_DISABLE_EXITS_CSTATE| \
806 KVM_X86_DISABLE_EXITS_PER_VCPU)
807
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH] KVM: x86: add kvm per-vCPU exits disable capability
2021-12-14 3:32 [RFC PATCH] KVM: x86: add kvm per-vCPU exits disable capability Kechen Lu
` (2 preceding siblings ...)
2021-12-14 9:58 ` kernel test robot
@ 2021-12-14 18:56 ` Sean Christopherson
2021-12-14 21:07 ` Kechen Lu
3 siblings, 1 reply; 7+ messages in thread
From: Sean Christopherson @ 2021-12-14 18:56 UTC (permalink / raw)
To: Kechen Lu
Cc: kvm, pbonzini, wanpengli, rkrcmar, vkuznets, somduttar, linux-kernel
On Mon, Dec 13, 2021, Kechen Lu wrote:
> ---
> Documentation/virt/kvm/api.rst | 8 +++++++-
> arch/x86/include/asm/kvm_host.h | 1 +
> arch/x86/kvm/cpuid.c | 2 +-
> arch/x86/kvm/svm/svm.c | 2 +-
> arch/x86/kvm/vmx/vmx.c | 4 ++--
> arch/x86/kvm/x86.c | 5 ++++-
> arch/x86/kvm/x86.h | 5 +++--
> include/uapi/linux/kvm.h | 4 +++-
> 8 files changed, 22 insertions(+), 9 deletions(-)
>
> diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
> index aeeb071c7688..9a44896dc950 100644
> --- a/Documentation/virt/kvm/api.rst
> +++ b/Documentation/virt/kvm/api.rst
> @@ -6580,6 +6580,9 @@ branch to guests' 0x200 interrupt vector.
>
> :Architectures: x86
> :Parameters: args[0] defines which exits are disabled
> + args[1] defines vCPU bitmask based on vCPU ID, 1 on
> + corresponding vCPU ID bit would enable exists
> + on that vCPU
> :Returns: 0 on success, -EINVAL when args[0] contains invalid exits
>
> Valid bits in args[0] are::
> @@ -6588,13 +6591,16 @@ Valid bits in args[0] are::
> #define KVM_X86_DISABLE_EXITS_HLT (1 << 1)
> #define KVM_X86_DISABLE_EXITS_PAUSE (1 << 2)
> #define KVM_X86_DISABLE_EXITS_CSTATE (1 << 3)
> + #define KVM_X86_DISABLE_EXITS_PER_VCPU (1UL << 63)
This doesn't scale, there are already plenty of use cases for VMs with 65+ vCPUs.
At a glance, I don't see anything fundamentally wrong with simply supporting a
vCPU-scoped ioctl().
The VM-scoped version already has an undocumented requirement that it be called
before vCPUs are created, because neither VMX nor SVM will update the controls
if exits are disabled after vCPUs are created. That means the flags checked at
runtime can be purely vCPU, with the per-VM flag picked up at vCPU creation.
Probably worth formalizing that requirement too, e.g.
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 85127b3e3690..6c9bc022a522 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5775,6 +5775,10 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
if (cap->args[0] & ~KVM_X86_DISABLE_VALID_EXITS)
break;
+ mutex_lock(&kvm->lock);
+ if (kvm->created_vcpus)
+ goto disable_exits_unlock;
+
if ((cap->args[0] & KVM_X86_DISABLE_EXITS_MWAIT) &&
kvm_can_mwait_in_guest())
kvm->arch.mwait_in_guest = true;
@@ -5785,6 +5789,8 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
if (cap->args[0] & KVM_X86_DISABLE_EXITS_CSTATE)
kvm->arch.cstate_in_guest = true;
r = 0;
+disable_exits_unlock:
+ mutex_unlock(&kvm->lock);
break;
case KVM_CAP_MSR_PLATFORM_INFO:
kvm->arch.guest_can_read_msr_platform_info = cap->args[0];
^ permalink raw reply related [flat|nested] 7+ messages in thread
* RE: [RFC PATCH] KVM: x86: add kvm per-vCPU exits disable capability
2021-12-14 18:56 ` Sean Christopherson
@ 2021-12-14 21:07 ` Kechen Lu
0 siblings, 0 replies; 7+ messages in thread
From: Kechen Lu @ 2021-12-14 21:07 UTC (permalink / raw)
To: Sean Christopherson
Cc: kvm, pbonzini, wanpengli, rkrcmar, vkuznets, Somdutta Roy, linux-kernel
> -----Original Message-----
> From: Sean Christopherson <seanjc@google.com>
> Sent: Tuesday, December 14, 2021 10:56 AM
> To: Kechen Lu <kechenl@nvidia.com>
> Cc: kvm@vger.kernel.org; pbonzini@redhat.com; wanpengli@tencent.com;
> rkrcmar@redhat.com; vkuznets@redhat.com; Somdutta Roy
> <somduttar@nvidia.com>; linux-kernel@vger.kernel.org
> Subject: Re: [RFC PATCH] KVM: x86: add kvm per-vCPU exits disable
> capability
>
> External email: Use caution opening links or attachments
>
>
> On Mon, Dec 13, 2021, Kechen Lu wrote:
> > ---
> > Documentation/virt/kvm/api.rst | 8 +++++++-
> > arch/x86/include/asm/kvm_host.h | 1 +
> > arch/x86/kvm/cpuid.c | 2 +-
> > arch/x86/kvm/svm/svm.c | 2 +-
> > arch/x86/kvm/vmx/vmx.c | 4 ++--
> > arch/x86/kvm/x86.c | 5 ++++-
> > arch/x86/kvm/x86.h | 5 +++--
> > include/uapi/linux/kvm.h | 4 +++-
> > 8 files changed, 22 insertions(+), 9 deletions(-)
> >
> > diff --git a/Documentation/virt/kvm/api.rst
> > b/Documentation/virt/kvm/api.rst index aeeb071c7688..9a44896dc950
> > 100644
> > --- a/Documentation/virt/kvm/api.rst
> > +++ b/Documentation/virt/kvm/api.rst
> > @@ -6580,6 +6580,9 @@ branch to guests' 0x200 interrupt vector.
> >
> > :Architectures: x86
> > :Parameters: args[0] defines which exits are disabled
> > + args[1] defines vCPU bitmask based on vCPU ID, 1 on
> > + corresponding vCPU ID bit would enable exists
> > + on that vCPU
> > :Returns: 0 on success, -EINVAL when args[0] contains invalid exits
> >
> > Valid bits in args[0] are::
> > @@ -6588,13 +6591,16 @@ Valid bits in args[0] are::
> > #define KVM_X86_DISABLE_EXITS_HLT (1 << 1)
> > #define KVM_X86_DISABLE_EXITS_PAUSE (1 << 2)
> > #define KVM_X86_DISABLE_EXITS_CSTATE (1 << 3)
> > + #define KVM_X86_DISABLE_EXITS_PER_VCPU (1UL << 63)
>
> This doesn't scale, there are already plenty of use cases for VMs with 65+
> vCPUs.
> At a glance, I don't see anything fundamentally wrong with simply supporting
> a vCPU-scoped ioctl().
>
Yeah, scale is the problem for using a 64bit mask, so in this RFC patch I use rol64(1UL, vcpu->vcpu_id) to rotating left shift the vCPU ID bits. But seems doing it through vcpu ioctl makes more sense.
From my understanding, so we could add a new vcpu ioctrl e.g. KVM_DISABLE_EXITS, with parameter flag which exists to be disabled, e.g. struct exits_in_guest (in), or even without parameter just like you mentioned, pick up the per-VM cap flag the userspace set.
> The VM-scoped version already has an undocumented requirement that it
> be called before vCPUs are created, because neither VMX nor SVM will
> update the controls if exits are disabled after vCPUs are created. That means
> the flags checked at runtime can be purely vCPU, with the per-VM flag
> picked up at vCPU creation.
>
> Probably worth formalizing that requirement too, e.g.
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index
> 85127b3e3690..6c9bc022a522 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -5775,6 +5775,10 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
> if (cap->args[0] & ~KVM_X86_DISABLE_VALID_EXITS)
> break;
>
> + mutex_lock(&kvm->lock);
> + if (kvm->created_vcpus)
> + goto disable_exits_unlock;
> +
> if ((cap->args[0] & KVM_X86_DISABLE_EXITS_MWAIT) &&
> kvm_can_mwait_in_guest())
> kvm->arch.mwait_in_guest = true; @@ -5785,6 +5789,8 @@ int
> kvm_vm_ioctl_enable_cap(struct kvm *kvm,
> if (cap->args[0] & KVM_X86_DISABLE_EXITS_CSTATE)
> kvm->arch.cstate_in_guest = true;
> r = 0;
> +disable_exits_unlock:
> + mutex_unlock(&kvm->lock);
> break;
> case KVM_CAP_MSR_PLATFORM_INFO:
> kvm->arch.guest_can_read_msr_platform_info = cap->args[0];
Got it. Will add this explicit requirement check as a subpatch in next version.
Thanks for the quick review!
Best Regards,
Kechen
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-12-14 21:07 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-14 3:32 [RFC PATCH] KVM: x86: add kvm per-vCPU exits disable capability Kechen Lu
2021-12-14 7:23 ` kernel test robot
2021-12-14 7:23 ` kernel test robot
2021-12-14 7:54 ` kernel test robot
2021-12-14 9:58 ` kernel test robot
2021-12-14 18:56 ` Sean Christopherson
2021-12-14 21:07 ` Kechen Lu
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.