From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 31B3C36A013 for ; Thu, 29 Jan 2026 22:23:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769725406; cv=none; b=jv40NBB/VED0S86yqZPgKzU7Fut5mivTFyzl+9uVA+15+p1KoPFzTXZfTVZKjX4ukFXxx1x5Lg/baU4rAEGYshGocZyEZ5Knpmzxzn+856VdNU3P1EwmmPWfqrC0PFpqwJJOLBHG/9LAVtrf77emkQJiog90vQ673gg7BCJm7pk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769725406; c=relaxed/simple; bh=XId/psBz2B6CRgPkYn1/L0PMl47eroAR8b7KTrFAN38=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=sGzLaz9g6u6R9w4tzsSWgFrIQjGW/WHqJXd5TPU8Ez1oKwPIrj81aYdWxK52cjhUkqQJWVY4iWUqbL+gk+96cXsz6FNumMMC6Znjcl3t87dkTuhzn9U5dU+Fnl3wo936iv0GkMdi8PIHjlv6VEvbaGC5vRD1Ydt6tLlwHrEOYAM= 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=bfwWZ9Aw; arc=none smtp.client-ip=209.85.216.74 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="bfwWZ9Aw" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-34ea5074935so1263653a91.0 for ; Thu, 29 Jan 2026 14:23:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769725404; x=1770330204; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=CjpoE/7MkU533iWOJXX/9jSCPi0JjIxUjWp+cR10TGk=; b=bfwWZ9AwhlrBj0Z61xrzMScoMjraIUfNpMG3VfxRuEKBBofb+Pzn/ZWKZ2P3Ch2p+Y xF15o8tocd9q9aYiNtcEvOVY27DxnwM/7on+At+vAzj8xAJ20+PBoc4ZoaJntnZj/3AH 6NDiVwOlYr9kYaK2W6HB2ByTMqaObMeXJh4X0bOBNZo+TIMOVdM5C7luW32vKwe9a7cr ah+hFUrduqDW9YeM1HuzeZcxxOmb6TMFETQkhAR5ZbZYbOiYANKyt5JdZ6DmKIarz9SJ ife/4514An3XPNlAAjbj5i2QdqogR5TyBVwJZ4l6ItEvlfYmSu7a2o3bOu+fegVY6QF6 vvUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769725404; x=1770330204; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=CjpoE/7MkU533iWOJXX/9jSCPi0JjIxUjWp+cR10TGk=; b=tdnvNpZWv5CMoTf2KTJwb+k11jYYBZAOaFLp3rpFZVpFjKSUIIbR7YbMb4tl0KmYmo eNRVfz+SSoWOiFPQCR5Wkx/gcSAbX6xdy/f43SJn8mNoEd1rXFEIxLFh8goehbzWh0nt kCfPbSOdQ7saA4uh6MFV+u/ZKUlft9KlGz6beKT/SLYBepwsnDnVvNCpaCT0XCMjhmYW V5/HxWMEvc/z5ly/Oy015NuGnd2S00/Tarsni/A6EHYi4rvHedmPpuWi0rVoS9cPmbgc BSUXnHcTQJmIE8bdLr5sWI9udqiiMjxJDZYO1xxXK6SCDtMqCNd/53tb2m2yTzAsVZ2B z01g== X-Forwarded-Encrypted: i=1; AJvYcCXcODurnZEtt7+3kV2EoTEeXEG1Y/I96yaZnT/Wplr+fkJuznFPdzV0T9Klg8si7ayfP/738AOsspOOML0=@vger.kernel.org X-Gm-Message-State: AOJu0YzGAVcKUE9sC1BjeTp9WusM83KVraDzSeJKMkzBzP3H+mr2vB/i /qsitnpPD8czJQRl/Nybo/by6nk5Puy0dZHGPDuunLLiRVyXMACAs6NY7094BFeoSZxSgTCPLSq J+JPZ+w== X-Received: from pjd11.prod.google.com ([2002:a17:90b:54cb:b0:353:28b4:c297]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:d445:b0:340:e8e9:cc76 with SMTP id 98e67ed59e1d1-3543b309885mr823538a91.11.1769725404404; Thu, 29 Jan 2026 14:23:24 -0800 (PST) Date: Thu, 29 Jan 2026 14:23:23 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260129011517.3545883-1-seanjc@google.com> <20260129011517.3545883-3-seanjc@google.com> Message-ID: Subject: Re: [RFC PATCH v5 02/45] KVM: x86/mmu: Update iter->old_spte if cmpxchg64 on mirror SPTE "fails" From: Sean Christopherson To: Rick P Edgecombe Cc: "x86@kernel.org" , "dave.hansen@linux.intel.com" , "kas@kernel.org" , "bp@alien8.de" , "mingo@redhat.com" , "pbonzini@redhat.com" , "tglx@kernel.org" , Kai Huang , "ackerleytng@google.com" , "sagis@google.com" , Vishal Annapurve , "linux-kernel@vger.kernel.org" , Yan Y Zhao , Xiaoyao Li , "kvm@vger.kernel.org" , "linux-coco@lists.linux.dev" , Isaku Yamahata , "binbin.wu@linux.intel.com" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Thu, Jan 29, 2026, Rick P Edgecombe wrote: > On Wed, 2026-01-28 at 17:14 -0800, Sean Christopherson wrote: > > Pass a pointer to iter->old_spte, not simply its value, when setting an > > external SPTE in __tdp_mmu_set_spte_atomic(), so that the iterator's va= lue > > will be updated if the cmpxchg64 to freeze the mirror SPTE fails. > >=20 >=20 > Might be being dense here, but is the bug that if cmpxchg64 *succeeds* an= d > set_external_spte() fails? Then old_spte is not updated and the local ret= ry will > expect the wrong old_spte. No, the bug is if the cmpxchg64 fails. On failure, the current mismatching= value is stored in the "old" param. KVM relies on the iter->old_spte holding the current value when restarting an operation without re-reading the SPTE from= memory. E.g. in __tdp_mmu_zap_root(), if tdp_mmu_set_spte_atomic() fails, iter->old= _spte *must* hold the current in-memroy value, otherwise the loop will hang becau= se it will re-attempt cmpxchg64 using the stale iter->old_spte. static void __tdp_mmu_zap_root(struct kvm *kvm, struct kvm_mmu_page *root, bool shared, int zap_level) { struct tdp_iter iter; for_each_tdp_pte_min_level_all(iter, root, zap_level) { retry: if (tdp_mmu_iter_cond_resched(kvm, &iter, false, shared)) continue; if (!is_shadow_present_pte(iter.old_spte)) continue; if (iter.level > zap_level) continue; if (!shared) tdp_mmu_iter_set_spte(kvm, &iter, SHADOW_NONPRESENT_VALUE); else if (tdp_mmu_set_spte_atomic(kvm, &iter, SHADOW_NONPRESENT_VALUE)) goto retry; } } > > =C2=A0 The bug > > is currently benign as TDX is mutualy exclusive with all paths that do > > "local" retry", e.g. clear_dirty_gfn_range() and wrprot_gfn_range(). >=20 >=20