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

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&

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

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 > > &g

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 long

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 >

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,

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(>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 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 1/6] KVM: x86/mmu: release audited pfns

2021-06-24 Thread Sean Christopherson
On Thu, Jun 24, 2021, Paolo Bonzini wrote: > On 24/06/21 10:43, Nicholas Piggin wrote: > > Excerpts from David Stevens's message of June 24, 2021 1:57 pm: > > > From: David Stevens > > > > Changelog? This looks like a bug, should it have a Fixes: tag? > > Probably has been there forever... The

Re: [PATCH] KVM: PPC: Book3S HV: Fix kvm_unmap_gfn_range_hv() for Hash MMU

2021-05-11 Thread Sean Christopherson
kvm_unmap_rmapp(). > > Fixes: 32b48bf8514c ("KVM: PPC: Book3S HV: Fix conversion to gfn-based MMU > notifier callbacks") > Signed-off-by: Michael Ellerman > --- > arch/powerpc/kvm/book3s_64_mmu_hv.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >

Re: [PATCH 4/5] KVM: selftests: Add a test for KVM_RUN+rseq to detect task migration bugs

2021-08-19 Thread Sean Christopherson
On Thu, Aug 19, 2021, Mathieu Desnoyers wrote: > - On Aug 17, 2021, at 8:12 PM, Sean Christopherson sea...@google.com > wrote: > > > Add a test to verify an rseq's CPU ID is updated correctly if the task is > > migrated while the kernel is handling KVM_RUN. This

Re: [PATCH 1/5] KVM: rseq: Update rseq when processing NOTIFY_RESUME on xfer to KVM guest

2021-08-19 Thread Sean Christopherson
On Thu, Aug 19, 2021, Mathieu Desnoyers wrote: > - On Aug 17, 2021, at 8:12 PM, Sean Christopherson sea...@google.com > wrote: > > @@ -250,7 +250,7 @@ static int rseq_ip_fixup(struct pt_regs *regs) > > * If not nested over a rseq critical section, restart is useless

[PATCH 2/5] entry: rseq: Call rseq_handle_notify_resume() in tracehook_notify_resume()

2021-08-17 Thread Sean Christopherson
ume() back in 2012. Punt cleaning that mess up to future patches. No functional change intended. Signed-off-by: Sean Christopherson --- arch/arm/kernel/signal.c | 1 - arch/arm64/kernel/signal.c | 1 - arch/csky/kernel/signal.c| 4 +--- arch/mips/kernel/signal.c| 4 +--- arch/powe

[PATCH 1/5] KVM: rseq: Update rseq when processing NOTIFY_RESUME on xfer to KVM guest

2021-08-17 Thread Sean Christopherson
. due to the CPU ID being stale after task migration. Fixes: 72c3c0fe54a3 ("x86/kvm: Use generic xfer to guest work function") Reported-by: Peter Foley Bisected-by: Doug Evans Cc: Shakeel Butt Cc: Thomas Gleixner Cc: sta...@vger.kernel.org Signed-off-by: Sean Christopherson --- ke

[PATCH 0/5] KVM: rseq: Fix and a test for a KVM+rseq bug

2021-08-17 Thread Sean Christopherson
that mirror kernel code, e.g. linux/types.h. This allows the new test in patch 4 to reference __NR_rseq without having to manually define it. Patch 4 is a regression test for the KVM+rseq bug. Patch 5 is a cleanup made possible by patch 3. Sean Christopherson (5): KVM: rseq: Update rseq when

[PATCH 4/5] KVM: selftests: Add a test for KVM_RUN+rseq to detect task migration bugs

2021-08-17 Thread Sean Christopherson
red by KVM without updating rseq, leading to a stale CPU ID and other badness. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile| 3 + tools/testing/selftests/kvm/rseq_test.c | 131 3 files ch

[PATCH 5/5] KVM: selftests: Remove __NR_userfaultfd syscall fallback

2021-08-17 Thread Sean Christopherson
Signed-off-by: Sean Christopherson --- tools/arch/x86/include/uapi/asm/unistd_64.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/arch/x86/include/uapi/asm/unistd_64.h b/tools/arch/x86/include/uapi/asm/unistd_64.h index 4205ed4158bf..cb52a3a8b8fc 100644 --- a/tools/arch/x86/include

[PATCH 3/5] tools: Move x86 syscall number fallbacks to .../uapi/

2021-08-17 Thread Sean Christopherson
/kvm's control. Prior to commit cec07f53c398 ("perf tools: Move syscall number fallbacks from perf-sys.h to tools/arch/x86/include/asm/"), the handcoded numbers were actual fallbacks, i.e. overriding unistd_{32,64}.h from the kernel headers was unintentional. Signed-off-by: Sean Chri

Re: [PATCH v2 4/5] KVM: selftests: Add a test for KVM_RUN+rseq to detect task migration bugs

2021-08-26 Thread Sean Christopherson
On Thu, Aug 26, 2021, Mathieu Desnoyers wrote: > - On Aug 25, 2021, at 8:51 PM, Sean Christopherson sea...@google.com > wrote: > >> >> + r = sched_setaffinity(0, sizeof(allowed_mask), > >> >> _mask); > >> >> + TE

Re: [PATCH v2 4/5] KVM: selftests: Add a test for KVM_RUN+rseq to detect task migration bugs

2021-08-25 Thread Sean Christopherson
On Mon, Aug 23, 2021, Mathieu Desnoyers wrote: > [ re-send to Darren Hart ] > > - On Aug 23, 2021, at 11:18 AM, Mathieu Desnoyers > mathieu.desnoy...@efficios.com wrote: > > > - On Aug 20, 2021, at 6:50 PM, Sean Christopherson sea...@google.com > > wrote: >

[PATCH v2 0/5] KVM: rseq: Fix and a test for a KVM+rseq bug

2021-08-20 Thread Sean Christopherson
] - Add Mathieu's ack for patch 2. - Add more comments in the test. v1: https://lkml.kernel.org/r/20210818001210.4073390-1-sea...@google.com Sean Christopherson (5): KVM: rseq: Update rseq when processing NOTIFY_RESUME on xfer to KVM guest entry: rseq: Call rseq_handle_notify_resume

[PATCH v2 1/5] KVM: rseq: Update rseq when processing NOTIFY_RESUME on xfer to KVM guest

2021-08-20 Thread Sean Christopherson
with KVM, e.g. due to the CPU ID being stale after task migration. Fixes: 72c3c0fe54a3 ("x86/kvm: Use generic xfer to guest work function") Reported-by: Peter Foley Bisected-by: Doug Evans Cc: Shakeel Butt Cc: Thomas Gleixner Cc: sta...@vger.kernel.org Signed-off-by: Sean Christopherson -

[PATCH v2 2/5] entry: rseq: Call rseq_handle_notify_resume() in tracehook_notify_resume()

2021-08-20 Thread Sean Christopherson
ume() back in 2012. Punt cleaning that mess up to future patches. No functional change intended. Acked-by: Mathieu Desnoyers Signed-off-by: Sean Christopherson --- arch/arm/kernel/signal.c | 1 - arch/arm64/kernel/signal.c | 1 - arch/csky/kernel/signal.c| 4 +--- arch/mips/kernel/signa

[PATCH v2 4/5] KVM: selftests: Add a test for KVM_RUN+rseq to detect task migration bugs

2021-08-20 Thread Sean Christopherson
red by KVM without updating rseq, leading to a stale CPU ID and other badness. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile| 3 + tools/testing/selftests/kvm/rseq_test.c | 154 3 files ch

[PATCH v2 3/5] tools: Move x86 syscall number fallbacks to .../uapi/

2021-08-20 Thread Sean Christopherson
/kvm's control. Prior to commit cec07f53c398 ("perf tools: Move syscall number fallbacks from perf-sys.h to tools/arch/x86/include/asm/"), the handcoded numbers were actual fallbacks, i.e. overriding unistd_{32,64}.h from the kernel headers was unintentional. Signed-off-by: Sean Chri

[PATCH v2 5/5] KVM: selftests: Remove __NR_userfaultfd syscall fallback

2021-08-20 Thread Sean Christopherson
Signed-off-by: Sean Christopherson --- tools/arch/x86/include/uapi/asm/unistd_64.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/arch/x86/include/uapi/asm/unistd_64.h b/tools/arch/x86/include/uapi/asm/unistd_64.h index 4205ed4158bf..cb52a3a8b8fc 100644 --- a/tools/arch/x86/include

Re: [PATCH 1/5] KVM: rseq: Update rseq when processing NOTIFY_RESUME on xfer to KVM guest

2021-08-20 Thread Sean Christopherson
On Fri, Aug 20, 2021, Mathieu Desnoyers wrote: > Without the lazy clear scheme, a rseq c.s. would look like: > > * init(rseq_cs) > * cpu = TLS->rseq::cpu_id_start > * [1] TLS->rseq::rseq_cs = rseq_cs > * [start_ip]

Re: [PATCH 4/5] KVM: selftests: Add a test for KVM_RUN+rseq to detect task migration bugs

2021-08-20 Thread Sean Christopherson
On Fri, Aug 20, 2021, Mathieu Desnoyers wrote: > I still really hate flakiness in tests, because then people stop caring when > they > fail once in a while. And with the nature of rseq, a once-in-a-while failure > is a > big deal. Let's see if we can use other tricks to ensure stability of the

[PATCH v3 5/5] KVM: selftests: Remove __NR_userfaultfd syscall fallback

2021-09-01 Thread Sean Christopherson
Gardon Signed-off-by: Sean Christopherson --- tools/arch/x86/include/uapi/asm/unistd_64.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/arch/x86/include/uapi/asm/unistd_64.h b/tools/arch/x86/include/uapi/asm/unistd_64.h index 4205ed4158bf..cb52a3a8b8fc 100644 --- a/tools/arch/x86

[PATCH v3 4/5] KVM: selftests: Add a test for KVM_RUN+rseq to detect task migration bugs

2021-09-01 Thread Sean Christopherson
red by KVM without updating rseq, leading to a stale CPU ID and other badness. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile| 3 + tools/testing/selftests/kvm/rseq_test.c | 236 3 files ch

[PATCH v3 2/5] entry: rseq: Call rseq_handle_notify_resume() in tracehook_notify_resume()

2021-09-01 Thread Sean Christopherson
ume() back in 2012. Punt cleaning that mess up to future patches. No functional change intended. Acked-by: Mathieu Desnoyers Signed-off-by: Sean Christopherson --- arch/arm/kernel/signal.c | 1 - arch/arm64/kernel/signal.c | 1 - arch/csky/kernel/signal.c| 4 +--- arch/mips/kernel/signa

[PATCH v3 3/5] tools: Move x86 syscall number fallbacks to .../uapi/

2021-09-01 Thread Sean Christopherson
/kvm's control. Prior to commit cec07f53c398 ("perf tools: Move syscall number fallbacks from perf-sys.h to tools/arch/x86/include/asm/"), the handcoded numbers were actual fallbacks, i.e. overriding unistd_{32,64}.h from the kernel headers was unintentional. Signed-off-by: Sean Chri

[PATCH v3 1/5] KVM: rseq: Update rseq when processing NOTIFY_RESUME on xfer to KVM guest

2021-09-01 Thread Sean Christopherson
Signed-off-by: Sean Christopherson --- kernel/entry/kvm.c | 4 +++- kernel/rseq.c | 14 +++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/kernel/entry/kvm.c b/kernel/entry/kvm.c index 49972ee99aff..049fd06b4c3d 100644 --- a/kernel/entry/kvm.c +++ b/kernel/entry/kvm.

[PATCH v3 0/5] KVM: rseq: Fix and a test for a KVM+rseq bug

2021-09-01 Thread Sean Christopherson
. [Mathieu] - Add Mathieu's ack for patch 2. - Add more comments in the test. v1: https://lkml.kernel.org/r/20210818001210.4073390-1-sea...@google.com Sean Christopherson (5): KVM: rseq: Update rseq when processing NOTIFY_RESUME on xfer to KVM guest entry: rseq: Call rseq_handle_not

Re: [PATCH 1/5] KVM: rseq: Update rseq when processing NOTIFY_RESUME on xfer to KVM guest

2021-09-07 Thread Sean Christopherson
On Mon, Sep 06, 2021, Paolo Bonzini wrote: > On 20/08/21 20:51, Mathieu Desnoyers wrote: > > > Ah, or is it the case that rseq_cs is non-NULL if and only if userspace > > > is in an > > > rseq critical section, and because syscalls in critical sections are > > > illegal, by > > > definition

Re: [PATCH 2/2] kvm: rename KVM_MAX_VCPU_ID to KVM_MAX_VCPU_IDS

2021-09-13 Thread Sean Christopherson
On Mon, Sep 13, 2021, Juergen Gross wrote: > KVM_MAX_VCPU_ID is not specifying the highest allowed vcpu-id, but the > number of allowed vcpu-ids. This has already led to confusion, so > rename KVM_MAX_VCPU_ID to KVM_MAX_VCPU_IDS to make its semantics more > clear My hesitation with this rename is

Re: [PATCH 2/2] kvm: rename KVM_MAX_VCPU_ID to KVM_MAX_VCPU_IDS

2021-09-13 Thread Sean Christopherson
On Mon, Sep 13, 2021, Eduardo Habkost wrote: > On Mon, Sep 13, 2021 at 12:24 PM Sean Christopherson > wrote: > > > > On Mon, Sep 13, 2021, Juergen Gross wrote: > > > KVM_MAX_VCPU_ID is not specifying the highest allowed vcpu-id, but the > > > number of al

Re: [PATCH 07/11] treewide: Replace the use of mem_encrypt_active() with prot_guest_has()

2021-07-30 Thread Sean Christopherson
On Tue, Jul 27, 2021, Tom Lendacky wrote: > @@ -451,7 +450,7 @@ void __init mem_encrypt_free_decrypted_mem(void) >* The unused memory range was mapped decrypted, change the encryption >* attribute from decrypted to encrypted before freeing it. >*/ > - if

Re: [PATCH v2 4/5] KVM: selftests: Add a test for KVM_RUN+rseq to detect task migration bugs

2021-08-27 Thread Sean Christopherson
On Fri, Aug 27, 2021, Mathieu Desnoyers wrote: > > So there are effectively three reasons we want a delay: > > > > 1. To allow sched_setaffinity() to coincide with ioctl(KVM_RUN) before KVM > > can > > enter the guest so that the guest doesn't need an arch-specific VM-Exit > > source. > >

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

2023-09-05 Thread Sean Christopherson
On Fri, Sep 01, 2023, 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 for

Re: [PATCH v7 3/8] KVM: Make __kvm_follow_pfn not imply FOLL_GET

2023-09-05 Thread Sean Christopherson
On Tue, Sep 05, 2023, David Stevens wrote: > On Wed, Jul 12, 2023 at 7:00 AM Sean Christopherson wrote: > > > > On Tue, Jul 11, 2023, Zhi Wang wrote: > > > On Thu, 6 Jul 2023 15:49:39 +0900 > > > David Stevens wrote: > > > > > > > On W

Re: [PATCH v7 3/8] KVM: Make __kvm_follow_pfn not imply FOLL_GET

2023-09-06 Thread Sean Christopherson
On Wed, Sep 06, 2023, David Stevens wrote: > On Wed, Sep 6, 2023 at 9:45 AM Sean Christopherson wrote: > > > > On Tue, Sep 05, 2023, David Stevens wrote: > > > For property 2, FOLL_GET is also important. If guarded_by_mmu_notifier > > > is set, then we're all good

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

2023-09-13 Thread Sean Christopherson
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 Cc: Anish Moorthy Suggested-by: S

[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 18/33] KVM: x86/mmu: Handle page fault for private memory

2023-09-13 Thread Sean Christopherson
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 insertions(+), 5 deletions(-) diff

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

2023-09-13 Thread Sean Christopherson
serspace 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 helper KVM: selftests: Expand set_memory_region_test to validate

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

2023-09-13 Thread Sean Christopherson
e 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 01/33] KVM: Tweak kvm_hva_range and hva_handler_t to allow reusing for gfn ranges

2023-09-13 Thread Sean Christopherson
ly 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/virt/

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

2023-09-13 Thread Sean Christopherson
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/powerpc.c @@ -635,11

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

2023-09-13 Thread Sean Christopherson
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 --git a/arch/pow

[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 14/33] KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory

2023-09-13 Thread Sean Christopherson
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 Signed-off-by: Sean Christopherson --- include/linux

[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

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

2023-09-13 Thread Sean Christopherson
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/private_mem_conversi

[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 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 17/33] KVM: x86: Disallow hugepages when memory attributes are mixed

2023-09-13 Thread Sean Christopherson
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 Christopherson Signed-off

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

2023-09-13 Thread Sean Christopherson
diate_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 b/arch/x86/kvm/x86.c inde

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

2023-09-13 Thread Sean Christopherson
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/powerpc/kvm/Kconfig

[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 06/33] KVM: Introduce KVM_SET_USER_MEMORY_REGION2

2023-09-13 Thread Sean Christopherson
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 Signed-off-by: Sean Christopherson ---

[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 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 33/33] KVM: selftests: Test KVM exit behavior for private memory/access

2023-09-13 Thread Sean Christopherson
ly 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 insertions(+) create m

[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 11/33] KVM: Introduce per-page memory attributes

2023-09-13 Thread Sean Christopherson
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 | 60

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

2023-09-13 Thread Sean Christopherson
o 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_main.

[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-off-by: Sean

[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 index

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

2023-09-13 Thread Sean Christopherson
estroy 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 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/selftests

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

2023-09-13 Thread Sean Christopherson
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 Christopherson

[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

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 > >

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 i

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

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

2023-09-15 Thread Sean Christopherson
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 changed, 45

[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 05/26] vfio: KVM: Pass get/put helpers from KVM to VFIO, don't do circular lookup

2023-09-15 Thread Sean Christopherson
-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/vfio.h b

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

2023-09-15 Thread Sean Christopherson
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-off-by: Sean

[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 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 13/26] KVM: arm64: Include KVM headers to get forward declarations

2023-09-15 Thread Sean Christopherson
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 bb3cb005873e.

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

2023-09-15 Thread Sean Christopherson
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_emulate.h | 3 +++ arch/arm64/include/

[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] Signed-of

[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 25/26] KVM: PPC: Rearrange code in kvm_ppc.h to isolate "public" information

2023-09-15 Thread Sean Christopherson
tails 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 72fee202d3ec..ea

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

2023-09-15 Thread Sean Christopherson
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 either). Signed-of

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

2023-09-15 Thread Sean Christopherson
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..89b40c34f0af 100

[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 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/events/in

[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

  1   2   3   4   5   >