From nobody Thu Oct 31 00:25:04 2024 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (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 4928414C596 for ; Thu, 1 Aug 2024 18:35:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722537309; cv=none; b=rZEh2HXSi87nFsnR05Ncz3w4ahQWAYcxhLz4WS4/x6yYnnN4lTjaeaDor7GAV/STFJCZ6MOhbFRaiLIcTNdDYoE0uW7NPgI0ME7EWENAv8D6MpvBmBP3TY7u6pjotSCq8iM0IpN25fWtyq9qZVbxCScz7D1uc3pq6dKIhrifG5A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722537309; c=relaxed/simple; bh=/XSoRdfaJzNo/ZGf04C230tSmY5GFwai1Y6z9V+ll3s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TbOroBtNPsgZ8kSwXADjqkLE6M6mIUW3icrru3skLkkiXqNX+ukdEkdWy6hIdJPSlZ/h4x9hQFXgLhCmCX1nwCmPwfHgghUQRel4mySgfiIUEOI4p6Fwwt9PrsZUbVVMBLF9cRd7Z7SkkmAChcutOudIJgO3TJhlZ3upQP39ggk= 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=T6f4Ughv; arc=none smtp.client-ip=209.85.210.202 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="T6f4Ughv" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7104f37771eso2359045b3a.2 for ; Thu, 01 Aug 2024 11:35:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722537308; x=1723142108; 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=YgfeHTUFXLVGjVFJpfNzwAaN7GsDEU7AXhuO1w5LlJU=; b=T6f4UghvEEptu57168f+L/zM2OSsfTUEmq1aYaownOtHbbaFnbOQ8PWU0JuKJgce0H 9fQZZawMVXL1956CtTaup8jRe66DfJ2jxln5sAhr19titUwv3w2uBWqXPqqVv6dd5WTu cGEgRY1qU5xXsf66qMwFiRjqe1LhSabKEpXXdGiP8fkoZFZ/AXnxagDFTf506ChfutbB BerF3q22V5B07c89wofMVqoMFo/AZJvDayCRHBYir2P56J1tZ7SoqPkDBHGQY5kJMLAd LCfJVXCXpldMdtKUwjNRwX2jOX+xLfvMyHOearGAJAIiUZPadY5Q6Hq2DGw2t2lH8qkY Il3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722537308; x=1723142108; 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=YgfeHTUFXLVGjVFJpfNzwAaN7GsDEU7AXhuO1w5LlJU=; b=klE+UCHLhe0f02uEL2TL3bRfIWOntPDfw8bK+zG70Ar+aWzA99eCSJUCUARnGPbY+q oEDtLBr6Bw1L/YajSoQUCt6nEr5cXatJy5mpocaOpfmW9o5YeZNGiz7ketxErVHVUBJG /lBmonlb9BjIDEhVV9DAf7HqmT5pE0frubChvm7CKUd+1q5RyRLyvCahkwlptpGjq+jX 7vwjScDbEWIsnip7z+kzy9EdojUOuPPT7cVMrkeBydHcTZiAi9ibkc3GT/12V4wqBaKM u+SJ+gZgBOZBnfZGx33WG2+Wn27h+RTun4PycZHosTKNPihEl73PKRJqbYSq/P6tRlLc DtIA== X-Forwarded-Encrypted: i=1; AJvYcCXoyeFjOSXPYRnUmveFntHCvI0Hr1TlT74vAPREikkMvpMGatKcYJgmREfnn8yz5kqbcA10pu+Y8oSMHjnZVajYJYPvpOiSGg91dn/Q X-Gm-Message-State: AOJu0YyR6PX5V+xtX2f/Vs1QISStcxEDHZY971OlGFGW9hdf62jjl7xx n9cccR33C07ydWqFKSVaMYjkcLz0T/i1YqbIqGLYMT5IiPRg2IRf04qkbxs8T1bdg/l4/vdMGcC qRA== X-Google-Smtp-Source: AGHT+IHTWEhjwHtp09vWEbUgtVyznzcr5+x5rCkfOWJrq49bIvfwRkVTlE43qqkCOx+dDWfaukt6/MOxYM0= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:949c:b0:705:ca19:2d08 with SMTP id d2e1a72fcca58-7106d0ca7camr8792b3a.6.1722537307533; Thu, 01 Aug 2024 11:35:07 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 1 Aug 2024 11:34:50 -0700 In-Reply-To: <20240801183453.57199-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: <20240801183453.57199-1-seanjc@google.com> X-Mailer: git-send-email 2.46.0.rc2.264.g509ed76dc8-goog Message-ID: <20240801183453.57199-7-seanjc@google.com> Subject: [RFC PATCH 6/9] KVM: x86/mmu: Process only valid TDP MMU roots when aging a gfn range From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Skip invalid TDP MMU roots when aging a gfn range. There is zero reason to process invalid roots, as they by definition hold stale information. E.g. if a root is invalid because its from a previous memslot generation, in the unlikely event the root has a SPTE for the gfn, then odds are good that the gfn=3D>hva mapping is different, i.e. doesn't map to the hva that is being aged by the primary MMU. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/tdp_mmu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 2b0fc601d2ce..b358642890e1 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -1202,9 +1202,11 @@ static __always_inline bool kvm_tdp_mmu_handle_gfn(s= truct kvm *kvm, =20 /* * Don't support rescheduling, none of the MMU notifiers that funnel - * into this helper allow blocking; it'd be dead, wasteful code. + * into this helper allow blocking; it'd be dead, wasteful code. Note, + * this helper must NOT be used to unmap GFNs, as it processes only + * valid roots! */ - for_each_tdp_mmu_root(kvm, root, range->slot->as_id) { + for_each_valid_tdp_mmu_root(kvm, root, range->slot->as_id) { rcu_read_lock(); =20 tdp_root_for_each_leaf_pte(iter, root, range->start, range->end) --=20 2.46.0.rc1.232.g9752f9e123-goog