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 45C39CFB43C for ; Mon, 7 Oct 2024 04:33:14 +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-Type:MIME-Version: Message-ID:Date:References:In-Reply-To:Subject:Cc:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=vm3pE10HNrFQztJZH786jEamo3/hGNfafwSFGRKjjBg=; b=bKvF/jiTYuGH+8BAI2ezU0WAu3 bBh9SK7u9KkSPUYPrJwLOMUqT5cTsZJnLw7m+2vcxxiRs5KAvtRtNivPyJ0lQj9oCvfJtwb1nGI+w GC6Z33L1lkkucuYRJKRBymXbxD+9/7OBt6raJJeX+J3MHEO3fHVZQZJW3QPv0CI0gACmfbhGnYb/t 4c66eULheVD//tteJiD2AjVMWUBsrGOgcYRskZhu+4XFE5qnDujJeB9puUr4MqicThDe6UclVF8na snDKL3BezrnIR326ZeERDpz1jO94KW+hFfYuF3jstgiK6dQVFyE+r8axLN9X9xzkVabiz7o6hwoMx 04jC1yLg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sxfQf-00000001EuN-2uOd; Mon, 07 Oct 2024 04:33:05 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sxfPO-00000001EkQ-122O for linux-arm-kernel@lists.infradead.org; Mon, 07 Oct 2024 04:31:47 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id CB87E5C5BDC; Mon, 7 Oct 2024 04:31:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97E00C4CEC6; Mon, 7 Oct 2024 04:31:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728275504; bh=h4BqdarIxiHAkZjTqrf5W1xk6PBnK/XznaYWb774zhU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=Ns5p+FPNQ6ghH8QdqMYD3NDD1rym469P8SEFY3wude6968PtVUVO1m3sETctDROEx NLAq6xLzPTAJFQVTGNeUG+y9HE8RtxgdgNvzG0o6v5eEB/pilsUmcb6tOZLL8y2Are D35iCJC7QYTDWm01Qy6wJmKoUpGFQ3xJkcpCGKy1LljNh95W5yxkt0h7wdyDmhPhy0 ikAU5uV8cEPCeGLLQyVQgUVElKTuilKtfCttAD48Z7x//dJaeI+NQJkLNkf36xPXEC ASr11zQZ/Y4MLavUsS9PH/8JFhHQnQkx6Nf/dBTeQ5dM2WSk//1i7CB16DuuvY8nt6 9oTQqp+ZnlLMw== X-Mailer: emacs 31.0.50 (via feedmail 11-beta-1 I) From: Aneesh Kumar K.V To: Steven Price , kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Steven Price , 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 Subject: Re: [PATCH v5 19/43] KVM: arm64: Handle realm MMIO emulation In-Reply-To: <20241004152804.72508-20-steven.price@arm.com> References: <20241004152804.72508-1-steven.price@arm.com> <20241004152804.72508-20-steven.price@arm.com> Date: Mon, 07 Oct 2024 10:01:33 +0530 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241006_213146_401834_6E196517 X-CRM114-Status: GOOD ( 22.82 ) 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 Steven Price writes: > MMIO emulation for a realm cannot be done directly with the VM's > registers as they are protected from the host. However, for emulatable > data aborts, the RMM uses GPRS[0] to provide the read/written value. > We can transfer this from/to the equivalent VCPU's register entry and > then depend on the generic MMIO handling code in KVM. > > For a MMIO read, the value is placed in the shared RecExit structure > during kvm_handle_mmio_return() rather than in the VCPU's register > entry. > > Signed-off-by: Steven Price > --- > v3: Adapt to previous patch changes > --- > arch/arm64/kvm/mmio.c | 10 +++++++++- > arch/arm64/kvm/rme-exit.c | 6 ++++++ > 2 files changed, 15 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/mmio.c b/arch/arm64/kvm/mmio.c > index cd6b7b83e2c3..66a838b3776a 100644 > --- a/arch/arm64/kvm/mmio.c > +++ b/arch/arm64/kvm/mmio.c > @@ -6,6 +6,7 @@ > > #include > #include > +#include > #include > > #include "trace.h" > @@ -90,6 +91,9 @@ int kvm_handle_mmio_return(struct kvm_vcpu *vcpu) > > vcpu->mmio_needed = 0; > > + if (vcpu_is_rec(vcpu)) > + vcpu->arch.rec.run->enter.flags |= REC_ENTER_EMULATED_MMIO; > + > if (!kvm_vcpu_dabt_iswrite(vcpu)) { > struct kvm_run *run = vcpu->run; > > @@ -108,7 +112,11 @@ int kvm_handle_mmio_return(struct kvm_vcpu *vcpu) > trace_kvm_mmio(KVM_TRACE_MMIO_READ, len, run->mmio.phys_addr, > &data); > data = vcpu_data_host_to_guest(vcpu, data, len); > - vcpu_set_reg(vcpu, kvm_vcpu_dabt_get_rd(vcpu), data); > + > + if (vcpu_is_rec(vcpu)) > + vcpu->arch.rec.run->enter.gprs[0] = data; > + else > + vcpu_set_reg(vcpu, kvm_vcpu_dabt_get_rd(vcpu), data); > } > > /* > Does a kvm_incr_pc(vcpu); make sense for realm guest? Should we do modified arch/arm64/kvm/mmio.c @@ -91,9 +91,6 @@ int kvm_handle_mmio_return(struct kvm_vcpu *vcpu) vcpu->mmio_needed = 0; - if (vcpu_is_rec(vcpu)) - vcpu->arch.rec.run->enter.flags |= RMI_EMULATED_MMIO; - if (!kvm_vcpu_dabt_iswrite(vcpu)) { struct kvm_run *run = vcpu->run; @@ -123,7 +120,10 @@ int kvm_handle_mmio_return(struct kvm_vcpu *vcpu) * The MMIO instruction is emulated and should not be re-executed * in the guest. */ - kvm_incr_pc(vcpu); + if (vcpu_is_rec(vcpu)) + vcpu->arch.rec.run->enter.flags |= RMI_EMULATED_MMIO; + else + kvm_incr_pc(vcpu); return 1; } > diff --git a/arch/arm64/kvm/rme-exit.c b/arch/arm64/kvm/rme-exit.c > index e96ea308212c..1ddbff123149 100644 > --- a/arch/arm64/kvm/rme-exit.c > +++ b/arch/arm64/kvm/rme-exit.c > @@ -25,6 +25,12 @@ static int rec_exit_reason_notimpl(struct kvm_vcpu *vcpu) > > static int rec_exit_sync_dabt(struct kvm_vcpu *vcpu) > { > + struct realm_rec *rec = &vcpu->arch.rec; > + > + if (kvm_vcpu_dabt_iswrite(vcpu) && kvm_vcpu_dabt_isvalid(vcpu)) > + vcpu_set_reg(vcpu, kvm_vcpu_dabt_get_rd(vcpu), > + rec->run->exit.gprs[0]); > + > return kvm_handle_guest_abort(vcpu); > } > > -- > 2.34.1