From patchwork Wed Jul 24 01:10:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13740505 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 D8CCEC3DA63 for ; Wed, 24 Jul 2024 01:11:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A38DA6B0099; Tue, 23 Jul 2024 21:11:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E9BE6B0098; Tue, 23 Jul 2024 21:11:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C6EE6B0099; Tue, 23 Jul 2024 21:11:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 531EC6B0096 for ; Tue, 23 Jul 2024 21:11:24 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 14C7040546 for ; Wed, 24 Jul 2024 01:11:24 +0000 (UTC) X-FDA: 82372868088.08.9E77D48 Received: from mail-ua1-f74.google.com (mail-ua1-f74.google.com [209.85.222.74]) by imf07.hostedemail.com (Postfix) with ESMTP id 5A8E540008 for ; Wed, 24 Jul 2024 01:11:22 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=4DFSQj5R; spf=pass (imf07.hostedemail.com: domain of 3uVSgZgoKCCAFPDKQCDPKJCKKCHA.8KIHEJQT-IIGR68G.KNC@flex--jthoughton.bounces.google.com designates 209.85.222.74 as permitted sender) smtp.mailfrom=3uVSgZgoKCCAFPDKQCDPKJCKKCHA.8KIHEJQT-IIGR68G.KNC@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721783419; 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=P6265Vr7ZBVKTm4Fxp+PtFVTNDBMV13LE1gmbTEV1Oo=; b=8QcE/Ya8JIoDVwY+l6iXL6O3XgeLce/vo/MbftAW/a5ssaarc0rzId9bmSabrlgys0b+vD AJU0hsdWq2rFmus7CbkA3y3ClEB8yN+1RckeWcqnRyYeOC1yWeuKtya7cc3pCtCMcKmWVl pCB0MnAucsE3EtVsE+JMrjp53lMqfIQ= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=4DFSQj5R; spf=pass (imf07.hostedemail.com: domain of 3uVSgZgoKCCAFPDKQCDPKJCKKCHA.8KIHEJQT-IIGR68G.KNC@flex--jthoughton.bounces.google.com designates 209.85.222.74 as permitted sender) smtp.mailfrom=3uVSgZgoKCCAFPDKQCDPKJCKKCHA.8KIHEJQT-IIGR68G.KNC@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721783419; a=rsa-sha256; cv=none; b=S7sCkkEXOHTtcE/b3rtDBJnRM6Ts0tCTTvpZboUeSxKY7N0bHS1UMvvk584ldcY8AKyoL0 Rm4DscjxMXdlihOPhO93byhjpk5TbgGJmbXprlqmP+u6aOuMWtRGZ82WH6LaPmmy50cvt5 Ds7OPz4t2iGE2ioS9GroWrICKWfJmS8= Received: by mail-ua1-f74.google.com with SMTP id a1e0cc1a2514c-821ba96962bso1585438241.1 for ; Tue, 23 Jul 2024 18:11:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721783481; x=1722388281; 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=P6265Vr7ZBVKTm4Fxp+PtFVTNDBMV13LE1gmbTEV1Oo=; b=4DFSQj5R/jRcSeHwzG03ImFWqyqdOLPDw1Orn7gQOYnA8V7Te3Tcdd2lNjlt7l5I4p DLvxCqn5YC0ivO6/qHFsgDHh2N4GOoDIuk8ztXCNoNmQADuyHmdYhDrz+6OwfGddmZtJ B+kI9PeUWzAdW72UfgaDy4r5RV73ekLK/+R876wsOVXul83rUrx4F6B3fjArl1/MrDI3 9wH/+UYZ/DVdPCSxqMPWcj8g0RM1oz9ZXHa3VC0BHaeYB7dM0QjYvIw7Pm/XXJ6njAfO Y+HetsSeM8dIKKzYRuwJq7ZQJsoQuBN3mYdrNGXU4iy26P9Du5hbc+fH4H7XBvfVfcW/ lL2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721783481; x=1722388281; 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=P6265Vr7ZBVKTm4Fxp+PtFVTNDBMV13LE1gmbTEV1Oo=; b=qiPF7PYT4tpGKwtxKsKLWyyeGGRHkyANh4izn9m8pnkHl7NlUkrHrV1FZvB5ALoTUc WU5u7HGEcdKrh1VrnNcq9NwPNlD/us23eCDfsq4pEVXUnIEQrSrU2xwaeYPYD71MKBge XvbL1VHkNN+5U367Z+QdhK1DPCq5lpPGNpn17U50sQ91gj0WpbLSwaxyT2bm6SPtnd/1 1neH9lGtNrF+kf1x9q1DO/D7o5QaPpxgSdPBSsxfYkAMSiIAS/loLb7TbrUGG8m6PCDX wdTISg4THbpj5m2Q2ydUk5kO+jb/Yh9nQatYxh8SD9r6dKuQrsUuoMU4qlf3LM5cu5Th 70Kw== X-Forwarded-Encrypted: i=1; AJvYcCVXdEVvBOFVcOLfWV4e0iSa7P0SGm37VIWC6ZCkhdBUSCtFxsJKxnddJvBb8mmfvnT1ScsapE39zgT5iwzejqhw0iY= X-Gm-Message-State: AOJu0YxJLokvQ1qvtDXBPN8b+CjngCnFaOgtLSPN5iykYMAT+vz16b2g I5bSxXi399mZsQmmzcNOG3wHabPjcofCbooWZ4ZMyfuEKgeW4yelSjsAB7t7duRcLi+88Z7EX6+ 9QD/dyXxuipioPfFuHQ== X-Google-Smtp-Source: AGHT+IGFz1kYjtJ2CB63i3kpIK8cbKQBNz86a9KHHAO5xzKcY+Rn5KgcFneR9rdE9iF/27GJgdzSYep0JZHDL1qb X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:6102:358f:b0:48c:403d:4428 with SMTP id ada2fe7eead31-493c4b17e64mr40150137.4.1721783481412; Tue, 23 Jul 2024 18:11:21 -0700 (PDT) Date: Wed, 24 Jul 2024 01:10:34 +0000 In-Reply-To: <20240724011037.3671523-1-jthoughton@google.com> Mime-Version: 1.0 References: <20240724011037.3671523-1-jthoughton@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240724011037.3671523-10-jthoughton@google.com> Subject: [PATCH v6 09/11] KVM: x86: Implement fast_only versions of kvm_{test_,}age_gfn From: James Houghton To: Andrew Morton , Paolo Bonzini Cc: Ankit Agrawal , Axel Rasmussen , Catalin Marinas , David Matlack , David Rientjes , James Houghton , James Morse , Jason Gunthorpe , Jonathan Corbet , Marc Zyngier , Oliver Upton , Raghavendra Rao Ananta , Ryan Roberts , Sean Christopherson , Shaoqin Huang , Suzuki K Poulose , Wei Xu , Will Deacon , Yu Zhao , Zenghui Yu , kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org X-Rspam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VRIBI+N8kYzJoKjYhVoOBE4PSd v7Ju5NOU Xk6DX8EVzzYfWcaHZdHtaG6Nk5n/ukO/Jb+eQ0X/v1e0e1+tNWeFeed2+mC1AUpxlHCp7f/TYuf2VmsZnhVZLwwCmBO6E9wRdYCCS/tlfLh18flFB4sbiQTgLaVQwgqBXGbVxzBoAqWfpNC7p4/WF+vyUaQJDL4ZMH9LQ74L6C0mexzwZDg7xEBPqN3vS7UwDZmOI8heuKoDx+wiL2yIapajhY64L4aoeTZjx8xRY2mmH4IRGNi2jY16d6Qp+NQR7mS3ZDsDDh4yHFqvqep8Y1LEsOETX0vrzqt5av6b5Mfj0oEeTLOzb9J7JigmzQr8aCf0RJxH/rcOR2CRwGgP3q454OJpa4ExeW7vbG1gn3XH2s/QGSE/9zBrpWNGQU502GSqyLQOQox6mbIkUS6xOOIGlNmR+wqPtTcVqNpleYa/UVp/cuHP+BbgMH3e6wuBMW+UPX2jJ3O4+b58sL/yMNxRBk+jn6hu4ujfGHKkBr48YtNTiMCdAjfMyKCUw1HFozffvFHyy6ZKuag18CiXiibsl+QZeJzPkqtPt7kQ0L8AEDEjGau47MzNaIaFyt1BVq8ygjzsbYCZIwpKnBirPO7xwjQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: These fast-only versions simply ignore the shadow MMU. We can locklessly handle the shadow MMU later. Set HAVE_KVM_MMU_NOTIFIER_YOUNG_FAST_ONLY for X86_64 only, as that is the only case where the TDP MMU might be used. Without the TDP MMU, the fast-only notifiers will always be no-ops. It would be ideal not to report has_fast_only if !tdp_mmu_enabled, but tdp_mmu_enabled can be changed at any time. Signed-off-by: James Houghton --- arch/x86/kvm/Kconfig | 1 + arch/x86/kvm/mmu/mmu.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig index 6ac43074c5e9..ed9049cf1255 100644 --- a/arch/x86/kvm/Kconfig +++ b/arch/x86/kvm/Kconfig @@ -24,6 +24,7 @@ config KVM select KVM_COMMON select KVM_GENERIC_MMU_NOTIFIER select KVM_MMU_NOTIFIER_YOUNG_LOCKLESS + select HAVE_KVM_MMU_NOTIFIER_YOUNG_FAST_ONLY if X86_64 select HAVE_KVM_IRQCHIP select HAVE_KVM_PFNCACHE select HAVE_KVM_DIRTY_RING_TSO diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 919d59385f89..3c6c9442434a 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -1641,7 +1641,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_has_shadow_mmu_sptes(kvm)) { + if (!range->arg.fast_only && kvm_has_shadow_mmu_sptes(kvm)) { write_lock(&kvm->mmu_lock); young = kvm_handle_gfn_range(kvm, range, kvm_age_rmap); write_unlock(&kvm->mmu_lock); @@ -1657,7 +1657,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_has_shadow_mmu_sptes(kvm)) { + if (!young && !range->arg.fast_only && kvm_has_shadow_mmu_sptes(kvm)) { write_lock(&kvm->mmu_lock); young = kvm_handle_gfn_range(kvm, range, kvm_test_age_rmap); write_unlock(&kvm->mmu_lock);