From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (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 2B3FD383991 for ; Mon, 24 Aug 2026 21:49:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787608166; cv=none; b=ugMN+EvL/QnP+Yg/kvMRRBkCsEvl2lJFmjuHP3o6S4Eub/fcBEGMSxtqSaqjcukjL0k+Np4y7UlsVI1wG6rj1jNql7WQt3iF3sQY9w6j2YMv1q6vVEnY1uEmGdELf/N1jGD+OGgYpoM1DGAtY9PBopBRt02xqkkMrS2mZesvH98= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787608166; c=relaxed/simple; bh=DdTBAQmYMGrMKj5qeC5Xmn1n4sUZQvGckJhixywAtpQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KTM14SYHd/lCNXJbaymSwLmhi6Bpe3GKja+uS9QC3cbVg7TF41UwzhUyo41yDdP29NpiHM2954+JWYflR7R35bV/XosGvDTLElmC0+ndRPB0uns6DDs1n8+4eUz6Ywty1jTgacYJohIxcYzNu3BgkWPAL74nLp6xdoC+RLecdLQ= 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=E6kOBltD; arc=none smtp.client-ip=209.85.215.198 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="E6kOBltD" Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-cab3e9cd922so2628111a12.0 for ; Mon, 24 Aug 2026 14:49:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1787608164; x=1788212964; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=fjc9nPW/BJpn6YJpX0n6jTXAEmBsoOmQkD4iHgcEHec=; b=E6kOBltDQCmiTQcXEvf0G2dHqNAi3mv9UWM/IqWJVujzt8idiNgwOUEPjgSLmuJYUB pBaxKSWYO1nqCaEHpT1SjDsztKrmHkUnJfLiT6TOrZARNJgQN9qbv0PyhE50NS4xMjHn nYUIipJiUS6T7GC8YAhAZOATG7dG+yMoOjNkTgF7xoP+HrrcKEiJsScD3i3ferZZOHUt nGtInoZzMASKZyqyfS8uWVP3i8G2ho+vwqgrftZ5CduNW/3ZJhKAhGyrS0FXWNeuSfr3 t04gw4BN65O/LLnaTC7q2nY6ur3tq1Ryqbu7v9taEhmocenGRxwnMIlpVvSL3W0winNr bhOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787608164; x=1788212964; h=content-transfer-encoding:content-type: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 :content-type; bh=fjc9nPW/BJpn6YJpX0n6jTXAEmBsoOmQkD4iHgcEHec=; b=rZ3e3bWMDBFDwQCi1HsjDc52mA3zsmqTsew9GrIYruO7qInKbi+7SGjQU4mczYRBlW 61ajAdsZmG5O8sRC3vKRxpgXcsPyCTGkaR8qAw2VVi+799D6N3NvPEj5IwHHx2uqMrCm 6lES2pC7P6JxYCs/KR8NnT8h82s/RMlJK1gaIECgNhfJ7yxlSLNWCqQtPnx6EwbNIxHo mvWXo4f6QNoBvkEfapOncR3siftcf8leLQs0Ti2Ru6mq2EL45U3Vh972pxm2moqCEWLL DMGYFJ/7M3lxOawVikuFjs8q38gHgLQZHGTyHll+CwfeCEw9iz84Gpe0eSd5uSAiE2KP 5rgA== X-Forwarded-Encrypted: i=1; AHgh+Rry4Hhs7xt/qutoIwf2nadosqsUQniQauueaIeCVC1ZBtqY9t+mtsTyY4tXBEq05NT51zatFccsSQYT/Wc=@vger.kernel.org X-Gm-Message-State: AFuF++kmNcnOT+GVs/APJHaYTqbE3dkAbS3zIa0puCSPrqo7TnPS10/7 3XV0obzoI2ftXdd4G4albGBo+2CAU1pyvvN47M/hbqSkNUIqG39//ShEXPRP81fDL8yz3iMoqVQ O1kOWEQ== X-Received: from pghp7.prod.google.com ([2002:a63:fe07:0:b0:cc1:507b:e025]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:1ca8:b0:84c:1cd2:142b with SMTP id d2e1a72fcca58-8523c8f0862mr3243509b3a.9.1787608164138; Mon, 24 Aug 2026 14:49:24 -0700 (PDT) Date: Mon, 24 Aug 2026 14:49:23 -0700 In-Reply-To: <303eb59af516335e288647c19254928f89fa833a.camel@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260822190224.3788887-1-nicoyip.dev@gmail.com> <303eb59af516335e288647c19254928f89fa833a.camel@intel.com> Message-ID: Subject: Re: [PATCH] KVM: x86/mmu: Protect noncoherent DMA zaps with SRCU From: Sean Christopherson To: Kai Huang Cc: "nicoyip.dev@gmail.com" , "linux-kernel@vger.kernel.org" , "bp@alien8.de" , "x86@kernel.org" , "hpa@zytor.com" , "mingo@redhat.com" , Yan Y Zhao , "dave.hansen@linux.intel.com" , "tglx@kernel.org" , "pbonzini@redhat.com" , "stable@vger.kernel.org" , "kvm@vger.kernel.org" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Mon, Aug 24, 2026, Kai Huang wrote: > On Mon, 2026-08-24 at 10:49 -0700, Sean Christopherson wrote: > > Alternatively, what if we have kvm_zap_gfn_range() acquire SRCU?=C2=A0 = Nesting "locks" > > is a-ok, and two of the three users of kvm_zap_gfn_range() have had thi= s bug (see > > commit 074c00800719 ("KVM: x86: Use SRCU to protect zap in > > __kvm_set_or_clear_apicv_inhibit()"). >=20 > kvm_vcpu_srcu_read_lock() doesn't allow nesting lock of KVM's SRCU. No, kvm_vcpu_srcu_read_lock() doesn't allow nested usage of itself. Commit 2031f2876896 ("KVM: Add helpers to wrap vcpu->srcu_idx and yell if it's abu= sed") added the protection because we had multiple bugs where KVM would clobber vcpu->srcu_idx and cause a deadlock by leaking a grace period reference. > Doesn't seem to be a problem for this particular case, though, because > sev_handle_rmp_fault() calls kvm_zap_gfn_range() after > kvm_vcpu_srcu_read_lock() is called. kvm_vcpu_srcu_read_lock() can nested inside an existing kvm->srcu critical = section, just so long as the existing critical section isn't tracking its grace peri= od via vcpu->____srcu_idx.