Re: [PATCH 2/2] KVM: arm64: selftests: Disable single-step without relying on ucall()

2022-11-16 Thread Reiji Watanabe
On Wed, Nov 16, 2022 at 4:24 PM Sean Christopherson wrote: > > Automatically disable single-step when the guest reaches the end of the > verified section instead of using an explicit ucall() to ask userspace to > disable single-step. An upcoming change to implement a pool-based scheme > for ucall

Re: [PATCH v4 06/16] KVM: arm64: PMU: Only narrow counters that are not 64bit wide

2022-11-16 Thread Reiji Watanabe
On Sun, Nov 13, 2022 at 8:38 AM Marc Zyngier wrote: > > The current PMU emulation sometimes narrows counters to 32bit > if the counter isn't the cycle counter. As this is going to > change with PMUv3p5 where the counters are all 64bit, fix > the couple of cases where this happens unconditionally.

Re: [PATCH v4 05/16] KVM: arm64: PMU: Narrow the overflow checking when required

2022-11-16 Thread Reiji Watanabe
On Sun, Nov 13, 2022 at 8:38 AM Marc Zyngier wrote: > > For 64bit counters that overflow on a 32bit boundary, make > sure we only check the bottom 32bit to generate a CHAIN event. > > Signed-off-by: Marc Zyngier > --- > arch/arm64/kvm/pmu-emul.c | 3 ++- > 1 file changed, 2 insertions(+), 1 dele

Re: [PATCH 1/2] KVM: arm64: selftests: Disable single-step with correct KVM define

2022-11-16 Thread Reiji Watanabe
On Wed, Nov 16, 2022 at 4:24 PM Sean Christopherson wrote: > > Disable single-step by setting debug.control to KVM_GUESTDBG_ENABLE, > not to SINGLE_STEP_DISABLE. The latter is an arbitrary test enum that > just happens to have the same value as KVM_GUESTDBG_ENABLE, and so > effectively disables s

Re: [PATCH 38/44] KVM: Disable CPU hotplug during hardware enabling

2022-11-16 Thread Huang, Kai
On Wed, 2022-11-16 at 17:11 +, Sean Christopherson wrote: > On Wed, Nov 16, 2022, Huang, Kai wrote: > > On Tue, 2022-11-15 at 20:16 +, Sean Christopherson wrote: > > > On Thu, Nov 10, 2022, Huang, Kai wrote: > > > > On Thu, 2022-11-10 at 01:33 +, Huang, Kai wrote: > > > > Hmm.. I wasn't

Re: [PATCH 2/2] KVM: arm64: selftests: Disable single-step without relying on ucall()

2022-11-16 Thread Sean Christopherson
On Thu, Nov 17, 2022, Oliver Upton wrote: > On Thu, Nov 17, 2022 at 12:23:50AM +, Sean Christopherson wrote: > > Automatically disable single-step when the guest reaches the end of the > > verified section instead of using an explicit ucall() to ask userspace to > > disable single-step. An upc

Re: [PATCH 2/2] KVM: arm64: selftests: Disable single-step without relying on ucall()

2022-11-16 Thread Oliver Upton
On Thu, Nov 17, 2022 at 12:23:50AM +, Sean Christopherson wrote: > Automatically disable single-step when the guest reaches the end of the > verified section instead of using an explicit ucall() to ask userspace to > disable single-step. An upcoming change to implement a pool-based scheme > fo

Re: [PATCH 1/2] KVM: arm64: selftests: Disable single-step with correct KVM define

2022-11-16 Thread Oliver Upton
On Thu, Nov 17, 2022 at 12:23:49AM +, Sean Christopherson wrote: > Disable single-step by setting debug.control to KVM_GUESTDBG_ENABLE, > not to SINGLE_STEP_DISABLE. The latter is an arbitrary test enum that > just happens to have the same value as KVM_GUESTDBG_ENABLE, and so > effectively dis

[PATCH 2/2] KVM: arm64: selftests: Disable single-step without relying on ucall()

2022-11-16 Thread Sean Christopherson
Automatically disable single-step when the guest reaches the end of the verified section instead of using an explicit ucall() to ask userspace to disable single-step. An upcoming change to implement a pool-based scheme for ucall() will add an atomic operation (bit test and set) in the guest ucall

[PATCH 1/2] KVM: arm64: selftests: Disable single-step with correct KVM define

2022-11-16 Thread Sean Christopherson
Disable single-step by setting debug.control to KVM_GUESTDBG_ENABLE, not to SINGLE_STEP_DISABLE. The latter is an arbitrary test enum that just happens to have the same value as KVM_GUESTDBG_ENABLE, and so effectively disables single-step debug. No functional change intended. Cc: Reiji Watanabe

[PATCH 0/2] KVM: arm64: selftests: Fixes for single-step test

2022-11-16 Thread Sean Christopherson
Marc, I would like to route this through Paolo's tree/queue for 6.2 along with a big pile of other selftests updates. I am hoping to get the selftests pile queued sooner than later as there is a lot of active development in that area, and don't want to have the selftests be in a broken state. I'm

Re: [PATCH 03/12] KVM: arm64: Block unsafe FF-A calls from the host

2022-11-16 Thread Oliver Upton
Sorry, hit send a bit too early. Reviewing the patch itself: On Wed, Nov 16, 2022 at 05:03:26PM +, Quentin Perret wrote: [...] > +static bool ffa_call_unsupported(u64 func_id) > +{ > + switch (func_id) { > + /* Unsupported memory management calls */ > + case FFA_FN64_MEM_RETRIEVE

Re: [PATCH 03/12] KVM: arm64: Block unsafe FF-A calls from the host

2022-11-16 Thread Oliver Upton
On Wed, Nov 16, 2022 at 05:03:26PM +, Quentin Perret wrote: > From: Will Deacon > > When KVM is initialised in protected mode, we must take care to filter > certain FFA calls from the host kernel so that the integrity of guest > and hypervisor memory is maintained and is not made available to

Re: disabling halt polling broken? (was Re: [PATCH 00/14] KVM: Halt-polling fixes, cleanups and a new stat)

2022-11-16 Thread David Matlack
On Tue, Nov 15, 2022 at 11:28:56AM +0800, wangyanan (Y) wrote: > Hi Sean, Paolo, > > I recently also notice the behavior change of param halt_poll_ns. > Now it loses the ability to: > 1) dynamically disable halt polling for all the running VMs > by `echo 0 > /sys` > 2) dynamically adjust the halt

Re: [PATCH 38/44] KVM: Disable CPU hotplug during hardware enabling

2022-11-16 Thread Sean Christopherson
On Wed, Nov 16, 2022, Huang, Kai wrote: > On Tue, 2022-11-15 at 20:16 +, Sean Christopherson wrote: > > On Thu, Nov 10, 2022, Huang, Kai wrote: > > > On Thu, 2022-11-10 at 01:33 +, Huang, Kai wrote: > > > Hmm.. I wasn't thinking thoroughly. I forgot CPU compatibility check also > > > happe

Re: [PATCH 12/12] ANDROID: KVM: arm64: pkvm: Add support for fragmented FF-A descriptors

2022-11-16 Thread Quentin Perret
On Wednesday 16 Nov 2022 at 17:03:35 (+), Quentin Perret wrote: > FF-A memory descriptors may need to be sent in fragments when they don't > fit in the mailboxes. Doing so involves using the FRAG_TX and FRAG_RX > primitives defined in the FF-A protocol. > > Add support in the pKVM FF-A relayer

[PATCH 12/12] ANDROID: KVM: arm64: pkvm: Add support for fragmented FF-A descriptors

2022-11-16 Thread Quentin Perret
FF-A memory descriptors may need to be sent in fragments when they don't fit in the mailboxes. Doing so involves using the FRAG_TX and FRAG_RX primitives defined in the FF-A protocol. Add support in the pKVM FF-A relayer for fragmented descriptors by monitoring outgoing FRAG_TX transactions and by

[PATCH 08/12] KVM: arm64: Add FF-A helpers to share/unshare memory with secure world

2022-11-16 Thread Quentin Perret
From: Will Deacon Extend pKVM's memory protection code so that we can update the host's stage-2 page-table to track pages shared with secure world by the host using FF-A and prevent those pages from being mapped into a guest. Co-developed-by: Andrew Walbran Signed-off-by: Andrew Walbran Signed

[PATCH 07/12] KVM: arm64: Handle FFA_RXTX_MAP and FFA_RXTX_UNMAP calls from the host

2022-11-16 Thread Quentin Perret
From: Will Deacon Handle FFA_RXTX_MAP and FFA_RXTX_UNMAP calls from the host by sharing the host's mailbox memory with the hypervisor and establishing a separate pair of mailboxes between the hypervisor and the SPMD at EL3. Co-developed-by: Andrew Walbran Signed-off-by: Andrew Walbran Signed-o

[PATCH 11/12] KVM: arm64: Handle FFA_MEM_LEND calls from the host

2022-11-16 Thread Quentin Perret
From: Will Deacon Handle FFA_MEM_LEND calls from the host by treating them identically to FFA_MEM_SHARE calls for the purposes of the host stage-2 page-table, but forwarding on the original request to EL3. Signed-off-by: Will Deacon Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/nvhe/ff

[PATCH 09/12] KVM: arm64: Handle FFA_MEM_SHARE calls from the host

2022-11-16 Thread Quentin Perret
From: Will Deacon Intercept FFA_MEM_SHARE/FFA_FN64_MEM_SHARE calls from the host and transition the host stage-2 page-table entries from the OWNED state to the SHARED_OWNED state prior to forwarding the call onto EL3. Co-developed-by: Andrew Walbran Signed-off-by: Andrew Walbran Signed-off-by:

[PATCH 10/12] KVM: arm64: Handle FFA_MEM_RECLAIM calls from the host

2022-11-16 Thread Quentin Perret
From: Will Deacon Intecept FFA_MEM_RECLAIM calls from the host and transition the host stage-2 page-table entries from the SHARED_OWNED state back to the OWNED state once EL3 has confirmed that the secure mapping has been reclaimed. Signed-off-by: Will Deacon Signed-off-by: Quentin Perret ---

[PATCH 06/12] KVM: arm64: Allocate pages for hypervisor FF-A mailboxes

2022-11-16 Thread Quentin Perret
From: Will Deacon The FF-A proxy code needs to allocate its own buffer pair for communication with EL3 and for forwarding calls from the host at EL1. Reserve a couple of pages for this purpose and use them to initialise the hypervisor's FF-A buffer structure. Co-developed-by: Andrew Walbran Si

[PATCH 04/12] KVM: arm64: Probe FF-A version and host/hyp partition ID during init

2022-11-16 Thread Quentin Perret
From: Will Deacon Probe FF-A during pKVM initialisation so that we can detect any inconsistencies in the version or partition ID early on. Signed-off-by: Will Deacon Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/arm.c | 1 + a

[PATCH 05/12] KVM: arm64: Handle FFA_FEATURES call from the host

2022-11-16 Thread Quentin Perret
From: Fuad Tabba Filter out advertising unsupported features, and only advertise features and properties that are supported by the hypervisor proxy. Signed-off-by: Fuad Tabba Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/nvhe/ffa.c | 44 +++ 1 file chang

[PATCH 03/12] KVM: arm64: Block unsafe FF-A calls from the host

2022-11-16 Thread Quentin Perret
From: Will Deacon When KVM is initialised in protected mode, we must take care to filter certain FFA calls from the host kernel so that the integrity of guest and hypervisor memory is maintained and is not made available to the secure world. As a first step, intercept and block all memory-relate

[PATCH 02/12] firmware: arm_ffa: Move comment before the field it is documenting

2022-11-16 Thread Quentin Perret
From: Will Deacon This is consistent with the other comments in the struct. Co-developed-by: Andrew Walbran Signed-off-by: Andrew Walbran Signed-off-by: Will Deacon Signed-off-by: Quentin Perret --- include/linux/arm_ffa.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/

[PATCH 00/12] KVM: arm64: FF-A proxy for pKVM

2022-11-16 Thread Quentin Perret
Hi all, pKVM's primary goal is to protect guest pages from a compromised host by enforcing access control restrictions using stage-2 page-tables. Sadly, this cannot prevent TrustZone from accessing non-secure memory, and a compromised host could, for example, perform a 'confused deputy' attack by

[PATCH 01/12] firmware: arm_ffa: Move constants to header file

2022-11-16 Thread Quentin Perret
From: Will Deacon FF-A function IDs and error codes will be needed in the hypervisor too, so move to them to the header file where they can be shared. Rename the version constants with an "FFA_" prefix so that they are less likely to clash with other code in the tree. Co-developed-by: Andrew Wal

[PATCH v3 2/2] KVM: arm64: Don't acquire RCU read lock for exclusive table walks

2022-11-16 Thread Oliver Upton
Marek reported a BUG resulting from the recent parallel faults changes, as the hyp stage-1 map walker attempted to allocate table memory while holding the RCU read lock: BUG: sleeping function called from invalid context at include/linux/sched/mm.h:274 in_atomic(): 0, irqs_disabled(): 0, non

[PATCH v3 1/2] KVM: arm64: Take a pointer to walker data in kvm_dereference_pteref()

2022-11-16 Thread Oliver Upton
Rather than passing through the state of the KVM_PGTABLE_WALK_SHARED flag, just take a pointer to the whole walker structure instead. Move around struct kvm_pgtable and the RCU indirection such that the associated ifdeffery remains in one place while ensuring the walker + flags definitions precede

[PATCH v3 0/2] KVM: arm64: Fixes for parallel faults series

2022-11-16 Thread Oliver Upton
Small set of fixes for the parallel faults series. Most importantly, stop taking the RCU read lock for walking hyp stage-1. For the sake of consistency, take a pointer to kvm_pgtable_walker in kvm_dereference_pteref() as well. Tested on an Ampere Altra system with kvm-arm.mode={nvhe,protected}. Ap

Re: [PATCH 13/44] KVM: x86: Serialize vendor module initialization (hardware setup)

2022-11-16 Thread Sean Christopherson
On Wed, Nov 16, 2022, Huang, Kai wrote: > On Wed, 2022-11-02 at 23:18 +, Sean Christopherson wrote: > > Acquire a new mutex, vendor_module_lock, in kvm_x86_vendor_init() while > > doing hardware setup to ensure that concurrent calls are fully serialized. > > KVM rejects attempts to load vendor

Re: [PATCH 38/44] KVM: Disable CPU hotplug during hardware enabling

2022-11-16 Thread Huang, Kai
On Tue, 2022-11-15 at 20:16 +, Sean Christopherson wrote: > On Thu, Nov 10, 2022, Huang, Kai wrote: > > On Thu, 2022-11-10 at 01:33 +, Huang, Kai wrote: > > > > @@ -9283,7 +9283,13 @@ static int > > > > kvm_x86_check_processor_compatibility(struct kvm_x86_init_ops *ops) > > > >   int

Re: [PATCH v2] KVM: arm64: Don't acquire RCU read lock for exclusive table walks

2022-11-16 Thread Oliver Upton
On Wed, Nov 16, 2022 at 07:27:27AM +, Oliver Upton wrote: > On Wed, Nov 16, 2022 at 03:08:49AM +, Marc Zyngier wrote: > > I'm not crazy about this sort of parameters. I think it would make a > > lot more sense to pass a pointer to the walker structure and do the > > flag check inside the he