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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 9E19BCCD1A5 for ; Fri, 17 Oct 2025 00:35:13 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4cnm5J19hrz3dK8; Fri, 17 Oct 2025 11:33:24 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::1049" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1760661204; cv=none; b=F7QdYYt8j6bbySyXEaTHq0NbPa3CnLbX2FQdVnCrvC2k/mQ4RhZ6+oWk5yey/rHM9CEugaBiPPWeZF4cDF5vox7Npx/7W5GIQbC3fuptEwNs3+TmcptHzWWYKsVxaYi3hPFj5O7cCdoeMZdAukjcVQopBh5hiDqp2IfwdA6kFkOrH03GctnZmyasd3UQq2Lw2JY1rbO2nJz8Rr6GJ+byJHXw03N0PptWYD5IV2NL7cfrZ7HLER/IKH1wei2B3A8M3fKKLtXeFN+D4jxFvigi/xyIe2UNqBzg5UVsYujuJK+6/0bzh5UI8tigRO23KB/V73dANGAwqGR0oUE3FXaYqA== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1760661204; c=relaxed/relaxed; bh=6nFGgJBVWEpkJy+c6A8c/BAOcJuYsJfcEhqI0sTwd+k=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ZeFzR92nv0LSD4vXtovsKMdfoJrXtEAQWFKdctBx3/oas45MxzvqiNyvtXkdtYgjlqbwnk7WzgFfbIDhokLQm7HnDvGaBbPzUlQSlQUvI6kiY0/Ot/xv8vRJhHyud3H4UHmXRUels/sEQM/x3R6OOx2ppjqt0Rtose0TxBLAy+WABHveTLK7MDgyJu4lIW1zAMQZVqaTi1pehl91685t+6mXcO+Ky53JkUx/keFrG4XZQIxZGXwf/HhYZzCKBZHdV8ge4fp9Lh43OzQ9uCK3YgdgshKIy6OdzCUp1w/VP3HHGouE5pDLITxPghxevM0nO4VJplznC9D+nrJp8kdvIg== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=s+8Cc8Mh; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::1049; helo=mail-pj1-x1049.google.com; envelope-from=30y7xaaykdaqwierngksskpi.gsqpmry1ttg-hizpmwxw.s3pefw.svk@flex--seanjc.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=s+8Cc8Mh; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--seanjc.bounces.google.com (client-ip=2607:f8b0:4864:20::1049; helo=mail-pj1-x1049.google.com; envelope-from=30y7xaaykdaqwierngksskpi.gsqpmry1ttg-hizpmwxw.s3pefw.svk@flex--seanjc.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4cnm5H3FSJz3dLK for ; Fri, 17 Oct 2025 11:33:23 +1100 (AEDT) Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-33bcb7796d4so677235a91.0 for ; Thu, 16 Oct 2025 17:33:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760661202; x=1761266002; darn=lists.ozlabs.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=6nFGgJBVWEpkJy+c6A8c/BAOcJuYsJfcEhqI0sTwd+k=; b=s+8Cc8Mh9HOS3nl5JrJVfxEGYM6QW2M2ZyFyLV7+sVUARfamdRgiLGJNgAl9oOGNAW xzVeo4CFjSeA1s6pw6/iMoMEQffawzPStXIIVQ8OTId6NK1zxiWSg8fgBHPPbGbX81C2 amBHtaUXndYBdoCIABqux4DnmaV25eBxTMWX2P1c/5FVAuTM7su7NyIxt7Dp8/GAH0ck XSWwGiJDAcNzd4+nX7XotKtXBFp6kxDoKXOft30Toe+wyr5oX05fBHe5ugTLOG4qVnVB Ic1+6x3t5VOYAIualwK32O4layNWNzf3paBA+E8NLH/ly+N6ienm72+8WGfLmSqEqsPX kbYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760661202; x=1761266002; 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=6nFGgJBVWEpkJy+c6A8c/BAOcJuYsJfcEhqI0sTwd+k=; b=rGO6DgwvBoDn8dqSAZVVVaNxe884H5YvIDnMncl681EApBYOsl+2Y52/Sha4XsqeMp hJlsN7SP+9hzxc5S3+nMMLkrI58kVV04KQq+9QgcovcDGG8enSsGeiNIemOiVy94irAq JR6RDVVInfKpIfdVXY7g5RW3shQQQCe//pN4O3NqWN/Cnsm2Gcf65A2YKEnUG86Ivw2L w8KAs1/nknH6CuQWj5tKT03EyD1ymYCZyj7zlEo2zk6wb0at9pRiJxx4bvHZl1daZOQP xnuqULta3ttUEcjZQTnWtUSsD1FtoqtGXCtMHTE8/3yynz9NviqqSOoYeCEGOYcXCxu1 GDGg== X-Forwarded-Encrypted: i=1; AJvYcCUbgzTfQdjJrIemNQv9ClS4Zmp4l+fT086Z7k8d/FyGuo54dQtOtQN4w6Mpe4ouQ8Ao8EW52D7robnY97o=@lists.ozlabs.org X-Gm-Message-State: AOJu0YztwBhXmltZ7mCLTgfKen/MCPau/1nPYzlZkianH5XCd4iifd2C bfsnu2qh5cHKrsIfOBoIPlS4iUMJrk4Tt9NHQjG97Gqv6u+9oaTIMN7qTi7cOO+NdYsXrfQ0NM3 miUK10A== X-Google-Smtp-Source: AGHT+IGwUk2DKc/Clop/mYKkbeytMt0iZD/Bzj0bONucI419CZOE9/NPfh2luTSi9dr6fi1GHUAnQKjomOI= X-Received: from pjnu19.prod.google.com ([2002:a17:90a:8913:b0:329:ec3d:72ad]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4fc6:b0:330:6d5e:f17e with SMTP id 98e67ed59e1d1-33bcf8faaeamr1865014a91.24.1760661201850; Thu, 16 Oct 2025 17:33:21 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 16 Oct 2025 17:32:37 -0700 In-Reply-To: <20251017003244.186495-1-seanjc@google.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: Precedence: list Mime-Version: 1.0 References: <20251017003244.186495-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251017003244.186495-20-seanjc@google.com> Subject: [PATCH v3 19/25] KVM: TDX: Assert that mmu_lock is held for write when removing S-EPT entries From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Madhavan Srinivasan , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini , "Kirill A. Shutemov" Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, x86@kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, Ira Weiny , Kai Huang , Michael Roth , Yan Zhao , Vishal Annapurve , Rick Edgecombe , Ackerley Tng , Binbin Wu Content-Type: text/plain; charset="UTF-8" Unconditionally assert that mmu_lock is held for write when removing S-EPT entries, not just when removing S-EPT entries triggers certain conditions, e.g. needs to do TDH_MEM_TRACK or kick vCPUs out of the guest. Conditionally asserting implies that it's safe to hold mmu_lock for read when those paths aren't hit, which is simply not true, as KVM doesn't support removing S-EPT entries under read-lock. Only two paths lead to remove_external_spte(), and both paths asserts that mmu_lock is held for write (tdp_mmu_set_spte() via lockdep, and handle_removed_pt() via KVM_BUG_ON()). Deliberately leave lockdep assertions in the "no vCPUs" helpers to document that wait_for_sept_zap is guarded by holding mmu_lock for write. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/tdx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index e517ad3d5f4f..f6782b0ffa98 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1711,8 +1711,6 @@ static void tdx_track(struct kvm *kvm) if (unlikely(kvm_tdx->state != TD_STATE_RUNNABLE)) return; - lockdep_assert_held_write(&kvm->mmu_lock); - err = tdh_mem_track(&kvm_tdx->td); if (unlikely(tdx_operand_busy(err))) { /* After no vCPUs enter, the second retry is expected to succeed */ @@ -1758,6 +1756,8 @@ static void tdx_sept_remove_private_spte(struct kvm *kvm, gfn_t gfn, gpa_t gpa = gfn_to_gpa(gfn); u64 err, entry, level_state; + lockdep_assert_held_write(&kvm->mmu_lock); + /* * HKID is released after all private pages have been removed, and set * before any might be populated. Warn if zapping is attempted when -- 2.51.0.858.gf9c4a03a3a-goog