From nobody Fri Nov 29 03:52:42 2024 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 C9DA418133C for ; Thu, 26 Sep 2024 01:35:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727314523; cv=none; b=Gjd5kHaMipquF/U76m+ejUJh8S9X1nk8vyaburjnCEp/axspagsSD2oabowO45DbP6v6lVIY705egeK0uBud118ntnR3QNHZWe5+c+hJ6ge0GDvVY+ZPvwB/RByRH1zu/BL9u2Cw/UE1f8+smEmxCi0p1JzSbb7b7N/42lcoHgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727314523; c=relaxed/simple; bh=MSP16v22spRDZgdygkuPyo99YM6MsaYwZUFeeUwYgi0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=alGgkjuovq/EZhG+RqwtQ6MlKxbD/qUtemZmcZuEejdYcO13I2+plJ9LW38zMejBMoE30wMUgfuhgUAXe15+JAmNOLvzZiyPo2f0OLjYNgPDBTdOXGDLqqQm5fCxIhneFEipX6KPZEMD6ohkr8KOoeV19XrKWuZJXvfbAa4O2ck= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jdNQFy2N; arc=none smtp.client-ip=209.85.219.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--jthoughton.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jdNQFy2N" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e0353b731b8so688954276.2 for ; Wed, 25 Sep 2024 18:35:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727314521; x=1727919321; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dAogBQT7i8/Ut4GrJolXC+/DUS73zZR+MbirDcTLTRg=; b=jdNQFy2NwTQ/OEl/hYfrxySWsR8l5S0fLcHy36u1gHEPeSSqeOIURi7gCyXgLwvZpc AQO1EgdhVH3Wyclw+tAf6dHCbiRyIfIkv8PSQUMww8F7cTGmOPQrYag7f3ktOutu/fG9 Ka5UoTl5Ll9GXwft750H3YchpS0SzknkFW/yX71291unvDA/ifaiGSfi03T7dFhYlg7l 6ydSFpeOKNqgE6lsec/GLG7e9oKL2XPyGQ+vPRpZErDtqYk6GWnjSAEUVgoCnnejuHm6 D3Y9FWxHPs9CFnd7czVolKBHWenxIu/YR/fBx+Nn8dSyp8HrqhX34PgGc8fcyvzLphHZ L/dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727314521; x=1727919321; h=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=dAogBQT7i8/Ut4GrJolXC+/DUS73zZR+MbirDcTLTRg=; b=RhWTcGDbPFsS1Rw2HwvVsKQOQR8jp8jCJzKRcpih8nqFdOxUzWBJ+0eMi5XGV2fAt9 AAwWrzCccdNsEesi8QMDC4JdlL57H4lGPF6YgdBoE1L8H2JriQ1JipiPeu1rLUekyssJ HJkv4zAikskKUWrahR6hapTV1XkAl7X6LpGcFZGAxkVIvUkfcb9oyOEoVFvqCXyotg80 QC6wzFvBJL2JBGAqJyW5MWsWlhcAj96b0kBNjWcN4hIqXId5lnzuuQcGJ3fzax7TjTpy LX28+HdPhLyWlraWZD9ZLwaLvehi5rigd1gfrLWjLD132PAVvlgudSFVVvu43oWbtqHG GwPQ== X-Forwarded-Encrypted: i=1; AJvYcCWad55uH4CS4UGT0PLu59S0ctwsBbBb0G3cXvX8LVl1FTW1fAcaGVw3khmfXH2oGH05oTGAN8VepdnZoFE=@vger.kernel.org X-Gm-Message-State: AOJu0YyxBF5DUpzVFxabhv3TzFXIBzZnsuV6OSbyoddczRXR/ovzxm4K DuYqh9z+TGnptEgdQytG7amEhNmOGX1eoQyrzX1O9goz+54yNugpFhdyFS1FmABSCw5/73AwW6l SzKAzD6jV8HxzZ1zkOg== X-Google-Smtp-Source: AGHT+IFQs3DNBWoE9LT9ciS2x6yC/841ISG2URP+wJo+4FsamoM+oSoqTqpMkGycanRDnHNwxgVEwB1O11ztgMfN X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:13d:fb22:ac12:a84b]) (user=jthoughton job=sendgmr) by 2002:a05:6902:1782:b0:e11:7a38:8883 with SMTP id 3f1490d57ef6-e24d9613a90mr3400276.7.1727314520739; Wed, 25 Sep 2024 18:35:20 -0700 (PDT) Date: Thu, 26 Sep 2024 01:34:53 +0000 In-Reply-To: <20240926013506.860253-1-jthoughton@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240926013506.860253-1-jthoughton@google.com> X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog Message-ID: <20240926013506.860253-6-jthoughton@google.com> Subject: [PATCH v7 05/18] KVM: x86/mmu: Rearrange kvm_{test_,}age_gfn From: James Houghton To: Sean Christopherson , Paolo Bonzini Cc: Andrew Morton , David Matlack , David Rientjes , James Houghton , Jason Gunthorpe , Jonathan Corbet , Marc Zyngier , Oliver Upton , Wei Xu , Yu Zhao , Axel Rasmussen , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Reorder the TDP MMU check to be first for both kvm_test_age_gfn and kvm_age_gfn. For kvm_test_age_gfn, this allows us to completely avoid needing to grab the MMU lock when the TDP MMU reports that the page is young. Do the same for kvm_age_gfn merely for consistency. Signed-off-by: James Houghton --- arch/x86/kvm/mmu/mmu.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 355a66c26517..03df592284ac 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -1649,15 +1649,15 @@ bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_ra= nge *range) { bool young =3D false; =20 + if (tdp_mmu_enabled) + young =3D kvm_tdp_mmu_age_gfn_range(kvm, range); + if (kvm_memslots_have_rmaps(kvm)) { write_lock(&kvm->mmu_lock); - young =3D kvm_rmap_age_gfn_range(kvm, range, false); + young |=3D kvm_rmap_age_gfn_range(kvm, range, false); write_unlock(&kvm->mmu_lock); } =20 - if (tdp_mmu_enabled) - young |=3D kvm_tdp_mmu_age_gfn_range(kvm, range); - return young; } =20 @@ -1665,15 +1665,15 @@ bool kvm_test_age_gfn(struct kvm *kvm, struct kvm_g= fn_range *range) { bool young =3D false; =20 - if (kvm_memslots_have_rmaps(kvm)) { + if (tdp_mmu_enabled) + young =3D kvm_tdp_mmu_test_age_gfn(kvm, range); + + if (!young && kvm_memslots_have_rmaps(kvm)) { write_lock(&kvm->mmu_lock); - young =3D kvm_rmap_age_gfn_range(kvm, range, true); + young |=3D kvm_rmap_age_gfn_range(kvm, range, true); write_unlock(&kvm->mmu_lock); } =20 - if (tdp_mmu_enabled) - young |=3D kvm_tdp_mmu_test_age_gfn(kvm, range); - return young; } =20 --=20 2.46.0.792.g87dc391469-goog