From mboxrd@z Thu Jan 1 00:00:00 1970 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 4061DC4345F for ; Fri, 19 Apr 2024 20:35:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C8306B007B; Fri, 19 Apr 2024 16:35:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7782A6B0082; Fri, 19 Apr 2024 16:35:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 618A36B0083; Fri, 19 Apr 2024 16: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 42AD36B007B for ; Fri, 19 Apr 2024 16:35:26 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A0DC4C156B for ; Fri, 19 Apr 2024 20:35:25 +0000 (UTC) X-FDA: 82027436610.17.C00711B Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) by imf21.hostedemail.com (Postfix) with ESMTP id E2F661C0003 for ; Fri, 19 Apr 2024 20:35:22 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=AekFLSOc; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf21.hostedemail.com: domain of jthoughton@google.com designates 209.85.160.180 as permitted sender) smtp.mailfrom=jthoughton@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713558922; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4Y0px2zCMzPrnpLTJJ0/3e4JM7/QQstbfzC053pVTkI=; b=WboAYkRTelW9rxA6xPr7bMtVgoPRYTo7DI+nGgDvASGbfjQetH2YJNZsGSdBat4HOP3SGD ArdppPBtIKU2VpCHW/3J2Oo5bKzyMw9Gk973PAocgd4obu9Ep1Ejkdy2c/LS0qKGct57Jq 8/Bjz35tDZEhtC4Nh7iylIlWGbdNK8E= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=AekFLSOc; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf21.hostedemail.com: domain of jthoughton@google.com designates 209.85.160.180 as permitted sender) smtp.mailfrom=jthoughton@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713558922; a=rsa-sha256; cv=none; b=t+s8fQPQx9I1dmKIEKQf4mjdQSZMOPmfFXe3qWdQIapqHwYb88gTyndfTHOww7QeqYcfPO 5OTG/iMwciHvz7fHsgbGnnWXDbeQk7LjkO4D1UU6XnX1/XRYk6mfEAXa7LjfK5pfXzQYx5 0bKh7v9D9EfpR5wDBN0QWwiyK9u43Cc= Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-436ed871225so21061cf.1 for ; Fri, 19 Apr 2024 13:35:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713558922; x=1714163722; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=4Y0px2zCMzPrnpLTJJ0/3e4JM7/QQstbfzC053pVTkI=; b=AekFLSOck2suMuY3WAb7ophSijDWQLuv7816YLgdIBTYsqMD7tVrdquvpn9+NvHlL6 GGi9nfDzmXiPwDQqOavL1rABG43aDutqqwydnc+YRYZKPdX1l/GqiqBvasaADNrIx9pS SgtedPaIY28N32CTzVANr2jXZfDwx8ZQhg8I4YziDMKYOquRv57G5Ql3X95va/bDqZ9T aQUmJiMXrJ9Y7D4cpd9UKDqgJ/z9ROUX1ZTinUomWF4IiK7MavYtsn/fIMhz1p/ONBoh IWnhU7wB0ygNMC3ZhPmu7TuPZCHoABXsVNP3DmAHDY3tG6P30uWOWc50qDJOoWs3864Z BKDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713558922; x=1714163722; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4Y0px2zCMzPrnpLTJJ0/3e4JM7/QQstbfzC053pVTkI=; b=VjWNfI8C+fPAXN1aIkgLlaBeFXCRJi234OCKKX1U0nudGLe0tJnYRk8GSn/lpbOOxU /0LlrJTkGObG156pkeMZnS4R+uwQngTEzIJ0e3SqFO3B3xeU4NHzW4ihjX9h4k/g2RrE tnW4r0vT0q3c0qSvlfAMIkgtCV/+d0Ye60VTTJn+cPbQ0YBlKGlVYKxmqlIuZhNGMnpn NS/5Ml8aEEL8jAOzMs7AKC5x8y59ZCoB1OA4hlDX+VWZDPq2djSJxow5bPUcmb/J8VnH T2I20Z3AK1lTzQkTinj7g5eMZGQBHA6X852NSAO6wa5DybZkLQvbA9AGH1lwVxW75dks 0SRg== X-Forwarded-Encrypted: i=1; AJvYcCUuaVFYpCkUppSZsWDaNJS9ZrVlauKvAM5cegnaXBqQWGzTPZSxuv0VZOPiA0/Y+SCV4ufedpxe2sLEhVqUILtcPTA= X-Gm-Message-State: AOJu0YyrTcpJVxOop/zi3A6YJLwbs/f8w9UiIH1I1sr0F67j0BT7SEh6 CTagiqAf3bGA2bNiLRvBlGYcTUcOoKz3yEJqh1Fj4Ea+8VJ1SfJMMBfZ94mRTtR5saXkRfz4WCA blAX56AhsKNW4EEj3mfrLdoYjT/QJUYAGz2h1 X-Google-Smtp-Source: AGHT+IHkJfmmAPvCAeL3PHiy9LxcBKxU4sSXwU9Wa6fLPfcfMdaU+/fg9082O+N/4bGE4vTBhG7w/N+0y3iUY9ReW7w= X-Received: by 2002:ac8:74cf:0:b0:437:b867:5782 with SMTP id j15-20020ac874cf000000b00437b8675782mr6844qtr.19.1713558921674; Fri, 19 Apr 2024 13:35:21 -0700 (PDT) MIME-Version: 1.0 References: <20240401232946.1837665-1-jthoughton@google.com> <20240401232946.1837665-2-jthoughton@google.com> In-Reply-To: From: James Houghton Date: Fri, 19 Apr 2024 13:34:44 -0700 Message-ID: Subject: Re: [PATCH v3 1/7] mm: Add a bitmap into mmu_notifier_{clear,test}_young To: David Matlack Cc: Andrew Morton , Paolo Bonzini , Yu Zhao , Marc Zyngier , Oliver Upton , Sean Christopherson , Jonathan Corbet , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Shaoqin Huang , Gavin Shan , Ricardo Koller , Raghavendra Rao Ananta , Ryan Roberts , David Rientjes , Axel Rasmussen , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E2F661C0003 X-Rspam-User: X-Stat-Signature: xkuo5u8ugxdp6d1dkkuc8sond35efdb1 X-HE-Tag: 1713558922-517735 X-HE-Meta: U2FsdGVkX18TZ/UvHy7Cx0rz9CpJqv6eZHjhLrpjApowG8y2XkFiAGOg6oNdmGJiOcNT8HYYNnvTpK8h+Yo1OqHg4r2mrTs9GQNmSmBEtqIJ32hJMewbaDolhCCio3b/4c1FGFlVJ9eF7dFcCfDF10J1bCo5JCQKzukniUo5qli+qIhBbBe5p5aC4o1xOvUtDu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fTymz4ASpKmySMR83+YrPAtewFgNmLfYG+8kXoSefjwB40CvjG93GHcRqAj7mzRE= 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: On Fri, Apr 12, 2024 at 11:45=E2=80=AFAM David Matlack wrote: > > On 2024-04-01 11:29 PM, James Houghton wrote: > > The bitmap is provided for secondary MMUs to use if they support it. Fo= r > > test_young(), after it returns, the bitmap represents the pages that > > were young in the interval [start, end). For clear_young, it represents > > the pages that we wish the secondary MMU to clear the accessed/young bi= t > > for. > > > > If a bitmap is not provided, the mmu_notifier_{test,clear}_young() API > > should be unchanged except that if young PTEs are found and the > > architecture supports passing in a bitmap, instead of returning 1, > > MMU_NOTIFIER_YOUNG_FAST is returned. > > > > This allows MGLRU's look-around logic to work faster, resulting in a 4% > > improvement in real workloads[1]. Also introduce MMU_NOTIFIER_YOUNG_FAS= T > > to indicate to main mm that doing look-around is likely to be > > beneficial. > > > > If the secondary MMU doesn't support the bitmap, it must return > > an int that contains MMU_NOTIFIER_YOUNG_BITMAP_UNRELIABLE. > > > > [1]: https://lore.kernel.org/all/20230609005935.42390-1-yuzhao@google.c= om/ > > > > Suggested-by: Yu Zhao > > Signed-off-by: James Houghton > > --- > > include/linux/mmu_notifier.h | 93 +++++++++++++++++++++++++++++++++--- > > include/trace/events/kvm.h | 13 +++-- > > mm/mmu_notifier.c | 20 +++++--- > > virt/kvm/kvm_main.c | 19 ++++++-- > > 4 files changed, 123 insertions(+), 22 deletions(-) > > > > diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.= h > > index f349e08a9dfe..daaa9db625d3 100644 > > --- a/include/linux/mmu_notifier.h > > +++ b/include/linux/mmu_notifier.h > > @@ -61,6 +61,10 @@ enum mmu_notifier_event { > > > > #define MMU_NOTIFIER_RANGE_BLOCKABLE (1 << 0) > > > > +#define MMU_NOTIFIER_YOUNG (1 << 0) > > +#define MMU_NOTIFIER_YOUNG_BITMAP_UNRELIABLE (1 << 1) > > MMU_NOTIFIER_YOUNG_BITMAP_UNRELIABLE appears to be unused by all callers > of test/clear_young(). I would vote to remove it. Works for me. > > > +#define MMU_NOTIFIER_YOUNG_FAST (1 << 2) > > Instead of MMU_NOTIFIER_YOUNG_FAST, how about > MMU_NOTIFIER_YOUNG_LOOK_AROUND? i.e. The secondary MMU is returning > saying it recommends doing a look-around and passing in a bitmap? > > That would avoid the whole "what does FAST really mean" confusion. I think MMU_NOTIFIER_YOUNG_LOOK_AROUND is fine. > > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > > index fb49c2a60200..ca4b1ef9dfc2 100644 > > --- a/virt/kvm/kvm_main.c > > +++ b/virt/kvm/kvm_main.c > > @@ -917,10 +917,15 @@ static int kvm_mmu_notifier_clear_flush_young(str= uct mmu_notifier *mn, > > static int kvm_mmu_notifier_clear_young(struct mmu_notifier *mn, > > struct mm_struct *mm, > > unsigned long start, > > - unsigned long end) > > + unsigned long end, > > + unsigned long *bitmap) > > { > > trace_kvm_age_hva(start, end); > > > > + /* We don't support bitmaps. Don't test or clear anything. */ > > + if (bitmap) > > + return MMU_NOTIFIER_YOUNG_BITMAP_UNRELIABLE; > > Wouldn't it be a bug to get a bitmap here? The main MM is only suppost > to pass in a bitmap if the secondary MMU returns > MMU_NOTIFIER_YOUNG_FAST, which KVM does not do at this point. > > Put another way, this check seems unneccessary. > > > + > > /* > > * Even though we do not flush TLB, this will still adversely > > * affect performance on pre-Haswell Intel EPT, where there is > > @@ -939,11 +944,17 @@ static int kvm_mmu_notifier_clear_young(struct mm= u_notifier *mn, > > > > static int kvm_mmu_notifier_test_young(struct mmu_notifier *mn, > > struct mm_struct *mm, > > - unsigned long address) > > + unsigned long start, > > + unsigned long end, > > + unsigned long *bitmap) > > { > > - trace_kvm_test_age_hva(address); > > + trace_kvm_test_age_hva(start, end); > > + > > + /* We don't support bitmaps. Don't test or clear anything. */ > > + if (bitmap) > > + return MMU_NOTIFIER_YOUNG_BITMAP_UNRELIABLE; > > Same thing here. I will remove them, they are indeed unnecessary, as it is just dead code.