* [PATCH 1/3] KVM: x86: Disallow enable KVM_CAP_X86_DISABLE_EXITS capability after vCPUs have been created
@ 2023-03-30 12:35 Hou Wenlong
2023-04-06 3:18 ` Sean Christopherson
2023-04-07 2:01 ` Xiaoyao Li
0 siblings, 2 replies; 3+ messages in thread
From: Hou Wenlong @ 2023-03-30 12:35 UTC (permalink / raw)
To: kvm
Cc: Paolo Bonzini, Jonathan Corbet, Sean Christopherson,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, linux-doc, linux-kernel
Disable PAUSE/MWAIT/HLT exits after vCPUs have been created is useless,
because PAUSE/MWAIT/HLT intercepts configuration is not changed after
vCPU created. And two vCPUs may have inconsistent configuration if
disable PAUSE/MWAIT/HLT exits between those two vCPUs creation. Since
it's a per-VM capability, all vCPUs should keep same configuration, so
disallow enable KVM_CAP_X86_DISABLE_EXITS capability after vCPUs have
been created.
Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com>
---
Documentation/virt/kvm/api.rst | 3 ++-
arch/x86/kvm/x86.c | 5 +++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index a69e91088d76..95a683a27cf2 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -7179,7 +7179,8 @@ branch to guests' 0x200 interrupt vector.
:Architectures: x86
:Parameters: args[0] defines which exits are disabled
-:Returns: 0 on success, -EINVAL when args[0] contains invalid exits
+:Returns: 0 on success, -EINVAL when args[0] contains invalid exits or
+ any vCPUs have been created.
Valid bits in args[0] are::
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2c0ff40e5345..7e97595465fc 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -6275,6 +6275,9 @@ 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_PAUSE)
kvm->arch.pause_in_guest = true;
@@ -6296,6 +6299,8 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
}
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];
base-commit: 27d6845d258b67f4eb3debe062b7dacc67e0c393
--
2.31.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/3] KVM: x86: Disallow enable KVM_CAP_X86_DISABLE_EXITS capability after vCPUs have been created
2023-03-30 12:35 [PATCH 1/3] KVM: x86: Disallow enable KVM_CAP_X86_DISABLE_EXITS capability after vCPUs have been created Hou Wenlong
@ 2023-04-06 3:18 ` Sean Christopherson
2023-04-07 2:01 ` Xiaoyao Li
1 sibling, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2023-04-06 3:18 UTC (permalink / raw)
To: Hou Wenlong
Cc: kvm, Paolo Bonzini, Jonathan Corbet, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, linux-doc,
linux-kernel
On Thu, Mar 30, 2023, Hou Wenlong wrote:
> Disable PAUSE/MWAIT/HLT exits after vCPUs have been created is useless,
> because PAUSE/MWAIT/HLT intercepts configuration is not changed after
> vCPU created. And two vCPUs may have inconsistent configuration if
> disable PAUSE/MWAIT/HLT exits between those two vCPUs creation. Since
> it's a per-VM capability, all vCPUs should keep same configuration, so
> disallow enable KVM_CAP_X86_DISABLE_EXITS capability after vCPUs have
> been created.
>
> Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com>
> ---
> Documentation/virt/kvm/api.rst | 3 ++-
> arch/x86/kvm/x86.c | 5 +++++
> 2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
> index a69e91088d76..95a683a27cf2 100644
> --- a/Documentation/virt/kvm/api.rst
> +++ b/Documentation/virt/kvm/api.rst
> @@ -7179,7 +7179,8 @@ branch to guests' 0x200 interrupt vector.
>
> :Architectures: x86
> :Parameters: args[0] defines which exits are disabled
> -:Returns: 0 on success, -EINVAL when args[0] contains invalid exits
> +:Returns: 0 on success, -EINVAL when args[0] contains invalid exits or
> + any vCPUs have been created.
>
> Valid bits in args[0] are::
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 2c0ff40e5345..7e97595465fc 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -6275,6 +6275,9 @@ 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_PAUSE)
> kvm->arch.pause_in_guest = true;
>
> @@ -6296,6 +6299,8 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
> }
>
> r = 0;
> +disable_exits_unlock:
Hah! I thought this looked familiar[*] :-)
[*] https://lkml.kernel.org/r/DM6PR12MB35000D46146BA68EE294953BCACB9%40DM6PR12MB3500.namprd12.prod.outlook.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/3] KVM: x86: Disallow enable KVM_CAP_X86_DISABLE_EXITS capability after vCPUs have been created
2023-03-30 12:35 [PATCH 1/3] KVM: x86: Disallow enable KVM_CAP_X86_DISABLE_EXITS capability after vCPUs have been created Hou Wenlong
2023-04-06 3:18 ` Sean Christopherson
@ 2023-04-07 2:01 ` Xiaoyao Li
1 sibling, 0 replies; 3+ messages in thread
From: Xiaoyao Li @ 2023-04-07 2:01 UTC (permalink / raw)
To: Hou Wenlong, kvm
Cc: Paolo Bonzini, Jonathan Corbet, Sean Christopherson,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, linux-doc, linux-kernel
On 3/30/2023 8:35 PM, Hou Wenlong wrote:
> Disable PAUSE/MWAIT/HLT exits after vCPUs have been created is useless,
> because PAUSE/MWAIT/HLT intercepts configuration is not changed after
> vCPU created.
PAUSE intercepts can be updated via
SET_CPUID->vmx_vcpu_after_set_cpuid() after vCPU is created.
Aside it, this patch looks good to me.
> And two vCPUs may have inconsistent configuration if
> disable PAUSE/MWAIT/HLT exits between those two vCPUs creation. Since
> it's a per-VM capability, all vCPUs should keep same configuration, so
> disallow enable KVM_CAP_X86_DISABLE_EXITS capability after vCPUs have
> been created.
>
> Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com>
> ---
> Documentation/virt/kvm/api.rst | 3 ++-
> arch/x86/kvm/x86.c | 5 +++++
> 2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
> index a69e91088d76..95a683a27cf2 100644
> --- a/Documentation/virt/kvm/api.rst
> +++ b/Documentation/virt/kvm/api.rst
> @@ -7179,7 +7179,8 @@ branch to guests' 0x200 interrupt vector.
>
> :Architectures: x86
> :Parameters: args[0] defines which exits are disabled
> -:Returns: 0 on success, -EINVAL when args[0] contains invalid exits
> +:Returns: 0 on success, -EINVAL when args[0] contains invalid exits or
> + any vCPUs have been created.
>
> Valid bits in args[0] are::
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 2c0ff40e5345..7e97595465fc 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -6275,6 +6275,9 @@ 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_PAUSE)
> kvm->arch.pause_in_guest = true;
>
> @@ -6296,6 +6299,8 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
> }
>
> 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];
>
> base-commit: 27d6845d258b67f4eb3debe062b7dacc67e0c393
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-04-07 2:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-30 12:35 [PATCH 1/3] KVM: x86: Disallow enable KVM_CAP_X86_DISABLE_EXITS capability after vCPUs have been created Hou Wenlong
2023-04-06 3:18 ` Sean Christopherson
2023-04-07 2:01 ` Xiaoyao Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).