From patchwork Wed Jul 24 01:10:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13740532 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 02FADC3DA49 for ; Wed, 24 Jul 2024 01:14:31 +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=xYFUlEH9+669o/RlL44au3jQWbYqLeFR1nQhpVmQt2k=; b=LLi4hWUEswWE2oxWPQN7QeiEOR HqMfHwAPcm6THAqlvF1q6wMZmluYVUrDK0veMI04XE+DE1lPQ1AGW5CUdOpxsAj9gx6iHR4SS22dj T96s/gIs2ri0Yt7wleedAxDbncW118QE1ku2IuGgWT+AD1y0J759FfAA4/E6A9kQzkgNS8vOdr1/A Rh22BljOZHMOFawTcouzL4f5WC8XER614gCeuQw6vWDqT3jt6m1EPDsUhx1gDhJjsl87ulWls5y4B p0q00rPbtMLeirdqe3k2mPj3E36RGhDnkM1sTbfU/6bVfbNuIua4G5WQfxRnnOtpTnUmzRty/6DSf ce335vLQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWQaD-0000000DyZp-28zX; Wed, 24 Jul 2024 01:14:21 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWQXI-0000000DxAz-3HAA for linux-arm-kernel@lists.infradead.org; Wed, 24 Jul 2024 01:11:22 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-66c0f57549fso108221157b3.0 for ; Tue, 23 Jul 2024 18:11:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721783479; x=1722388279; 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=xYFUlEH9+669o/RlL44au3jQWbYqLeFR1nQhpVmQt2k=; b=3mblQ7bnD8u+a2CVxyi7vmBVmcFwlsMG5PH3wLbfsSM1HGJkIxgZuKZgcnBpa/rbZX sMIuZk2kwSJGchnaIAjLbYwDdPg91276oyyduvHvtW3E33DvNITkF26J2njMKlFWYKAq eX64LVrqEgKHSQXAFqtCLd1Jfu1OOcdNGK4lrCPBNy8iGGNMx/fscL5OqXbPBR1t8Tbj jSwrgVtLZ1R61KCe3FQ+7lK7g+qqJvfG9WrHiztTNnliE4y2azlpApxm3SU+VK3B1UCs yY3tesv9TYvnMcVKQmsDiXmA2vFPaCPUXDtwaZExsRGXb5423f6tw3KXc0XKSyqWTIgU HZxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721783479; x=1722388279; 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=xYFUlEH9+669o/RlL44au3jQWbYqLeFR1nQhpVmQt2k=; b=g88MK9jCwhC8fKjHwI5nKiAfO2XRbSVn0P603QJuYixAIz80Vhf5j+W1Qn00dpXcFs wI55ZLtnWoiq7HH/qwBs9WKO7gVk6INXQhJ/GWXvZaDdL6M6P1uLq/+OkP4yBI4/XSpJ BLe9HLWk6YlCdxtKzqB0zuJUO27LepUdbrE/CW1/gKHLD0Wth/MgnZPfzIcGAGfMYaQv fQ9Qh0LI5hB8XHeBq4phKZf5Q/PxDICGHoGIff7OLfVXLB740OG1eRTFJbFhnCl57MsS tNVmUgEKx+o9SgffrN6H9HscvKxTgBvpL5+p7ZmNhPG5TLo4D4swVOveK7jaiAPLNNUe ZSTQ== X-Forwarded-Encrypted: i=1; AJvYcCUa9ve8V2SaOVmQ4zZvtwczIlw7rc9bzu+2SkoyaQ61a4qOMfAhen2z1ThiPVkgmCU5uNl74SM/u+SDXWAdmNhutAHL60uZ+JaN74YNS2t0MXDw5CY= X-Gm-Message-State: AOJu0YzrNordqY38dYcbz+WraTIvX01n+93Hkh2NaQdCnT/Ts5qFr2ua ghCErYElxAlAmQ+JsIesGAbc15NPJjOMM5hvAEJ+4ABV2raf7kqoxAVhXvWHvxempreW/EHBPQ+ zEQYPn6KT2MQjZNXdag== X-Google-Smtp-Source: AGHT+IEN/Y2KcEHN/92i673drFtDbgqlQb3JUSQlrIWx5MUp4ovVZHssNawTpvQt6yIfvMN/stHEpv668SrbKdDV X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:690c:289:b0:630:28e3:2568 with SMTP id 00721157ae682-671f1095e3fmr479257b3.3.1721783479490; Tue, 23 Jul 2024 18:11:19 -0700 (PDT) Date: Wed, 24 Jul 2024 01:10:32 +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-8-jthoughton@google.com> Subject: [PATCH v6 07/11] KVM: Pass fast_only to 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_181120_865569_201FFAA1 X-CRM114-Status: GOOD ( 13.80 ) 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 Provide the basics for architectures to implement a fast-only version of kvm_{test_,}age_gfn. Add CONFIG_HAVE_KVM_MMU_NOTIFIER_YOUNG_FAST_ONLY that architectures will set if they non-trivially implement test_young() and clear_young() when called with fast_only. Signed-off-by: James Houghton --- include/linux/kvm_host.h | 1 + virt/kvm/Kconfig | 4 ++++ virt/kvm/kvm_main.c | 37 +++++++++++++++++++++---------------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 8cd80f969cff..944c5fba2344 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -258,6 +258,7 @@ int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu); #ifdef CONFIG_KVM_GENERIC_MMU_NOTIFIER union kvm_mmu_notifier_arg { unsigned long attributes; + bool fast_only; }; struct kvm_gfn_range { diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig index 632334861001..cb4d5384c2f2 100644 --- a/virt/kvm/Kconfig +++ b/virt/kvm/Kconfig @@ -103,6 +103,10 @@ config KVM_GENERIC_MMU_NOTIFIER config KVM_MMU_NOTIFIER_YOUNG_LOCKLESS bool +config HAVE_KVM_MMU_NOTIFIER_YOUNG_FAST_ONLY + select KVM_GENERIC_MMU_NOTIFIER + bool + config KVM_GENERIC_MEMORY_ATTRIBUTES depends on KVM_GENERIC_MMU_NOTIFIER bool diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 959b6d5d8ce4..86fb2b560d98 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -697,18 +697,20 @@ static __always_inline int kvm_handle_hva_range(struct mmu_notifier *mn, static __always_inline int kvm_handle_hva_range_no_flush(struct mmu_notifier *mn, unsigned long start, unsigned long end, - gfn_handler_t handler) + gfn_handler_t handler, + bool fast_only) { struct kvm *kvm = mmu_notifier_to_kvm(mn); const struct kvm_mmu_notifier_range range = { - .start = start, - .end = end, - .handler = handler, - .on_lock = (void *)kvm_null_fn, - .flush_on_ret = false, - .may_block = false, - .lockless = + .start = start, + .end = end, + .handler = handler, + .on_lock = (void *)kvm_null_fn, + .flush_on_ret = false, + .may_block = false, + .lockless = IS_ENABLED(CONFIG_KVM_MMU_NOTIFIER_YOUNG_LOCKLESS), + .arg.fast_only = fast_only, }; return __kvm_handle_hva_range(kvm, &range).ret; @@ -900,7 +902,8 @@ static int kvm_mmu_notifier_clear_young(struct mmu_notifier *mn, * cadence. If we find this inaccurate, we might come up with a * more sophisticated heuristic later. */ - return kvm_handle_hva_range_no_flush(mn, start, end, kvm_age_gfn); + return kvm_handle_hva_range_no_flush(mn, start, end, kvm_age_gfn, + fast_only); } static int kvm_mmu_notifier_test_young(struct mmu_notifier *mn, @@ -911,7 +914,7 @@ static int kvm_mmu_notifier_test_young(struct mmu_notifier *mn, trace_kvm_test_age_hva(address, fast_only); return kvm_handle_hva_range_no_flush(mn, address, address + 1, - kvm_test_age_gfn); + kvm_test_age_gfn, fast_only); } static void kvm_mmu_notifier_release(struct mmu_notifier *mn, @@ -926,17 +929,19 @@ static void kvm_mmu_notifier_release(struct mmu_notifier *mn, } static const struct mmu_notifier_ops kvm_mmu_notifier_ops = { - .invalidate_range_start = kvm_mmu_notifier_invalidate_range_start, - .invalidate_range_end = kvm_mmu_notifier_invalidate_range_end, - .clear_flush_young = kvm_mmu_notifier_clear_flush_young, - .clear_young = kvm_mmu_notifier_clear_young, - .test_young = kvm_mmu_notifier_test_young, - .release = kvm_mmu_notifier_release, + .invalidate_range_start = kvm_mmu_notifier_invalidate_range_start, + .invalidate_range_end = kvm_mmu_notifier_invalidate_range_end, + .clear_flush_young = kvm_mmu_notifier_clear_flush_young, + .clear_young = kvm_mmu_notifier_clear_young, + .test_young = kvm_mmu_notifier_test_young, + .release = kvm_mmu_notifier_release, }; static int kvm_init_mmu_notifier(struct kvm *kvm) { kvm->mmu_notifier.ops = &kvm_mmu_notifier_ops; + kvm->mmu_notifier.has_fast_aging = + IS_ENABLED(CONFIG_HAVE_KVM_MMU_NOTIFIER_YOUNG_FAST_ONLY); return mmu_notifier_register(&kvm->mmu_notifier, current->mm); }