From patchwork Wed Jul 24 01:10:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13740531 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 AE81EC3DA63 for ; Wed, 24 Jul 2024 01:14:09 +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=RjwIFwaGyFm0pqYoSJRPlexY59ZZdKZ6ixfPL8P7AvM=; b=VKm2K6OtZcbHrG8eLkfRH37h+9 1Da8KuhluR1crN1sxVdn7cCwVW5XBObE9IfladESp6Pw6LBoAvt3rhjDEZ9XBTDmsptrrKBwrSHFq pL+cTnJ7QXY5X91THb/I3GjE7AiUW1q70xnTf+r1hWH2IXSs5OdMC6tByqomn6ZbAe8fg7DkHR35T F6aOf6jWhzEyIHRxNDXhCnJl90XXRfi2JFTH56VZjz4C/Den+KEK+OK7xrHLL0yknv3iBVRfxWnso O/D4/GRB3MDpnkBC++C45CimbXRoCj/Oo76ppSy0j1tNqibGV9+Eop95AJ5M48OQ5PJzp7suqSbTR cFoRryMQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWQZq-0000000DyQp-0qHz; Wed, 24 Jul 2024 01:13:58 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWQXI-0000000DxAD-1KLf for linux-arm-kernel@lists.infradead.org; Wed, 24 Jul 2024 01:11:21 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-e087c6181e9so8134717276.3 for ; Tue, 23 Jul 2024 18:11:19 -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=RjwIFwaGyFm0pqYoSJRPlexY59ZZdKZ6ixfPL8P7AvM=; b=RTe41U3GgaP6E6s6y5vtkNwdnnHO2mxwr9Aqp84ksgHDGBpQuRim+8BVl+DrH03P1R xs/k5ggUCe5V8kp7tNuIitPE6k2oIzVuwt48FzkU5XXgHQlNCHPBkWu5mYCNk+C684hi O3zPQB7sdg1YpClgLhIRYs2nGNjkdmxfkHP4Hyhl/in2VEotJdNE7ZEAoWoco1YHCDnS qkvlsjP1uE6NuJwDe0MyQQe8c0w+e/wRY3EmAkts36xV+g8Es+xkQpsbXgk/j9T9i0kP X6ZEhfb+EXso6OGcGI/58XhIY0YpYe0IG3nuPWtQWZAZq7c/BC7EVK2e0esPTDvZ2W6i gdLg== 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=RjwIFwaGyFm0pqYoSJRPlexY59ZZdKZ6ixfPL8P7AvM=; b=fDOC4p8nQkGOlFVXiC9bv20tGM1d9VxML0ztSwp+qQpEIOKW1jlgl3xXy86qSrSSCZ Qz/cprOyguRJymRKsq2aK5vDOYvKeXNX/T6uw6VwwL3xrob5nlJlwU7tVy+dCxrsOPYe QF3rl7aP/0givR8im/sB+pbSh4pEb/rkGOubmchx6knHeEAMmeS14weqLHB49D9LbwEJ RQ8aoH3g5DAac+iiaAaYSJtFdZF2noQKbKBtL8DDro8nduP1QItusTSHV9TCh1NvKMOU E1a9xQRYvit7ntSZW3Zj2sLAVGquDHD6Bx4Y7+QdNZjhi0NkLtc0l+JNemBYxMG+isJH M9cg== X-Forwarded-Encrypted: i=1; AJvYcCWq8WKIGMsOkyo6gc85A+n4ehp0tgBbLnADYjUZ76H+v+WyBg29P4/0B1OcuV/0xOS2AkXgKlem0GlTDGO1iapAyqNmFE+ymk/qvoZUb80lXuINjYE= X-Gm-Message-State: AOJu0YxUyLoHc34XHWv5d/TRf4VyV72VC5Mpm2qqWN3/x37kJ92K29Na jtUL8RpYvCfjpY1j7Ds4GmKquJ+3rn7u+mwfULUskQGMkF+lFf8E6STkMG5/0RO+BLSwrFqS/hJ jhyYqnI4DVWINZN1YSg== X-Google-Smtp-Source: AGHT+IEf8LhPu+J2AQj8JKbpYxC+Q+/7UmZG6e+vLGbTXrpNe4bcC8God4ZSRUYFG8d6cpp91FbqTUc9FhMyYUjh X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:6902:20ca:b0:e08:5554:b2be with SMTP id 3f1490d57ef6-e0b0e60b370mr1189276.9.1721783478588; Tue, 23 Jul 2024 18:11:18 -0700 (PDT) Date: Wed, 24 Jul 2024 01:10:31 +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-7-jthoughton@google.com> Subject: [PATCH v6 06/11] mm: Add has_fast_aging to struct mmu_notifier 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_457358_9C620DDF X-CRM114-Status: GOOD ( 16.10 ) 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 has_fast_aging should be set by subscribers that non-trivially implement fast_only versions of both test_young() and clear_young(). Fast aging must be opt-in. For a subscriber that has not been enlightened with "fast aging", the test/clear_young() will behave identically whether or not fast_only is given. Given that KVM is the only test/clear_young() implementer, we could instead add an equivalent check in KVM, but doing so would incur an indirect function call every time, even if the notifier ends up being a no-op. Add mm_has_fast_young_notifiers() in case a caller wants to know if it should skip many calls to the mmu notifiers that may not be necessary (like MGLRU look-around). Signed-off-by: James Houghton --- include/linux/mmu_notifier.h | 14 ++++++++++++++ mm/mmu_notifier.c | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h index 45c5995ebd84..e23fc10f864b 100644 --- a/include/linux/mmu_notifier.h +++ b/include/linux/mmu_notifier.h @@ -233,6 +233,7 @@ struct mmu_notifier { struct mm_struct *mm; struct rcu_head rcu; unsigned int users; + bool has_fast_aging; }; /** @@ -387,6 +388,7 @@ extern int __mmu_notifier_clear_young(struct mm_struct *mm, extern int __mmu_notifier_test_young(struct mm_struct *mm, unsigned long address, bool fast_only); +extern bool __mm_has_fast_young_notifiers(struct mm_struct *mm); extern int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *r); extern void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *r); extern void __mmu_notifier_arch_invalidate_secondary_tlbs(struct mm_struct *mm, @@ -449,6 +451,13 @@ static inline int mmu_notifier_test_young_fast_only(struct mm_struct *mm, return 0; } +static inline bool mm_has_fast_young_notifiers(struct mm_struct *mm) +{ + if (mm_has_notifiers(mm)) + return __mm_has_fast_young_notifiers(mm); + return 0; +} + static inline void mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) { @@ -653,6 +662,11 @@ static inline int mmu_notifier_test_young_fast_only(struct mm_struct *mm, return 0; } +static inline bool mm_has_fast_young_notifiers(struct mm_struct *mm) +{ + return 0; +} + static inline void mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) { diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index f9a0ca6ffe65..f9ec810c8a1b 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -382,6 +382,26 @@ int __mmu_notifier_clear_flush_young(struct mm_struct *mm, return young; } +bool __mm_has_fast_young_notifiers(struct mm_struct *mm) +{ + struct mmu_notifier *subscription; + bool has_fast_aging = false; + int id; + + id = srcu_read_lock(&srcu); + hlist_for_each_entry_rcu(subscription, + &mm->notifier_subscriptions->list, hlist, + srcu_read_lock_held(&srcu)) { + if (subscription->has_fast_aging) { + has_fast_aging = true; + break; + } + } + srcu_read_unlock(&srcu, id); + + return has_fast_aging; +} + int __mmu_notifier_clear_young(struct mm_struct *mm, unsigned long start, unsigned long end, @@ -394,6 +414,9 @@ int __mmu_notifier_clear_young(struct mm_struct *mm, hlist_for_each_entry_rcu(subscription, &mm->notifier_subscriptions->list, hlist, srcu_read_lock_held(&srcu)) { + if (fast_only && !subscription->has_fast_aging) + continue; + if (subscription->ops->clear_young) young |= subscription->ops->clear_young(subscription, mm, start, end, @@ -415,6 +438,9 @@ int __mmu_notifier_test_young(struct mm_struct *mm, hlist_for_each_entry_rcu(subscription, &mm->notifier_subscriptions->list, hlist, srcu_read_lock_held(&srcu)) { + if (fast_only && !subscription->has_fast_aging) + continue; + if (subscription->ops->test_young) { young = subscription->ops->test_young(subscription, mm, address,