From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A090E606A330 for ; Mon, 30 Nov 2026 16:43:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=IIu/2K51; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MDV6FhDS 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:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=KXzLLcSqTdMfprzzs1srJCVXrRwN1qBPSxzvH1QsW7o=; b=IIu/2K51JHkTw+ dY6dLYMTLZcepYlgZLJhfcECKb2EFzHa7nlg9brVL+mrniau4W0NQxQP2zxAqqmxUAy7bxHNREpFj 3a16DDrvY8yNr5h7oV6hp5mIUeGP2FxUtnJCSWPEIhTqft7SQee5ZCYrvVWuedrRTDbltozLxxmzJ J8wWJUF88X8kAiURzz7RFNa8lcvhhNPKUfWol6qWiWZQkn/eHAtu2mjInIKQojlbuyxQ7qzGtE4RO svJSRNO/wlRimY3wtnV1zZcdnsdtsnKvZXalTs6EjFtSnJxSq9WQ5o0mgQsOaSoxt4+kisl98aVxG 8ewIggs+FeuMNW/sfFAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY4TY-00000005IGc-21z7; Mon, 30 Nov 2026 16:43:36 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY4TH-00000005I8h-0cO5 for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2026 16:43:19 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 9673A61AE2; Mon, 30 Nov 2026 16:43:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 464251F00927; Mon, 30 Nov 2026 16:43:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796056998; bh=KXzLLcSqTdMfprzzs1srJCVXrRwN1qBPSxzvH1QsW7o=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=MDV6FhDS9X/8pmlbE2n1GHix+eNN9TqKlrnU2nC8e3E1sDbli8GO75o2kSve7CPhi xuTcgIS/U2lsZaXGSm6UmvNujroLW6ONsEXOsr6RKMMdpGCAjlRBxTTDnkKCom5W8O KH3fG0Z3qvndwtim4i7E6+KgO03TeGBIu092w2Zs6yPoaOcWpcECIwlQbkrNw9Uhzd heK/6fBdxWvGAWVl9Uuw4MLWgE0zjIS8U0Nz3+FdvXsfHv7tqQxtX9uMIdJQKcTNmr YCEzDVswON6cj1jseyhzJ9D7kq0aZEOoy4dSjwNLziAVyQTsKd6p5/l+T+9Q0eWRzi UZabBWNsHqRfA== From: Mark Brown Date: Mon, 30 Nov 2026 16:35:45 +0000 Subject: [PATCH v22 04/16] KVM: arm64: Ensure GCS memory effects are visible X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261130-arm64-gcs-v22-4-80454edf47ea@kernel.org> References: <20261130-arm64-gcs-v22-0-80454edf47ea@kernel.org> In-Reply-To: <20261130-arm64-gcs-v22-0-80454edf47ea@kernel.org> To: Catalin Marinas , Will Deacon , Marc Zyngier , Joey Gouly , Suzuki K Poulose , Shuah Khan , Oliver Upton , Fuad Tabba Cc: Peter Maydell , Leonardo Bras , Wei-Lin Chang , Yao Yuan , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown , "Lorenzo Stoakes (ARM)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2451; i=broonie@kernel.org; h=from:subject:message-id; bh=qjNwgiA2CIv8zDLdTWpmgXi8vH1ed1QQSxKeVaIVHoQ=; b=owGbwMvMwCWm/754w+YLFp2Mp9WSGLJ5l7fHLU7+ENj3/Ojmn24djF1mp//WnJ88I/vppv2XH M32Hvo8qaOUhUGMi0FWTJElLov7ZX3J6zV8Bxe2wcxhZQIZwsDFKQAT+fSN4b//FfmZF8MzF937 aqN1vcPv1Azl8suTcieePXrgRkfv0rpwRoYbZxLfVGqGKwnxvo9RPvEnqtri3aIjXLcZmbrKj5f 0dzIBAA== X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 In order to allow efficient implementation of GCS implementations are permitted to do GCS specific caching, with barriers implicit in stack switch operations and GCSB DSYNC as an explicit barrier. Since we do not use GCS in the hypervisor or host kernel the hypervisor cannot rely on any barriers being present in vCPU context switches other than those it explicitly inserts. Add explicit barriers when saving vCPU state, unless we're doing it due to a nested EL transition in which case there is no need since the guest will not change. Reviewed-by: Yuan Yao Reviewed-by: Leonardo Bras Reviewed-by: Lorenzo Stoakes (ARM) Signed-off-by: Mark Brown --- arch/arm64/kvm/arm.c | 18 ++++++++++++++++++ arch/arm64/kvm/hyp/nvhe/hyp-main.c | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index a148e80d0aef..2064cff8e92a 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -826,6 +826,16 @@ static void vhe_vcpu_put(struct kvm_vcpu *vcpu) if (vcpu_has_nv(vcpu)) kvm_vcpu_put_hw_mmu(vcpu); + /* + * Ensure any GCS memory effects from the outgoing vCPU are + * visible elsewhere, nested guests transitioning ELs do not + * need this. + */ + if (kvm_has_gcs(vcpu->kvm) && + !vcpu_get_flag(vcpu, IN_NESTED_ERET) && + !vcpu_get_flag(vcpu, IN_NESTED_EXCEPTION)) + gcsb_dsync(); + vcpu_put_mmu(vcpu); } @@ -836,6 +846,14 @@ static void nvhe_vcpu_put(struct kvm_vcpu *vcpu) kvm_timer_vcpu_put(vcpu); kvm_vgic_put(vcpu); kvm_vcpu_pmu_restore_host(vcpu); + + /* + * Ensure any GCS memory effects from the outgoing vCPU are + * visible elsewhere. + */ + if (kvm_has_gcs(vcpu->kvm)) + gcsb_dsync(); + vcpu_put_mmu(vcpu); } diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index 0c023ee0cf42..18030dd0dc0a 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -871,6 +871,13 @@ DEFINE_KVM_HOST_HCALL0(void, __pkvm_vcpu_put) sync_hyp_vcpu_state(hyp_vcpu); } + /* + * Ensure any GCS memory effects from the outgoing vCPU are + * visible elsewhere even if the host skips syncing. + */ + if (kvm_has_gcs(hyp_vcpu->vcpu.kvm)) + gcsb_dsync(); + pkvm_put_hyp_vcpu(hyp_vcpu); } } -- 2.47.3