From nobody Wed Apr 8 04:39:43 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 912733F23CF for ; Tue, 10 Mar 2026 23:49:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773186541; cv=none; b=UnAlSqcHKi2VpKqWhKI2GclF8flPucjC26tAAdUZka01uDnFLmh0ZV//lw4p29kPxRFBbxtYZxHNrWVZnRKjjQpHKPnUonwH27EnlDmVzsh21NyOg3B+MieeVmDzESjI/9wdd3ITjtHvBjxD97ZjgBebuY1iofMYnxKD6/6DHs8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773186541; c=relaxed/simple; bh=s5PHNN6ivra7JTqKpFtmgQ4VhrnCt+DVMv2IumBMKZQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=F83OvMrvflQWhvzOop4iwYhtKhyj11fXB2uC9oKiUOdx2Xa2/7yB2XDr9BPur2y6fqrdygotUf4MQ6QwX/NfzZpaSn8Bz5nxrp7rBdGMqjFkl3KhZp0sp16kgJzwIzmcLW1Ln/C9Xw8YakuqljZbX5bJWW/qeKg50ALnZSwFNnk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MeMrgjih; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MeMrgjih" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2ae3badc00dso115224895ad.3 for ; Tue, 10 Mar 2026 16:49:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1773186540; x=1773791340; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=v+UG8GmpftbH/hU/LDZZ4z/cbiXMAWddtqqIMRz+5yA=; b=MeMrgjihuw22a+0ulO/nBGiAgTcFplvjDfNWUI40kLa07iJK+J55UXNSJFbiLonhrW yR+FVR2T82MwIXIIRHNb31ULw56ZWQ9tK53d0zTLWOe5Y06KYKUNBcBc0N3YrSOjvSHK xEFt5zbHPOKRDZjPZGsT5jM0q9LX4WQo6Q1Nf3HtSt64ixkCuzbPlRgF2IWHDdj3vLqI 4r5dMkz9ND1zgOxg3Qt0svUVw0x1RXMuBjYDRMK3/YmpVuicMwnMIGCnWw8AXS8/QmZ9 yP9Mm7Fia99h+HbdOh00KhW48DCyOQy5MWXRcf5yBNrgUgXGEbBF0HGCngD1KcCMih/Y ouTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773186540; x=1773791340; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=v+UG8GmpftbH/hU/LDZZ4z/cbiXMAWddtqqIMRz+5yA=; b=FgMVM0xtHoovhH0vFSbMrH3bzv0u1eA/Rno5DMJ4R0yJFDw3VhN7Iq6OHOj7oswyFu VqSGAPjEwosnEjeT1p6fOS5aRirzBWknwtkf3L4o/5QqMS9AH6yJgKLmjqzujgOWYK+f c1P65f694kf2tSh3lxq1DjwsoZEUxIsmzfv2pxSQSqtWFivsm41GIHsh+oT9eZBBAknv b7ZwvmDoUY6YzrvqmwD5dZeRVm09/BbR6NBjXprVxdy/vVkXxRAJ34J9KDKR4n1qScqL LfjOj9e69EYK0vMxFTv9wHGr293s1X7OKs6dBlW9uowQ57xlwpDUqCYMpGMIgZOw7pu+ mkKg== X-Forwarded-Encrypted: i=1; AJvYcCXccSaxGkPG4Go/5e91dFkNSZuHJLyoPhQeKtgA7rYEXhBQLzOpnjJqp8igYiby6b3mKh8SxGK2og83+NQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyL5c7KriS00qcnOD6P8JQByqlzDtWlZAPM+h2FTsCODyzhF5NQ Vq9uxHQuuNbXrBqCOKXoSE30kfdKbeeQLi+RIL9HlcJqrfPeNAZNcWbXGMCjZNf2y/CPwYM0Oc7 PKdgwNA== X-Received: from pldy4.prod.google.com ([2002:a17:902:cac4:b0:2ae:3a49:7600]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:4b4b:b0:2ae:5eab:1338 with SMTP id d9443c01a7336-2aeae795720mr5642965ad.8.1773186539824; Tue, 10 Mar 2026 16:48:59 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 10 Mar 2026 16:48:22 -0700 In-Reply-To: <20260310234829.2608037-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260310234829.2608037-1-seanjc@google.com> X-Mailer: git-send-email 2.53.0.473.g4a7958ca14-goog Message-ID: <20260310234829.2608037-15-seanjc@google.com> Subject: [PATCH 14/21] KVM: SEV: Document that checking for SEV+ guests when reclaiming memory is "safe" From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Jethro Beekman , Alexander Potapenko , "=?UTF-8?q?Carlos=20L=C3=B3pez?=" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Document that the check for an SEV+ guest when reclaiming guest memory is safe even though kvm->lock isn't held. This will allow asserting that kvm->lock is held in the SEV accessors, without triggering false positives on the "safe" cases. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/sev.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 9a907bc057d0..7bb9318f0703 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -3296,8 +3296,14 @@ void sev_guest_memory_reclaimed(struct kvm *kvm) * With SNP+gmem, private/encrypted memory is unreachable via the * hva-based mmu notifiers, i.e. these events are explicitly scoped to * shared pages, where there's no need to flush caches. + * + * Checking for SEV+ outside of kvm->lock is safe as __sev_guest_init() + * can only be done before vCPUs are created, caches can be incoherent + * if and only if a vCPU was run, and either this task will see the VM + * as being SEV+ or the vCPU won't be to access the memory (because of + * the in-progress invalidation). */ - if (!sev_guest(kvm) || sev_snp_guest(kvm)) + if (!____sev_guest(kvm) || ____sev_snp_guest(kvm)) return; =20 sev_writeback_caches(kvm); --=20 2.53.0.473.g4a7958ca14-goog