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 19734CFB43F for ; Mon, 7 Oct 2024 10:23:54 +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=Rb+EQza3sImiDWNfUIbUSvtP/wcdPn/kYm+ky/+mdvM=; b=uFOfcUXUTdAF82JnK4Tl/2xXU4 Uy7XZ1PsMpxJGFFE3ibPY/5fBbWIlFdIWydMEovOcYlxmQXvrQVc3YVwaHITYLkvJreGQQuy8ZCc/ 6olDKp9afXZJ+UPseeCUwoywwRm59HbB8qIGA9bB4KAjKhRyOq47ZmDOvkpjovnoc3mpB0Pz0W7wY uiZi5ztuSTI9M5fLpld6QdPfq7DAUM8EjBPSfErE33ophlpHotCOGudgk+P3fVzEz/UV5lp3xmz5M 39jX2RWeGB/EFDymLAhcs3v3/HDGveFervBtu8opxH6MOsMWdunwOE0vkjZlg9bNuYONJ74uld5MZ KZ8EEx/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sxkty-000000022lo-2O3u; Mon, 07 Oct 2024 10:23:42 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sxksg-000000022dV-1rLD for linux-arm-kernel@lists.infradead.org; Mon, 07 Oct 2024 10:22:24 +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 0E2E7FEC; Mon, 7 Oct 2024 03:22:49 -0700 (PDT) Received: from [10.57.78.166] (unknown [10.57.78.166]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B63263F64C; Mon, 7 Oct 2024 03:22:15 -0700 (PDT) Message-ID: <3dd5059b-a42d-496b-8de3-e16012d6dafd@arm.com> Date: Mon, 7 Oct 2024 11:22:13 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 19/43] KVM: arm64: Handle realm MMIO emulation 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: <20241004152804.72508-1-steven.price@arm.com> <20241004152804.72508-20-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-20241007_032222_607408_5D84710D X-CRM114-Status: GOOD ( 22.25 ) 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 07/10/2024 05:31, Aneesh Kumar K.V wrote: > 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 The PC is ignored when restarting realm guest, so kvm_incr_pr() is effectively a no-op. But I guess REC_ENTER_EMULATED_MMIO is our way of signalling to the RMM that it should skip the instruction, so your proposed patch below makes the code slightly clearer. Thanks, Steve > 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