Re: [PATCH 11/14] KVM: selftests: Disable "gnu-variable-sized-type-not-at-end" warning

2022-12-12 Thread Sean Christopherson
On Mon, Dec 12, 2022, Nick Desaulniers wrote: > > diff --git a/tools/testing/selftests/kvm/Makefile > > b/tools/testing/selftests/kvm/Makefile > > index 2487db21b177..9cff99a1cb2e 100644 > > --- a/tools/testing/selftests/kvm/Makefile > > +++ b/tools/testing/selftests/kvm/Makefile > > @@ -196,6 +19

Re: [RFC PATCH 01/37] KVM: x86/mmu: Store the address space ID directly in kvm_mmu_page_role

2022-12-12 Thread Sean Christopherson
On Mon, Dec 12, 2022, Paolo Bonzini wrote: > On 12/12/22 18:39, Sean Christopherson wrote: > > My preference would be to leave .smm in x86's page role > > What about defining a byte of arch_role and a macro to build it? I think David already carved out a big chunk for arch role bits, my objection

Re: [PATCH 11/14] KVM: selftests: Disable "gnu-variable-sized-type-not-at-end" warning

2022-12-12 Thread Nick Desaulniers
On Mon, Dec 12, 2022 at 4:17 PM Sean Christopherson wrote: > > Disable gnu-variable-sized-type-not-at-end so that tests and libraries > can create overlays of variable sized arrays at the end of structs when > using a fixed number of entries, e.g. to get/set a single MSR. > > It's possible to fudg

Re: [RFC PATCH 01/37] KVM: x86/mmu: Store the address space ID directly in kvm_mmu_page_role

2022-12-12 Thread David Matlack
On Mon, Dec 12, 2022 at 11:50:29PM +0100, Paolo Bonzini wrote: > On 12/12/22 18:39, Sean Christopherson wrote: > > > The notion of address spaces is already existing architecture-neutral > > > concept in KVM (e.g. see uses of KVM_ADDRESS_SPACE_NUM in > > > virt/kvm/kvm_main.c), although SMM is the

Re: [RFC PATCH 01/37] KVM: x86/mmu: Store the address space ID directly in kvm_mmu_page_role

2022-12-12 Thread David Matlack
On Mon, Dec 12, 2022 at 06:17:36PM +, Oliver Upton wrote: > On Mon, Dec 12, 2022 at 05:39:38PM +, Sean Christopherson wrote: > > On Fri, Dec 09, 2022, David Matlack wrote: > > > On Fri, Dec 9, 2022 at 9:25 AM Oliver Upton > > > wrote: > > My preference would be to leave .smm in x86's page

Re: [RFC PATCH 02/37] KVM: MMU: Move struct kvm_mmu_page_role into common code

2022-12-12 Thread David Matlack
On Mon, Dec 12, 2022 at 3:11 PM Paolo Bonzini wrote: > > On 12/8/22 20:38, David Matlack wrote: > > +/* > > + * kvm_mmu_page_role tracks the properties of a shadow page (where shadow > > page > > + * also includes TDP pages) to determine whether or not a page can be used > > in > > + * the given

Re: [RFC PATCH 20/37] KVM: x86/mmu: Abstract away computing the max mapping level

2022-12-12 Thread Sean Christopherson
On Mon, Dec 12, 2022, David Matlack wrote: > On Mon, Dec 12, 2022 at 11:32 AM Ben Gardon wrote: > > > > On Thu, Dec 8, 2022 at 11:39 AM David Matlack wrote: > > > > > > Abstract away kvm_mmu_max_mapping_level(), which is an x86-specific > > > function for computing the max level that a given GFN

[PATCH 13/14] KVM: selftests: Use wildcards to find targets and test source files

2022-12-12 Thread Sean Christopherson
Use $(wildcard ...) to find the test targets (.sh files) and test source files (.c and .S) instead of manually adding files/targets for every architecture, which is a maintenance burden and error prone, e.g. RISC-V supports RSEQ but doesn't build the test for reasons unknown. To deal with common t

[PATCH 14/14] KVM: selftests: Enable RSEQ test for RISC-V

2022-12-12 Thread Sean Christopherson
Enable the RSEQ test for RISC-V, which according to HAVE_RSEQ is supported by the kernel and thus should be tested. The RSEQ test was added shortly before RISC-V selftests support landed, i.e. was likely overlooked during merging. Note, the RSEQ test currently doesn't compile with clang due to an

[PATCH 12/14] KVM: selftests: Use wildcards to find library source files

2022-12-12 Thread Sean Christopherson
Use $(wildcard ...) to find the library source files instead of manually defining the inputs, which is a maintenance burden and error prone. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/Makefile | 45 1 file changed, 5 insertions(+), 40 deletion

[PATCH 11/14] KVM: selftests: Disable "gnu-variable-sized-type-not-at-end" warning

2022-12-12 Thread Sean Christopherson
Disable gnu-variable-sized-type-not-at-end so that tests and libraries can create overlays of variable sized arrays at the end of structs when using a fixed number of entries, e.g. to get/set a single MSR. It's possible to fudge around the warning, e.g. by defining a custom struct that hardcodes t

[PATCH 10/14] KVM: selftests: Include lib.mk before consuming $(CC)

2022-12-12 Thread Sean Christopherson
Include lib.mk before consuming $(CC) and document that lib.mk overwrites $(CC) unless make was invoked with -e or $(CC) was specified after make (which apparently makes the environment override the Makefile?!?!). Including lib.mk after using it for probing, e.g. for -no-pie, can lead to weirdness.

[PATCH 06/14] KVM: selftests: Rename UNAME_M to ARCH_DIR, fill explicitly for x86

2022-12-12 Thread Sean Christopherson
Rename UNAME_M to ARCH_DIR and explicitly set it directly for x86. At this point, the name of the arch directory really doesn't have anything to do with `uname -m`, and UNAME_M is unnecessarily confusing given that its purpose is purely to identify the arch specific directory. Signed-off-by: Sean

[PATCH 09/14] KVM: selftests: Explicitly disable builtins for mem*() overrides

2022-12-12 Thread Sean Christopherson
Explicitly disable the compiler's builtin memcmp(), memcpy(), and memset(). Because only lib/string_override.c is built with -ffreestanding, the compiler reserves the right to do what it wants and can try to link the non-freestanding code to its own crud. /usr/bin/x86_64-linux-gnu-ld: /lib/x86_

[PATCH 05/14] KVM: selftests: Fix a typo in x86-64's kvm_get_cpu_address_width()

2022-12-12 Thread Sean Christopherson
Fix a == vs. = typo in kvm_get_cpu_address_width() that results in @pa_bits being left unset if the CPU doesn't support enumerating its MAX_PHY_ADDR. Flagged by clang's unusued-value warning. lib/x86_64/processor.c:1034:51: warning: expression result unused [-Wunused-value] *pa_b

[PATCH 04/14] KVM: selftests: Use pattern matching in .gitignore

2022-12-12 Thread Sean Christopherson
Use pattern matching to exclude everything except .c, .h, .S, and .sh files from Git. Manually adding every test target has an absurd maintenance cost, is comically error prone, and leads to bikeshedding over whether or not the targets should be listed in alphabetical order. Deliberately do not i

[PATCH 08/14] KVM: selftests: Probe -no-pie with actual CFLAGS used to compile

2022-12-12 Thread Sean Christopherson
Probe -no-pie with the actual set of CFLAGS used to compile the tests, clang whines about -no-pie being unused if the tests are compiled with -static. clang: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument] Signed-off-by: Sean Christopherson --- tools/

[PATCH 07/14] KVM: selftests: Use proper function prototypes in probing code

2022-12-12 Thread Sean Christopherson
Make the main() functions in the probing code proper prototypes so that compiling the probing code with more strict flags won't generate false negatives. :1:5: error: function declaration isn’t a prototype [-Werror=strict-prototypes] Signed-off-by: Sean Christopherson --- tools/testing/selft

[PATCH 03/14] KVM: selftests: Fix divide-by-zero bug in memslot_perf_test

2022-12-12 Thread Sean Christopherson
Check that the number of pages per slot is non-zero in get_max_slots() prior to computing the remaining number of pages. clang generates code that uses an actual DIV for calculating the remaining, which causes a #DE if the total number of pages is less than the number of slots. traps: memslot_p

[PATCH 02/14] KVM: selftests: Delete dead code in x86_64/vmx_tsc_adjust_test.c

2022-12-12 Thread Sean Christopherson
Delete an unused struct definition in x86_64/vmx_tsc_adjust_test.c. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c | 5 - 1 file changed, 5 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c b/tools/testing/se

[PATCH 00/14] KVM: selftests: Clang fixes, Makefile cleanup

2022-12-12 Thread Sean Christopherson
Fix a variety of KVM selftests issues exposed by clang, and rework the Makefile and .gitignore to reduce the maintenance burden of selftests. For the Makefile, programmatically generate the list of targets by looking for .c files, and opt-out via a dummy macro in the source instead of forcing arch

[PATCH 01/14] KVM: selftests: Define literal to asm constraint in aarch64 as unsigned long

2022-12-12 Thread Sean Christopherson
Define a literal '0' asm input constraint to aarch64/page_fault_test's guest_cas() as an unsigned long to make clang happy. tools/testing/selftests/kvm/aarch64/page_fault_test.c:120:16: error: value size does not match register size specified by the constraint and modifier [-Werror,-Wasm

Re: [RFC PATCH 00/37] KVM: Refactor the KVM/x86 TDP MMU into common code

2022-12-12 Thread Paolo Bonzini
On 12/13/22 00:26, Sean Christopherson wrote: I would strongly be in favor of discarding the shadow paging residue if x86 folks are willing to part ways with it 😄 Yes, absolutely. Something like to_shadow_page->to_mmu_data, sp->md, spt->hpt, spte->spte, sptep->hptep. "host" will be confusing i

Re: [RFC PATCH 00/37] KVM: Refactor the KVM/x86 TDP MMU into common code

2022-12-12 Thread Sean Christopherson
On Mon, Dec 12, 2022, Paolo Bonzini wrote: > On 12/9/22 20:07, Oliver Upton wrote: > > > - Naming. This series does not change the names of any existing code. > > > So all the KVM/x86 Shadow MMU-style terminology like > > > "shadow_page"/"sp"/"spte" persists. Should we keep that style in

Re: [RFC PATCH 04/37] KVM: x86/mmu: Invert sp->tdp_mmu_page to sp->shadow_mmu_page

2022-12-12 Thread Paolo Bonzini
On 12/8/22 20:38, David Matlack wrote: Invert the meaning of sp->tdp_mmu_page and rename it accordingly. This allows the TDP MMU code to not care about this field, which will be used in a subsequent commit to move the TDP MMU to common code. No functional change intended. Let's use a bit of th

Re: [RFC PATCH 02/37] KVM: MMU: Move struct kvm_mmu_page_role into common code

2022-12-12 Thread Paolo Bonzini
On 12/8/22 20:38, David Matlack wrote: +/* + * kvm_mmu_page_role tracks the properties of a shadow page (where shadow page + * also includes TDP pages) to determine whether or not a page can be used in + * the given MMU context. + */ +union kvm_mmu_page_role { + u32 word; + struct { +

Re: [RFC PATCH 00/37] KVM: Refactor the KVM/x86 TDP MMU into common code

2022-12-12 Thread Paolo Bonzini
On 12/9/22 20:07, Oliver Upton wrote: - Naming. This series does not change the names of any existing code. So all the KVM/x86 Shadow MMU-style terminology like "shadow_page"/"sp"/"spte" persists. Should we keep that style in common code or move toward something less shadow-paging-s

Re: [RFC PATCH 01/37] KVM: x86/mmu: Store the address space ID directly in kvm_mmu_page_role

2022-12-12 Thread Paolo Bonzini
On 12/12/22 18:39, Sean Christopherson wrote: The notion of address spaces is already existing architecture-neutral concept in KVM (e.g. see uses of KVM_ADDRESS_SPACE_NUM in virt/kvm/kvm_main.c), although SMM is the only use-case I'm aware of. Yes, SMM is currently the only use-case. It's pos

Re: [RFC PATCH 06/37] KVM: MMU: Move struct kvm_mmu_page to common code

2022-12-12 Thread David Matlack
On Mon, Dec 12, 2022 at 2:32 PM Paolo Bonzini wrote: > > On 12/8/22 20:38, David Matlack wrote: > > This commit increases the size of struct kvm_mmu_page by 64 bytes on > > x86_64 (184 bytes -> 248 bytes). The size of this struct can be reduced > > in future commits by moving TDP MMU root fields i

Re: [RFC PATCH 33/37] KVM: Move kvm_arch_flush_remote_tlbs_memslot() to common code

2022-12-12 Thread David Matlack
On Mon, Dec 12, 2022 at 2:03 PM Ben Gardon wrote: > > On Thu, Dec 8, 2022 at 11:40 AM David Matlack wrote: > > > > Move kvm_arch_flush_remote_tlbs_memslot() to common code and drop > > "arch_" from the name. kvm_arch_flush_remote_tlbs_memslot() is just a > > range-based TLB invalidation where the

Re: [RFC PATCH 06/37] KVM: MMU: Move struct kvm_mmu_page to common code

2022-12-12 Thread Paolo Bonzini
On 12/8/22 20:38, David Matlack wrote: This commit increases the size of struct kvm_mmu_page by 64 bytes on x86_64 (184 bytes -> 248 bytes). The size of this struct can be reduced in future commits by moving TDP MMU root fields into a separate struct and by dynamically allocating fields only used

Re: [RFC PATCH 10/37] KVM: MMU: Move struct kvm_page_fault to common code

2022-12-12 Thread David Matlack
On Mon, Dec 12, 2022 at 10:24:31AM -0800, Ben Gardon wrote: > On Thu, Dec 8, 2022 at 11:39 AM David Matlack wrote: > > > > Move struct kvm_page_fault to common code. This will be used in a future > > commit to move the TDP MMU to common code. > > > > No functional change intended. > > > > Signed-o

Re: [RFC PATCH 10/37] KVM: MMU: Move struct kvm_page_fault to common code

2022-12-12 Thread Paolo Bonzini
On 12/8/22 20:38, David Matlack wrote: + + /* Derived from mmu and global state. */ + const bool is_tdp; I think this could stay in the architecture-independent part. Paolo ___ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://li

Re: [RFC PATCH 33/37] KVM: Move kvm_arch_flush_remote_tlbs_memslot() to common code

2022-12-12 Thread Ben Gardon
On Thu, Dec 8, 2022 at 11:40 AM David Matlack wrote: > > Move kvm_arch_flush_remote_tlbs_memslot() to common code and drop > "arch_" from the name. kvm_arch_flush_remote_tlbs_memslot() is just a > range-based TLB invalidation where the range is defined by the memslot. > Now that kvm_flush_remote_t

Re: [RFC PATCH 20/37] KVM: x86/mmu: Abstract away computing the max mapping level

2022-12-12 Thread David Matlack
On Mon, Dec 12, 2022 at 11:32 AM Ben Gardon wrote: > > On Thu, Dec 8, 2022 at 11:39 AM David Matlack wrote: > > > > Abstract away kvm_mmu_max_mapping_level(), which is an x86-specific > > function for computing the max level that a given GFN can be mapped in > > KVM's page tables. This will be us

Re: [kvm-unit-tests PATCH 1/3] arm: pmu: Fix overflow checks for PMUv3p5 long counters

2022-12-12 Thread Ricardo Koller
On Fri, Dec 09, 2022 at 05:47:14PM +, Alexandru Elisei wrote: > Hi, > > On Fri, Dec 02, 2022 at 04:55:25AM +, Ricardo Koller wrote: > > PMUv3p5 uses 64-bit counters irrespective of whether the PMU is configured > > for overflowing at 32 or 64-bits. The consequence is that tests that check

Re: [RFC PATCH 20/37] KVM: x86/mmu: Abstract away computing the max mapping level

2022-12-12 Thread Ben Gardon
On Thu, Dec 8, 2022 at 11:39 AM David Matlack wrote: > > Abstract away kvm_mmu_max_mapping_level(), which is an x86-specific > function for computing the max level that a given GFN can be mapped in > KVM's page tables. This will be used in a future commit to enable moving > the TDP MMU to common c

Re: [RFC PATCH 17/37] KVM: Move struct kvm_gfn_range to kvm_types.h

2022-12-12 Thread Ben Gardon
On Thu, Dec 8, 2022 at 11:39 AM David Matlack wrote: > > Move struct kvm_gfn_range to kvm_types.h so that it's definition can be > accessed in a future commit by arch/x86/include/asm/kvm/tdp_pgtable.h > without needing to include the mega-header kvm_host.h. > > No functional change intended. > > S

Re: [RFC PATCH 10/37] KVM: MMU: Move struct kvm_page_fault to common code

2022-12-12 Thread Ben Gardon
On Thu, Dec 8, 2022 at 11:39 AM David Matlack wrote: > > Move struct kvm_page_fault to common code. This will be used in a future > commit to move the TDP MMU to common code. > > No functional change intended. > > Signed-off-by: David Matlack > --- > arch/x86/include/asm/kvm/mmu_types.h | 20 +++

Re: [RFC PATCH 01/37] KVM: x86/mmu: Store the address space ID directly in kvm_mmu_page_role

2022-12-12 Thread Oliver Upton
On Mon, Dec 12, 2022 at 05:39:38PM +, Sean Christopherson wrote: > On Fri, Dec 09, 2022, David Matlack wrote: > > On Fri, Dec 9, 2022 at 9:25 AM Oliver Upton wrote: > > > > > > On Fri, Dec 09, 2022 at 10:37:47AM +0800, Yang, Weijiang wrote: > > > > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/

Re: [RFC PATCH 06/37] KVM: MMU: Move struct kvm_mmu_page to common code

2022-12-12 Thread Ben Gardon
On Thu, Dec 8, 2022 at 11:39 AM David Matlack wrote: > > Move struct kvm_mmu_page to common code and all x86-specific fields into > kvm_mmu_page_arch. > > This commit increases the size of struct kvm_mmu_page by 64 bytes on > x86_64 (184 bytes -> 248 bytes). The size of this struct can be reduced

Re: [RFC PATCH 02/37] KVM: MMU: Move struct kvm_mmu_page_role into common code

2022-12-12 Thread Ben Gardon
On Thu, Dec 8, 2022 at 11:39 AM David Matlack wrote: > > Move struct kvm_mmu_page_role into common code, and move all > x86-specific fields into a separate sub-struct within the role, > kvm_mmu_page_role_arch. > > Signed-off-by: David Matlack > --- > MAINTAINERS | 4 +-

Re: [RFC PATCH 01/37] KVM: x86/mmu: Store the address space ID directly in kvm_mmu_page_role

2022-12-12 Thread Sean Christopherson
On Fri, Dec 09, 2022, David Matlack wrote: > On Fri, Dec 9, 2022 at 9:25 AM Oliver Upton wrote: > > > > On Fri, Dec 09, 2022 at 10:37:47AM +0800, Yang, Weijiang wrote: > > > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > > > > index 4d188f056933..f375b719f565 100644 > > > > --- a

Re: [kvm-unit-tests PATCH 1/3] arm: pmu: Fix overflow checks for PMUv3p5 long counters

2022-12-12 Thread Alexandru Elisei
Hi, On Mon, Dec 12, 2022 at 09:05:02AM +, Marc Zyngier wrote: > Alex, > > On Sun, 11 Dec 2022 11:40:39 +, > Alexandru Elisei wrote: > > > > A simple "hey, you're wrong here, the PMU extensions do not follow the > > principles of the ID scheme for fields in ID registers" would have > > s

Re: [PATCH v2 7/7] KVM: selftests: Avoid infinite loop if ucall_alloc() fails

2022-12-12 Thread Paolo Bonzini
On 12/9/22 22:03, Sean Christopherson wrote: From: Sean Christopherson Date: Fri, 9 Dec 2022 12:55:44 -0800 Subject: [PATCH] KVM: selftests: Use magic value to signal ucall_alloc() failure Use a magic value to signal a ucall_alloc() failure instead of simply doing GUEST_ASSERT(). GUEST_ASSERT

Re: [PATCH v2 0/7] KVM: selftests: Fixes for ucall pool + page_fault_test

2022-12-12 Thread Paolo Bonzini
On 12/9/22 02:52, Oliver Upton wrote: The combination of the pool-based ucall implementation + page_fault_test resulted in some 'fun' bugs. As has always been the case, KVM selftests is a house of cards. Small series to fix up the issues on kvm/queue. Patches 1-2 can probably be squashed into Pa

Re: [PATCH v2 4/7] KVM: selftests: Correctly initialize the VA space for TTBR0_EL1

2022-12-12 Thread Paolo Bonzini
On 12/9/22 02:53, Oliver Upton wrote: @@ -268,17 +305,17 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode) #ifdef __aarch64__ if (vm->pa_bits != 40) vm->type = KVM_VM_TYPE_ARM_IPA_SIZE(vm->pa_bits); + + /* selftests use TTBR0 only, meaning there is a single

Re: [PATCH 0/1] KVM: arm64: PMU: Fix PMCR_EL0 reset value

2022-12-12 Thread Marc Zyngier
On Fri, 9 Dec 2022 16:44:45 +, James Clark wrote: > We noticed qemu failing to run because of an assert on our CI. I don't see > the issue anymore with > this fix. > > Applies to kvmarm/next (753d734f3f34) > > Thanks > > [...] Applied to fixes, thanks! [1/1] KVM: arm64: PMU: Fix PMCR_EL0

Re: [kvm-unit-tests PATCH 1/3] arm: pmu: Fix overflow checks for PMUv3p5 long counters

2022-12-12 Thread Marc Zyngier
Alex, On Sun, 11 Dec 2022 11:40:39 +, Alexandru Elisei wrote: > > A simple "hey, you're wrong here, the PMU extensions do not follow the > principles of the ID scheme for fields in ID registers" would have > sufficed. This is what I did, and saved you the hassle of looking it up. > Guess y