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 4C045CD98F2 for ; Thu, 18 Jun 2026 10:16:49 +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: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date: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=66JgIZ+ZfVcAOFUVboi0UgekLa+PJ0VEWzz7UjtLzxI=; b=nZ0WN3zlPV8QvDb9rdsl1a20nr NLQnxSUQmC4w40afTL4uzdM94+aswrgtTT/K25FO/6U9tmbVRUAhdBtPgvwWHxuBOVAmondLiDM3j yq755JcfU3bSB9HrAR1wAlgOBTDxval+TggR1CXNyvrQMsrGxCvwPFWYIz+9c1E2kw+hsBTXHjY1o dFTxzErS//oxXZdSv6ouQ463J+sjjYUEFRST8OJV1dtcO1lPtW+aqEZf5XGt5igSKQQWGIy9irDfB 9c0DRsnHal0OagB2qIWEWpAIK+NPS7O6ybCAIPqWgme1ABpEujXNfNToX9X1l/1n8xLXsnk4iN4Uq fV4Ef/9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wa9ne-000000014uf-12fy; Thu, 18 Jun 2026 10:16:42 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wa9nc-000000014uU-2XFb for linux-arm-kernel@lists.infradead.org; Thu, 18 Jun 2026 10:16:40 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 081CB441CF; Thu, 18 Jun 2026 10:16:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBA971F000E9; Thu, 18 Jun 2026 10:16:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1781777799; bh=66JgIZ+ZfVcAOFUVboi0UgekLa+PJ0VEWzz7UjtLzxI=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=EJWyH5g1605DUv6IWjNVuxBmHWLdme+hDdzyJx7Sc5pjfRoZPQOleZzMUSh9AvfbE 9Wc4l4SDqRoJsC/6h/b6nB4gPDxbu1JyLXtn7IBNl8QIKk1ob2J63NxBEdy5bR+9/e TKSsf2W03FjQIPvm7QPe4sJB7WzLSJLtI7yBrkj8HjMefZ3hvlEL9JWsFMCldxyTNG NPEh0mNOXXM12j+U7yHdNkhtn2V5ab4Yk36/GLEAKD8zSnvJqW7rtD4QXYAerDSeUL wu+O9afpG4PYom2Q1Ure3+Ec0DP0FlNvPlhoCUtOW2gSB1WsI0cvxSKGtLNgGpUGG8 eE93SJGnh7r9Q== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wa9na-0000000Dxvj-00Cx; Thu, 18 Jun 2026 10:16:38 +0000 Date: Thu, 18 Jun 2026 11:16:37 +0100 Message-ID: <86fr2krw56.wl-maz@kernel.org> From: Marc Zyngier To: tabba@google.com Cc: Oliver Upton , Will Deacon , Catalin Marinas , Quentin Perret , Vincent Donnefort , Sebastian Ene , Per Larsen , Suzuki K Poulose , Zenghui Yu , Joey Gouly , Steffen Eiden , Mark Rutland , Jonathan Cameron , Hyunwoo Kim , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1 11/11] KVM: arm64: Implement lazy vCPU state sync for non-protected guests In-Reply-To: <20260612065925.755562-12-tabba@google.com> References: <20260612065925.755562-1-tabba@google.com> <20260612065925.755562-12-tabba@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: tabba@google.com, oupton@kernel.org, will@kernel.org, catalin.marinas@arm.com, qperret@google.com, vdonnefort@google.com, sebastianene@google.com, perlarsen@google.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, joey.gouly@arm.com, seiden@linux.ibm.com, mark.rutland@arm.com, jonathan.cameron@huawei.com, imv4bel@gmail.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false 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 Fri, 12 Jun 2026 07:59:25 +0100, tabba@google.com wrote: > > pKVM copies a non-protected guest's register context between the host > and the hypervisor on every world switch, even when the host never > inspects it. Defer the copy: on entry, flush the host context into the > hyp vCPU only when the host marked it dirty (PKVM_HOST_STATE_DIRTY); on > exit, leave it in the hyp vCPU and copy it back only when the host needs > it, via a __pkvm_vcpu_sync_state hypercall on trap handling or at vcpu > put. A protected guest's context is copied as before, since lazy sync > only helps where the host is trusted to see the guest's registers. > > The PC is the exception: it is copied back on every exit so the > kvm_exit tracepoint reports the guest's real exit PC rather than the > value left by the previous sync. > > Signed-off-by: Fuad Tabba > --- > arch/arm64/include/asm/kvm_asm.h | 1 + > arch/arm64/include/asm/kvm_host.h | 2 + > arch/arm64/kvm/arm.c | 7 +++ > arch/arm64/kvm/handle_exit.c | 22 ++++++++ > arch/arm64/kvm/hyp/nvhe/hyp-main.c | 88 ++++++++++++++++++++++++++++-- > 5 files changed, 115 insertions(+), 5 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h > index 043495f7fc78..6e1135b3ded4 100644 > --- a/arch/arm64/include/asm/kvm_asm.h > +++ b/arch/arm64/include/asm/kvm_asm.h > @@ -113,6 +113,7 @@ enum __kvm_host_smccc_func { > __KVM_HOST_SMCCC_FUNC___pkvm_finalize_teardown_vm, > __KVM_HOST_SMCCC_FUNC___pkvm_vcpu_load, > __KVM_HOST_SMCCC_FUNC___pkvm_vcpu_put, > + __KVM_HOST_SMCCC_FUNC___pkvm_vcpu_sync_state, > __KVM_HOST_SMCCC_FUNC___pkvm_tlb_flush_vmid, > > MARKER(__KVM_HOST_SMCCC_FUNC_MAX) > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > index a49042bfa801..1ef660774adc 100644 > --- a/arch/arm64/include/asm/kvm_host.h > +++ b/arch/arm64/include/asm/kvm_host.h > @@ -1113,6 +1113,8 @@ struct kvm_vcpu_arch { > /* SError pending for nested guest */ > #define NESTED_SERROR_PENDING __vcpu_single_flag(sflags, BIT(8)) > > +/* pKVM host vcpu state is dirty, needs resync (nVHE-only) */ > +#define PKVM_HOST_STATE_DIRTY __vcpu_single_flag(iflags, BIT(4)) Please don't add flags in random positions. Keep them grouped by type. Also, it is unclear to me whether this is really an input to the hypervisor (which is what iflags indicates), but rather a new type of flag that indicate some hypervisor-private state. May not be that important right now, but worth keeping in mind. M. -- Without deviation from the norm, progress is not possible.