Re: mm/debug_vm_pgtable.c:860 warning triggered

2023-11-05 Thread Michael Ellerman
Anshuman Khandual writes: > Hello Daniel, > > This test just ensures that PFN is preserved during pte <--> swap pte > transformations > , and the warning here seems to have been caused by powerpc platform specific > helpers > and/or its pte_t representation. Adding powerpc folks and platform mai

Re: mm/debug_vm_pgtable.c:860 warning triggered

2023-11-05 Thread Daniel Walker (danielwa)
On Mon, Nov 06, 2023 at 08:39:26AM +0530, Anshuman Khandual wrote: > Hello Daniel, > > This test just ensures that PFN is preserved during pte <--> swap pte > transformations > , and the warning here seems to have been caused by powerpc platform specific > helpers > and/or its pte_t representati

Re: mm/debug_vm_pgtable.c:860 warning triggered

2023-11-05 Thread Anshuman Khandual
Hello Daniel, This test just ensures that PFN is preserved during pte <--> swap pte transformations , and the warning here seems to have been caused by powerpc platform specific helpers and/or its pte_t representation. Adding powerpc folks and platform mailing list here. - Anshuman On 11/4/23

[PATCH 1/2] tty: hvc: Make hvc_remove() return no value

2023-11-05 Thread Uwe Kleine-König
The function hvc_remove() returns zero unconditionally. Make it return void instead to make it obvious that the caller doesn't need to do any error handling. Accordingly drop the error handling from hvc_opal_remove(). Signed-off-by: Uwe Kleine-König --- drivers/tty/hvc/hvc_console.c | 3 +-- dr

[PATCH 2/2] tty: hvc: hvc_opal: Convert to platform remove callback returning void

2023-11-05 Thread Uwe Kleine-König
The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is ignored (apart from emitting a warning) and this typically results in resource leaks. To improve h

[PATCH 0/2] tty: hvc: Convert to platform remove callback returning void

2023-11-05 Thread Uwe Kleine-König
Hello, The hvc_opal driver had an error path in its remove function resulting in returning a non-zero value. This is a bad thing because the core doesn't do error handling and effectively ignores the return value. In this case it's not as bad as it sounds though, as this error path is never taken

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

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson Extended guest_memfd to allow backing guest memory with transparent hugepages. Require userspace to opt-in via a flag even though there's no known/anticipated use case for forcing small pages as THP is optional, i.e. to avoid ending up in a situation where userspace is

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

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson 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 reached via mmu_no

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

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson Add a subtest to set_memory_region_test to verify that KVM rejects invalid flags and combinations with -EINVAL. KVM might or might not fail with EINVAL anyways, but we can at least try. Signed-off-by: Sean Christopherson Message-Id: <20231031002049.3915752-1-sea...@go

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

2023-11-05 Thread Paolo Bonzini
From: Ackerley Tng "Testing private access when memslot gets deleted" tests the behavior of KVM when a private memslot gets deleted while the VM is using the private memslot. When KVM looks up the deleted (slot = NULL) memslot, KVM should exit to userspace with KVM_EXIT_MEMORY_FAULT. In the seco

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

2023-11-05 Thread Paolo Bonzini
From: Chao Peng Add a selftest to verify the basic functionality of guest_memfd(): + file descriptor created with the guest_memfd() ioctl does not allow read/write/mmap operations + file size and block size as returned from fstat are as expected + fallocate on the fd checks that offset/length

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

2023-11-05 Thread Paolo Bonzini
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 bindings Signed-off-by: Chao Peng Co-developed-b

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

2023-11-05 Thread Paolo Bonzini
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

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

2023-11-05 Thread Paolo Bonzini
From: Vishal Annapurve Add a selftest to exercise implicit/explicit conversion functionality within KVM and verify: - Shared memory is visible to host userspace - Private memory is not visible to host userspace - Host userspace and guest can communicate over shared memory - Data in shared ba

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

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

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson Add a "vm_shape" structure to encapsulate the selftests-defined "mode", along with the KVM-defined "type" for use when creating a new VM. "mode" tracks physical and virtual address properties, as well as the preferred backing memory type, while "type" corresponds to the

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

2023-11-05 Thread Paolo Bonzini
From: Vishal Annapurve Add helpers for x86 guests to invoke the KVM_HC_MAP_GPA_RANGE hypercall, which KVM will forward to userspace and thus can be used by tests to coordinate private<=>shared conversions between host userspace code and guest code. Signed-off-by: Vishal Annapurve [sean: drop sh

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

2023-11-05 Thread Paolo Bonzini
From: Vishal Annapurve Add helpers to convert memory between private and shared via KVM's memory attributes, as well as helpers to free/allocate guest_memfd memory via fallocate(). Userspace, i.e. tests, is NOT required to do fallocate() when converting memory, as the attributes are the single s

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

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson Add support for creating "private" memslots via KVM_CREATE_GUEST_MEMFD and KVM_SET_USER_MEMORY_REGION2. Make vm_userspace_mem_region_add() a wrapper to its effective replacement, vm_mem_add(), so that private memslots are fully opt-in, i.e. don't require update all test

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

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson Use KVM_SET_USER_MEMORY_REGION2 throughout KVM's selftests library so that support for guest private memory can be added without needing an entirely separate set of helpers. Note, this obviously makes selftests backwards-incompatible with older KVM versions from this po

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

2023-11-05 Thread Paolo Bonzini
From: 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

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

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson 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 future, e.g. a la pKVM. The private memory support in KVM x86 is aimed at AMD's SEV-

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

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson Let x86 track the number of address spaces on a per-VM basis so that KVM can disallow SMM memslots for confidential VMs. Confidentials VMs are fundamentally incompatible with emulating SMM, which as the name suggests requires being able to read and write guest memory an

[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: <20231027182217.36152

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

2023-11-05 Thread Paolo Bonzini
From: Chao Peng Add support for resolving page faults on guest private memory for VMs that differentiate between "shared" and "private" memory. For such VMs, KVM_MEM_PRIVATE memslots can include both fd-based private memory and hva-based shared memory, and KVM needs to map in the "correct" varia

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

2023-11-05 Thread Paolo Bonzini
From: Chao Peng Disallow creating hugepages with mixed memory attributes, e.g. shared versus private, as mapping a hugepage in this case would allow the guest to access memory with the wrong attributes, e.g. overlaying private memory with a shared hugepage. Tracking whether or not attributes are

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

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson Initialize run->exit_reason to KVM_EXIT_UNKNOWN early in KVM_RUN to reduce the probability of exiting to userspace with a stale run->exit_reason that *appears* to be valid. To support fd-based guest memory (guest memory without a corresponding userspace virtual address)

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

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson Introduce an ioctl(), KVM_CREATE_GUEST_MEMFD, to allow creating file-based memory that is tied to a specific KVM virtual machine and whose primary purpose is to serve guest memory. A guest-first memory subsystem allows for optimizations and enhancements that are kludgy

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

2023-11-05 Thread Paolo Bonzini
The call to the inode_init_security_anon() LSM hook is not the sole reason to use anon_inode_getfile_secure() or anon_inode_getfd_secure(). For example, the functions also allow one to create a file with non-zero size, without needing a full-blown filesystem. In this case, you don't need a "secure

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

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson 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 under folio lock as a

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

2023-11-05 Thread Paolo Bonzini
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 other potential use cases for per-page memory attributes, e.g. to make memory read-only (or no-exec, o

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

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson Drop the .on_unlock() mmu_notifer hook now that it's no longer used for notifying arch code that memory has been reclaimed. Adding .on_unlock() and invoking it *after* dropping mmu_lock was a terrible idea, as doing so resulted in .on_lock() and .on_unlock() having dive

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

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson Handle AMD SEV's kvm_arch_guest_memory_reclaimed() hook by having __kvm_handle_hva_range() return whether or not an overlapping memslot was found, i.e. mmu_lock was acquired. Using the .on_unlock() hook works, but kvm_arch_guest_memory_reclaimed() needs to run after dro

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

2023-11-05 Thread Paolo Bonzini
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 (without terminating the guest). KVM will initially use KVM_EXIT_MEMORY_FAULT to report implicit conversions between private and shared memory.

[PATCH 08/34] KVM: Introduce KVM_SET_USER_MEMORY_REGION2

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson Introduce a "version 2" of KVM_SET_USER_MEMORY_REGION so that additional information can be supplied without setting userspace up to fail. The padding in the new kvm_userspace_memory_region2 structure will be used to pass a file descriptor in addition to the userspace_a

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

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson Convert KVM_ARCH_WANT_MMU_NOTIFIER into a Kconfig and select it where appropriate to effectively maintain existing behavior. Using a proper Kconfig will simplify building more functionality on top of KVM's mmu_notifier infrastructure. Add a forward declaration of kvm_g

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

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson Advertise that KVM's MMU is synchronized with the primary MMU for all flavors of PPC KVM support, i.e. advertise that the MMU is synchronized when CONFIG_KVM_BOOK3S_HV_POSSIBLE=y but the VM is not using hypervisor mode (a.k.a. PR VMs). PR VMs, via kvm_unmap_gfn_range_pr

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

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson Assert that both KVM_ARCH_WANT_MMU_NOTIFIER and CONFIG_MMU_NOTIFIER are defined when KVM is enabled, and return '1' unconditionally for the CONFIG_KVM_BOOK3S_HV_POSSIBLE=n path. All flavors of PPC support for KVM select MMU_NOTIFIER, and KVM_ARCH_WANT_MMU_NOTIFIER is un

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

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson Add an assertion that there are no in-progress MMU invalidations when a VM is being destroyed, with the exception of the scenario where KVM unregisters its MMU notifier between an .invalidate_range_start() call and the corresponding .invalidate_range_end(). KVM can't de

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

2023-11-05 Thread Paolo Bonzini
From: Chao Peng Currently in mmu_notifier invalidate path, hva range is recorded and then checked against by mmu_invalidate_retry_hva() in the page fault handling path. However, for the soon-to-be-introduced private memory, a page fault may not have a hva associated, checking gfn(gpa) makes more

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

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson Move the assertion on the in-progress invalidation count from the primary MMU's notifier path to KVM's common notification path, i.e. assert that the count doesn't go negative even when the invalidation is coming from KVM itself. Opportunistically convert the assertion

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

2023-11-05 Thread Paolo Bonzini
From: Sean Christopherson 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 context, i.e. that aren't tied to a host virtual address. Rename the handler typedef too (arguably it should always have

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

2023-11-05 Thread Paolo Bonzini
[If the introduction below is not enough, go read https://lwn.net/SubscriberLink/949277/118520c1248ace63/ and subscribe to LWN] Introduce several new KVM uAPIs to ultimately create a guest-first memory subsystem within KVM, a.k.a. guest_memfd. Guest-first memory allows KVM to provide features, e

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

2023-11-05 Thread Xu Yilun
> +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, > + PAGE_SIZE, fault->write, fault->exec,