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 5AA67C61DA4 for ; Mon, 6 Mar 2023 15:39:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=n3UmbxRzlRnIPKDOUdxicPGZlFHw5efuv5bIhhQY+eI=; b=1OfUASxbN/u3aM RCNQoqTlD90i6LCFaEGIf5UCjxcp/4OtDmwe8KqQudXyqBvnqKzpniv+tyfRDeTbmziYLhQdrCj/Z Gatp5ywExzuq+n05vQBjkKsLQNQcEdj4YEbdl2GRK8/3Z4rmNKzG4Ay3WdCmigNOBLt2F2yEr0CYy Bv6SROoC57mUzVhqAAuxnKp53xYkhhq7HMXRozEONB7I+YsIu2LIE7utBC8bZ/4RPH8TW5+k3ViYn M52hYZA8ogpaWvzdtYxX6RN13h4I7gXwqSubhjzRkWqQVDP5iL8iDbFoBVc8emYDMEHx4RZ/Nt6SH u4KC+/KZTLPz83TGxgGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZCuX-00DdWP-4o; Mon, 06 Mar 2023 15:38:01 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZCuT-00DdUk-Df for linux-arm-kernel@lists.infradead.org; Mon, 06 Mar 2023 15:37:58 +0000 Received: by mail-lf1-x136.google.com with SMTP id t11so13315473lfr.1 for ; Mon, 06 Mar 2023 07:37:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678117072; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=5hDMsqcdGIfiCOVeyjU4Ba4iMqQn+GOWjCwhWYk6SdI=; b=cg1/O1TWCoAT+12txvkiPpk8WOQTLsVbbyntUVywAm++PWVMzFM4JjQRWDOUOYRScg pvFU352A9exDJyfmr6d8LqJgbi0luBH+enT3u31nc54Hmh05vWYHCkSSe7oGk7lmhxyE gQSPcdZk5nGsoTod4x/9xM1gvrso7kjeMYYHWi2P08jqU+eAbw3oqFZsorHQ0S/CRtHA d+foYcEAUnenuImuL8oP9UXM5FRNCKBTKRUghgv+c1d+jCyNJQcf5Z8sqJZPTHfcasad gO4Za/039IiZBBKhDDxAJK9l/nUdtBwyQUaEdwEM3X27LHjxursB5jxdMGtDxQkwzSHu Mqpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678117072; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5hDMsqcdGIfiCOVeyjU4Ba4iMqQn+GOWjCwhWYk6SdI=; b=oNEgZ5hmPbd/St/3i+mMF4s9YkLtkydy9ZdoGjOTYNr/ZUcCinOfVokV9NySrjw5Zw fUNQgAuOrBoOS7iP4CBsDnagznJcyaXdr0FjLLQNggQXXgfXqvsA8U+2zXyQkWczYvAK iG3QUSFKrp8zVw3zKCT5Mu32CQkyQy80kSvKx8blZ5nFXcLWpxok/7uO9/fuvm+BrMPD oeRQqIq4Wa9AkqCsv8XY6Rrh70aVQJsl+gYMBq4csPmO6WPY/JvHCYd6qSrw1gFg5zTw S1V2KdanXEfpp7G3A1TNp5uKo25x8g8dKKVQYoIJ0KGn/V78ukQKSU2tDc+QBizCqVvn Gd1g== X-Gm-Message-State: AO0yUKX70bjnbJFfPpCFZeXZLc2dmT0S1esBR/fDIa/Nps4oWgE8G/fc v+BXn6cGV7foz8L9y1qu2AE= X-Google-Smtp-Source: AK7set/mMWXfBFsiLU1XkaTiImOSmqnWmfXifYoeEmJfJYsfZbSf6DihYHx9KRJq7C6ZcNvQWlxpEQ== X-Received: by 2002:a19:f011:0:b0:4cb:3a60:65c9 with SMTP id p17-20020a19f011000000b004cb3a6065c9mr2589865lfc.2.1678117072501; Mon, 06 Mar 2023 07:37:52 -0800 (PST) Received: from localhost (88-115-161-74.elisa-laajakaista.fi. [88.115.161.74]) by smtp.gmail.com with ESMTPSA id g22-20020ac25396000000b004cb14fa604csm1680397lfh.262.2023.03.06.07.37.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 07:37:52 -0800 (PST) Date: Mon, 6 Mar 2023 17:37:51 +0200 From: Zhi Wang To: Steven Price Cc: kvm@vger.kernel.org, kvmarm@lists.linux.dev, 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 Subject: Re: [RFC PATCH 15/28] KVM: arm64: Handle realm MMIO emulation Message-ID: <20230306173751.000026d4@gmail.com> In-Reply-To: <20230127112932.38045-16-steven.price@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127112932.38045-1-steven.price@arm.com> <20230127112932.38045-16-steven.price@arm.com> X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230306_073757_494615_A4D0BDC7 X-CRM114-Status: GOOD ( 25.66 ) 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: , 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 On Fri, 27 Jan 2023 11:29:19 +0000 Steven Price wrote: > MMIO emulation for a realm cannot be done directly with the VM's > registers as they are protected from the host. However the RMM interface > provides a structure member for providing the read/written value and More details would be better for helping the review. I can only see the emulated mmio value from the device model (kvmtool or kvm_io_bus) is put into the GPRS[0] of the RecEntry object. But the rest of the flow is missing. I guess RMM copies the value in the RecEntry.GPRS[0] to the target GPR in the guest context in RMI_REC_ENTER when seeing RMI_EMULATED_MMIO. This is for the guest MMIO read path. How about the MMIO write path? I don't see where the RecExit.GPRS[0] is loaded to a varible and returned to the userspace. > we can transfer this to the appropriate VCPU's register entry and then > depend on the generic MMIO handling code in KVM. > > Signed-off-by: Steven Price > --- > arch/arm64/kvm/mmio.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/arch/arm64/kvm/mmio.c b/arch/arm64/kvm/mmio.c > index 3dd38a151d2a..c4879fa3a8d3 100644 > --- a/arch/arm64/kvm/mmio.c > +++ b/arch/arm64/kvm/mmio.c > @@ -6,6 +6,7 @@ > > #include > #include > +#include > #include > > #include "trace.h" > @@ -109,6 +110,9 @@ int kvm_handle_mmio_return(struct kvm_vcpu *vcpu) > &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->entry.gprs[0] = data; I think the guest context is maintained by RMM (while KVM can only touch Rec{Entry, Exit} object) so that guest context in the legacy VHE mode is unused. If yes, I guess here is should be: if (unlikely(vcpu_is_rec(vcpu))) vcpu->arch.rec.run->entry.gprs[0] = data; else vcpu_set_reg(vcpu, kvm_vcpu_dabt_get_rd(vcpu), data); > } > > /* > @@ -179,6 +183,9 @@ int io_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa) > run->mmio.len = len; > vcpu->mmio_needed = 1; > > + if (vcpu_is_rec(vcpu)) > + vcpu->arch.rec.run->entry.flags |= RMI_EMULATED_MMIO; > + Wouldn't it be better to set this in the kvm_handle_mmio_return where the MMIO read emulation has been surely successful? > if (!ret) { > /* We handled the access successfully in the kernel. */ > if (!is_write) _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel