* [PATCH 0/3] KVM: x86: Cleanups
@ 2023-08-14 22:08 Michal Luczaj
2023-08-14 22:08 ` [PATCH 1/3] KVM: x86: Remove redundant vcpu->arch.cr0 assignments Michal Luczaj
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Michal Luczaj @ 2023-08-14 22:08 UTC (permalink / raw)
To: pbonzini, seanjc, corbet; +Cc: kvm, Michal Luczaj
As discussed[*], some minor clean-ups. Plus an attempt to smuggle a fix for
a typo in API documentation.
[*] https://lore.kernel.org/kvm/e55656be-2752-a317-80eb-ad40e474b62f@redhat.com/
Michal Luczaj (3):
KVM: x86: Remove redundant vcpu->arch.cr0 assignments
KVM: x86: Force TLB flush on changes to special registers
KVM: Correct kvm_vcpu_event(s) typo in KVM API documentation
Documentation/virt/kvm/api.rst | 34 +++++++++++++++++-----------------
arch/x86/kvm/smm.c | 1 -
arch/x86/kvm/x86.c | 9 ++++++---
3 files changed, 23 insertions(+), 21 deletions(-)
--
2.41.0
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 1/3] KVM: x86: Remove redundant vcpu->arch.cr0 assignments 2023-08-14 22:08 [PATCH 0/3] KVM: x86: Cleanups Michal Luczaj @ 2023-08-14 22:08 ` Michal Luczaj 2023-08-14 22:08 ` [PATCH 2/3] KVM: x86: Force TLB flush on changes to special registers Michal Luczaj ` (2 subsequent siblings) 3 siblings, 0 replies; 9+ messages in thread From: Michal Luczaj @ 2023-08-14 22:08 UTC (permalink / raw) To: pbonzini, seanjc, corbet; +Cc: kvm, Michal Luczaj Drop the vcpu->arch.cr0 assignment after static_call(kvm_x86_set_cr0). CR0 was already set by {vmx,svm}_set_cr0(). Signed-off-by: Michal Luczaj <mhal@rbox.co> --- arch/x86/kvm/smm.c | 1 - arch/x86/kvm/x86.c | 1 - 2 files changed, 2 deletions(-) diff --git a/arch/x86/kvm/smm.c b/arch/x86/kvm/smm.c index b42111a24cc2..dc3d95fdca7d 100644 --- a/arch/x86/kvm/smm.c +++ b/arch/x86/kvm/smm.c @@ -324,7 +324,6 @@ void enter_smm(struct kvm_vcpu *vcpu) cr0 = vcpu->arch.cr0 & ~(X86_CR0_PE | X86_CR0_EM | X86_CR0_TS | X86_CR0_PG); static_call(kvm_x86_set_cr0)(vcpu, cr0); - vcpu->arch.cr0 = cr0; static_call(kvm_x86_set_cr4)(vcpu, 0); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c381770bcbf1..c247d3a7f6f9 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11522,7 +11522,6 @@ static int __set_sregs_common(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs, *mmu_reset_needed |= kvm_read_cr0(vcpu) != sregs->cr0; static_call(kvm_x86_set_cr0)(vcpu, sregs->cr0); - vcpu->arch.cr0 = sregs->cr0; *mmu_reset_needed |= kvm_read_cr4(vcpu) != sregs->cr4; static_call(kvm_x86_set_cr4)(vcpu, sregs->cr4); -- 2.41.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/3] KVM: x86: Force TLB flush on changes to special registers 2023-08-14 22:08 [PATCH 0/3] KVM: x86: Cleanups Michal Luczaj 2023-08-14 22:08 ` [PATCH 1/3] KVM: x86: Remove redundant vcpu->arch.cr0 assignments Michal Luczaj @ 2023-08-14 22:08 ` Michal Luczaj 2023-08-14 22:08 ` [PATCH 3/3] KVM: Correct kvm_vcpu_event(s) typo in KVM API documentation Michal Luczaj 2023-09-28 16:41 ` [PATCH 0/3] KVM: x86: Cleanups Sean Christopherson 3 siblings, 0 replies; 9+ messages in thread From: Michal Luczaj @ 2023-08-14 22:08 UTC (permalink / raw) To: pbonzini, seanjc, corbet; +Cc: kvm, Michal Luczaj Userspace can directly modify content of vCPU's EFER/CRn via KVM_SYNC_X86_SREGS and KVM_SET_SREGS{,2}. Make sure that when MMU context reset is triggered, guest's TLB and paging-structure caches will be flushed. Suggested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Michal Luczaj <mhal@rbox.co> --- arch/x86/kvm/x86.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c247d3a7f6f9..4e92ef30a736 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11565,8 +11565,10 @@ static int __set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) if (ret) return ret; - if (mmu_reset_needed) + if (mmu_reset_needed) { kvm_mmu_reset_context(vcpu); + kvm_make_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu); + } max_bits = KVM_NR_INTERRUPTS; pending_vec = find_first_bit( @@ -11607,8 +11609,10 @@ static int __set_sregs2(struct kvm_vcpu *vcpu, struct kvm_sregs2 *sregs2) mmu_reset_needed = 1; vcpu->arch.pdptrs_from_userspace = true; } - if (mmu_reset_needed) + if (mmu_reset_needed) { kvm_mmu_reset_context(vcpu); + kvm_make_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu); + } return 0; } -- 2.41.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/3] KVM: Correct kvm_vcpu_event(s) typo in KVM API documentation 2023-08-14 22:08 [PATCH 0/3] KVM: x86: Cleanups Michal Luczaj 2023-08-14 22:08 ` [PATCH 1/3] KVM: x86: Remove redundant vcpu->arch.cr0 assignments Michal Luczaj 2023-08-14 22:08 ` [PATCH 2/3] KVM: x86: Force TLB flush on changes to special registers Michal Luczaj @ 2023-08-14 22:08 ` Michal Luczaj 2023-08-14 22:28 ` Michal Luczaj 2023-09-28 16:41 ` [PATCH 0/3] KVM: x86: Cleanups Sean Christopherson 3 siblings, 1 reply; 9+ messages in thread From: Michal Luczaj @ 2023-08-14 22:08 UTC (permalink / raw) To: pbonzini, seanjc, corbet; +Cc: kvm, Michal Luczaj Set KVM_GET_VCPU_EVENTS and KVM_SET_VCPU_EVENTS parameter type to `struct kvm_vcpu_events`. Events, plural. Opportunistically fix few other typos. Signed-off-by: Michal Luczaj <mhal@rbox.co> --- I understand that typo fixes are not always welcomed, but this kvm_vcpu_event(s) did actually bit me, causing minor irritation. Documentation/virt/kvm/api.rst | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index c0ddd3035462..b7176e4609ee 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -540,7 +540,7 @@ ioctl is useful if the in-kernel PIC is not used. PPC: ^^^^ -Queues an external interrupt to be injected. This ioctl is overleaded +Queues an external interrupt to be injected. This ioctl is overloaded with 3 different irq values: a) KVM_INTERRUPT_SET @@ -578,7 +578,7 @@ This is an asynchronous vcpu ioctl and can be invoked from any thread. RISC-V: ^^^^^^^ -Queues an external interrupt to be injected into the virutal CPU. This ioctl +Queues an external interrupt to be injected into the virtual CPU. This ioctl is overloaded with 2 different irq values: a) KVM_INTERRUPT_SET @@ -965,7 +965,7 @@ be set in the flags field of this ioctl: The KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL flag requests KVM to generate the contents of the hypercall page automatically; hypercalls will be intercepted and passed to userspace through KVM_EXIT_XEN. In this -ase, all of the blob size and address fields must be zero. +case, all of the blob size and address fields must be zero. The KVM_XEN_HVM_CONFIG_EVTCHN_SEND flag indicates to KVM that userspace will always use the KVM_XEN_HVM_EVTCHN_SEND ioctl to deliver event @@ -1070,7 +1070,7 @@ Other flags returned by ``KVM_GET_CLOCK`` are accepted but ignored. :Extended by: KVM_CAP_INTR_SHADOW :Architectures: x86, arm64 :Type: vcpu ioctl -:Parameters: struct kvm_vcpu_event (out) +:Parameters: struct kvm_vcpu_events (out) :Returns: 0 on success, -1 on error X86: @@ -1193,7 +1193,7 @@ directly to the virtual CPU). :Extended by: KVM_CAP_INTR_SHADOW :Architectures: x86, arm64 :Type: vcpu ioctl -:Parameters: struct kvm_vcpu_event (in) +:Parameters: struct kvm_vcpu_events (in) :Returns: 0 on success, -1 on error X86: @@ -2722,7 +2722,7 @@ The isa config register can be read anytime but can only be written before a Guest VCPU runs. It will have ISA feature bits matching underlying host set by default. -RISC-V core registers represent the general excution state of a Guest VCPU +RISC-V core registers represent the general execution state of a Guest VCPU and it has the following id bit patterns:: 0x8020 0000 02 <index into the kvm_riscv_core struct:24> (32bit Host) @@ -3061,7 +3061,7 @@ as follow:: }; An entry with a "page_shift" of 0 is unused. Because the array is -organized in increasing order, a lookup can stop when encoutering +organized in increasing order, a lookup can stop when encountering such an entry. The "slb_enc" field provides the encoding to use in the SLB for the @@ -3453,7 +3453,7 @@ Possible features: - KVM_RUN and KVM_GET_REG_LIST are not available; - KVM_GET_ONE_REG and KVM_SET_ONE_REG cannot be used to access - the scalable archietctural SVE registers + the scalable architectural SVE registers KVM_REG_ARM64_SVE_ZREG(), KVM_REG_ARM64_SVE_PREG() or KVM_REG_ARM64_SVE_FFR; @@ -4399,7 +4399,7 @@ This will have undefined effects on the guest if it has not already placed itself in a quiescent state where no vcpu will make MMU enabled memory accesses. -On succsful completion, the pending HPT will become the guest's active +On successful completion, the pending HPT will become the guest's active HPT and the previous HPT will be discarded. On failure, the guest will still be operating on its previous HPT. @@ -5014,7 +5014,7 @@ before the vcpu is fully usable. Between KVM_ARM_VCPU_INIT and KVM_ARM_VCPU_FINALIZE, the feature may be configured by use of ioctls such as KVM_SET_ONE_REG. The exact configuration -that should be performaned and how to do it are feature-dependent. +that should be performed and how to do it are feature-dependent. Other calls that depend on a particular feature being finalized, such as KVM_RUN, KVM_GET_REG_LIST, KVM_GET_ONE_REG and KVM_SET_ONE_REG, will fail with @@ -5232,7 +5232,7 @@ KVM_PV_DISABLE Deregister the VM from the Ultravisor and reclaim the memory that had been donated to the Ultravisor, making it usable by the kernel again. All registered VCPUs are converted back to non-protected ones. If a - previous protected VM had been prepared for asynchonous teardown with + previous protected VM had been prepared for asynchronous teardown with KVM_PV_ASYNC_CLEANUP_PREPARE and not subsequently torn down with KVM_PV_ASYNC_CLEANUP_PERFORM, it will be torn down in this call together with the current protected VM. @@ -5473,7 +5473,7 @@ KVM_XEN_ATTR_TYPE_EVTCHN from the guest. A given sending port number may be directed back to a specified vCPU (by APIC ID) / port / priority on the guest, or to trigger events on an eventfd. The vCPU and priority can be changed - by setting KVM_XEN_EVTCHN_UPDATE in a subsequent call, but but other + by setting KVM_XEN_EVTCHN_UPDATE in a subsequent call, but other fields cannot change for a given sending port. A port mapping is removed by using KVM_XEN_EVTCHN_DEASSIGN in the flags field. Passing KVM_XEN_EVTCHN_RESET in the flags field removes all interception of @@ -6263,7 +6263,7 @@ to the byte array. It is strongly recommended that userspace use ``KVM_EXIT_IO`` (x86) or ``KVM_EXIT_MMIO`` (all except s390) to implement functionality that -requires a guest to interact with host userpace. +requires a guest to interact with host userspace. .. note:: KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO. @@ -7510,7 +7510,7 @@ APIC/MSRs/etc). attribute is not supported by KVM. KVM_CAP_SGX_ATTRIBUTE enables a userspace VMM to grant a VM access to one or -more priveleged enclave attributes. args[0] must hold a file handle to a valid +more privileged enclave attributes. args[0] must hold a file handle to a valid SGX attribute file corresponding to an attribute that is supported/restricted by KVM (currently only PROVISIONKEY). @@ -7928,7 +7928,7 @@ writing to the respective MSRs. This capability indicates that userspace can load HV_X64_MSR_VP_INDEX msr. Its value is used to denote the target vcpu for a SynIC interrupt. For -compatibilty, KVM initializes this msr to KVM's internal vcpu index. When this +compatibility, KVM initializes this msr to KVM's internal vcpu index. When this capability is absent, userspace can still query this msr's value. 8.13 KVM_CAP_S390_AIS_MIGRATION @@ -8286,7 +8286,7 @@ the KVM_XEN_ATTR_TYPE_RUNSTATE_UPDATE_FLAG attribute in the KVM_XEN_SET_ATTR and KVM_XEN_GET_ATTR ioctls. This controls whether KVM will set the XEN_RUNSTATE_UPDATE flag in guest memory mapped vcpu_runstate_info during updates of the runstate information. Note that versions of KVM which support -the RUNSTATE feature above, but not thie RUNSTATE_UPDATE_FLAG feature, will +the RUNSTATE feature above, but not the RUNSTATE_UPDATE_FLAG feature, will always set the XEN_RUNSTATE_UPDATE flag when updating the guest structure, which is perhaps counterintuitive. When this flag is advertised, KVM will behave more correctly, not using the XEN_RUNSTATE_UPDATE flag until/unless @@ -8335,7 +8335,7 @@ Architectures: x86 When enabled, KVM will disable emulated Hyper-V features provided to the guest according to the bits Hyper-V CPUID feature leaves. Otherwise, all -currently implmented Hyper-V features are provided unconditionally when +currently implemented Hyper-V features are provided unconditionally when Hyper-V identification is set in the HYPERV_CPUID_INTERFACE (0x40000001) leaf. -- 2.41.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] KVM: Correct kvm_vcpu_event(s) typo in KVM API documentation 2023-08-14 22:08 ` [PATCH 3/3] KVM: Correct kvm_vcpu_event(s) typo in KVM API documentation Michal Luczaj @ 2023-08-14 22:28 ` Michal Luczaj 2023-09-27 20:10 ` Sean Christopherson 0 siblings, 1 reply; 9+ messages in thread From: Michal Luczaj @ 2023-08-14 22:28 UTC (permalink / raw) To: pbonzini, seanjc, corbet; +Cc: kvm On 8/15/23 00:08, Michal Luczaj wrote: > I understand that typo fixes are not always welcomed, but this > kvm_vcpu_event(s) did actually bit me, causing minor irritation. ^^^ Oh, I do feel silly for sending typo fixes with typos... ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] KVM: Correct kvm_vcpu_event(s) typo in KVM API documentation 2023-08-14 22:28 ` Michal Luczaj @ 2023-09-27 20:10 ` Sean Christopherson 2023-09-28 11:58 ` Michal Luczaj 0 siblings, 1 reply; 9+ messages in thread From: Sean Christopherson @ 2023-09-27 20:10 UTC (permalink / raw) To: Michal Luczaj; +Cc: pbonzini, corbet, kvm On Tue, Aug 15, 2023, Michal Luczaj wrote: > On 8/15/23 00:08, Michal Luczaj wrote: > > I understand that typo fixes are not always welcomed, but this > > kvm_vcpu_event(s) did actually bit me, causing minor irritation. > ^^^ FWIW, my bar for fixing typos is if the typo causes any amount of confusion or wasted time. If it causes one person pain, odds are good it'll cause others pain in the future. > Oh, I do feel silly for sending typo fixes with typos... LOL, I'm just disappointed your typo isn't in the changelog proper, because I was absolutely planning on leaving it in there for my own amusement :-) ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] KVM: Correct kvm_vcpu_event(s) typo in KVM API documentation 2023-09-27 20:10 ` Sean Christopherson @ 2023-09-28 11:58 ` Michal Luczaj 2023-09-28 14:37 ` Sean Christopherson 0 siblings, 1 reply; 9+ messages in thread From: Michal Luczaj @ 2023-09-28 11:58 UTC (permalink / raw) To: Sean Christopherson; +Cc: pbonzini, corbet, kvm On 9/27/23 22:10, Sean Christopherson wrote: > On Tue, Aug 15, 2023, Michal Luczaj wrote: >> On 8/15/23 00:08, Michal Luczaj wrote: >>> I understand that typo fixes are not always welcomed, but this >>> kvm_vcpu_event(s) did actually bit me, causing minor irritation. >> ^^^ > > FWIW, my bar for fixing typos is if the typo causes any amount of confusion or > wasted time. If it causes one person pain, odds are good it'll cause others pain > in the future. OK, do you want me to resend just the kvm_vcpu_event(s) fix? (and, empathetically, introduce a typo in the changelog proper :P) >> Oh, I do feel silly for sending typo fixes with typos... > > LOL, I'm just disappointed your typo isn't in the changelog proper, because I was > absolutely planning on leaving it in there for my own amusement :-) ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] KVM: Correct kvm_vcpu_event(s) typo in KVM API documentation 2023-09-28 11:58 ` Michal Luczaj @ 2023-09-28 14:37 ` Sean Christopherson 0 siblings, 0 replies; 9+ messages in thread From: Sean Christopherson @ 2023-09-28 14:37 UTC (permalink / raw) To: Michal Luczaj; +Cc: pbonzini, corbet, kvm On Thu, Sep 28, 2023, Michal Luczaj wrote: > On 9/27/23 22:10, Sean Christopherson wrote: > > On Tue, Aug 15, 2023, Michal Luczaj wrote: > >> On 8/15/23 00:08, Michal Luczaj wrote: > >>> I understand that typo fixes are not always welcomed, but this > >>> kvm_vcpu_event(s) did actually bit me, causing minor irritation. > >> ^^^ > > > > FWIW, my bar for fixing typos is if the typo causes any amount of confusion or > > wasted time. If it causes one person pain, odds are good it'll cause others pain > > in the future. > > OK, do you want me to resend just the kvm_vcpu_event(s) fix? > (and, empathetically, introduce a typo in the changelog proper :P) Oh, no, sorry. I'll take this as-is. Opportunistically fixing misspellings like you did it totally fine, especially since this is documentation. What I was trying to say is that if a patch fixes a real issue for someone, I'll definitely take the time to get it applied. I didn't mean to say I wouldn't take other typo fixes (though I am inclined to leave code/comments alone if a typo is benign, in order to reduce the churn in git history). ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/3] KVM: x86: Cleanups 2023-08-14 22:08 [PATCH 0/3] KVM: x86: Cleanups Michal Luczaj ` (2 preceding siblings ...) 2023-08-14 22:08 ` [PATCH 3/3] KVM: Correct kvm_vcpu_event(s) typo in KVM API documentation Michal Luczaj @ 2023-09-28 16:41 ` Sean Christopherson 3 siblings, 0 replies; 9+ messages in thread From: Sean Christopherson @ 2023-09-28 16:41 UTC (permalink / raw) To: Sean Christopherson, pbonzini, corbet, Michal Luczaj; +Cc: kvm On Tue, 15 Aug 2023 00:08:34 +0200, Michal Luczaj wrote: > As discussed[*], some minor clean-ups. Plus an attempt to smuggle a fix for > a typo in API documentation. > > [*] https://lore.kernel.org/kvm/e55656be-2752-a317-80eb-ad40e474b62f@redhat.com/ > > Michal Luczaj (3): > KVM: x86: Remove redundant vcpu->arch.cr0 assignments > KVM: x86: Force TLB flush on changes to special registers > KVM: Correct kvm_vcpu_event(s) typo in KVM API documentation > > [...] Applied 1 and 2 to kvm-x86 misc, and 3 to docs. I massaged the changelog for patch 2 to make it clear that flushing whenever the MMU context is reset is overkill. I had to go back to the original discussion between you and Paolo to understand why Paolo suggested blasting a guest TLB flush. Thanks! [1/3] KVM: x86: Remove redundant vcpu->arch.cr0 assignments https://github.com/kvm-x86/linux/commit/9dbb029b9c44 [2/3] KVM: x86: Force TLB flush on changes to special registers https://github.com/kvm-x86/linux/commit/4346db6e6e7a [3/3] KVM: Correct kvm_vcpu_event(s) typo in KVM API documentation https://github.com/kvm-x86/linux/commit/57f33f1a8756 -- https://github.com/kvm-x86/linux/tree/next ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-09-28 16:41 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-08-14 22:08 [PATCH 0/3] KVM: x86: Cleanups Michal Luczaj 2023-08-14 22:08 ` [PATCH 1/3] KVM: x86: Remove redundant vcpu->arch.cr0 assignments Michal Luczaj 2023-08-14 22:08 ` [PATCH 2/3] KVM: x86: Force TLB flush on changes to special registers Michal Luczaj 2023-08-14 22:08 ` [PATCH 3/3] KVM: Correct kvm_vcpu_event(s) typo in KVM API documentation Michal Luczaj 2023-08-14 22:28 ` Michal Luczaj 2023-09-27 20:10 ` Sean Christopherson 2023-09-28 11:58 ` Michal Luczaj 2023-09-28 14:37 ` Sean Christopherson 2023-09-28 16:41 ` [PATCH 0/3] KVM: x86: Cleanups Sean Christopherson
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox