Re: [PATCH 1/3] KVM: PPC: Fix kernel crash with PR KVM

2020-03-18 Thread Sean Christopherson
Signed-off-by: Greg Kurz > --- Dang, I see where I went wrong. Sorry :-( Reviewed-by: Sean Christopherson

Re: [PATCH v1 03/10] KVM: Prepare kvm_is_reserved_pfn() for PG_reserved changes

2019-11-05 Thread Sean Christopherson
On Tue, Nov 05, 2019 at 11:02:46AM +0100, David Hildenbrand wrote: > On 05.11.19 10:49, David Hildenbrand wrote: > >On 05.11.19 10:17, David Hildenbrand wrote: > >>On 05.11.19 05:38, Dan Williams wrote: > >>>On Thu, Oct 24, 2019 at 5:11 AM David Hildenbrand wrote: > > Right now, ZONE_DEVI

Re: [PATCH v1 03/10] KVM: Prepare kvm_is_reserved_pfn() for PG_reserved changes

2019-11-05 Thread Sean Christopherson
On Tue, Nov 05, 2019 at 09:30:53PM +0100, David Hildenbrand wrote: > >>>I think I know what's going wrong: > >>> > >>>Pages that are pinned via gfn_to_pfn() and friends take a references, > >>>however are often released via > >>>kvm_release_pfn_clean()/kvm_release_pfn_dirty()/kvm_release_page_clean

Re: [PATCH v1 03/10] KVM: Prepare kvm_is_reserved_pfn() for PG_reserved changes

2019-11-05 Thread Sean Christopherson
On Tue, Nov 05, 2019 at 03:02:40PM -0800, Dan Williams wrote: > On Tue, Nov 5, 2019 at 12:31 PM David Hildenbrand wrote: > > > The scarier code (for me) is transparent_hugepage_adjust() and > > > kvm_mmu_zap_collapsible_spte(), as I don't at all understand the > > > interaction between THP and _PA

Re: [PATCH v1 03/10] KVM: Prepare kvm_is_reserved_pfn() for PG_reserved changes

2019-11-05 Thread Sean Christopherson
On Tue, Nov 05, 2019 at 03:30:00PM -0800, Dan Williams wrote: > On Tue, Nov 5, 2019 at 3:13 PM Sean Christopherson > wrote: > > > > On Tue, Nov 05, 2019 at 03:02:40PM -0800, Dan Williams wrote: > > > On Tue, Nov 5, 2019 at 12:31 PM David Hildenbrand > > > wr

Re: [PATCH v1 03/10] KVM: Prepare kvm_is_reserved_pfn() for PG_reserved changes

2019-11-05 Thread Sean Christopherson
On Tue, Nov 05, 2019 at 03:43:29PM -0800, Dan Williams wrote: > On Tue, Nov 5, 2019 at 3:30 PM Dan Williams wrote: > > > > On Tue, Nov 5, 2019 at 3:13 PM Sean Christopherson > > wrote: > > > > > > On Tue, Nov 05, 2019 at 03:02:40PM -0800, Dan Williams wrot

Re: [PATCH v1 03/10] KVM: Prepare kvm_is_reserved_pfn() for PG_reserved changes

2019-11-06 Thread Sean Christopherson
On Wed, Nov 06, 2019 at 07:56:34AM +0100, David Hildenbrand wrote: > On 06.11.19 01:08, Dan Williams wrote: > >On Tue, Nov 5, 2019 at 4:03 PM Sean Christopherson > >>But David's proposed fix for the above refcount bug is to omit the patch > >>so that KVM no lo

Re: [PATCH 1/1] powerpc/kvm/book3s: Fixes possible 'use after release' of kvm

2019-11-26 Thread Sean Christopherson
On Tue, Nov 26, 2019 at 02:52:12PM -0300, Leonardo Bras wrote: > Fixes a possible 'use after free' of kvm variable. > It does use mutex_unlock(&kvm->lock) after possible freeing a variable > with kvm_put_kvm(kvm). Moving the calls to kvm_put_kvm() to the end of the functions doesn't actually fix a

Re: [PATCH 7/11] KVM: Remove redundant check in the kvm_get_dirty_log_protect()

2019-01-04 Thread Sean Christopherson
On Fri, Jan 04, 2019 at 04:54:01PM +0800, lantianyu1...@gmail.com wrote: > From: Lan Tianyu > > The dirty bits have already been checked in the previous check of > "dirty_bitmap" and mask must be non-zero value at this point. > > Signed-off-by: Lan Tianyu > --- > virt/kvm/kvm_main.c | 8 +++---

Re: [PATCH 6/11] KVM/MMU: Flush tlb with range list in sync_page()

2019-01-04 Thread Sean Christopherson
On Fri, Jan 04, 2019 at 04:54:00PM +0800, lantianyu1...@gmail.com wrote: > From: Lan Tianyu > > This patch is to flush tlb via flush list function. More explanation of why this is beneficial would be nice. Without the context of the overall series it's not immediately obvious what kvm_flush_rem

Re: [PATCH 7/11] KVM: Remove redundant check in the kvm_get_dirty_log_protect()

2019-01-04 Thread Sean Christopherson
On Fri, Jan 04, 2019 at 07:50:36AM -0800, Sean Christopherson wrote: > On Fri, Jan 04, 2019 at 04:54:01PM +0800, lantianyu1...@gmail.com wrote: > > From: Lan Tianyu > > > > The dirty bits have already been checked in the previous check of > > "dirty_bitmap&quo

Re: [PATCH gmem FIXUP v2] mm, compaction: make testing mapping_unmovable() safe

2023-09-08 Thread Sean Christopherson
On Fri, 08 Sep 2023 09:42:23 +0200, Vlastimil Babka wrote: > As Kirill pointed out, mapping can be removed under us due to > truncation. Test it under folio lock as already done for the async > compaction / dirty folio case. To prevent locking every folio with > mapping to do the test, do it only f

[RFC PATCH v12 00/33] KVM: guest_memfd() and per-page attributes

2023-09-13 Thread Sean Christopherson
fier_retry KVM: Add KVM_EXIT_MEMORY_FAULT exit to report faults to userspace KVM: Introduce per-page memory attributes KVM: x86: Disallow hugepages when memory attributes are mixed KVM: x86/mmu: Handle page fault for private memory KVM: selftests: Add KVM_SET_USER_MEMORY_REGION2 helpe

[RFC PATCH v12 01/33] KVM: Tweak kvm_hva_range and hva_handler_t to allow reusing for gfn ranges

2023-09-13 Thread Sean Christopherson
y meaningful change is to store start+end as u64s instead of unsigned longs. Reviewed-by: Paolo Bonzini Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 34 +++--- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/virt/kvm/kvm_main.c b/

[RFC PATCH v12 02/33] KVM: Use gfn instead of hva for mmu_notifier_retry

2023-09-13 Thread Sean Christopherson
small. Suggested-by: Sean Christopherson Signed-off-by: Chao Peng Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba [sean: convert vmx_set_apic_access_page_addr() to gfn-based API] Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 10 ++ arch/x86/kvm/vmx/vmx.c | 11

[RFC PATCH v12 03/33] KVM: PPC: Drop dead code related to KVM_ARCH_WANT_MMU_NOTIFIER

2023-09-13 Thread Sean Christopherson
ER) checks into a single #ifdef CONFIG_KVM_GENERIC_MMU_NOTIFIER without having to worry about PPC's "bare" usage of KVM_ARCH_WANT_MMU_NOTIFIER. Signed-off-by: Sean Christopherson --- arch/powerpc/kvm/powerpc.c | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff -

[RFC PATCH v12 04/33] KVM: PPC: Return '1' unconditionally for KVM_CAP_SYNC_MMU

2023-09-13 Thread Sean Christopherson
: Paolo Bonzini Signed-off-by: Sean Christopherson --- arch/powerpc/kvm/powerpc.c | 4 1 file changed, 4 deletions(-) diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c index b0a512ede764..8d3ec483bc2b 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/power

[RFC PATCH v12 05/33] KVM: Convert KVM_ARCH_WANT_MMU_NOTIFIER to CONFIG_KVM_GENERIC_MMU_NOTIFIER

2023-09-13 Thread Sean Christopherson
define it in common KVM. Signed-off-by: Sean Christopherson --- arch/arm64/include/asm/kvm_host.h | 2 -- arch/arm64/kvm/Kconfig | 2 +- arch/mips/include/asm/kvm_host.h| 2 -- arch/mips/kvm/Kconfig | 2 +- arch/powerpc/include/asm/kvm_host.h | 2 -- arch

[RFC PATCH v12 06/33] KVM: Introduce KVM_SET_USER_MEMORY_REGION2

2023-09-13 Thread Sean Christopherson
more robust, e.g. if the new fd field is guarded only by a flag and not a new ioctl(), then a userspace bug (setting a "bad" flag) would generate out-of-bounds access instead of an -EINVAL error. Cc: Jarkko Sakkinen Reviewed-by: Paolo Bonzini Signed-off-by: Sean Christopherson ---

[RFC PATCH v12 07/33] KVM: Add KVM_EXIT_MEMORY_FAULT exit to report faults to userspace

2023-09-13 Thread Sean Christopherson
stacks, e.g. in emulation paths, is infeasible as doing so would require a near-complete overhaul of KVM, whereas KVM already propagates -errno return codes to userspace even when the -errno originated in a low level helper. Link: https://lore.kernel.org/all/20230908222905.1321305-5-amoor...@google.com

[RFC PATCH v12 08/33] KVM: Add a dedicated mmu_notifier flag for reclaiming freed memory

2023-09-13 Thread Sean Christopherson
(not to mention the size of the struct will be two bytes in practice). Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 53 +++-- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c

[RFC PATCH v12 10/33] KVM: Set the stage for handling only shared mappings in mmu_notifier events

2023-09-13 Thread Sean Christopherson
dd two flags so that KVM can handle the three possibilities (shared, private, and shared+private) without needing something like a tri-state enum. Link: https://lore.kernel.org/all/zjx0hk+kpqp0k...@google.com Signed-off-by: Sean Christopherson --- include/linux/kvm_host.h | 2 ++ virt/kvm/kvm_

[RFC PATCH v12 11/33] KVM: Introduce per-page memory attributes

2023-09-13 Thread Sean Christopherson
tions to if/when they are needed. Suggested-by: Sean Christopherson Link: https://lore.kernel.org/all/y2wb48kd0j4vg...@google.com Cc: Fuad Tabba Cc: Xu Yilun Signed-off-by: Chao Peng Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson --- Documentation/virt/kvm/api.rst

[RFC PATCH v12 12/33] mm: Add AS_UNMOVABLE to mark mapping as completely unmovable

2023-09-13 Thread Sean Christopherson
Wilcox Co-developed-by: Vlastimil Babka Signed-off-by: Vlastimil Babka Signed-off-by: Sean Christopherson --- include/linux/pagemap.h | 19 +- mm/compaction.c | 43 + mm/migrate.c| 2 ++ 3 files changed, 51 inserti

[RFC PATCH v12 13/33] security: Export security_inode_init_security_anon() for use by KVM

2023-09-13 Thread Sean Christopherson
TODO: Throw this away, assuming KVM drops its dedicated file system. Acked-by: Paul Moore Signed-off-by: Sean Christopherson --- security/security.c | 1 + 1 file changed, 1 insertion(+) diff --git a/security/security.c b/security/security.c index 23b129d482a7..0024156f867a 100644 --- a

[RFC PATCH v12 14/33] KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory

2023-09-13 Thread Sean Christopherson
. Shutemov Co-developed-by: Yu Zhang Signed-off-by: Yu Zhang Co-developed-by: Chao Peng Signed-off-by: Chao Peng Co-developed-by: Ackerley Tng Signed-off-by: Ackerley Tng Co-developed-by: Isaku Yamahata Signed-off-by: Isaku Yamahata Signed-off-by: Sean Christopherson --- include/linux

[RFC PATCH v12 15/33] KVM: Add transparent hugepage support for dedicated guest memory

2023-09-13 Thread Sean Christopherson
TODO: writeme Signed-off-by: Sean Christopherson --- include/uapi/linux/kvm.h | 2 ++ virt/kvm/guest_mem.c | 54 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index b6f90a273e2e

[RFC PATCH v12 16/33] KVM: x86: "Reset" vcpu->run->exit_reason early in KVM_RUN

2023-09-13 Thread Sean Christopherson
KVM_RUN when run->immediate_exit is true. Link: https://lore.kernel.org/all/20230908222905.1321305-1-amoor...@google.com Link: https://lore.kernel.org/all/zffbwoxz5ui%2fg...@google.com Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kvm/x86.c

[RFC PATCH v12 17/33] KVM: x86: Disallow hugepages when memory attributes are mixed

2023-09-13 Thread Sean Christopherson
that info into the refcount is unnecessarily complex as it would require knowing the previous state of the mixed count when updating attributes. Using a flag means KVM just needs to ensure the current status is reflected in the memslots. Signed-off-by: Chao Peng Co-developed-by: Sean Christopher

[RFC PATCH v12 18/33] KVM: x86/mmu: Handle page fault for private memory

2023-09-13 Thread Sean Christopherson
lt. Co-developed-by: Yu Zhang Signed-off-by: Yu Zhang Signed-off-by: Chao Peng Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 94 +++-- arch/x86/kvm/mmu/mmu_internal.h | 1 + 2 files changed, 90 inser

[RFC PATCH v12 19/33] KVM: Drop superfluous __KVM_VCPU_MULTIPLE_ADDRESS_SPACE macro

2023-09-13 Thread Sean Christopherson
Drop __KVM_VCPU_MULTIPLE_ADDRESS_SPACE and instead check the value of KVM_ADDRESS_SPACE_NUM. No functional change intended. Reviewed-by: Paolo Bonzini Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 1 - include/linux/kvm_host.h| 2 +- 2 files changed, 1

[RFC PATCH v12 20/33] KVM: Allow arch code to track number of memslot address spaces per VM

2023-09-13 Thread Sean Christopherson
. Disallowing SMM will simplify support for guest private memory, as KVM will not need to worry about tracking memory attributes for multiple address spaces (SMM is the only "non-default" address space across all architectures). Signed-off-by: Sean Christopherson --- arch/powerpc/kvm/book3s_hv

[RFC PATCH v12 21/33] KVM: x86: Add support for "protected VMs" that can utilize private memory

2023-09-13 Thread Sean Christopherson
Signed-off-by: Sean Christopherson --- Documentation/virt/kvm/api.rst | 32 arch/x86/include/asm/kvm_host.h | 15 +-- arch/x86/include/uapi/asm/kvm.h | 3 +++ arch/x86/kvm/Kconfig| 12 arch/x86/kvm/mmu/mmu_internal.h | 1

[RFC PATCH v12 22/33] KVM: selftests: Drop unused kvm_userspace_memory_region_find() helper

2023-09-13 Thread Sean Christopherson
Drop kvm_userspace_memory_region_find(), it's unused and a terrible API (probably why it's unused). If anything outside of kvm_util.c needs to get at the memslot, userspace_mem_region_find() can be exposed to give others full access to all memory region/slot information. Signed-of

[RFC PATCH v12 23/33] KVM: selftests: Convert lib's mem regions to KVM_SET_USER_MEMORY_REGION2

2023-09-13 Thread Sean Christopherson
Use KVM_SET_USER_MEMORY_REGION2 throughough KVM's selftests library so that support for guest private memory can be added without needing an entirely separate set of helpers. Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/kvm_util_base.h | 2 +- tools/testing/self

[RFC PATCH v12 24/33] KVM: selftests: Add support for creating private memslots

2023-09-13 Thread Sean Christopherson
rst destroy memslots. Co-developed-by: Ackerley Tng Signed-off-by: Ackerley Tng Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/kvm_util_base.h | 23 + .../testing/selftests/kvm/include/test_util.h | 5 ++ tools/testing/selftests/kvm/lib/kvm_util.c| 85 +++

[RFC PATCH v12 25/33] KVM: selftests: Add helpers to convert guest memory b/w private and shared

2023-09-13 Thread Sean Christopherson
ingle source of true. The fallocate() helpers are provided so that tests can mimic a userspace that frees private memory on conversion, e.g. to prioritize memory usage over performance. Signed-off-by: Vishal Annapurve Co-developed-by: Sean Christopherson Signed-off-by: Sean Christoph

[RFC PATCH v12 26/33] KVM: selftests: Add helpers to do KVM_HC_MAP_GPA_RANGE hypercalls (x86)

2023-09-13 Thread Sean Christopherson
: drop shared/private helpers (let tests specify flags)] Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/x86_64/processor.h | 15 +++ 1 file changed, 15 insertions(+) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftes

[RFC PATCH v12 27/33] KVM: selftests: Introduce VM "shape" to allow tests to specify the VM type

2023-09-13 Thread Sean Christopherson
double down and require unique VM types for TDX and SNP guests. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/dirty_log_test.c | 2 +- .../selftests/kvm/include/kvm_util_base.h | 54 +++ .../selftests/kvm/kvm_page_table_test.c | 2

[RFC PATCH v12 28/33] KVM: selftests: Add GUEST_SYNC[1-6] macros for synchronizing more data

2023-09-13 Thread Sean Christopherson
Add GUEST_SYNC[1-6]() so that tests can pass the maximum amount of information supported via ucall(), without needing to resort to shared memory. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/ucall_common.h | 11 +++ 1 file changed, 11 insertions(+) diff

[RFC PATCH v12 29/33] KVM: selftests: Add x86-only selftest for private memory conversions

2023-09-13 Thread Sean Christopherson
ikely open a can of worms, i.e. delay things even further. Signed-off-by: Vishal Annapurve Co-developed-by: Ackerley Tng Signed-off-by: Ackerley Tng Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/Makefile | 1 + .../kvm/x86_64/

[RFC PATCH v12 30/33] KVM: selftests: Add KVM_SET_USER_MEMORY_REGION2 helper

2023-09-13 Thread Sean Christopherson
From: Chao Peng Add helpers to invoke KVM_SET_USER_MEMORY_REGION2 directly so that tests can validate of features that are unique to "version 2" of "set user memory region", e.g. do negative testing on gmem_fd and gmem_offset. Provide a raw version as well as an assert-success version to reduce

[RFC PATCH v12 31/33] KVM: selftests: Expand set_memory_region_test to validate guest_memfd()

2023-09-13 Thread Sean Christopherson
-by: Ackerley Tng Signed-off-by: Ackerley Tng [sean: trim the testcases to remove duplicate coverage] Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/kvm_util_base.h | 10 ++ .../selftests/kvm/set_memory_region_test.c| 100 ++ 2 files changed, 110

[RFC PATCH v12 32/33] KVM: selftests: Add basic selftest for guest_memfd()

2023-09-13 Thread Sean Christopherson
on fallocate(FALLOC_FL_PUNCH_HOLE) should be page aligned + invalid inputs (misaligned size, invalid flags) are rejected Signed-off-by: Chao Peng Co-developed-by: Ackerley Tng Signed-off-by: Ackerley Tng Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson --- tools

[RFC PATCH v12 33/33] KVM: selftests: Test KVM exit behavior for private memory/access

2023-09-13 Thread Sean Christopherson
U is actually running and accessing memory when converting and deleting. Signed-off-by: Ackerley Tng Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/Makefile | 1 + .../kvm/x86_64/private_mem_kvm_exits_test.c | 121 ++ 2 files changed, 122 insertio

Re: [RFC PATCH v12 02/33] KVM: Use gfn instead of hva for mmu_notifier_retry

2023-09-14 Thread Sean Christopherson
On Thu, Sep 14, 2023, Binbin Wu wrote: > > On 9/14/2023 9:55 AM, Sean Christopherson wrote: > > +void kvm_mmu_invalidate_end(struct kvm *kvm) > > { > > /* > > * This sequence increase will notify the kvm page fault that > > @@ -833,6 +848,13 @@ vo

Re: [RFC PATCH v11 12/29] KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory

2023-09-14 Thread Sean Christopherson
On Mon, Aug 28, 2023, Ackerley Tng wrote: > Sean Christopherson writes: > >> If we track struct kvm with the inode, then I think (a), (b) and (c) can > >> be independent of the refcounting method. What do you think? > > > > No go. Because again, the inode (p

Re: [RFC PATCH v11 12/29] KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory

2023-09-14 Thread Sean Christopherson
On Mon, Aug 28, 2023, Elliot Berman wrote: > I had a 3rd question that's related to how to wire the gmem up to a virtual > machine: > > I learned of a usecase to implement copy-on-write for gmem. The premise > would be to have a "golden copy" of the memory that multiple virtual > machines can map

Re: [RFC PATCH v11 12/29] KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory

2023-09-14 Thread Sean Christopherson
On Thu, Sep 14, 2023, Ackerley Tng wrote: > Sean Christopherson writes: > > > On Mon, Aug 28, 2023, Ackerley Tng wrote: > >> Sean Christopherson writes: > >> >> If we track struct kvm with the inode, then I think (a), (b) and (c) can > >> >> be

Re: [RFC PATCH v12 18/33] KVM: x86/mmu: Handle page fault for private memory

2023-09-15 Thread Sean Christopherson
On Fri, Sep 15, 2023, Yan Zhao wrote: > On Wed, Sep 13, 2023 at 06:55:16PM -0700, Sean Christopherson wrote: > > > +static void kvm_mmu_prepare_memory_fault_exit(struct kvm_vcpu *vcpu, > > + struct kvm

Re: [RFC PATCH v12 01/33] KVM: Tweak kvm_hva_range and hva_handler_t to allow reusing for gfn ranges

2023-09-15 Thread Sean Christopherson
On Fri, Sep 15, 2023, Xiaoyao Li wrote: > On 9/14/2023 9:54 AM, Sean Christopherson wrote: > > Rework and rename "struct kvm_hva_range" into "kvm_mmu_notifier_range" so > > that the structure can be used to handle notifications that operate on gfn > >

[PATCH 00/26] KVM: vfio: Hide KVM internals from others

2023-09-15 Thread Sean Christopherson
slowly clean things up so that some day KVM only exposes a handful of APIs to the rest of the kernel (probably a pipe dream). Anish Ghulati (1): KVM: arm64: Move arm_{psci,hypercalls}.h to an internal KVM path Sean Christopherson (25): vfio: Wrap KVM helpers with CONFIG_KVM instead of CONFI

[PATCH 01/26] vfio: Wrap KVM helpers with CONFIG_KVM instead of CONFIG_HAVE_KVM

2023-09-15 Thread Sean Christopherson
is nonsensical. Drop the guard around linux/kvm_host.h entirely, conditionally including a generic headers is completely unnecessary. Signed-off-by: Sean Christopherson --- drivers/vfio/vfio.h | 2 +- drivers/vfio/vfio_main.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff

[PATCH 02/26] vfio: Move KVM get/put helpers to colocate it with other KVM related code

2023-09-15 Thread Sean Christopherson
Move the definitions of vfio_device_get_kvm_safe() and vfio_device_put_kvm() down in vfio_main.c to colocate them with other KVM-specific functions, e.g. to allow wrapping them all with a single CONFIG_KVM check. Signed-off-by: Sean Christopherson --- drivers/vfio/vfio_main.c | 104

[PATCH 03/26] virt: Declare and define vfio_file_set_kvm() iff CONFIG_KVM is enabled

2023-09-15 Thread Sean Christopherson
Hide vfio_file_set_kvm() and its unique helpers if KVM is not enabled, nothing else in the kernel (or out of the kernel) should be using a KVM specific helper. Signed-off-by: Sean Christopherson --- drivers/vfio/vfio_main.c | 2 +- include/linux/vfio.h | 2 ++ 2 files changed, 3 insertions

[PATCH 04/26] vfio: Add struct to hold KVM assets and dedup group vs. iommufd code

2023-09-15 Thread Sean Christopherson
t/put helpers from KVM. Signed-off-by: Sean Christopherson --- drivers/vfio/device_cdev.c | 9 +--- drivers/vfio/group.c | 18 ++-- drivers/vfio/vfio.h| 22 +-- drivers/vfio/vfio_main.c | 43 +++--- 4 files change

[PATCH 05/26] vfio: KVM: Pass get/put helpers from KVM to VFIO, don't do circular lookup

2023-09-15 Thread Sean Christopherson
igned-off-by: Sean Christopherson --- drivers/vfio/vfio.h | 2 ++ drivers/vfio/vfio_main.c | 74 +++- include/linux/vfio.h | 4 ++- virt/kvm/vfio.c | 9 +++-- 4 files changed, 47 insertions(+), 42 deletions(-) diff --git a/drivers/vfio/vfi

[PATCH 06/26] KVM: Drop CONFIG_KVM_VFIO and just look at KVM+VFIO

2023-09-15 Thread Sean Christopherson
where RISC-V doesn't select KVM_VFIO, i.e. would silently fail to do connect KVM and VFIO, even though RISC-V supports VFIO. The bug is benign as the only driver in all of Linux that actually uses the KVM reference provided by VFIO is KVM-GT, which is x86/Intel specific. Signed-of

[PATCH 07/26] x86/idt: Wrap KVM logic with CONFIG_KVM instead of CONFIG_HAVE_KVM

2023-09-15 Thread Sean Christopherson
rupts that end up being handled by the host, everything else is completely dead code when KVM is disabled. And if KVM is disabled, there should not be any posted interrupts, i.e. NOT wiring up the "dummy" handlers and treating IRQs on those vectors as spurious is the right thing to do.

[PATCH 08/26] KVM: x86: Stop selecting and depending on HAVE_KVM

2023-09-15 Thread Sean Christopherson
Now that nothing in x86 or architecture agnostic code consumes HAVE_KVM, stop selecting it in x86. This is one of several steps towards deleting HAVE_KVM from the common KVM Kconfig. Signed-off-by: Sean Christopherson --- arch/x86/Kconfig | 1 - arch/x86/kvm/Kconfig | 2 -- 2 files changed

[PATCH 09/26] KVM: arm64: Stop selecting and depending on HAVE_KVM

2023-09-15 Thread Sean Christopherson
Now that nothing in arm64 or architecture agnostic code consumes HAVE_KVM, stop selecting it in arm64. This is one of several steps towards deleting HAVE_KVM from the common KVM Kconfig. Signed-off-by: Sean Christopherson --- arch/arm64/Kconfig | 1 - arch/arm64/kvm/Kconfig | 1 - 2 files

[PATCH 10/26] KVM: s390: Stop selecting and depending on HAVE_KVM

2023-09-15 Thread Sean Christopherson
Now that nothing in s390 or architecture agnostic code consumes HAVE_KVM, stop selecting it in s390. This is one of several steps towards deleting HAVE_KVM from the common KVM Kconfig. Signed-off-by: Sean Christopherson --- arch/s390/Kconfig | 1 - arch/s390/kvm/Kconfig | 1 - 2 files

[PATCH 11/26] KVM: MIPS: Make HAVE_KVM a MIPS-only Kconfig

2023-09-15 Thread Sean Christopherson
Now that MIPS is the sole remaining user of HAVE_KVM, make HAVE_KVM a MIPS-only Kconfig. Because most architectures unconditionally support virtualization, advertising to the kernel at-large that an arch has KVM just led to a bunch of useless and misguided #ifdefs. Signed-off-by: Sean

[PATCH 12/26] KVM: arm64: Move arm_{psci,hypercalls}.h to an internal KVM path

2023-09-15 Thread Sean Christopherson
From: Anish Ghulati Move arm_hypercalls.h and arm_psci.h into arch/arm64/kvm now that KVM no longer supports 32-bit ARM, i.e. now that there's no reason to make the hypercall and PSCI APIs "public". Signed-off-by: Anish Ghulati [sean: squash into one patch, write changelog] Sign

[PATCH 13/26] KVM: arm64: Include KVM headers to get forward declarations

2023-09-15 Thread Sean Christopherson
o maintain alphabetic ordering. Reported-by: kernel test robot Signed-off-by: Sean Christopherson --- include/kvm/arm_arch_timer.h | 2 ++ include/kvm/arm_pmu.h| 2 ++ 2 files changed, 4 insertions(+) diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h index bb3

[PATCH 14/26] KVM: arm64: Move ARM specific headers in include/kvm to arch directory

2023-09-15 Thread Sean Christopherson
Move kvm/arm_{arch_timer,pmu,vgic}.h to arch/arm64/include/asm and drop the "arm" prefix from all file names. Now that KVM no longer supports 32-bit ARM, there is no reason to expose ARM specific headers to other architectures beyond arm64. Signed-off-by: Sean Christopherson ---

[PATCH 15/26] KVM: Move include/kvm/iodev.h to include/linux as kvm_iodev.h

2023-09-15 Thread Sean Christopherson
Move iodev.h, the last remaining holdout in include/kvm, to the standard include/linux directory as kvm_iodev.h and delete include/kvm. Signed-off-by: Sean Christopherson --- MAINTAINERS| 1 - arch/arm64/include/asm/kvm_vgic.h | 2 +- arch/arm64/kvm/vgic

[PATCH 16/26] KVM: MIPS: Stop adding virt/kvm to the arch include path

2023-09-15 Thread Sean Christopherson
m" was copied from a different architecture's Makefile when MIPS support was first added. Signed-off-by: Sean Christopherson --- arch/mips/kvm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/mips/kvm/Makefile b/arch/mips/kvm/Makefile index 805aeea2166e.

[PATCH 17/26] KVM: PPC: Stop adding virt/kvm to the arch include path

2023-09-15 Thread Sean Christopherson
m" was copied from a different architecture's Makefile when PPC support was first added. Signed-off-by: Sean Christopherson --- arch/powerpc/kvm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/kvm/Makefile b/arch/powerpc/kvm/Makefile index 5319

[PATCH 18/26] KVM: s390: Stop adding virt/kvm to the arch include path

2023-09-15 Thread Sean Christopherson
t/kvm" was copied from a x86's Makefile when s390 support was first added. The only headers in virt/kvm at the time were the x86 specific ioapic.h, and iodev.h, neither of which shows up as an #include in the diff for the commit range 37817f2982d0f..e976a2b997fc4. Signed-off-by: Sean Christo

[PATCH 19/26] KVM: Standardize include paths across all architectures

2023-09-15 Thread Sean Christopherson
laced with ccflags-y (commit c73028a02887 ("s390: change to new flag variable") and commit 4108d9ba9091 ("powerpc/Makefiles: Change to new flag variables")). Signed-off-by: Sean Christopherson --- arch/arm64/kvm/Makefile | 2 -- arch/mips/kvm/Makefile| 2 -- arch/powerpc/kvm/

[PATCH 20/26] perf/x86: KVM: Have perf define a dedicated struct for getting guest PEBS data

2023-09-15 Thread Sean Christopherson
i.e. isn't used by KVM. Perf should also own its APIs, i.e. define what fields/data it needs, not rely on KVM to throw fields into data structures that effectively hold KVM-internal state. Signed-off-by: Sean Christopherson --- arch/x86/events/core.c| 5 +++-- arch/x86/even

[PATCH 21/26] entry/kvm: Drop @vcpu param from arch_xfer_to_guest_mode_handle_work()

2023-09-15 Thread Sean Christopherson
Drop the "struct kvm_vcpu" parameter from arch_xfer_to_guest_mode_handle_work() as a preparatory step towards removing the vCPU parameter from xfer_to_guest_mode_work() as well. Signed-off-by: Sean Christopherson --- include/linux/entry-kvm.h | 7 ++- kernel/entry/kvm.c

[PATCH 22/26] entry/kvm: KVM: Move KVM details related to signal/-EINTR into KVM proper

2023-09-15 Thread Sean Christopherson
said API and the definition of "struct kvm_vcpu" from the kernel. Alternatively, entry/kvm.c could be treated as part of KVM, i.e. be given access to KVM internals, but that's not obviously better than having KVM react to -EINTR (though it's not obviously worse eith

[PATCH 23/26] KVM: arm64: Move and consolidate "public" functions in asm/kvm_host.h

2023-09-15 Thread Sean Christopherson
imal amount of #ifdeffery. Signed-off-by: Sean Christopherson --- arch/arm64/include/asm/kvm_host.h | 48 ++- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 90cfbf420545..89b40c34f0a

[PATCH 24/26] powerpc/xics: Move declaration of xics_wake_cpu() out of kvm_ppc.h

2023-09-15 Thread Sean Christopherson
xics_wake_cpu() is provided by core PPC code, not by KVM. Move its declaration out of kvm_ppc.h and into xics.h. Signed-off-by: Sean Christopherson --- arch/powerpc/include/asm/kvm_ppc.h | 2 -- arch/powerpc/include/asm/xics.h| 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff

[PATCH 25/26] KVM: PPC: Rearrange code in kvm_ppc.h to isolate "public" information

2023-09-15 Thread Sean Christopherson
etails from the kernel at-large. Signed-off-by: Sean Christopherson --- arch/powerpc/include/asm/kvm_ppc.h | 302 +++-- 1 file changed, 153 insertions(+), 149 deletions(-) diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h index 72fee202d3e

[PATCH 26/26] KVM: Hide KVM internal data structures and values from kernel at-large

2023-09-15 Thread Sean Christopherson
s and an s390 declaration as needed, and opportunistically include kvm_host.h in trace/events.kvm.h instead of relying on the parent to provide the right includes. Cc: Anish Ghulati Cc: Venkatesh Srinivas Cc: Andrew Thornton Signed-off-by: Sean Christopherson --- arch/arm64/include/asm/kvm_em

Re: [PATCH 05/26] vfio: KVM: Pass get/put helpers from KVM to VFIO, don't do circular lookup

2023-09-18 Thread Sean Christopherson
On Mon, Sep 18, 2023, Jason Gunthorpe wrote: > On Fri, Sep 15, 2023 at 05:30:57PM -0700, Sean Christopherson wrote: > > Explicitly pass KVM's get/put helpers to VFIO when attaching a VM to > > VFIO instead of having VFIO do a symbol lookup back into KVM. Having both > &

Re: [PATCH 06/26] KVM: Drop CONFIG_KVM_VFIO and just look at KVM+VFIO

2023-09-18 Thread Sean Christopherson
On Mon, Sep 18, 2023, Jason Gunthorpe wrote: > On Fri, Sep 15, 2023 at 05:30:58PM -0700, Sean Christopherson wrote: > > Drop KVM's KVM_VFIO Kconfig, and instead compile in VFIO support if > > and only if VFIO itself is enabled. Similar to the recent change to have >

Re: [RFC PATCH v12 10/33] KVM: Set the stage for handling only shared mappings in mmu_notifier events

2023-09-18 Thread Sean Christopherson
On Mon, Sep 18, 2023, Binbin Wu wrote: > > > On 9/14/2023 9:55 AM, Sean Christopherson wrote: > > Add flags to "struct kvm_gfn_range" to let notifier events target only > > shared and only private mappings, and write up the existing mmu_notifier > > events

Re: [RFC PATCH v12 10/33] KVM: Set the stage for handling only shared mappings in mmu_notifier events

2023-09-18 Thread Sean Christopherson
On Mon, Sep 18, 2023, Michael Roth wrote: > On Wed, Sep 13, 2023 at 06:55:08PM -0700, Sean Christopherson wrote: > > Add flags to "struct kvm_gfn_range" to let notifier events target only > > shared and only private mappings, and write up the existing mmu_notifier >

Re: [RFC PATCH v12 02/33] KVM: Use gfn instead of hva for mmu_notifier_retry

2023-09-20 Thread Sean Christopherson
On Wed, Sep 20, 2023, Xu Yilun wrote: > On 2023-09-13 at 18:55:00 -0700, Sean Christopherson wrote: > > +void kvm_mmu_invalidate_range_add(struct kvm *kvm, gfn_t start, gfn_t end) > > +{ > > + lockdep_assert_held_write(&kvm->mmu_lock); > > + > > + WARN_

Re: [RFC PATCH v12 14/33] KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory

2023-09-20 Thread Sean Christopherson
On Tue, Sep 19, 2023, Binbin Wu wrote: > > > On 9/14/2023 9:55 AM, Sean Christopherson wrote: > [...] > > + > > +static void kvm_gmem_invalidate_begin(struct kvm_gmem *gmem, pgoff_t start, > > + pgoff_t end) > > +{

Re: [RFC PATCH v12 11/33] KVM: Introduce per-page memory attributes

2023-09-20 Thread Sean Christopherson
On Fri, Sep 15, 2023, Yan Zhao wrote: > On Wed, Sep 13, 2023 at 06:55:09PM -0700, Sean Christopherson wrote: > > From: Chao Peng > > > > In confidential computing usages, whether a page is private or shared is > > necessary information for KVM to perform operations l

Re: [RFC PATCH v12 11/33] KVM: Introduce per-page memory attributes

2023-09-20 Thread Sean Christopherson
On Mon, Sep 18, 2023, Binbin Wu wrote: > > > On 9/14/2023 9:55 AM, Sean Christopherson wrote: > > From: Chao Peng > [...] > > +#ifdef CONFIG_KVM_GENERIC_MEMORY_ATTRIBUTES > > +/* > > + * Returns true if _all_ gfns in the range [@start, @end) hav

Re: [RFC PATCH v12 14/33] KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory

2023-09-20 Thread Sean Christopherson
On Mon, Sep 18, 2023, Michael Roth wrote: > > +static long kvm_gmem_punch_hole(struct inode *inode, loff_t offset, loff_t > > len) > > +{ > > + struct list_head *gmem_list = &inode->i_mapping->private_list; > > + pgoff_t start = offset >> PAGE_SHIFT; > > + pgoff_t end = (offset + len) >> PAG

Re: [RFC PATCH v12 02/33] KVM: Use gfn instead of hva for mmu_notifier_retry

2023-09-21 Thread Sean Christopherson
On Thu, Sep 21, 2023, Xu Yilun wrote: > When the invalidation acrosses multiple slots, I'm not sure if the > contiguous HVA range must correspond to contiguous GFN range. If not, > are we producing a larger range than required? Multiple invalidations are all but guaranteed to yield a range that co

Re: [RFC PATCH v12 18/33] KVM: x86/mmu: Handle page fault for private memory

2023-09-21 Thread Sean Christopherson
On Mon, Sep 18, 2023, Yan Zhao wrote: > On Fri, Sep 15, 2023 at 07:26:16AM -0700, Sean Christopherson wrote: > > On Fri, Sep 15, 2023, Yan Zhao wrote: > > > > static int __kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct > > > > kvm_page_fault *fault)

Re: [RFC PATCH v12 14/33] KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory

2023-09-21 Thread Sean Christopherson
On Wed, Sep 13, 2023, Sean Christopherson wrote: > virt/kvm/guest_mem.c | 593 + Getting to the really important stuff... Anyone object to naming the new file guest_memfd.c instead of guest_mem.c? Just the file, i.e. still keep the gmem namesp

Re: [RFC PATCH v12 07/33] KVM: Add KVM_EXIT_MEMORY_FAULT exit to report faults to userspace

2023-09-22 Thread Sean Christopherson
On Fri, Sep 22, 2023, Xiaoyao Li wrote: > On 9/14/2023 9:55 AM, Sean Christopherson wrote: > > From: Chao Peng > > > > Add a new KVM exit type to allow userspace to handle memory faults that > > KVM cannot resolve, but that userspace *may* be able to handle (withou

Re: [RFC PATCH v12 11/33] KVM: Introduce per-page memory attributes

2023-09-25 Thread Sean Christopherson
On Thu, Sep 21, 2023, Yan Zhao wrote: > On Wed, Sep 20, 2023 at 02:00:22PM -0700, Sean Christopherson wrote: > > On Fri, Sep 15, 2023, Yan Zhao wrote: > > > On Wed, Sep 13, 2023 at 06:55:09PM -0700, Sean Christopherson wrote: > > > > +/* Set @attributes f

Re: [RFC PATCH v12 11/33] KVM: Introduce per-page memory attributes

2023-10-03 Thread Sean Christopherson
On Tue, Oct 03, 2023, Fuad Tabba wrote: > Hi, > > > diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h > > index d2d913acf0df..f8642ff2eb9d 100644 > > --- a/include/uapi/linux/kvm.h > > +++ b/include/uapi/linux/kvm.h > > @@ -1227,6 +1227,7 @@ struct kvm_ppc_resize_hpt { > > #define

Re: [RFC PATCH v12 11/33] KVM: Introduce per-page memory attributes

2023-10-03 Thread Sean Christopherson
On Tue, Oct 03, 2023, Fuad Tabba wrote: > On Tue, Oct 3, 2023 at 4:59 PM Sean Christopherson wrote: > > On Tue, Oct 03, 2023, Fuad Tabba wrote: > > > > +#define KVM_MEMORY_ATTRIBUTE_PRIVATE (1ULL << 3) > > > > + > > > > > >

Re: [RFC PATCH v12 11/33] KVM: Introduce per-page memory attributes

2023-10-05 Thread Sean Christopherson
On Thu, Oct 05, 2023, Fuad Tabba wrote: > Hi Sean, > > On Tue, Oct 3, 2023 at 9:51 PM Sean Christopherson wrote: > > > Like I said, pKVM doesn't need a userspace ABI for managing > > > PRIVATE/SHARED, > > > just a way of tracking in the host kernel o

[PATCH v13 01/35] KVM: Tweak kvm_hva_range and hva_handler_t to allow reusing for gfn ranges

2023-10-27 Thread Sean Christopherson
s have been gfn_handler_t). Practically speaking, this is a nop for 64-bit kernels as the only meaningful change is to store start+end as u64s instead of unsigned longs. Reviewed-by: Paolo Bonzini Reviewed-by: Xiaoyao Li Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 34 +

[PATCH v13 00/35] KVM: guest_memfd() and per-page attributes

2023-10-27 Thread Sean Christopherson
M: x86/mmu: Handle page fault for private memory KVM: selftests: Add KVM_SET_USER_MEMORY_REGION2 helper KVM: selftests: Expand set_memory_region_test to validate guest_memfd() KVM: selftests: Add basic selftest for guest_memfd() Sean Christopherson (23): KVM: Tweak kvm_hva_range and hva

[PATCH v13 02/35] KVM: Assert that mmu_invalidate_in_progress *never* goes negative

2023-10-27 Thread Sean Christopherson
or even problematic to anything other than the target VM, e.g. the underlying bug could simply be a duplicate call to end(). And it's much more likely that a missed invalidation, i.e. a potential use-after-free, would manifest as no notification whatsoever, not an end() without a star

[PATCH v13 03/35] KVM: Use gfn instead of hva for mmu_notifier_retry

2023-10-27 Thread Sean Christopherson
small. Suggested-by: Sean Christopherson Cc: Xu Yilun Signed-off-by: Chao Peng Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba [sean: convert vmx_set_apic_access_page_addr() to gfn-based API] Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 10 ++ arch/x86/kvm/vmx/vmx.c

[PATCH v13 04/35] KVM: WARN if there are dangling MMU invalidations at VM destruction

2023-10-27 Thread Sean Christopherson
from the mmu_notifier due to the above exception waiver, but the assertion can detect KVM bugs, e.g. such as the bug that *almost* escaped initial guest_memfd development. Link: https://lore.kernel.org/all/e397d30c-c6af-e68f-d18e-b4e3739c5...@linux.intel.com Signed-off-by: Sean Christopherson ---

  1   2   3   4   5   6   7   8   >