Re: [PATCH 0/4] KVM, mm: remove the .change_pte() MMU notifier and set_pte_at_notify()

2024-04-11 Thread Paolo Bonzini
On Wed, Apr 10, 2024 at 11:30 PM Andrew Morton wrote: > On Fri, 5 Apr 2024 07:58:11 -0400 Paolo Bonzini wrote: > > Please review! Also feel free to take the KVM patches through the mm > > tree, as I don't expect any conflicts. > > It's mainly a KVM thing and the MM changes

Re: [PATCH 1/4] KVM: delete .change_pte MMU notifier callback

2024-04-11 Thread Paolo Bonzini
On Mon, Apr 8, 2024 at 3:56 PM Peter Xu wrote: > Paolo, > > I may miss a bunch of details here (as I still remember some change_pte > patches previously on the list..), however not sure whether we considered > enable it? Asked because I remember Andrea used to have a custom tree > maintaining

[PATCH 4/4] mm: replace set_pte_at_notify() with just set_pte_at()

2024-04-05 Thread Paolo Bonzini
With the demise of the .change_pte() MMU notifier callback, there is no notification happening in set_pte_at_notify(). It is a synonym of set_pte_at() and can be replaced with it. Signed-off-by: Paolo Bonzini --- include/linux/mmu_notifier.h | 2 -- kernel/events/uprobes.c | 5 ++--- mm

[PATCH 2/4] KVM: remove unused argument of kvm_handle_hva_range()

2024-04-05 Thread Paolo Bonzini
The only user was kvm_mmu_notifier_change_pte(), which is now gone. Signed-off-by: Paolo Bonzini --- virt/kvm/kvm_main.c | 7 +-- 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 2fcd9979752a..970111ad 100644 --- a/virt/kvm

[PATCH 3/4] mmu_notifier: remove the .change_pte() callback

2024-04-05 Thread Paolo Bonzini
set_pte_at_notify() even though it is just a synonym for set_pte_at(). Signed-off-by: Paolo Bonzini --- include/linux/mmu_notifier.h | 46 ++-- mm/mmu_notifier.c| 17 - 2 files changed, 2 insertions(+), 61 deletions(-) diff --git a/include/linux

[PATCH 1/4] KVM: delete .change_pte MMU notifier callback

2024-04-05 Thread Paolo Bonzini
t, because KVM unmaps the sPTEs during .invalidate_range_start() and therefore .change_pte() has no hope of finding a sPTE to change. Drop the generic KVM code that dispatches to kvm_set_spte_gfn(), as well as all the architecture specific implementations. Signed-off-by: Paolo Bonzini --- arch

[PATCH 0/4] KVM, mm: remove the .change_pte() MMU notifier and set_pte_at_notify()

2024-04-05 Thread Paolo Bonzini
ks, Paolo Paolo Bonzini (4): KVM: delete .change_pte MMU notifier callback KVM: remove unused argument of kvm_handle_hva_range() mmu_notifier: remove the .change_pte() callback mm: replace set_pte_at_notify() with just set_pte_at() arch/arm64/kvm/mmu.c | 34 -

Re: [PATCH] KVM: Get rid of return value from kvm_arch_create_vm_debugfs()

2024-02-23 Thread Paolo Bonzini
ail VM creation. > > Change to a void return to discourage architectures from making debugfs > failures fatal for the VM. Seems like everyone already had the right > idea, as all implementations already return 0 unconditionally. > > Signed-off-by: Oliver Upton Acked-by: Paolo Bonzini

Re: [PATCH v2 2/4] eventfd: simplify eventfd_signal()

2024-02-07 Thread Paolo Bonzini
; keeping that additional argument. > > Signed-off-by: Christian Brauner > --- > arch/x86/kvm/hyperv.c | 2 +- > arch/x86/kvm/xen.c| 2 +- > virt/kvm/eventfd.c| 4 ++-- > 30 files changed, 60 insertions(

Re: [PATCH 34/34] KVM: selftests: Add a memory region subtest to validate invalid flags

2023-11-21 Thread Paolo Bonzini
6_64__, while the usages introduced here aren't. > > > > Should > > > > On Sun, Nov 5, 2023 at 8:35 AM Paolo Bonzini wrote: > > > > > > + test_invalid_memory_region_flags(); > > > > be #ifdef'd, perhaps? I'm not quite sure what the intent

Re: [PATCH v14 00/34] KVM: guest_memfd() and per-page attributes

2023-11-13 Thread Paolo Bonzini
On 11/5/23 17:30, Paolo Bonzini wrote: The "development cycle" for this version is going to be very short; ideally, next week I will merge it as is in kvm/next, taking this through the KVM tree for 6.8 immediately after the end of the merge window. The series is still based on 6.6

Re: [PATCH 27/34] KVM: selftests: Introduce VM "shape" to allow tests to specify the VM type

2023-11-09 Thread Paolo Bonzini
On 11/9/23 00:37, Anish Moorthy wrote: On Wed, Nov 8, 2023 at 9:00 AM Anish Moorthy wrote: This commit breaks the arm64 selftests build btw: looks like a simple oversight? Yup, fix is a one-liner. Posted below. diff --git a/tools/testing/selftests/kvm/aarch64/page_fault_test.c

Re: [PATCH 31/34] KVM: selftests: Expand set_memory_region_test to validate guest_memfd()

2023-11-06 Thread Paolo Bonzini
On 11/5/23 17:30, Paolo Bonzini wrote: From: Chao Peng Expand set_memory_region_test to exercise various positive and negative testcases for private memory. - Non-guest_memfd() file descriptor for private memory - guest_memfd() from different VM - Overlapping bindings - Unaligned

Re: [PATCH v13 23/35] KVM: x86: Add support for "protected VMs" that can utilize private memory

2023-11-06 Thread Paolo Bonzini
On 11/6/23 12:00, Fuad Tabba wrote: Hi, On Fri, Oct 27, 2023 at 7:23 PM Sean Christopherson wrote: Add a new x86 VM type, KVM_X86_SW_PROTECTED_VM, to serve as a development and testing vehicle for Confidential (CoCo) VMs, and potentially to even become a "real" product in the distant

[PATCH 36/34] KVM: Add transparent hugepage support for dedicated guest memory

2023-11-05 Thread Paolo Bonzini
com> [Allow even with CONFIG_TRANSPARENT_HUGEPAGE; dropped momentarily due to uneasiness about the API. - Paolo] Signed-off-by: Paolo Bonzini --- Documentation/virt/kvm/api.rst| 7 ++ include/uapi/linux/kvm.h | 2 + .../testing/selftests/kvm/guest_memfd_

[PATCH 35/34] KVM: Prepare for handling only shared mappings in mmu_notifier events

2023-11-05 Thread Paolo Bonzini
17.3615211-13-sea...@google.com> Signed-off-by: Paolo Bonzini --- include/linux/kvm_host.h | 2 ++ virt/kvm/kvm_main.c | 17 + 2 files changed, 19 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 3ebc6912c54a..4d5d139b0bde 100644 ---

[PATCH 34/34] KVM: selftests: Add a memory region subtest to validate invalid flags

2023-11-05 Thread Paolo Bonzini
sea...@google.com> Signed-off-by: Paolo Bonzini --- .../selftests/kvm/set_memory_region_test.c| 49 +++ 1 file changed, 49 insertions(+) diff --git a/tools/testing/selftests/kvm/set_memory_region_test.c b/tools/testing/selftests/kvm/set_memory_region_test.c index 189177

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

2023-11-05 Thread Paolo Bonzini
OTECTED_VM without its prerequisites. Signed-off-by: Ackerley Tng [sean: call out the similarities with set_memory_region_test] Signed-off-by: Sean Christopherson Message-Id: <20231027182217.3615211-36-sea...@google.com> Signed-off-by: Paolo Bonzini --- tools/testing/selftests/kvm/Makefil

[PATCH 32/34] KVM: selftests: Add basic selftest for guest_memfd()

2023-11-05 Thread Paolo Bonzini
Signed-off-by: Ackerley Tng Co-developed-by: Paolo Bonzini Signed-off-by: Paolo Bonzini Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Message-Id: <20231027182217.3615211-35-sea...@google.com> Signed-off-by: Paolo Bonzini --- tools/testing/selftests/kvm/Ma

[PATCH 31/34] KVM: selftests: Expand set_memory_region_test to validate guest_memfd()

2023-11-05 Thread Paolo Bonzini
-by: Ackerley Tng Signed-off-by: Ackerley Tng [sean: trim the testcases to remove duplicate coverage] Signed-off-by: Sean Christopherson Message-Id: <20231027182217.3615211-34-sea...@google.com> Signed-off-by: Paolo Bonzini --- .../selftests/kvm/include/kvm_util_base.h

[PATCH 30/34] KVM: selftests: Add KVM_SET_USER_MEMORY_REGION2 helper

2023-11-05 Thread Paolo Bonzini
ss version to reduce the amount of boilerplate code need for basic usage. Signed-off-by: Chao Peng Signed-off-by: Ackerley Tng Signed-off-by: Sean Christopherson Message-Id: <20231027182217.3615211-33-sea...@google.com> Signed-off-by: Paolo Bonzini --- .../selftests/kvm/includ

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

2023-11-05 Thread Paolo Bonzini
opherson Signed-off-by: Sean Christopherson Message-Id: <20231027182217.3615211-32-sea...@google.com> Signed-off-by: Paolo Bonzini --- tools/testing/selftests/kvm/Makefile | 1 + .../kvm/x86_64/private_mem_conversions_test.c | 482 ++ 2 files changed, 483 inserti

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

2023-11-05 Thread Paolo Bonzini
From: 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 Message-Id: <20231027182217.3615211-31-sea...@google.com> Signed-off-by: Paolo B

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

2023-11-05 Thread Paolo Bonzini
t's expected that x86 will double down and require unique VM types for TDX and SNP guests. Signed-off-by: Sean Christopherson Message-Id: <20231027182217.3615211-30-sea...@google.com> Signed-off-by: Paolo Bonzini --- tools/testing/selftests/kvm/dirty_log_test.c |

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

2023-11-05 Thread Paolo Bonzini
: drop shared/private helpers (let tests specify flags)] Signed-off-by: Sean Christopherson Message-Id: <20231027182217.3615211-29-sea...@google.com> Signed-off-by: Paolo Bonzini --- .../selftests/kvm/include/x86_64/processor.h | 15 +++ 1 file changed, 15 insertions(+)

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

2023-11-05 Thread Paolo Bonzini
: <20231027182217.3615211-28-sea...@google.com> Signed-off-by: Paolo Bonzini --- .../selftests/kvm/include/kvm_util_base.h | 48 +++ tools/testing/selftests/kvm/lib/kvm_util.c| 28 +++ 2 files changed, 76 insertions(+) diff --git a/tools/testing/selftests/kvm/i

[PATCH 24/34] KVM: selftests: Add support for creating private memslots

2023-11-05 Thread Paolo Bonzini
he fd without having to first destroy memslots. Co-developed-by: Ackerley Tng Signed-off-by: Ackerley Tng Signed-off-by: Sean Christopherson Message-Id: <20231027182217.3615211-27-sea...@google.com> Signed-off-by: Paolo Bonzini --- .../selftests/kvm/include/kvm_util_base.h | 23 ++

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

2023-11-05 Thread Paolo Bonzini
this point forward. Signed-off-by: Sean Christopherson Message-Id: <20231027182217.3615211-26-sea...@google.com> Signed-off-by: Paolo Bonzini --- .../selftests/kvm/include/kvm_util_base.h | 2 +- tools/testing/selftests/kvm/lib/kvm_util.c| 19 ++- 2 files chang

[PATCH 22/34] KVM: selftests: Drop unused kvm_userspace_memory_region_find() helper

2023-11-05 Thread Paolo Bonzini
information. Signed-off-by: Sean Christopherson Message-Id: <20231027182217.3615211-25-sea...@google.com> Signed-off-by: Paolo Bonzini --- .../selftests/kvm/include/kvm_util_base.h | 4 --- tools/testing/selftests/kvm/lib/kvm_util.c| 29 --- 2 files changed, 33 deletions(-)

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

2023-11-05 Thread Paolo Bonzini
tic option. At the very least, KVM_X86_SW_PROTECTED_VM will enable a variety of selftests for guest_memfd and private memory support without requiring unique hardware. Signed-off-by: Sean Christopherson Reviewed-by: Paolo Bonzini Message-Id: <20231027182217.3615211-24-sea...@google.com> Sign

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

2023-11-05 Thread Paolo Bonzini
Reviewed-by: Paolo Bonzini Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba Message-Id: <20231027182217.3615211-23-sea...@google.com> Signed-off-by: Paolo Bonzini --- arch/powerpc/kvm/book3s_hv.c| 2 +- arch/x86/include/asm/kvm_host.h | 8 +++- arch/x86/kvm/debugfs.c | 2 +-

[PATCH 19/34] KVM: Drop superfluous __KVM_VCPU_MULTIPLE_ADDRESS_SPACE macro

2023-11-05 Thread Paolo Bonzini
From: 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 Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba Message-Id

[PATCH 18/34] KVM: x86/mmu: Handle page fault for private memory

2023-11-05 Thread Paolo Bonzini
ys come from a guest_memfd instance. 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 Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba Message-Id: <20231027182217.3615211-21-sea.

[PATCH 17/34] KVM: x86: Disallow hugepages when memory attributes are mixed

2023-11-05 Thread Paolo Bonzini
-by: Sean Christopherson Message-Id: <20231027182217.3615211-20-sea...@google.com> Signed-off-by: Paolo Bonzini --- arch/x86/include/asm/kvm_host.h | 3 + arch/x86/kvm/mmu/mmu.c | 154 +++- arch/x86/kvm/x86.c | 4 + 3 files change

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

2023-11-05 Thread Paolo Bonzini
_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 Reviewed-by: Paolo Bonzini Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba Message-Id: &l

[PATCH 15/34] KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory

2023-11-05 Thread Paolo Bonzini
Signed-off-by: Kirill A. 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 Co-developed-by: Paolo Bonzini Signed-off

[PATCH 14/34] fs: Rename anon_inode_getfile_secure() and anon_inode_getfd_secure()

2023-11-05 Thread Paolo Bonzini
is no in-tree module that uses it, and the old name is gone anyway. If anybody actually needs the symbol, they can ask or they can just use anon_inode_create_getfile(), which will be exported very soon for use in KVM. Suggested-by: Christian Brauner Signed-off-by: Paolo Bonzini --- fs/anon_inod

[PATCH 13/34] mm: Add AS_UNMOVABLE to mark mapping as completely unmovable

2023-11-05 Thread Paolo Bonzini
NEVICTABLE. Cc: Matthew Wilcox Co-developed-by: Vlastimil Babka Signed-off-by: Vlastimil Babka Signed-off-by: Sean Christopherson Message-Id: <20231027182217.3615211-15-sea...@google.com> Signed-off-by: Paolo Bonzini --- include/linux/pagemap.h | 19 +- mm/compactio

[PATCH 12/34] KVM: Introduce per-page memory attributes

2023-11-05 Thread Paolo Bonzini
231027182217.3615211-14-sea...@google.com> Signed-off-by: Paolo Bonzini --- Documentation/virt/kvm/api.rst | 36 ++ include/linux/kvm_host.h | 19 +++ include/uapi/linux/kvm.h | 13 ++ virt/kvm/Kconfig | 4 + virt/kvm/kvm_main.c| 216 ++

[PATCH 11/34] KVM: Drop .on_unlock() mmu_notifier hook

2023-11-05 Thread Paolo Bonzini
of this nature. Reported-by: Isaku Yamahata Link: https://lore.kernel.org/all/20230802203119.gb2021...@ls.amr.corp.intel.com Signed-off-by: Sean Christopherson Reviewed-by: Paolo Bonzini Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba Message-Id: <20231027182217.3615211-12-sea...@google.com> Sign

[PATCH 10/34] KVM: Add a dedicated mmu_notifier flag for reclaiming freed memory

2023-11-05 Thread Paolo Bonzini
from a function call (not to mention the size of the struct will be two bytes in practice). Signed-off-by: Sean Christopherson Reviewed-by: Paolo Bonzini Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba Message-Id: <20231027182217.3615211-11-sea...@google.com> Signed-off-by: Paolo B

[PATCH 09/34] KVM: Add KVM_EXIT_MEMORY_FAULT exit to report faults to userspace

2023-11-05 Thread Paolo Bonzini
ristopherson Signed-off-by: Sean Christopherson Reviewed-by: Paolo Bonzini Message-Id: <20231027182217.3615211-10-sea...@google.com> Signed-off-by: Paolo Bonzini --- Documentation/virt/kvm/api.rst | 41 ++ arch/x86/kvm/x86.c | 1 + include/linux/kvm_ho

[PATCH 08/34] KVM: Introduce KVM_SET_USER_MEMORY_REGION2

2023-11-05 Thread Paolo Bonzini
tection of bad flags a bit 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 Reviewed-by: X

[PATCH 07/34] KVM: Convert KVM_ARCH_WANT_MMU_NOTIFIER to CONFIG_KVM_GENERIC_MMU_NOTIFIER

2023-11-05 Thread Paolo Bonzini
reason not to define it in common KVM. Acked-by: Anup Patel Signed-off-by: Sean Christopherson Reviewed-by: Paolo Bonzini Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba Message-Id: <20231027182217.3615211-8-sea...@google.com> Signed-off-by: Paolo Bonzini --- arch/arm64/include/asm/kvm_

[PATCH 06/34] KVM: PPC: Return '1' unconditionally for KVM_CAP_SYNC_MMU

2023-11-05 Thread Paolo Bonzini
. Suggested-by: Paolo Bonzini Signed-off-by: Sean Christopherson Message-Id: <20231027182217.3615211-7-sea...@google.com> Signed-off-by: Paolo Bonzini --- 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

[PATCH 05/34] KVM: PPC: Drop dead code related to KVM_ARCH_WANT_MMU_NOTIFIER

2023-11-05 Thread Paolo Bonzini
defined(KVM_ARCH_WANT_MMU_NOTIFIER) 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 Reviewed-by: Paolo Bonzini Reviewed-by: Fuad Tabba Message-Id: <2023102

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

2023-11-05 Thread Paolo Bonzini
-by: Sean Christopherson Reviewed-by: Paolo Bonzini Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba Message-Id: <20231027182217.3615211-5-sea...@google.com> Signed-off-by: Paolo Bonzini --- virt/kvm/kvm_main.c | 9 - 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/vi

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

2023-11-05 Thread Paolo Bonzini
is expected 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 Reviewed-by: Paolo Bonzini Reviewed-by: Xu Yilun Message-Id

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

2023-11-05 Thread Paolo Bonzini
(). Signed-off-by: Sean Christopherson Reviewed-by: Paolo Bonzini Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba Message-Id: <20231027182217.3615211-3-sea...@google.com> Signed-off-by: Paolo Bonzini --- virt/kvm/kvm_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git

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

2023-11-05 Thread Paolo Bonzini
t should always 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 Reviewed-by: Fuad Ta

[PATCH v14 00/34] KVM: guest_memfd() and per-page attributes

2023-11-05 Thread Paolo Bonzini
VM_SET_USER_MEMORY_REGION2 helper KVM: selftests: Expand set_memory_region_test to validate guest_memfd() KVM: selftests: Add basic selftest for guest_memfd() Paolo Bonzini (1): fs: Rename anon_inode_getfile_secure() and anon_inode_getfd_secure() Sean Christopherson (23): KVM: Tweak kvm_hv

Re: [PATCH v13 20/35] KVM: x86/mmu: Handle page fault for private memory

2023-11-05 Thread Paolo Bonzini
On Sun, Nov 5, 2023 at 2:04 PM Xu Yilun wrote: > > > +static void kvm_mmu_prepare_memory_fault_exit(struct kvm_vcpu *vcpu, > > + struct kvm_page_fault *fault) > > +{ > > + kvm_prepare_memory_fault_exit(vcpu, fault->gfn << PAGE_SHIFT, > > +

Re: [PATCH v13 15/35] fs: Export anon_inode_getfile_secure() for use by KVM

2023-11-03 Thread Paolo Bonzini
On 11/2/23 17:24, Christian Brauner wrote: On Fri, Oct 27, 2023 at 11:21:57AM -0700, Sean Christopherson wrote: Export anon_inode_getfile_secure() so that it can be used by KVM to create and manage file-based guest memory without need a fullblow filesystem. The "standard" anon_inode_getfd()

Re: [PATCH v13 17/35] KVM: Add transparent hugepage support for dedicated guest memory

2023-11-02 Thread Paolo Bonzini
On Thu, Nov 2, 2023 at 4:38 PM Sean Christopherson wrote: > Actually, looking that this again, there's not actually a hard dependency on > THP. > A THP-enabled kernel _probably_ gives a higher probability of using > hugepages, > but mostly because THP selects COMPACTION, and I suppose because

Re: [PATCH v13 16/35] KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory

2023-11-02 Thread Paolo Bonzini
On 10/31/23 23:39, David Matlack wrote: Maybe can you sketch out how you see this proposal being extensible to using guest_memfd for shared mappings? For in-place conversions, e.g. pKVM, no additional guest_memfd is needed. What's missing there is the ability to (safely) mmap() guest_memfd,

Re: [PATCH v13 12/35] KVM: Prepare for handling only shared mappings in mmu_notifier events

2023-11-02 Thread Paolo Bonzini
On 11/2/23 06:59, Binbin Wu 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 to be shared-only (private memory is never associated with a userspace virtual address, i.e. can't be

Re: [PATCH v13 09/35] KVM: Add KVM_EXIT_MEMORY_FAULT exit to report faults to userspace

2023-11-02 Thread Paolo Bonzini
On 11/2/23 10:35, Huang, Kai wrote: IIUC KVM can already handle the case of poisoned page by sending signal to user app: static int kvm_handle_error_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) { ... if

Re: [PATCH v13 09/35] KVM: Add KVM_EXIT_MEMORY_FAULT exit to report faults to userspace

2023-11-02 Thread Paolo Bonzini
On 11/1/23 18:36, Sean Christopherson wrote: A good example is KVM_RUN with -EINTR; if KVM were to return something other than -EINTR on a pending signal or vcpu->run->immediate_exit, userspace would fall over. And dually if KVM were to return KVM_EXIT_INTR together with something other

Re: [PATCH v13 13/35] KVM: Introduce per-page memory attributes

2023-11-02 Thread Paolo Bonzini
On 11/2/23 04:01, Huang, Kai wrote: On Fri, 2023-10-27 at 11:21 -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 like page fault handling, page zapping etc. There are

Re: [PATCH v13 17/35] KVM: Add transparent hugepage support for dedicated guest memory

2023-11-01 Thread Paolo Bonzini
On Wed, Nov 1, 2023 at 11:35 PM Sean Christopherson wrote: > > On Wed, Nov 01, 2023, Paolo Bonzini wrote: > > On 11/1/23 17:36, Sean Christopherson wrote: > > > > > "Allow" isn't perfect, e.g. I would much prefer a straight &g

Re: [PATCH v13 17/35] KVM: Add transparent hugepage support for dedicated guest memory

2023-11-01 Thread Paolo Bonzini
On 11/1/23 17:36, Sean Christopherson wrote: "Allow" isn't perfect, e.g. I would much prefer a straight KVM_GUEST_MEMFD_USE_HUGEPAGES or KVM_GUEST_MEMFD_HUGEPAGES flag, but I wanted the name to convey that KVM doesn't (yet) guarantee hugepages. I.e. KVM_GUEST_MEMFD_ALLOW_HUGEPAGE is stronger

Re: [PATCH v13 17/35] KVM: Add transparent hugepage support for dedicated guest memory

2023-11-01 Thread Paolo Bonzini
On Wed, Nov 1, 2023 at 2:41 PM Sean Christopherson wrote: > > On Wed, Nov 01, 2023, Xiaoyao Li wrote: > > On 10/31/2023 10:16 PM, Sean Christopherson wrote: > > > On Tue, Oct 31, 2023, Xiaoyao Li wrote: > > > > On 10/28/2023 2:21 AM, Sean Christopherson wrote: > > > > > Extended guest_memfd to

Re: [PATCH v13 16/35] KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory

2023-10-31 Thread Paolo Bonzini
On Tue, Oct 31, 2023 at 11:13 PM Sean Christopherson wrote: > On Tue, Oct 31, 2023, Fuad Tabba wrote: > > On Fri, Oct 27, 2023 at 7:23 PM Sean Christopherson > > wrote: > Since we now know that at least pKVM will use guest_memfd for shared memory, > and > odds are quite good that "regular" VMs

Re: [PATCH v13 08/35] KVM: Introduce KVM_SET_USER_MEMORY_REGION2

2023-10-30 Thread Paolo Bonzini
On 10/30/23 21:25, Sean Christopherson wrote: On Mon, Oct 30, 2023, Paolo Bonzini wrote: On 10/27/23 20:21, Sean Christopherson wrote: + if (ioctl == KVM_SET_USER_MEMORY_REGION) + size = sizeof(struct kvm_userspace_memory_region); This also needs a memset

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

2023-10-30 Thread Paolo Bonzini
On 10/27/23 20:21, Sean Christopherson wrote: Non-KVM people, please take a gander at two small-ish patches buried in the middle of this series: fs: Export anon_inode_getfile_secure() for use by KVM mm: Add AS_UNMOVABLE to mark mapping as completely unmovable Our plan/hope is to take

Re: [PATCH v13 23/35] KVM: x86: Add support for "protected VMs" that can utilize private memory

2023-10-30 Thread Paolo Bonzini
mory isn't a realistic option. At the very least, KVM_X86_SW_PROTECTED_VM will enable a variety of selftests for guest_memfd and private memory support without requiring unique hardware. Signed-off-by: Sean Christopherson Reviewed-by: Paolo Bonzini with one nit: +- + +:

Re: [PATCH v13 22/35] KVM: Allow arch code to track number of memslot address spaces per VM

2023-10-30 Thread Paolo Bonzini
and write guest memory and register state. 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). Reviewed-by: Paolo Bonzini

Re: [PATCH v13 18/35] KVM: x86: "Reset" vcpu->run->exit_reason early in KVM_RUN

2023-10-30 Thread Paolo Bonzini
--git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index ee3cd8c3c0ef..f41dbb1465a0 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10963,6 +10963,7 @@ static int vcpu_run(struct kvm_vcpu *vcpu) { int r; + vcpu->run->exit_reason = KVM_EXIT_UNKNOWN; vcpu->ar

Re: [PATCH v13 15/35] fs: Export anon_inode_getfile_secure() for use by KVM

2023-10-30 Thread Paolo Bonzini
On 10/27/23 20:21, Sean Christopherson wrote: Export anon_inode_getfile_secure() so that it can be used by KVM to create and manage file-based guest memory without need a fullblow without introducing a full-blown Otherwise, Reviewed-by: Paolo Bonzini Paolo filesystem. The "sta

Re: [PATCH v13 14/35] mm: Add AS_UNMOVABLE to mark mapping as completely unmovable

2023-10-30 Thread Paolo Bonzini
On 10/27/23 20:21, Sean Christopherson wrote: Add an "unmovable" flag for mappings that cannot be migrated under any circumstance. KVM will use the flag for its upcoming GUEST_MEMFD support, which will not support compaction/migration, at least not in the foreseeable future. Test AS_UNMOVABLE

Re: [PATCH v13 09/35] KVM: Add KVM_EXIT_MEMORY_FAULT exit to report faults to userspace

2023-10-30 Thread Paolo Bonzini
d-off-by: Chao Peng Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Reviewed-by: Paolo Bonzini --- Documentation/virt/kvm/api.rst | 41 ++ arch/x86/kvm/x86.c | 1 + include/linux/kvm_host.h | 11 + in

Re: [PATCH v13 12/35] KVM: Prepare for handling only shared mappings in mmu_notifier events

2023-10-30 Thread Paolo Bonzini
On 10/27/23 20:21, Sean Christopherson wrote: @@ -635,6 +635,13 @@ static __always_inline kvm_mn_ret_t __kvm_handle_hva_range(struct kvm *kvm, * the second or later invocation of the handler). */ gfn_range.arg =

Re: [PATCH v13 11/35] KVM: Drop .on_unlock() mmu_notifier hook

2023-10-30 Thread Paolo Bonzini
future bugs of this nature. This is what David suggested to do in patch 3, FWIW. Reviewed-by: Paolo Bonzini Paolo Reported-by: Isaku Yamahata Link: https://lore.kernel.org/all/20230802203119.gb2021...@ls.amr.corp.intel.com Signed-off-by: Sean Christopherson ---

Re: [PATCH v13 10/35] KVM: Add a dedicated mmu_notifier flag for reclaiming freed memory

2023-10-30 Thread Paolo Bonzini
actually be returned from a function call (not to mention the size of the struct will be two bytes in practice). Could have been split in two patches, but it's fine anyway. Reviewed-by: Paolo Bonzini Paolo

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

2023-10-30 Thread Paolo Bonzini
On Mon, Oct 30, 2023 at 5:53 PM David Matlack wrote: > > On 2023-10-27 11:21 AM, Sean Christopherson wrote: > > From: Chao Peng > > > > Currently in mmu_notifier invalidate path, hva range is recorded and > > then checked against by mmu_notifier_retry_hva() in the page fault > > handling path.

Re: [PATCH v13 08/35] KVM: Introduce KVM_SET_USER_MEMORY_REGION2

2023-10-30 Thread Paolo Bonzini
On 10/27/23 20:21, Sean Christopherson wrote: + if (ioctl == KVM_SET_USER_MEMORY_REGION) + size = sizeof(struct kvm_userspace_memory_region); This also needs a memset(, 0, sizeof(mem)), otherwise the out-of-bounds access of the commit message becomes a

Re: [PATCH v13 07/35] KVM: Convert KVM_ARCH_WANT_MMU_NOTIFIER to CONFIG_KVM_GENERIC_MMU_NOTIFIER

2023-10-30 Thread Paolo Bonzini
and I'll post it for 6.8. Reviewed-by: Paolo Bonzini Paolo

Re: [PATCH v13 05/35] KVM: PPC: Drop dead code related to KVM_ARCH_WANT_MMU_NOTIFIER

2023-10-30 Thread Paolo Bonzini
r = 1; #else - r = 0; + r = 1; #endif break; #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE Reviewed-by: Paolo Bonzini

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

2023-10-30 Thread Paolo Bonzini
...@linux.intel.com Signed-off-by: Sean Christopherson Reviewed-by: Paolo Bonzini Paolo

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

2023-10-30 Thread Paolo Bonzini
. Such aliasing should be uncommon, so the impact is expected small. Reviewed-by: Paolo Bonzini Paolo

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

2023-10-30 Thread Paolo Bonzini
() without a start(). Reviewed-by: Paolo Bonzini Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 0524933856d4..5a97e6c7d9c2 100644 --- a/virt/kvm/kvm_main.c +++ b

Re: [RFC PATCH v11 13/29] KVM: Add transparent hugepage support for dedicated guest memory

2023-09-06 Thread Paolo Bonzini
On Fri, Jul 21, 2023 at 7:13 PM Sean Christopherson wrote: > On Fri, Jul 21, 2023, Paolo Bonzini wrote: > > On 7/19/23 01:44, Sean Christopherson wrote: > > > @@ -413,6 +454,9 @@ int kvm_gmem_create(struct kvm *kvm, struct > > > kvm_create_guest_memfd *args) > &

Re: [RFC PATCH v11 06/29] KVM: Introduce KVM_SET_USER_MEMORY_REGION2

2023-07-31 Thread Paolo Bonzini
On 7/29/23 02:03, Sean Christopherson wrote: KVM would need to do multiple uaccess reads, but that's not a big deal. Am I missing something, or did past us just get too clever and miss the obvious solution? You would have to introduce struct kvm_userspace_memory_region2 anyway, though not a

Re: [RFC PATCH v11 10/29] mm: Add AS_UNMOVABLE to mark mapping as completely unmovable

2023-07-28 Thread Paolo Bonzini
On 7/28/23 18:02, Vlastimil Babka wrote: There's even a comment to that effect later on in the function: Hmm, well spotted. But it wouldn't be so great if we now had to lock every inspected page (and not just dirty pages), just to check the AS_ bit. But I wonder if this is leftover from

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

2023-07-21 Thread Paolo Bonzini
On 7/19/23 01:44, Sean Christopherson wrote: + inode = alloc_anon_inode(mnt->mnt_sb); + if (IS_ERR(inode)) + return PTR_ERR(inode); + + err = security_inode_init_security_anon(inode, , NULL); + if (err) + goto err_inode; + I don't understand

Re: [RFC PATCH v11 18/29] KVM: selftests: Drop unused kvm_userspace_memory_region_find() helper

2023-07-21 Thread Paolo Bonzini
On 7/19/23 01:45, Sean Christopherson wrote: 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

Re: [RFC PATCH v11 16/29] KVM: Allow arch code to track number of memslot address spaces per VM

2023-07-21 Thread Paolo Bonzini
On 7/19/23 01:44, Sean Christopherson wrote: @@ -4725,9 +4725,9 @@ static int kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg) case KVM_CAP_IRQ_ROUTING: return KVM_MAX_IRQ_ROUTES; #endif -#if KVM_ADDRESS_SPACE_NUM > 1 +#if KVM_MAX_NR_ADDRESS_SPACES > 1

Re: [RFC PATCH v11 14/29] KVM: x86/mmu: Handle page fault for private memory

2023-07-21 Thread Paolo Bonzini
ch/x86/kvm/mmu/mmutrace.h b/arch/x86/kvm/mmu/mmutrace.h index ae86820cef69..2d7555381955 100644 --- a/arch/x86/kvm/mmu/mmutrace.h +++ b/arch/x86/kvm/mmu/mmutrace.h @@ -58,6 +58,7 @@ TRACE_DEFINE_ENUM(RET_PF_CONTINUE); TRACE_DEFINE_ENUM(RET_PF_RETRY); TRACE_DEFINE_ENUM(RET_PF_EMULATE); TRACE_DEFINE_ENUM(RET_PF_INVALID); +TRACE_DEFINE_ENUM(RET_PF_USER); TRACE_DEFINE_ENUM(RET_PF_FIXED); TRACE_DEFINE_ENUM(RET_PF_SPURIOUS); Reviewed-by: Paolo Bonzini

Re: [RFC PATCH v11 15/29] KVM: Drop superfluous __KVM_VCPU_MULTIPLE_ADDRESS_SPACE macro

2023-07-21 Thread Paolo Bonzini
TIPLE_ADDRESS_SPACE +#if KVM_ADDRESS_SPACE_NUM == 1 static inline int kvm_arch_vcpu_memslots_id(struct kvm_vcpu *vcpu) { return 0; Reviewed-by: Paolo Bonzini

Re: [RFC PATCH v11 13/29] KVM: Add transparent hugepage support for dedicated guest memory

2023-07-21 Thread Paolo Bonzini
On 7/19/23 01:44, Sean Christopherson wrote: @@ -413,6 +454,9 @@ int kvm_gmem_create(struct kvm *kvm, struct kvm_create_guest_memfd *args) u64 flags = args->flags; u64 valid_flags = 0; + if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) + valid_flags |=

Re: [RFC PATCH v11 09/29] KVM: x86: Disallow hugepages when memory attributes are mixed

2023-07-21 Thread Paolo Bonzini
On 7/19/23 01:44, Sean Christopherson wrote: +static bool range_has_attrs(struct kvm *kvm, gfn_t start, gfn_t end, + unsigned long attrs) +{ + XA_STATE(xas, >mem_attr_array, start); + unsigned long index; + bool has_attrs; + void *entry; + +

Re: [RFC PATCH v11 08/29] KVM: Introduce per-page memory attributes

2023-07-21 Thread Paolo Bonzini
Reviewed-by: Paolo Bonzini

Re: [RFC PATCH v11 06/29] KVM: Introduce KVM_SET_USER_MEMORY_REGION2

2023-07-21 Thread Paolo Bonzini
KVM_GET_DIRTY_LOG: { Reviewed-by: Paolo Bonzini

Re: [RFC PATCH v11 04/29] KVM: PPC: Drop dead code related to KVM_ARCH_WANT_MMU_NOTIFIER

2023-07-19 Thread Paolo Bonzini
On 7/19/23 01:44, Sean Christopherson wrote: Signed-off-by: Sean Christopherson --- arch/powerpc/kvm/powerpc.c | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c index 7197c8256668..5cf9e5e3112a 100644 ---

Re: [RFC PATCH v11 02/29] KVM: Tweak kvm_hva_range and hva_handler_t to allow reusing for gfn ranges

2023-07-19 Thread Paolo Bonzini
On 7/19/23 01:44, Sean Christopherson wrote: Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 34 +++--- 1 file changed, 19 insertions(+), 15 deletions(-) Reviewed-by: Paolo Bonzini

Re: [RFC PATCH v11 03/29] KVM: Use gfn instead of hva for mmu_notifier_retry

2023-07-19 Thread Paolo Bonzini
should be uncommon, so the impact is expected small. Reviewed-by: Paolo Bonzini 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

Re: [RFC PATCH v11 01/29] KVM: Wrap kvm_gfn_range.pte in a per-action union

2023-07-19 Thread Paolo Bonzini
bility is to remove 'raw' and just assign the whole union. Apart from this, Reviewed-by: Paolo Bonzini Paolo + BUILD_BUG_ON(sizeof(gfn_range.arg) != sizeof(range->arg));

Re: [PATCH mm-unstable v2 00/10] mm/kvm: locklessly clear the accessed bit

2023-06-09 Thread Paolo Bonzini
On 5/27/23 01:44, Yu Zhao wrote: TLDR This patchset adds a fast path to clear the accessed bit without taking kvm->mmu_lock. It can significantly improve the performance of guests when the host is under heavy memory pressure. ChromeOS has been using a similar approach [1] since mid 2021

Re: [PATCH mm-unstable v2 09/10] kvm/x86: add kvm_arch_test_clear_young()

2023-06-09 Thread Paolo Bonzini
On 5/27/23 01:44, Yu Zhao wrote: +#define kvm_arch_has_test_clear_young kvm_arch_has_test_clear_young +static inline bool kvm_arch_has_test_clear_young(void) +{ + return IS_ENABLED(CONFIG_X86_64) && + (!IS_REACHABLE(CONFIG_KVM) || (tdp_mmu_enabled && shadow_accessed_mask));

Re: [PATCH mm-unstable v2 01/10] mm/kvm: add mmu_notifier_ops->test_clear_young()

2023-06-09 Thread Paolo Bonzini
On 5/31/23 21:17, Jason Gunthorpe wrote: + int (*test_clear_young)(struct mmu_notifier *mn, struct mm_struct *mm, + unsigned long start, unsigned long end, + bool clear, unsigned long *bitmap); + Why leave clear_young behind?

  1   2   3   >