On Fri, Apr 18, 2025, Paolo Bonzini wrote:
> kvm_arch_has_irq_bypass() is a small function and even though it does
> not appear in any *really* hot paths, it's also not entirely rare.
> Make it inline---it also works out nicely in preparation for using it in
> kvm-intel.ko and kvm-amd.ko, since the
On Thu, Mar 06, 2025, Thomas Huth wrote:
> On 22/02/2025 02.45, Sean Christopherson wrote:
> > Convert all non-x86 #ifdefs from __ASSEMBLY__ to __ASSEMBLER__, and remove
> > all manual __ASSEMBLY__ #defines. __ASSEMBLY_ was inherited blindly from
> > the Linux kernel, and mus
Odd, what commit caused this problem? Any hint as to what commit is
> missing to fix it?
833f69be62ac. It most definitely should be reverted. The "dependency" for
commit
87ecfdbc699c ("KVM: e500: always restore irqs") is a superficial code conflict.
Oof. The same buggy patch w
On Wed, Feb 26, 2025, Paolo Bonzini wrote:
> On 2/25/25 00:55, Sean Christopherson wrote:
> > Free vCPUs before freeing any VM state, as both SVM and VMX may access
> > VM state when "freeing" a vCPU that is currently "in" L2, i.e. that needs
> &
On Tue, Feb 25, 2025, Yan Zhao wrote:
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index 58b82d6fd77c..045c61cc7e54 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -12890,11 +12890,11 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
> > mutex_unlock(&
On Tue, Feb 25, 2025, Yan Zhao wrote:
> On Mon, Feb 24, 2025 at 03:55:39PM -0800, Sean Christopherson wrote:
> > Don't load (and then put) a vCPU when unloading its MMU during VM
> > destruction, as nothing in kvm_mmu_unload() accesses vCPU state beyond the
> > root pag
On Tue, Feb 25, 2025, Yan Zhao wrote:
> On Mon, Feb 24, 2025 at 03:55:38PM -0800, Sean Christopherson wrote:
> > After freeing a vCPU, assert that it is no longer reachable, and that
> > kvm_get_vcpu() doesn't return garbage or a pointer to some other vCPU.
> > While
Remove kvm_arch_sync_events() now that x86 no longer uses it (no other
arch has ever used it).
No functional change intended.
Signed-off-by: Sean Christopherson
---
arch/arm64/include/asm/kvm_host.h | 2 --
arch/loongarch/include/asm/kvm_host.h | 1 -
arch/mips/include/asm/kvm_host.h
_list.
Note, the PIT also needs to be stopped before IRQ routing is freed
(because KVM's IRQ routing is garbage and assumes there is always non-NULL
routing).
Opportunistically add comments to explain why KVM stops/frees certain
assets early.
Signed-off-by: Sean Christopherson
---
arch/x86/kvm/
by-one. I.e. triggering a VM-wide request would hit a
use-after-free.
Signed-off-by: Sean Christopherson
---
arch/x86/kvm/x86.c | 15 +++
1 file changed, 3 insertions(+), 12 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 9978ed4c0917..a61dbd1f0d01
Don't load (and then put) a vCPU when unloading its MMU during VM
destruction, as nothing in kvm_mmu_unload() accesses vCPU state beyond the
root page/address of each MMU, i.e. can't possible need to run with the
vCPU loaded.
Signed-off-by: Sean Christopherson
---
arch/x86/kvm
adding logic to the requests
path is unnecessary, and trying to make requests illegal during teardown
would be a fool's errand.
Signed-off-by: Sean Christopherson
---
virt/kvm/kvm_main.c | 8
1 file changed, 8 insertions(+)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 2
g/all/20240703175618.2304869-2-aaronle...@google.com
Cc: Jim Mattson
Cc: Yan Zhao
Cc: Rick P Edgecombe
Cc: Kai Huang
Cc: Isaku Yamahata
Signed-off-by: Sean Christopherson
---
arch/x86/kvm/x86.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x8
s
PIC emulation that causes KVM to make spurious KVM_REQ_EVENT requests (and
apparently no one ever ran the test with split IRQ chips).
Cc: sta...@vger.kernel.org
Signed-off-by: Sean Christopherson
---
arch/x86/kvm/vmx/nested.c | 11 +++
1 file changed, 11 insertions(+)
diff --git a/arch/x8
ion from
destroying vCPUs, all because when guest SMP support was added, KVM had a
kludgy MMU teardown flow that broken when a VM had more than one 1 vCPU.
And that oddity lived on, for 18 years...
Sean Christopherson (7):
KVM: x86: Free vCPUs before freeing VM state
KVM: nVMX: Process events o
.
__ASSEMBLER__ on the other hand is automatically defined by the compiler
when preprocessing assembly, i.e. doesn't require manually #defines for
the code to function correctly.
Ignore x86, as x86 doesn't actually rely on __ASSEMBLY__ at the moment,
and is undergoing a parallel cleanup.
Signed-of
On Mon, Jan 13, 2025, Marc Zyngier wrote:
> On Mon, 13 Jan 2025 18:58:45 +,
> Sean Christopherson wrote:
> >
> > On Mon, Jan 13, 2025, Marc Zyngier wrote:
> > > On Mon, 13 Jan 2025 15:44:28 +,
> > > Sean Christopherson wrote:
> > > >
On Mon, Jan 13, 2025, Marc Zyngier wrote:
> On Mon, 13 Jan 2025 15:44:28 +,
> Sean Christopherson wrote:
> >
> > On Sat, Jan 11, 2025, Marc Zyngier wrote:
> > > On Sat, 11 Jan 2025 01:24:48 +,
> > > Sean Christopherson wrote:
> > > >
>
On Mon, Jan 13, 2025, Chao Gao wrote:
> On Fri, Jan 10, 2025 at 05:24:48PM -0800, Sean Christopherson wrote:
> >Add a kvm_run flag, KVM_RUN_NEEDS_COMPLETION, to communicate to userspace
> >that KVM_RUN needs to be re-executed prior to save/restore in order to
> >complete the
On Sat, Jan 11, 2025, Marc Zyngier wrote:
> On Sat, 11 Jan 2025 01:24:48 +,
> Sean Christopherson wrote:
> >
> > Add a kvm_run flag, KVM_RUN_NEEDS_COMPLETION, to communicate to userspace
> > that KVM_RUN needs to be re-executed prior to save/restore in order to
>
Add selftests coverage for KVM_RUN_NEEDS_COMPLETION by redoing KVM_RUN if
and only if KVM states that completion is required.
Opportunistically rename the helper to replace "io" with "exit", as exits
that require completion are no longer limited to I/O.
Signed-off-by:
immediate exit.
No functional change intended.
Signed-off-by: Sean Christopherson
---
tools/testing/selftests/kvm/include/kvm_util.h | 9 -
tools/testing/selftests/kvm/lib/kvm_util.c | 2 +-
tools/testing/selftests/kvm/x86/nested_exceptions_test.c | 3 +--
3 fil
lback, i.e. in theory, this is a
one-time thing for KVM x86 (and other architectures could follow suit with
additional refactoring).
Signed-off-by: Sean Christopherson
---
Documentation/virt/kvm/api.rst| 48 ++-
arch/powerpc/kvm/book3s_emulate.c | 1 +
arch/powerp
Clear kvm_run.flags at the start of KVM_RUN for all architectures to
minimize the probability of leaving a stale flag set.
Signed-off-by: Sean Christopherson
---
arch/arm64/kvm/arm.c | 1 -
arch/arm64/kvm/handle_exit.c | 2 +-
arch/powerpc/kvm/book3s_hv.c | 4 +---
arch/x86/kvm/x86.c
error prone.
Note, this series is *very* lightly tested (borderline RFC).
Sean Christopherson (5):
KVM: x86: Document that KVM_EXIT_HYPERCALL requires completion
KVM: Clear vcpu->run->flags at start of KVM_RUN for all architectures
KVM: Add a common kvm_run flag to communicate an exit
Fixes: 0dbb11230437 ("KVM: X86: Introduce KVM_HC_MAP_GPA_RANGE hypercall")
Cc: sta...@vger.kernel.org
Signed-off-by: Sean Christopherson
---
Documentation/virt/kvm/api.rst | 39 +-
1 file changed, 20 insertions(+), 19 deletions(-)
diff --git a/Documen
On Thu, Jan 09, 2025, Paolo Bonzini wrote:
> @@ -483,7 +383,7 @@ static inline int kvmppc_e500_shadow_map(struct
> kvmppc_vcpu_e500 *vcpu_e500,
>* can't run hence pfn won't change.
>*/
> local_irq_save(flags);
> - ptep = find_linux_pte(pgdir, hva, NULL, NULL);
> + pte
On Thu, Jan 09, 2025, Paolo Bonzini wrote:
> kvmppc_e500_ref_setup is returning whether the guest TLB entry is writable,
> which is than passed to kvm_release_faultin_page. This makes little sense
s/than/then
> for two reasons: first, because the function sets up the private data for
> the page
On Thu, Jan 09, 2025, Paolo Bonzini wrote:
> Avoid a NULL pointer dereference if the memslot table changes between the
> exit and the call to kvmppc_e500_shadow_map().
>
> Cc: sta...@vger.kernel.org
> Signed-off-by: Paolo Bonzini
> ---
> arch/powerpc/kvm/e500_mmu_host.c | 5 +
> 1 file chang
On Mon, Jan 06, 2025, Sean Christopherson wrote:
> On Wed, Jan 01, 2025, Paolo Bonzini wrote:
> > kvm_follow_pfn() is able to work with NULL in the .map_writable field
> > of the homonymous struct. But __kvm_faultin_pfn() rejects the combo
> > despite KVM for e500 tryi
On Wed, Jan 01, 2025, Paolo Bonzini wrote:
> kvm_follow_pfn() is able to work with NULL in the .map_writable field
> of the homonymous struct. But __kvm_faultin_pfn() rejects the combo
> despite KVM for e500 trying to use it. Indeed .map_writable is not
> particularly useful if the flags include
On Thu, Oct 17, 2024, Paolo Bonzini wrote:
> On Thu, Oct 10, 2024 at 8:24 PM Sean Christopherson wrote:
> > v13:
> > - Rebased onto v6.12-rc2
> > - Collect reviews. [Alex and others]
> > - Fix a transient bug in arm64 and RISC-V where KVM would leak a page
> >
On Mon, Oct 21, 2024, Yan Zhao wrote:
> On Thu, Oct 10, 2024 at 11:23:53AM -0700, Sean Christopherson wrote:
> > Use __kvm_faultin_page() get the APIC access page so that KVM can
> > precisely release the refcounted page, i.e. to remove yet another user
> > of kvm_pfn_to_refc
On Mon, Oct 21, 2024, Yan Zhao wrote:
> On Thu, Oct 10, 2024 at 11:23:36AM -0700, Sean Christopherson wrote:
> > When creating a memory map for read, don't request a writable pfn from the
> > primary MMU. While creating read-only mappings can be theoretically slower,
> &g
On Mon, Oct 21, 2024, Yan Zhao wrote:
> On Thu, Oct 10, 2024 at 11:23:21AM -0700, Sean Christopherson wrote:
> > --- a/virt/kvm/pfncache.c
> > +++ b/virt/kvm/pfncache.c
> > @@ -159,6 +159,12 @@ static kvm_pfn_t hva_to_pfn_retry(struct
> > gfn_to_pfn_cache *gpc
art
in KVM, this allows KVM to map non-refcounted struct page memory into the
guest, e.g. for exposing GPU TTM buffers to KVM guests.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
include/linux/kvm_host.h | 3 --
virt/kvm/kvm_main.c | 75 ++---
Remove all kvm_{release,set}_pfn_*() APIs now that all users are gone.
No functional change intended.
Reviewed-by: Alex Bennée
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
include/linux/kvm_host.h | 5
virt/kvm/kvm_main.c | 55
push "accessed" updates to the primary MMU.
Dropping use of kvm_set_pfn_accessed() also paves the way for removing
kvm_pfn_to_refcounted_page() and all its users.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
arch/arm64/include/asm/kvm_pgtable.h | 4 +---
arch/arm64/kvm/
t KVM
marks the page accessed.
Dropping x86's use of kvm_set_pfn_accessed() also paves the way for
removing kvm_pfn_to_refcounted_page() and all its users.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
arch/x86/kvm/mmu/mmu.c | 17 -
arch/x86/kvm/mmu/td
Now that the legacy gfn_to_pfn() APIs are gone, and all callers of
hva_to_pfn() pass in a refcounted_page pointer, make it a required field
to ensure all future usage in KVM plays nice.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
virt/kvm/kvm_main.c | 6 --
1 file changed
Use kvm_release_page_dirty() when unpinning guest pages, as the pfn was
retrieved via pin_guest_page(), i.e. is guaranteed to be backed by struct
page memory. This will allow dropping kvm_release_pfn_dirty() and
friends.
Signed-off-by: Sean Christopherson
---
arch/s390/kvm/vsie.c | 2 +-
1
Drop gfn_to_pfn() and all its variants now that all users are gone.
No functional change intended.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
include/linux/kvm_host.h | 11
virt/kvm/kvm_main.c | 59
2 files changed, 70
ikely a bug fix, not a reduction in KVM capabilities.
Switching to gfn_to_page() will eventually allow removing gfn_to_pfn()
and kvm_pfn_to_refcounted_page().
Signed-off-by: Sean Christopherson
---
arch/powerpc/kvm/book3s_hv_uvmem.c | 25 -
1 file changed, 12 insertions(+
Use __gfn_to_page() instead when copying MTE tags between guest and
userspace. This will eventually allow removing gfn_to_pfn_prot(),
gfn_to_pfn(), kvm_pfn_to_refcounted_page(), and related APIs.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
arch/arm64/kvm/guest.c | 21
to do (though there are such scenarios).
Add a FIXME to call out that KVM probably should be pinning pages, not
just getting pages.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
include/linux/kvm_host.h | 7 ++-
virt/kvm/kvm_main.c | 15 ---
2 files changed
Convert gfn_to_page() to the new kvm_follow_pfn() internal API, which will
eventually allow removing gfn_to_pfn() and kvm_pfn_to_refcounted_page().
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
virt/kvm/kvm_main.c | 16 +---
1 file changed, 9 insertions(+), 7
n the pages
unpin_user_pages()
INCORRECT (uses FOLL_GET calls):
get_user_pages()
write to the data within the pages
put_page()
As a happy bonus, using kvm_vcpu_{,un}map() takes care of creating a
mapping and marking the page dirty.
Signed-off-by:
Don't manually do get_page() when patching dcbz, as gfn_to_page() gifts
the caller a reference. I.e. doing get_page() will leak the page due to
not putting all references.
Signed-off-by: Sean Christopherson
---
arch/powerpc/kvm/book3s_pr.c | 1 -
1 file changed, 1 deletion(-)
diff --
Convert MIPS to kvm_faultin_pfn()+kvm_release_faultin_page(), which
are new APIs to consolidate arch code and provide consistent behavior
across all KVM architectures.
Signed-off-by: Sean Christopherson
---
arch/mips/kvm/mmu.c | 14 ++
1 file changed, 6 insertions(+), 8 deletions
Mark pages accessed before dropping mmu_lock when faulting in guest memory
so that MIPS can convert to kvm_release_faultin_page() without tripping
its lockdep assertion on mmu_lock being held.
Signed-off-by: Sean Christopherson
---
arch/mips/kvm/mmu.c | 5 ++---
1 file changed, 2 insertions
y MMU will call into KVM via mmu_notifiers when aging pages. I.e.
KVM participates in a "pull" model, so there's no need to also "push"
updates.
Signed-off-by: Sean Christopherson
---
arch/mips/kvm/mmu.c | 12 ++--
1 file changed, 2 insertions(+), 10 deletions(-
race is minuscule, hence the lack of complaints).
See the link below for details.
Link: https://lore.kernel.org/all/cover.1683044162.git.lstoa...@gmail.com
Signed-off-by: Sean Christopherson
---
arch/mips/kvm/mmu.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/mips
Convert LoongArch to kvm_faultin_pfn()+kvm_release_faultin_page(), which
are new APIs to consolidate arch code and provide consistent behavior
across all KVM architectures.
Signed-off-by: Sean Christopherson
---
arch/loongarch/kvm/mmu.c | 14 ++
1 file changed, 6 insertions(+), 8
Mark pages accessed before dropping mmu_lock when faulting in guest memory
so that LoongArch can convert to kvm_release_faultin_page() without
tripping its lockdep assertion on mmu_lock being held.
Reviewed-by: Bibo Mao
Signed-off-by: Sean Christopherson
---
arch/loongarch/kvm/mmu.c | 2 +-
1
Mark pages accessed only in the slow path, before dropping mmu_lock when
faulting in guest memory so that LoongArch can convert to
kvm_release_faultin_page() without tripping its lockdep assertion on
mmu_lock being held.
Reviewed-by: Bibo Mao
Signed-off-by: Sean Christopherson
---
arch
race is minuscule, hence the lack of complaints).
See the link below for details.
Link: https://lore.kernel.org/all/cover.1683044162.git.lstoa...@gmail.com
Reviewed-by: Bibo Mao
Signed-off-by: Sean Christopherson
---
arch/loongarch/kvm/mmu.c | 18 ++
1 file changed, 10 insertions
Convert Book3S PR to __kvm_faultin_pfn()+kvm_release_faultin_page(), which
are new APIs to consolidate arch code and provide consistent behavior
across all KVM architectures.
Signed-off-by: Sean Christopherson
---
arch/powerpc/include/asm/kvm_book3s.h | 2 +-
arch/powerpc/kvm/book3s.c
...@gmail.com
Signed-off-by: Sean Christopherson
---
arch/powerpc/kvm/book3s_64_mmu_host.c | 10 +-
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/arch/powerpc/kvm/book3s_64_mmu_host.c
b/arch/powerpc/kvm/book3s_64_mmu_host.c
index bc6a381b5346..d0e4f7bbdc3d 100644
--- a/arch
Drop @kvm_ro from kvmppc_book3s_instantiate_page() as it is now only
written, and never read.
No functional change intended.
Signed-off-by: Sean Christopherson
---
arch/powerpc/include/asm/kvm_book3s.h | 2 +-
arch/powerpc/kvm/book3s_64_mmu_radix.c | 6 ++
arch/powerpc/kvm
changed (KVM tries fast GUP
for all writable mappings).
Signed-off-by: Sean Christopherson
---
arch/powerpc/kvm/book3s_64_mmu_radix.c | 29 +-
1 file changed, 5 insertions(+), 24 deletions(-)
diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c
b/arch/powerpc/kvm
es fast GUP
for all writable mappings).
Signed-off-by: Sean Christopherson
---
arch/powerpc/kvm/book3s_64_mmu_hv.c | 25 -
1 file changed, 4 insertions(+), 21 deletions(-)
diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c
b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index 2f1d58984b4
-off-by: Sean Christopherson
---
arch/riscv/kvm/mmu.c | 11 ---
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c
index 2e9aee518142..e11ad1b616f3 100644
--- a/arch/riscv/kvm/mmu.c
+++ b/arch/riscv/kvm/mmu.c
@@ -601,6 +601,7 @@ int
outside of mmu_lock can make filesystems unhappy (see the link below).
Do both under mmu_lock to minimize the chances of doing the wrong thing in
the future.
Link: https://lore.kernel.org/all/cover.1683044162.git.lstoa...@gmail.com
Reviewed-by: Andrew Jones
Acked-by: Anup Patel
Signed-off-by: Sean
ed-by: Andrew Jones
Acked-by: Anup Patel
Signed-off-by: Sean Christopherson
---
arch/riscv/kvm/mmu.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c
index b63650f9b966..06aa5a0d056d 100644
--- a/arch/riscv/kvm/mmu.c
+++ b/arch/risc
Convert arm64 to use __kvm_faultin_pfn()+kvm_release_faultin_page().
Three down, six to go.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
arch/arm64/kvm/mmu.c | 15 ++-
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64
teback.
See the link below for additional details.
This will also allow converting arm64 to kvm_release_faultin_page(), which
requires that mmu_lock be held (for the aforementioned reason).
Link: https://lore.kernel.org/all/cover.1683044162.git.lstoa...@gmail.com
Signed-off-by: Sean Christopherson
Convert PPC e500 to use __kvm_faultin_pfn()+kvm_release_faultin_page(),
and continue the inexorable march towards the demise of
kvm_pfn_to_refcounted_page().
Signed-off-by: Sean Christopherson
---
arch/powerpc/kvm/e500_mmu_host.c | 8 +++-
1 file changed, 3 insertions(+), 5 deletions
_dirty_ outside of mmu_lock can make filesystems unhappy.
Signed-off-by: Sean Christopherson
---
arch/powerpc/kvm/e500_mmu_host.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/arch/powerpc/kvm/e500_mmu_host.c b/arch/powerpc/kvm/e500_mmu_host.c
index 5c2adfd19e12..334dd96f8081
ndant kvm_set_pfn_accessed(), as
shadow_map() puts the page via kvm_release_pfn_clean().
Signed-off-by: Sean Christopherson
---
arch/powerpc/kvm/e500_mmu_host.c | 13 ++---
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/arch/powerpc/kvm/e500_mmu_host.c b/arch/powerp
g the pfn into a VMCS field instead of a secondary MMU.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
arch/x86/kvm/vmx/vmx.c | 13 +
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 851be0820e04..44cc25d
eally just marking folios dirty that is problematic), but there's no
reason not to be paranoid (moving the APIC access page isn't a hot path),
and no reason to be different from other mmu_notifier-protected flows in
KVM.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
ar
Move KVM x86's helper that "finishes" the faultin process to common KVM
so that the logic can be shared across all architectures. Note, not all
architectures implement a fast page fault path, but the gist of the
comment applies to all architectures.
Tested-by: Alex Bennée
Sign
about to access, it's far more likely that the gfn=>pfn mapping was
was invalidated, e.g. due a memslot change, or because the corresponding
VMA is being modified.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
arch/x86/kvm/mmu/mmu.c | 4 +++-
1 file changed, 3 insertions(
Now that all x86 page fault paths precisely track refcounted pages, use
Use kvm_page_fault.refcounted_page to put references to struct page memory
when finishing page faults. This is a baby step towards eliminating
kvm_pfn_to_refcounted_page().
Tested-by: Alex Bennée
Signed-off-by: Sean
Provide the "struct page" associated with a guest_memfd pfn as an output
from __kvm_gmem_get_pfn() so that KVM guest page fault handlers can
directly put the page instead of having to rely on
kvm_pfn_to_refcounted_page().
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
page",
which requires the index into the folio, without a redoing the index
calculation multiple times (which isn't costly, just hard to follow).
Opportunistically add a kvm_gmem_get_index() helper to make the copy+pasted
code easier to understand.
Signed-off-by: Sean Christopherson
Convert KVM x86 to use the recently introduced __kvm_faultin_pfn().
Opportunstically capture the refcounted_page grabbed by KVM for use in
future changes.
No functional change intended.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
arch/x86/kvm/mmu/mmu.c | 14
architectures need to be
converted to a common API before that can happen.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
include/linux/kvm_host.h | 12
virt/kvm/kvm_main.c | 22 ++
2 files changed, 34 insertions(+)
diff --git a/include/linux/k
Move the memslot lookup helpers further up in kvm_host.h so that they can
be used by inlined "to pfn" wrappers.
No functional change intended.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
include/linux/kvm_host.h | 8 +---
1 file changed, 5 insertions(+), 3
page memory.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
arch/x86/kvm/mmu/mmu.c | 30 --
arch/x86/kvm/mmu/paging_tmpl.h | 5 +
arch/x86/kvm/mmu/spte.c| 11 ---
3 files changed, 33 insertions(+), 13 deletions(-)
diff --
"finish" API across all architectures.
No functional change intended.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
arch/x86/kvm/mmu/mmu.c | 12 +---
arch/x86/kvm/mmu/paging_tmpl.h | 2 +-
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git
ennée
Signed-off-by: Sean Christopherson
---
arch/x86/kvm/mmu/mmu.c | 40 +-
arch/x86/kvm/mmu/paging_tmpl.h | 13 +--
2 files changed, 26 insertions(+), 27 deletions(-)
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 62924f9
Alex Bennée
Signed-off-by: Sean Christopherson
---
arch/x86/kvm/mmu/mmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index e451e1b9a55a..62924f95a398 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -2965
Prefix x86's faultin_pfn helpers with "mmu" so that the mmu-less names can
be used by common KVM for similar APIs.
No functional change intended.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
arch/x86/kvm/mmu/mmu.c | 19 ++-
a
eturn -EFAULT
on the future page fault.
Suggested-by: Paolo Bonzini
Signed-off-by: Sean Christopherson
---
arch/x86/kvm/lapic.c | 12
1 file changed, 12 deletions(-)
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 20526e4d6c62..65412640cfc7 100644
--- a/arch/x86/kvm/la
necessary. The APIs are used exclusively by x86's nested virtualization
support, and there is no known (or sane) use case for mapping PFN-mapped
memory a KVM guest _and_ letting the guest use it for virtualization
structures.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
a mapping isn't
a super hot path, and getting a writable mapping for reading is weird and
confusing.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
virt/kvm/kvm_main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/k
st GUP due to the need to break CoW before mapping
the underlying PFN. But practically speaking, creating a mapping isn't
a super hot path, and getting a writable mapping for reading is weird and
confusing.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
arch/x86/kvm/svm/nested
le to the guest
(though obviously highly unlikely to be problematic in practice).
Marking the map dirty will allow specifying the write vs. read-only when
*mapping* the memory, which in turn will allow creating read-only maps.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
arch/x86/k
field.
Link: https://lwn.net/Articles/930667
Link: https://lore.kernel.org/all/cover.1683044162.git.lstoa...@gmail.com
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
include/linux/kvm_host.h | 2 +-
virt/kvm/kvm_main.c | 54 +---
virt/kvm/
[sean: use a pointer instead of a boolean]
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
include/linux/kvm_host.h | 2 +-
virt/kvm/kvm_main.c | 26 --
2 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/include/linux/kvm_host.h b/include
Track refcounted struct page memory using kvm_follow_pfn.refcounted_page
instead of relying on kvm_release_pfn_clean() to correctly detect that the
pfn is associated with a struct page.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
virt/kvm/pfncache.c | 11 +++
1 file
Hoist the kvm_{set,release}_page_{clean,dirty}() APIs further up in
kvm_main.c so that they can be used by the kvm_follow_pfn family of APIs.
No functional change intended.
Reviewed-by: Alex Bennée
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
virt/kvm/kvm_main.c | 82
is error prone and
can't detect pfns that are valid, but aren't (currently) refcounted.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
virt/kvm/kvm_main.c | 99 +
virt/kvm/kvm_mm.h | 9 +
2 files changed, 56 insertion
Use a single pointer instead of a single-entry array for the struct page
pointer in hva_to_pfn_fast(). Using an array makes the code unnecessarily
annoying to read and update.
No functional change intended.
Reviewed-by: Alex Bennée
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
Add a helper to dedup unmapping the vmcs12 pages. This will reduce the
amount of churn when a future patch refactors the kvm_vcpu_unmap() API.
No functional change intended.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
arch/x86/kvm/vmx/nested.c | 32
Remove vcpu_vmx.msr_bitmap_map and instead use an on-stack structure in
the one function that uses the map, nested_vmx_prepare_msr_bitmap().
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
arch/x86/kvm/vmx/nested.c | 8
arch/x86/kvm/vmx/vmx.h| 2 --
2 files changed
pu_vmx, i.e. the map starts out invalid/NULL.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
arch/x86/kvm/vmx/nested.c | 7 ++-
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index a8e7bc04d9bf..e94a25373a59
e a
blatant and egregious KVM bug.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
---
include/linux/kvm_host.h | 4
virt/kvm/kvm_main.c | 4 ++--
2 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
ind
Explicitly initialize the entire kvm_host_map structure when mapping a
pfn, as some callers declare their struct on the stack, i.e. don't
zero-initialize the struct, which makes the map->hva in kvm_vcpu_unmap()
*very* suspect.
Tested-by: Alex Bennée
Signed-off-by: Sean Christopherson
-
1 - 100 of 701 matches
Mail list logo