From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DA3FC43461 for ; Wed, 16 Sep 2020 13:16:34 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3C1BA22246 for ; Wed, 16 Sep 2020 13:16:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="0RK8qBZi"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="jXLBnEr6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3C1BA22246 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Subject:To:From: Message-ID:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+ta3I0o270/n8PWRncKkcnomEh4Mf4YDTOnS6xJ80dY=; b=0RK8qBZi4URSVN9DQSPK21LKT Lyrbka/kLO3vkxXJ/twoQy0dCqwCGnP8LZCF3ZKfslXKsekHIyzHmTcwj/4UiTIt9dVGsU1Tw8Y+f BPE5xqeA0HPBmZQG4DVqzi81ACfxlV1Z6w3B9NmZavG2lhWguPK52WbKSQaAfOEshMutm4oljfz12 dFZK1RHku+I35FE2yUPpASjOOg18BHhXmNdazBs258PRCg5cDkK0YswrZBMgcW2QrTsgH+RBHQ7Bw I+3ayINy/fiEiiQUzf7q1F7lVsLMwE0hMEW5ARbvgmngA6EPwJZiH2oOTi08qvEIK4acwj9bv8wtC Km4PuxuJw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIXH7-0003sl-5N; Wed, 16 Sep 2020 13:15:05 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIXH4-0003rx-EP for linux-arm-kernel@lists.infradead.org; Wed, 16 Sep 2020 13:15:03 +0000 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5FA702225F; Wed, 16 Sep 2020 13:15:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600262101; bh=fbo6I986stQIkRNEU9yZnkOQuTnyuhBLGQoNhgcUg1Q=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=jXLBnEr6egqTDm8T2nwBMCjR74pHXRD3CqA6rBb4V+qVO7vhQfLsuIXSA4rbTidYA GbYTweuxY1uUofFd2hco+kJCSkqh2qA6fWlAe20K2bld/OUDsr7jujjc50KVwwqmP7 j1WFNDMpQk/uQqr898xEHW6Gh1dTU7yvcKMQ7k04= Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kIXH1-00CLpj-5K; Wed, 16 Sep 2020 14:14:59 +0100 Date: Wed, 16 Sep 2020 14:14:58 +0100 Message-ID: <87imcdrhgt.wl-maz@kernel.org> From: Marc Zyngier To: Andrew Scull Subject: Re: [PATCH v4 12/19] KVM: arm64: nVHE: Switch to hyp context for EL2 In-Reply-To: <20200915104643.2543892-13-ascull@google.com> References: <20200915104643.2543892-1-ascull@google.com> <20200915104643.2543892-13-ascull@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 EasyPG/1.0.0 Emacs/26.3 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: ascull@google.com, kvmarm@lists.cs.columbia.edu, james.morse@arm.com, suzuki.poulose@arm.com, julien.thierry.kdev@gmail.com, will@kernel.org, catalin.marinas@arm.com, kernel-team@android.com, sudeep.holla@arm.com, linux-arm-kernel@lists.infradead.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200916_091502_616040_EBA93D17 X-CRM114-Status: GOOD ( 32.68 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel-team@android.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, james.morse@arm.com, linux-arm-kernel@lists.infradead.org, Sudeep Holla , will@kernel.org, kvmarm@lists.cs.columbia.edu, julien.thierry.kdev@gmail.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Andrew, A few very minor comments below, which we can sort in a subsequent patch: On Tue, 15 Sep 2020 11:46:36 +0100, Andrew Scull wrote: > > Save and restore the host context when switching to and from hyp. This > gives hyp its own context that the host will not see as a step towards a > full trust boundary between the two. > > SP_EL0 and pointer authentication keys are currently shared between the > host and hyp so don't need to be switched yet. > > Signed-off-by: Andrew Scull > --- > arch/arm64/kvm/hyp/include/hyp/switch.h | 2 + > arch/arm64/kvm/hyp/nvhe/Makefile | 2 +- > arch/arm64/kvm/hyp/nvhe/host.S | 68 ++++++++++++++++++------- > arch/arm64/kvm/hyp/nvhe/hyp-main.c | 36 +++++++++++++ > 4 files changed, 89 insertions(+), 19 deletions(-) > create mode 100644 arch/arm64/kvm/hyp/nvhe/hyp-main.c > > diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h > index 821721b78ad9..4536b50ddc06 100644 > --- a/arch/arm64/kvm/hyp/include/hyp/switch.h > +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h > @@ -372,6 +372,8 @@ static inline bool esr_is_ptrauth_trap(u32 esr) > ctxt_sys_reg(ctxt, key ## KEYHI_EL1) = __val; \ > } while(0) > > +DECLARE_PER_CPU(struct kvm_cpu_context, kvm_hyp_ctxt); > + Why do we need this declaration? Isn't the one from patch 8 enough? Or is it just a spurious addition (things seem to compile fine without it). > static inline bool __hyp_handle_ptrauth(struct kvm_vcpu *vcpu) > { > struct kvm_cpu_context *ctxt; > diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile > index ddf98eb07b9d..46c89e8c30bc 100644 > --- a/arch/arm64/kvm/hyp/nvhe/Makefile > +++ b/arch/arm64/kvm/hyp/nvhe/Makefile > @@ -6,7 +6,7 @@ > asflags-y := -D__KVM_NVHE_HYPERVISOR__ > ccflags-y := -D__KVM_NVHE_HYPERVISOR__ > > -obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o > +obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o hyp-main.o > obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \ > ../fpsimd.o ../hyp-entry.o > > diff --git a/arch/arm64/kvm/hyp/nvhe/host.S b/arch/arm64/kvm/hyp/nvhe/host.S > index 9ab7814e6114..d26e41773dc4 100644 > --- a/arch/arm64/kvm/hyp/nvhe/host.S > +++ b/arch/arm64/kvm/hyp/nvhe/host.S > @@ -12,6 +12,55 @@ > > .text > > +SYM_FUNC_START(__host_exit) > + stp x0, x1, [sp, #-16]! > + > + get_host_ctxt x0, x1 > + > + ALTERNATIVE(nop, SET_PSTATE_PAN(1), ARM64_HAS_PAN, CONFIG_ARM64_PAN) > + It isn't obvious to me why we mess with PAN here. nVHE doesn't have an EL0, and the spec says that PAN only exists at EL2 when HCR_EL2.E2H==1. > + /* Store the host regs x2 and x3 */ > + stp x2, x3, [x0, #CPU_XREG_OFFSET(2)] > + > + /* Retrieve the host regs x0-x1 from the stack */ > + ldp x2, x3, [sp], #16 // x0, x1 > + > + /* Store the host regs x0-x1 and x4-x17 */ > + stp x2, x3, [x0, #CPU_XREG_OFFSET(0)] > + stp x4, x5, [x0, #CPU_XREG_OFFSET(4)] > + stp x6, x7, [x0, #CPU_XREG_OFFSET(6)] > + stp x8, x9, [x0, #CPU_XREG_OFFSET(8)] > + stp x10, x11, [x0, #CPU_XREG_OFFSET(10)] > + stp x12, x13, [x0, #CPU_XREG_OFFSET(12)] > + stp x14, x15, [x0, #CPU_XREG_OFFSET(14)] > + stp x16, x17, [x0, #CPU_XREG_OFFSET(16)] > + > + /* Store the host regs x18-x29, lr */ > + save_callee_saved_regs x0 > + > + /* Save the host context pointer in x29 across the function call */ > + mov x29, x0 > + bl handle_trap > + > + /* Restore host regs x0-x17 */ > + ldp x0, x1, [x29, #CPU_XREG_OFFSET(0)] > + ldp x2, x3, [x29, #CPU_XREG_OFFSET(2)] > + ldp x4, x5, [x29, #CPU_XREG_OFFSET(4)] > + ldp x6, x7, [x29, #CPU_XREG_OFFSET(6)] > + ldp x8, x9, [x29, #CPU_XREG_OFFSET(8)] > + ldp x10, x11, [x29, #CPU_XREG_OFFSET(10)] > + ldp x12, x13, [x29, #CPU_XREG_OFFSET(12)] > + ldp x14, x15, [x29, #CPU_XREG_OFFSET(14)] > + ldp x16, x17, [x29, #CPU_XREG_OFFSET(16)] > + > + /* Restore host regs x18-x29, lr */ > + restore_callee_saved_regs x29 > + > + /* Do not touch any register after this! */ > + eret > + sb > +SYM_FUNC_END(__host_exit) > + > SYM_FUNC_START(__hyp_do_panic) > mov lr, #(PSR_F_BIT | PSR_I_BIT | PSR_A_BIT | PSR_D_BIT |\ > PSR_MODE_EL1h) > @@ -34,7 +83,7 @@ SYM_FUNC_END(__hyp_do_panic) > > /* Check for a stub HVC call */ > cmp x0, #HVC_STUB_HCALL_NR > - b.hs 1f > + b.hs __host_exit > > /* > * Compute the idmap address of __kvm_handle_stub_hvc and > @@ -50,23 +99,6 @@ SYM_FUNC_END(__hyp_do_panic) > /* x5 = __pa(x5) */ > sub x5, x5, x6 > br x5 > - > -1: > - /* > - * Shuffle the parameters before calling the function > - * pointed to in x0. Assumes parameters in x[1,2,3]. > - */ > - kern_hyp_va x0 > - str lr, [sp, #-16]! > - mov lr, x0 > - mov x0, x1 > - mov x1, x2 > - mov x2, x3 > - blr lr > - ldr lr, [sp], #16 > - > - eret > - sb > .L__vect_end\@: > .if ((.L__vect_end\@ - .L__vect_start\@) > 0x80) > .error "host_el1_sync_vect larger than vector entry" > diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c > new file mode 100644 > index 000000000000..570c3896f42e > --- /dev/null > +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c > @@ -0,0 +1,36 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (C) 2020 - Google Inc > + * Author: Andrew Scull > + */ > + > +#include > + > +#include > +#include > +#include > +#include > +#include > + > +typedef unsigned long (*hypcall_fn_t) > + (unsigned long, unsigned long, unsigned long); > + > +void handle_trap(struct kvm_cpu_context *host_ctxt) This probably needs to have the asmlinkage attribute, although I'm not sure we use it for anything on arm64 just yet. Thanks, M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel