From patchwork Thu Sep 26 01:34:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13812681 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B661CCFA10 for ; Thu, 26 Sep 2024 01:35:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5543B6B00BA; Wed, 25 Sep 2024 21:35:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4DA776B00BC; Wed, 25 Sep 2024 21:35:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 32C9C6B00BD; Wed, 25 Sep 2024 21:35:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 072D46B00BA for ; Wed, 25 Sep 2024 21:35:26 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 96CAEA06FE for ; Thu, 26 Sep 2024 01:35:25 +0000 (UTC) X-FDA: 82605171810.04.0B078B4 Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.201]) by imf12.hostedemail.com (Postfix) with ESMTP id DF68B4000C for ; Thu, 26 Sep 2024 01:35:22 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=bR+2CdIP; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of 3Wbr0ZgoKCN4JTHOUGHTONGOOGLE.COMLINUX-MMKVACK.ORG@flex--jthoughton.bounces.google.com designates 209.85.160.201 as permitted sender) smtp.mailfrom=3Wbr0ZgoKCN4JTHOUGHTONGOOGLE.COMLINUX-MMKVACK.ORG@flex--jthoughton.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727314486; a=rsa-sha256; cv=none; b=yTBjrtj5Wlnz3UM8dVmem6nZPG7jgwnQ39S8FB2RB9eI6iDyRKOGJXXQFc2qGrqq8OVoph OO4cEI0iIMOIEEwV3r3FfUSwWRYT7g7W3nJH+MycBsbS6doF9A6+cWs5S64C54uR5h4gO3 4/TkhJ7xgL8MtxVtRh3GqHcf9Jxrn2U= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=bR+2CdIP; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of 3Wbr0ZgoKCN4JTHOUGHTONGOOGLE.COMLINUX-MMKVACK.ORG@flex--jthoughton.bounces.google.com designates 209.85.160.201 as permitted sender) smtp.mailfrom=3Wbr0ZgoKCN4JTHOUGHTONGOOGLE.COMLINUX-MMKVACK.ORG@flex--jthoughton.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727314486; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZiB+e++yi01uCPO64xcLvipIH38DTgOpYlfSBrXkWpM=; b=nZfMz2rHpwyDAdcST4t557Z0kMXj/i78JxMewF1atP1Im1T6TNmteYgbssl9D6wpCzncRf IvpEpyp+seCI5fDc8qVnTv231GglxxLP9dZiZYeDnQNsjLJyKtzkghexvn+hBvd9F4kYqj aQpefxS7BLsNCV26ghJUUSP2zsrFA1I= Received: by mail-qt1-f201.google.com with SMTP id d75a77b69052e-458353d3635so9499241cf.0 for ; Wed, 25 Sep 2024 18:35:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727314522; x=1727919322; darn=kvack.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=ZiB+e++yi01uCPO64xcLvipIH38DTgOpYlfSBrXkWpM=; b=bR+2CdIPcvpJHh0a1zvXvi7svmoT2fEApXuCiS0k1UPrd13Z5PEP+wglieIsSk2RZa YdX/x4RsDs0I4reakX0ULEVYPpfhXEFTIcFIkw7vrm+gAqf8VKTu6p0CQfCQ2i99qFPK XQFB7BEJxLd5HGlqUvALG1kvCdRp+bYUrYpMAVUSoG2GnxhTvrSWYDDe0LEhzZkOg9X7 iClUaxXnkwwXEkjzLl2aqp5y0Cz6gBfLNVLhsJiyMRBHgso6rAS8uOWAeVpsPJ78g0z6 4FZs+/4cTfqMPm+qsdq3ZKUAAyrhjanMTvL7mVp6Sr971lxiphqjjuBQkYOKcepZ4zhI 7oAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727314522; x=1727919322; 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=ZiB+e++yi01uCPO64xcLvipIH38DTgOpYlfSBrXkWpM=; b=jvYOJptH/wNF7n601V3DDOrjZRTvteGys3TSC8iW92Yg4Dt3AAszm7x0ghVL1ZoFcS Axhs/hXL5Y9HDHTTA513+KaAy3XS/dWSmgO2tr3/Jd8yEUXvPzCEhiE1jT/g1PqRQ7Xn SRBSdyQ2Y4Nqs+6JvDNLkSlhsReTDyGVWLhCqKzXErsBHbpIn7UFqD052EcQ7coEruhG JzqPxyjAFy0qiLk/haoEDGcj4XtLj8wX94Zxb+6UaQ9YNog+f2g2nhJvzk5Paq2lVDYd f7TjJsQLAidXPAwFEU3INPHVOVGALwf0/LjQ5g0qm2bdFiR5X8lZ1JUSdiglG5WoZAlR bpbw== X-Forwarded-Encrypted: i=1; AJvYcCVQAWuzz7ntEZm9a5Lp0UsWj7O9WsvhlqaySpHcwYWahPaWzkDp4R77oKl8lwR5M69F/1JD7O6QMg==@kvack.org X-Gm-Message-State: AOJu0YxLzFGXUP7ZoZ1m+CSdF9DReLqgzxg5Ehv3XNWk2XYLEenQARTQ 46bcEV6sFrNMqIdITyzYuGurwr2g7U+Q6EY8TD6f6e73KnQ8MfSjgXAP84qimANUNGcEW0iFR4p zm1e2cYgr78m2baRs1A== X-Google-Smtp-Source: AGHT+IEij2jZTZ7Qfz4w3meuEhq8eeslauQ2yZtvTlXKLk5ZsUhbavG3fPazfw188lkIpQjxnlBFPCvmtl1c33sQ X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:13d:fb22:ac12:a84b]) (user=jthoughton job=sendgmr) by 2002:ac8:43cf:0:b0:458:4a61:2020 with SMTP id d75a77b69052e-45c9493ec3dmr13541cf.2.1727314521861; Wed, 25 Sep 2024 18:35:21 -0700 (PDT) Date: Thu, 26 Sep 2024 01:34:54 +0000 In-Reply-To: <20240926013506.860253-1-jthoughton@google.com> 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-7-jthoughton@google.com> Subject: [PATCH v7 06/18] KVM: x86/mmu: Only check gfn age in shadow MMU if indirect_shadow_pages > 0 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 X-Rspam-User: X-Rspamd-Queue-Id: DF68B4000C X-Rspamd-Server: rspam01 X-Stat-Signature: yiy551eb83i7616on7w3xjuhk6c8h3a4 X-HE-Tag: 1727314522-877493 X-HE-Meta: U2FsdGVkX1+NAFUuonPKw05nW5ddeJcJshE7pDBBxCPn583e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+2udRDfuLciRglin4plP/OTklCAF15iGVWU9Te37WTgERNhWnWMqajXdir5Ra/JjkaZi88vw0XfJLlrsfzm1b9xj3oPPLR956IlrPD5zTi6ZX9ixNSewNqi3ErHEcJ5hbswtC0h09VJ/VCBmnGr8hJ0JFKAs0N+mcPfqN8J7y5J+5G1gRPcsCGQQIZEPPQ0G2VNclPpC47ZTVFTP7sM0oXE+RQZOksMw2GJtPDz00AddCqny6BshJTXRcJ+7tiZ5tSg5/cYw6GS7R6svyi+wbNy0JmB2xNhTv2UPJxND0vQALJ9/u/TiuQHV3QmVnp/DRdhsDdSBYwaQuGC8gkYZJsbD+hwcdtNnFEw+wkoecNxI8PqFs2rKo45FQEBFFl6my3heTxzK69+hx2U/44tdrEswzKf98BtSLvLKJADNiO/j8kgRP+IJcIJGEhchL7UXUAzLBMmjNffGI1zEAcv2s5AXhcexqG8c1i17c+2qtKAVmAVGmMadzSGjH65Df5qA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000026, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Optimize both kvm_age_gfn and kvm_test_age_gfn's interaction with the shadow MMU by, rather than checking if our memslot has rmaps, check if there are any indirect_shadow_pages at all. Signed-off-by: James Houghton --- arch/x86/kvm/mmu/mmu.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 03df592284ac..b4e543bdf3f0 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -1645,6 +1645,11 @@ static bool kvm_rmap_age_gfn_range(struct kvm *kvm, return young; } +static bool kvm_has_shadow_mmu_sptes(struct kvm *kvm) +{ + return !tdp_mmu_enabled || READ_ONCE(kvm->arch.indirect_shadow_pages); +} + bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range) { bool young = false; @@ -1652,7 +1657,7 @@ bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range) if (tdp_mmu_enabled) young = kvm_tdp_mmu_age_gfn_range(kvm, range); - if (kvm_memslots_have_rmaps(kvm)) { + if (kvm_has_shadow_mmu_sptes(kvm)) { write_lock(&kvm->mmu_lock); young |= kvm_rmap_age_gfn_range(kvm, range, false); write_unlock(&kvm->mmu_lock); @@ -1668,7 +1673,7 @@ bool kvm_test_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range) if (tdp_mmu_enabled) young = kvm_tdp_mmu_test_age_gfn(kvm, range); - if (!young && kvm_memslots_have_rmaps(kvm)) { + if (!young && kvm_has_shadow_mmu_sptes(kvm)) { write_lock(&kvm->mmu_lock); young |= kvm_rmap_age_gfn_range(kvm, range, true); write_unlock(&kvm->mmu_lock);