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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6DAEEC52D7C for ; Thu, 22 Aug 2024 15:06:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=HxU9dd1ypYmQwawZ3Ds8LqYripAsFtWIk2FIDqzPmtY=; b=dpEtFpt8Pslu81Fw5MkcDVjSPs lrLf551yDoqgVtURmiYHkl98WeY6Q//Iw1u1xu/Os5JvVnfXS2KZWz+KDVkHZqFl1HqCnNZCJQCzz JiL4qwis6iEdUnBSc3g3KG6PmLmn7FjYst0sxmnL6cAWTwf1As8ivErqcjtoPpsOu0ImK8DZQBf/I UbTItZkqzPKV72BspWKpwx720uubYx2DO891Aa7Yxk17B+rEfjiZCNolukWaY2JueY3k0lXobRoK0 u0dy2iYdj3ft7Yw1u2k98PURCgAR0V8BjwaewJz3P+q8lH3DfzQvJPym6+cLwnNRNR8A+mVmmkuHv VsHWqCqQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh9OV-0000000DGzJ-0ezZ; Thu, 22 Aug 2024 15:06:35 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh9Nk-0000000DGq1-29oM for linux-arm-kernel@lists.infradead.org; Thu, 22 Aug 2024 15:05:49 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D8A22DA7; Thu, 22 Aug 2024 08:06:13 -0700 (PDT) Received: from [10.57.85.214] (unknown [10.57.85.214]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CEED43F58B; Thu, 22 Aug 2024 08:05:43 -0700 (PDT) Message-ID: <039e21db-5705-4f1c-bf0f-35130ccbcfd4@arm.com> Date: Thu, 22 Aug 2024 16:05:41 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 18/43] arm64: RME: Handle realm enter/exit To: "Aneesh Kumar K.V" , kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Suzuki K Poulose , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni , Gavin Shan , Shanker Donthineni , Alper Gun References: <20240821153844.60084-1-steven.price@arm.com> <20240821153844.60084-19-steven.price@arm.com> From: Steven Price Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240822_080548_680171_F15A233E X-CRM114-Status: GOOD ( 23.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 22/08/2024 04:53, Aneesh Kumar K.V wrote: > Steven Price writes: > >> Entering a realm is done using a SMC call to the RMM. On exit the >> exit-codes need to be handled slightly differently to the normal KVM >> path so define our own functions for realm enter/exit and hook them >> in if the guest is a realm guest. >> >> Signed-off-by: Steven Price >> --- >> Changes since v2: >> * realm_set_ipa_state() now provides an output parameter for the >> top_iap that was changed. Use this to signal the VMM with the correct >> range that has been transitioned. >> * Adapt to previous patch changes. >> --- >> arch/arm64/include/asm/kvm_rme.h | 3 + >> arch/arm64/kvm/Makefile | 2 +- >> arch/arm64/kvm/arm.c | 19 +++- >> arch/arm64/kvm/rme-exit.c | 181 +++++++++++++++++++++++++++++++ >> arch/arm64/kvm/rme.c | 11 ++ >> 5 files changed, 210 insertions(+), 6 deletions(-) >> create mode 100644 arch/arm64/kvm/rme-exit.c >> >> diff --git a/arch/arm64/include/asm/kvm_rme.h b/arch/arm64/include/asm/kvm_rme.h >> index c064bfb080ad..0e44b20cfa48 100644 >> --- a/arch/arm64/include/asm/kvm_rme.h >> +++ b/arch/arm64/include/asm/kvm_rme.h >> @@ -96,6 +96,9 @@ void kvm_realm_destroy_rtts(struct kvm *kvm, u32 ia_bits); >> int kvm_create_rec(struct kvm_vcpu *vcpu); >> void kvm_destroy_rec(struct kvm_vcpu *vcpu); >> >> +int kvm_rec_enter(struct kvm_vcpu *vcpu); >> +int handle_rme_exit(struct kvm_vcpu *vcpu, int rec_run_status); >> + >> void kvm_realm_unmap_range(struct kvm *kvm, >> unsigned long ipa, >> u64 size, >> diff --git a/arch/arm64/kvm/Makefile b/arch/arm64/kvm/Makefile >> index 5e79e5eee88d..9f893e86cac9 100644 >> --- a/arch/arm64/kvm/Makefile >> +++ b/arch/arm64/kvm/Makefile >> @@ -21,7 +21,7 @@ kvm-y += arm.o mmu.o mmio.o psci.o hypercalls.o pvtime.o \ >> vgic/vgic-mmio.o vgic/vgic-mmio-v2.o \ >> vgic/vgic-mmio-v3.o vgic/vgic-kvm-device.o \ >> vgic/vgic-its.o vgic/vgic-debug.o \ >> - rme.o >> + rme.o rme-exit.o >> >> kvm-$(CONFIG_HW_PERF_EVENTS) += pmu-emul.o pmu.o >> kvm-$(CONFIG_ARM64_PTR_AUTH) += pauth.o >> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c >> index 568e9e6e5a4e..e8dabb996705 100644 >> --- a/arch/arm64/kvm/arm.c >> +++ b/arch/arm64/kvm/arm.c >> @@ -1282,7 +1282,10 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) >> trace_kvm_entry(*vcpu_pc(vcpu)); >> guest_timing_enter_irqoff(); >> >> - ret = kvm_arm_vcpu_enter_exit(vcpu); >> + if (vcpu_is_rec(vcpu)) >> + ret = kvm_rec_enter(vcpu); >> + else >> + ret = kvm_arm_vcpu_enter_exit(vcpu); >> >> vcpu->mode = OUTSIDE_GUEST_MODE; >> vcpu->stat.exits++; >> @@ -1336,10 +1339,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) >> >> local_irq_enable(); >> >> - trace_kvm_exit(ret, kvm_vcpu_trap_get_class(vcpu), *vcpu_pc(vcpu)); >> - >> /* Exit types that need handling before we can be preempted */ >> - handle_exit_early(vcpu, ret); >> + if (!vcpu_is_rec(vcpu)) { >> + trace_kvm_exit(ret, kvm_vcpu_trap_get_class(vcpu), >> + *vcpu_pc(vcpu)); >> + >> + handle_exit_early(vcpu, ret); >> + } >> >> preempt_enable(); >> >> @@ -1362,7 +1368,10 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) >> ret = ARM_EXCEPTION_IL; >> } >> >> - ret = handle_exit(vcpu, ret); >> + if (vcpu_is_rec(vcpu)) >> + ret = handle_rme_exit(vcpu, ret); >> + else >> + ret = handle_exit(vcpu, ret); >> } >> > > like kvm_rec_enter, should we name this as handle_rec_exit()? Fair enough, will rename. Steve > > arch/arm64/include/asm/kvm_rme.h | 2 +- > arch/arm64/kvm/arm.c | 2 +- > arch/arm64/kvm/rme-exit.c | 2 +- > 3 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_rme.h b/arch/arm64/include/asm/kvm_rme.h > index a72e06cf4ea6..cd42c19ca21d 100644 > --- a/arch/arm64/include/asm/kvm_rme.h > +++ b/arch/arm64/include/asm/kvm_rme.h > @@ -102,7 +102,7 @@ int kvm_create_rec(struct kvm_vcpu *vcpu); > void kvm_destroy_rec(struct kvm_vcpu *vcpu); > > int kvm_rec_enter(struct kvm_vcpu *vcpu); > -int handle_rme_exit(struct kvm_vcpu *vcpu, int rec_run_status); > +int handle_rec_exit(struct kvm_vcpu *vcpu, int rec_run_status); > > void kvm_realm_unmap_range(struct kvm *kvm, > unsigned long ipa, > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index 05d9062470c2..1e34541d88db 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -1391,7 +1391,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > } > > if (vcpu_is_rec(vcpu)) > - ret = handle_rme_exit(vcpu, ret); > + ret = handle_rec_exit(vcpu, ret); > else > ret = handle_exit(vcpu, ret); > } > diff --git a/arch/arm64/kvm/rme-exit.c b/arch/arm64/kvm/rme-exit.c > index 0940575b0a14..f888cfe72dfa 100644 > --- a/arch/arm64/kvm/rme-exit.c > +++ b/arch/arm64/kvm/rme-exit.c > @@ -156,7 +156,7 @@ static void update_arch_timer_irq_lines(struct kvm_vcpu *vcpu) > * Return > 0 to return to guest, < 0 on error, 0 (and set exit_reason) on > * proper exit to userspace. > */ > -int handle_rme_exit(struct kvm_vcpu *vcpu, int rec_run_ret) > +int handle_rec_exit(struct kvm_vcpu *vcpu, int rec_run_ret) > { > struct realm_rec *rec = &vcpu->arch.rec; > u8 esr_ec = ESR_ELx_EC(rec->run->exit.esr);