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 50099C433EF for ; Tue, 8 Mar 2022 12:27:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF4568D0002; Tue, 8 Mar 2022 07:27:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AA3898D0001; Tue, 8 Mar 2022 07:27:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96BC78D0002; Tue, 8 Mar 2022 07:27:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0186.hostedemail.com [216.40.44.186]) by kanga.kvack.org (Postfix) with ESMTP id 83BF38D0001 for ; Tue, 8 Mar 2022 07:27:28 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 419DE182DA42B for ; Tue, 8 Mar 2022 12:27:28 +0000 (UTC) X-FDA: 79221144576.23.2247051 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) by imf23.hostedemail.com (Postfix) with ESMTP id B88DA14000A for ; Tue, 8 Mar 2022 12:27:27 +0000 (UTC) Received: by mail-qk1-f174.google.com with SMTP id c7so14576168qka.7 for ; Tue, 08 Mar 2022 04:27:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hTAK4h6I/f4aYr0uuTBK/wljPedCHuRUgXIuqUwShxc=; b=kYwnMC10etEHUbaSWT8HC5HO41YjrILU6b1IjtyH40JtrcCznOIHH/1dbbmyxsfYPe oIFwScOS5gJUdAhnleYlP1m8XWOoOgMiOCJBI0ISqkeAVGnOCko6Fdk/forMZbdheNaG ogSNKeRhXqoDhaKN+9gVOg3QxIcBvFFo6Bdd7BLhsm/BzKIDjE8t1ur/FLS9ihYHdbyL aTtl9RBdwa7kDK9c8HfHdpQ/iatcdSP4hysH5TzY0x5gN/DkSPjVXYBXWYZN+/IVHtLR A0b6ai3t7U9fejTpdAS50GmqLiYRiduB/MYTOZjtMEVsFnligUQ3ervjgUnA6JCA+EVj H0FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hTAK4h6I/f4aYr0uuTBK/wljPedCHuRUgXIuqUwShxc=; b=Xm/MIc8eivGQ/G6ge5t1vIcIS+41OxQvKJCbT0UFse9IeMQnDLu8479b0G9W7gXlfc CP/mjo8Zn32H4BJmFYInmyHoVQXb+OsLc2L3BnbncQx2fupA8mXMWVbqYbAtgOA7FgIL uG2CbeEOQVJ+g5hPIrCjp3TuNpXSLQcYmDTOPJVad/qfv7xgiCMOwarq1m5FnCgDS86O uw4fdFu+0s//B4gVsh6+L1LUOZLnPLiup96TyGOEce4JCJTDX22oisl6/MZow74kHE06 +MJaXwsZw3DMgD1HgKrSW1BUcXZMfp7XJidR/qqzYEt7aT6cguN/y5KtrMdNfCl3t/i3 sdJA== X-Gm-Message-State: AOAM530k3C/V63LN0LojrUXDg+nblQJ/BSoUe16dfKKtDMqvXO4rZOCB Ghc9TYtlqcZajemLo+Hp7QCLuW0rGePIVmcuArpjjg== X-Google-Smtp-Source: ABdhPJxm55+/booRGlowkLCKClDoIoXir0y39F/Ro5RNr/fPGbGhx5ZnCidzoskO/FSfR/JvD7ry55MAVFk3CwpVSNQ= X-Received: by 2002:ae9:f712:0:b0:609:4803:51c1 with SMTP id s18-20020ae9f712000000b00609480351c1mr9590919qkg.745.1646742446754; Tue, 08 Mar 2022 04:27:26 -0800 (PST) MIME-Version: 1.0 References: <20220308122023.3068150-1-elver@google.com> In-Reply-To: <20220308122023.3068150-1-elver@google.com> From: Alexander Potapenko Date: Tue, 8 Mar 2022 13:26:50 +0100 Message-ID: Subject: Re: [PATCH] kfence: allow use of a deferrable timer To: Marco Elver Cc: Andrew Morton , Dmitry Vyukov , kasan-dev , LKML , Linux Memory Management List Content-Type: multipart/alternative; boundary="00000000000093d64005d9b41a88" X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: B88DA14000A X-Stat-Signature: 8haeaiqaic9ugnyoex7o63x3nrocq3qh Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=kYwnMC10; spf=pass (imf23.hostedemail.com: domain of glider@google.com designates 209.85.222.174 as permitted sender) smtp.mailfrom=glider@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1646742447-767399 X-Bogosity: Ham, tests=bogofilter, spamicity=0.037290, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: --00000000000093d64005d9b41a88 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Mar 8, 2022 at 1:20 PM Marco Elver wrote: > Allow the use of a deferrable timer, which does not force CPU wake-ups > when the system is idle. A consequence is that the sample interval > becomes very unpredictable, to the point that it is not guaranteed that > the KFENCE KUnit test still passes. > > Nevertheless, on power-constrained systems this may be preferable, so > let's give the user the option should they accept the above trade-off. > > Signed-off-by: Marco Elver > Reviewed-by: Alexander Potapenko > --- > lib/Kconfig.kfence | 12 ++++++++++++ > mm/kfence/core.c | 15 +++++++++++++-- > 2 files changed, 25 insertions(+), 2 deletions(-) > > diff --git a/lib/Kconfig.kfence b/lib/Kconfig.kfence > index 912f252a41fc..1cf2ea2a1ac7 100644 > --- a/lib/Kconfig.kfence > +++ b/lib/Kconfig.kfence > @@ -45,6 +45,18 @@ config KFENCE_NUM_OBJECTS > pages are required; with one containing the object and two > adjacent > ones used as guard pages. > > +config KFENCE_DEFERRABLE > + bool "Use a deferrable timer to trigger allocations" if EXPERT > + help > + Use a deferrable timer to trigger allocations. This avoids > forcing > + CPU wake-ups if the system is idle, at the risk of a less > predictable > + sample interval. > + > + Warning: The KUnit test suite fails with this option enabled - > due to > + the unpredictability of the sample interval! > + > + Say N if you are unsure. > + > config KFENCE_STATIC_KEYS > bool "Use static keys to set up allocations" if EXPERT > depends on JUMP_LABEL > diff --git a/mm/kfence/core.c b/mm/kfence/core.c > index f126b53b9b85..451277b41bfb 100644 > --- a/mm/kfence/core.c > +++ b/mm/kfence/core.c > @@ -95,6 +95,10 @@ module_param_cb(sample_interval, > &sample_interval_param_ops, &kfence_sample_inte > static unsigned long kfence_skip_covered_thresh __read_mostly =3D 75; > module_param_named(skip_covered_thresh, kfence_skip_covered_thresh, > ulong, 0644); > > +/* If true, use a deferrable timer at the risk of unpredictable sample > intervals. */ > +static bool kfence_deferrable __read_mostly =3D > IS_ENABLED(CONFIG_KFENCE_DEFERRABLE); > +module_param_named(deferrable, kfence_deferrable, bool, 0444); > Could you please add a line or two to Documentation/dev-tools/kfence.rst as well? --=20 Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Stra=C3=9Fe, 33 80636 M=C3=BCnchen Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Liana Sebastian Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Diese E-Mail ist vertraulich. Falls Sie diese f=C3=A4lschlicherweise erhalt= en haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter, l=C3=B6schen Sie alle Kopien und Anh=C3=A4nge davon und lassen Sie mich bit= te wissen, dass die E-Mail an die falsche Person gesendet wurde. This e-mail is confidential. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it has gone to the wrong person. --00000000000093d64005d9b41a88 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Tue, Mar 8, 2022 at 1:20 PM Marco = Elver <elver@google.com> wrot= e:
Allow the use= of a deferrable timer, which does not force CPU wake-ups
when the system is idle. A consequence is that the sample interval
becomes very unpredictable, to the point that it is not guaranteed that
the KFENCE KUnit test still passes.

Nevertheless, on power-constrained systems this may be preferable, so
let's give the user the option should they accept the above trade-off.<= br>
Signed-off-by: Marco Elver <elver@google.com>
Reviewed-by: Alex= ander Potapenko <glider@google.com<= /a>>
---
=C2=A0lib/Kconfig.kfence | 12 ++++++++++++
=C2=A0mm/kfence/core.c=C2=A0 =C2=A0| 15 +++++++++++++--
=C2=A02 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/lib/Kconfig.kfence b/lib/Kconfig.kfence
index 912f252a41fc..1cf2ea2a1ac7 100644
--- a/lib/Kconfig.kfence
+++ b/lib/Kconfig.kfence
@@ -45,6 +45,18 @@ config KFENCE_NUM_OBJECTS
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pages are required; with one containing = the object and two adjacent
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ones used as guard pages.

+config KFENCE_DEFERRABLE
+=C2=A0 =C2=A0 =C2=A0 =C2=A0bool "Use a deferrable timer to trigger al= locations" if EXPERT
+=C2=A0 =C2=A0 =C2=A0 =C2=A0help
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Use a deferrable timer to trigger alloca= tions. This avoids forcing
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0CPU wake-ups if the system is idle, at t= he risk of a less predictable
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sample interval.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Warning: The KUnit test suite fails with= this option enabled - due to
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0the unpredictability of the sample inter= val!
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Say N if you are unsure.
+
=C2=A0config KFENCE_STATIC_KEYS
=C2=A0 =C2=A0 =C2=A0 =C2=A0 bool "Use static keys to set up allocation= s" if EXPERT
=C2=A0 =C2=A0 =C2=A0 =C2=A0 depends on JUMP_LABEL
diff --git a/mm/kfence/core.c b/mm/kfence/core.c
index f126b53b9b85..451277b41bfb 100644
--- a/mm/kfence/core.c
+++ b/mm/kfence/core.c
@@ -95,6 +95,10 @@ module_param_cb(sample_interval, &sample_interval_pa= ram_ops, &kfence_sample_inte
=C2=A0static unsigned long kfence_skip_covered_thresh __read_mostly =3D 75;=
=C2=A0module_param_named(skip_covered_thresh, kfence_skip_covered_thresh, u= long, 0644);

+/* If true, use a deferrable timer at the risk of unpredictable sample int= ervals. */
+static bool kfence_deferrable __read_mostly =3D IS_ENABLED(CONFIG_KFENCE_D= EFERRABLE);
+module_param_named(deferrable, kfence_deferrable, bool, 0444);
Could you please add a line or two to=C2=A0Documentation/dev-tool= s/kfence.rst as well?


--
Alexander Potapenko<= br>Software Engineer

Google Germany GmbH
Erika-Mann-Stra=C3=9Fe, = 33
80636 M=C3=BCnchen

Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Li= ana Sebastian
Registergericht und -nummer: Hamburg, HRB 86891
Sitz de= r Gesellschaft: Hamburg

Diese E-Mail ist vertraulich. Falls Sie dies= e f=C3=A4lschlicherweise erhalten haben sollten, leiten Sie diese bitte nic= ht an jemand anderes weiter, l=C3=B6schen Sie alle Kopien und Anh=C3=A4nge = davon und lassen Sie mich bitte wissen, dass die E-Mail an die falsche Pers= on gesendet wurde.

=C2=A0 =C2=A0 =C2=A0

This e-mail is confi= dential. If you received this communication by mistake, please don't fo= rward it to anyone else, please erase all copies and attachments, and pleas= e let me know that it has gone to the wrong person.
--00000000000093d64005d9b41a88--