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: 13740534 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 D3655C3DA63 for ; Wed, 24 Jul 2024 01:15:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=P6265Vr7ZBVKTm4Fxp+PtFVTNDBMV13LE1gmbTEV1Oo=; b=R23Qtqne0AQSVioBADImD7Hw4Q O1LgoWhf43FRBFYBytihDOZHQJw/LttJ8i8meTDR9gDXce9fcRasBG6fUBf6ea9VUf0C1L++5o7mv 33mjSkXYXC3HjFkrm6pJ47NUjmYIKpOQdpU2f3W+3L9CR0rnOfMUtPqucE4n6S1ZphQeiuxH855q+ f9YL6EKUuRwJ5CY94XqpsiomrcdIURPmPpfSyrXnHESbw9wAURSgCfhMmvS2GkHb/VcLDq+LBSVfc bkk6dbFtW16thTR2g03ZlUb747U7KVT9MyDVkSefdrJuMMH+H6vC/u+SYrL92EGnWEXqNhm2zWZ0o 7JIZMrvA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWQaz-0000000Dytx-1f0b; Wed, 24 Jul 2024 01:15:09 +0000 Received: from mail-ua1-x949.google.com ([2607:f8b0:4864:20::949]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWQXK-0000000DxCC-49KG for linux-arm-kernel@lists.infradead.org; Wed, 24 Jul 2024 01:11:24 +0000 Received: by mail-ua1-x949.google.com with SMTP id a1e0cc1a2514c-81f331938a1so1763601241.0 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=lists.infradead.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=rVwSyX+j0P+NBeXUwthAnf/zF8O3yU1tafHpB4o9gUhyYK4vP+XIQOUKR30yKCfeWH mdlcOCRIAHV6sMI23WLpS0c8fZNQXyXN467V2RGbFQpRHFKH7S7GucA+Y+y5BgqS0MZe CqOk3gV+Ec3Dh9TXCMKyyyePG2MBjlhgGPyOiG5JpGhMYOM5VdWQo6oa+gS8YSJb0f3c 8SZGmzLGgwSeOyaMWwSQ3p1F7RQlDzQOAU8Kh5i4ZuirYoHCVwf1HOtA000wU5LFe7XN hxc91RPow/olOBQYy/1xhnZQ9faYQWtPhImek/9F1RZHi1zy01dH8dhcUdHMCRyMcvGi SHoA== 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=afbfKNTUHvKLIBG+PF8W1NcFfioi4wIoTpRJ0wzZodyl7JA+kCqyH9R7vxN6GnyJ9V q7e4tpFJ2icJOXHimV/ixHzcEqU00yojQlMTpROfiLNBimUGtAucvZe6H72g0RVFp34m WTbbDZxNztQs4pE+s7VOVpNB7g2cOvj/6IvhoKVzygSUqoJ89XlIAkiWW6wxpseHHMQh +WtWPlJSj1PbE4fNawrXnFUNrHRjpMKXOE6b7D/rdjE/oNr8lmVC6JIqMCQBr08Fda1N 8Zz59B2r5AbWD6RjlBYBxK81gtVJkk76UNY6YweJ+HpQetDrCPjHvpEhVqexO8h37ol4 Qq1w== X-Forwarded-Encrypted: i=1; AJvYcCXg03RrwVnoKvpVY7Baf8gQ8KHJgkqYK0u/k5Q/c/IiBTC40ETgVI+GecgiaOKLly0VTIWvmOnNWCYnFJhL8tfPWg1kBsyUKQvX+W75ziFTyBXmzSQ= X-Gm-Message-State: AOJu0Ywq62MwtQ/eEGB4Q13/xEXVDMPGBmMdN1CcNO0oyqGcz7Jmi6Kr 5KxCf9L6Uc6nK1fSXcaWqoRiemBm+59Tmo8kVaniLAHJm9wfAXgVm5CeCPvNdIW68dHzVwU7By4 JSvPA/S10+s1uERTvIA== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240723_181123_049687_0944D4E1 X-CRM114-Status: GOOD ( 14.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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);