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 F10F0C433F5 for ; Wed, 2 Mar 2022 17:46:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BA768D0002; Wed, 2 Mar 2022 12:46:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 76A418D0001; Wed, 2 Mar 2022 12:46:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6335A8D0002; Wed, 2 Mar 2022 12:46:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 56E718D0001 for ; Wed, 2 Mar 2022 12:46:56 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1002C20AA6 for ; Wed, 2 Mar 2022 17:46:56 +0000 (UTC) X-FDA: 79200176832.14.2F13A79 Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) by imf02.hostedemail.com (Postfix) with ESMTP id 546668001F for ; Wed, 2 Mar 2022 17:46:55 +0000 (UTC) Received: by mail-qt1-f179.google.com with SMTP id v3so2305456qta.11 for ; Wed, 02 Mar 2022 09:46:55 -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=fZWesjVlnNPom3VAQBATiQ2w4HQw0ODH2qGAjfL9wDI=; b=bomc0j4ZYAuigPhDcrREe5BdKnGOGs2kjgiyqBuvpILN8dftt4MmA2/vuPLFCv+xTh hckKCahwmhYxkCD6G9msRSxGbEBHwIac+a0cWmuaiZUVoF+9RO+FTK4XzGhVumEnIBAb dtKIwCfq1F82m4aDfbJU0x02DO3jtg6Lp3VhnvdtN6lyv3SC5YoR493SIMf8cNidaxLI CZg42OB39tAxMOJZjFJYP3mhzBH3Drq1xMDAiZbs5VXD5YTOoSq/4hAbwUPrYi1u5MO5 uCWQVL8RjW5OYMqln+0GLKMfzzl4lx7g2NtYh6x1gzPjF8Y59yvWvmf09vqfQzQ/Tr3H 1ZIw== 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=fZWesjVlnNPom3VAQBATiQ2w4HQw0ODH2qGAjfL9wDI=; b=ADbWOksF8Eiuvj1r2IRgGwaIcfTFKZpPUaTRXKnOAbcSn7uTwXsrdtgyLuivPUCquu GQrMbom6Fgxevq9T9k1zCZRmEpW6FOjmFKC8yERO9yd8P/fl1iY54+wmdbo2ik71W8wI O93/GUR42uPfv7wt0UPY72bPEgaWwcHMcUpBzd+pyWGcrR0ujFnNr7GTc3SYYQlAB/H5 Ivsk5TBf/QRpKERskGqac0P4LWqo2At/rL7HH+lAnFy2lho+XiUaaJz2wyRff4mawp3I zFo/8nMfPa4O0vhBR6N7y92TavXJYKTB7Ex+JsoFGJMi4K+nfGdL92gvX+diuYu8JHVf 1Zlg== X-Gm-Message-State: AOAM530vRZK+f8rZXejJjNpVBPDtM5e5xqCkcIW6fzkTh+veSI7Kjvv+ JCMWzZhRiqcMdayZSati9uuQgmsW5K2Dow7b+QBEjw== X-Google-Smtp-Source: ABdhPJw+S6c42b4riCzzSbtvOKQaK7bvZeAShkldwi+5f5PT/4JIg0GPHDgERZqiSI05nFiKuhWBmABDRkan9f/Qh38= X-Received: by 2002:a05:622a:15d2:b0:2de:323e:e964 with SMTP id d18-20020a05622a15d200b002de323ee964mr24949794qty.79.1646243214418; Wed, 02 Mar 2022 09:46:54 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Alexander Potapenko Date: Wed, 2 Mar 2022 18:46:17 +0100 Message-ID: Subject: Re: [PATCH mm 07/22] kasan: simplify kasan_update_kunit_status and call sites To: andrey.konovalov@linux.dev Cc: Marco Elver , Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev , Andrew Morton , Linux Memory Management List , LKML , Andrey Konovalov Content-Type: multipart/alternative; boundary="00000000000002c57105d93fde81" X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 546668001F X-Stat-Signature: wins8m73mceg47yy9xxxt4rc9jb1hz7a Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=bomc0j4Z; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of glider@google.com designates 209.85.160.179 as permitted sender) smtp.mailfrom=glider@google.com X-HE-Tag: 1646243215-973112 X-Bogosity: Ham, tests=bogofilter, spamicity=0.115464, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: --00000000000002c57105d93fde81 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Mar 2, 2022 at 5:37 PM wrote: > From: Andrey Konovalov > > - Rename kasan_update_kunit_status() to update_kunit_status() > (the function is static). > > - Move the IS_ENABLED(CONFIG_KUNIT) to the function's > definition instead of duplicating it at call sites. > > - Obtain and check current->kunit_test within the function. > > Signed-off-by: Andrey Konovalov > Reviewed-by: Alexander Potapenko > --- > mm/kasan/report.c | 30 ++++++++++++++---------------- > 1 file changed, 14 insertions(+), 16 deletions(-) > > diff --git a/mm/kasan/report.c b/mm/kasan/report.c > index 2d892ec050be..59db81211b8a 100644 > --- a/mm/kasan/report.c > +++ b/mm/kasan/report.c > @@ -357,24 +357,31 @@ static bool report_enabled(void) > } > > #if IS_ENABLED(CONFIG_KUNIT) > -static void kasan_update_kunit_status(struct kunit *cur_test, bool sync) > +static void update_kunit_status(bool sync) > { > + struct kunit *test; > struct kunit_resource *resource; > struct kunit_kasan_status *status; > > - resource =3D kunit_find_named_resource(cur_test, "kasan_status"); > + test =3D current->kunit_test; > + if (!test) > + return; > > + resource =3D kunit_find_named_resource(test, "kasan_status"); > if (!resource) { > - kunit_set_failure(cur_test); > + kunit_set_failure(test); > return; > } > > status =3D (struct kunit_kasan_status *)resource->data; > WRITE_ONCE(status->report_found, true); > WRITE_ONCE(status->sync_fault, sync); > + > kunit_put_resource(resource); > } > -#endif /* IS_ENABLED(CONFIG_KUNIT) */ > +#else > +static void update_kunit_status(bool sync) { } > +#endif > > void kasan_report_invalid_free(void *object, unsigned long ip) > { > @@ -383,10 +390,7 @@ void kasan_report_invalid_free(void *object, unsigne= d > long ip) > > object =3D kasan_reset_tag(object); > > -#if IS_ENABLED(CONFIG_KUNIT) > - if (current->kunit_test) > - kasan_update_kunit_status(current->kunit_test, true); > -#endif /* IS_ENABLED(CONFIG_KUNIT) */ > + update_kunit_status(true); > > start_report(&flags); > pr_err("BUG: KASAN: double-free or invalid-free in %pS\n", (void > *)ip); > @@ -402,10 +406,7 @@ void kasan_report_async(void) > { > unsigned long flags; > > -#if IS_ENABLED(CONFIG_KUNIT) > - if (current->kunit_test) > - kasan_update_kunit_status(current->kunit_test, false); > -#endif /* IS_ENABLED(CONFIG_KUNIT) */ > + update_kunit_status(false); > > start_report(&flags); > pr_err("BUG: KASAN: invalid-access\n"); > @@ -424,10 +425,7 @@ static void __kasan_report(unsigned long addr, size_= t > size, bool is_write, > void *untagged_addr; > unsigned long flags; > > -#if IS_ENABLED(CONFIG_KUNIT) > - if (current->kunit_test) > - kasan_update_kunit_status(current->kunit_test, true); > -#endif /* IS_ENABLED(CONFIG_KUNIT) */ > + update_kunit_status(true); > > disable_trace_on_warning(); > > -- > 2.25.1 > > -- > You received this message because you are subscribed to the Google Groups > "kasan-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to kasan-dev+unsubscribe@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/kasan-dev/dac26d811ae31856c3d7666de0b10= 8a3735d962d.1646237226.git.andreyknvl%40google.com > . > --=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. --00000000000002c57105d93fde81 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Wed, Mar 2, 2022 at 5:37 PM <andrey.konovalov@linux.dev&= gt; wrote:
From:= Andrey Konovalov <andreyknvl@google.com>

- Rename kasan_update_kunit_status() to update_kunit_status()
=C2=A0 (the function is static).

- Move the IS_ENABLED(CONFIG_KUNIT) to the function's
=C2=A0 definition instead of duplicating it at call sites.

- Obtain and check current->kunit_test within the function.

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>

=
Reviewed-by: Alexander Potapenko <glider@google.com>
=C2=A0
---
=C2=A0mm/kasan/report.c | 30 ++++++++++++++----------------
=C2=A01 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/mm/kasan/report.c b/mm/kasan/report.c
index 2d892ec050be..59db81211b8a 100644
--- a/mm/kasan/report.c
+++ b/mm/kasan/report.c
@@ -357,24 +357,31 @@ static bool report_enabled(void)
=C2=A0}

=C2=A0#if IS_ENABLED(CONFIG_KUNIT)
-static void kasan_update_kunit_status(struct kunit *cur_test, bool sync) +static void update_kunit_status(bool sync)
=C2=A0{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0struct kunit *test;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct kunit_resource *resource;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct kunit_kasan_status *status;

-=C2=A0 =C2=A0 =C2=A0 =C2=A0resource =3D kunit_find_named_resource(cur_test= , "kasan_status");
+=C2=A0 =C2=A0 =C2=A0 =C2=A0test =3D current->kunit_test;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!test)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return;

+=C2=A0 =C2=A0 =C2=A0 =C2=A0resource =3D kunit_find_named_resource(test, &q= uot;kasan_status");
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (!resource) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0kunit_set_failure(c= ur_test);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0kunit_set_failure(t= est);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }

=C2=A0 =C2=A0 =C2=A0 =C2=A0 status =3D (struct kunit_kasan_status *)resourc= e->data;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 WRITE_ONCE(status->report_found, true);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 WRITE_ONCE(status->sync_fault, sync);
+
=C2=A0 =C2=A0 =C2=A0 =C2=A0 kunit_put_resource(resource);
=C2=A0}
-#endif /* IS_ENABLED(CONFIG_KUNIT) */
+#else
+static void update_kunit_status(bool sync) { }
+#endif

=C2=A0void kasan_report_invalid_free(void *object, unsigned long ip)
=C2=A0{
@@ -383,10 +390,7 @@ void kasan_report_invalid_free(void *object, unsigned = long ip)

=C2=A0 =C2=A0 =C2=A0 =C2=A0 object =3D kasan_reset_tag(object);

-#if IS_ENABLED(CONFIG_KUNIT)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0if (current->kunit_test)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0kasan_update_kunit_= status(current->kunit_test, true);
-#endif /* IS_ENABLED(CONFIG_KUNIT) */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0update_kunit_status(true);

=C2=A0 =C2=A0 =C2=A0 =C2=A0 start_report(&flags);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 pr_err("BUG: KASAN: double-free or invalid= -free in %pS\n", (void *)ip);
@@ -402,10 +406,7 @@ void kasan_report_async(void)
=C2=A0{
=C2=A0 =C2=A0 =C2=A0 =C2=A0 unsigned long flags;

-#if IS_ENABLED(CONFIG_KUNIT)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0if (current->kunit_test)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0kasan_update_kunit_= status(current->kunit_test, false);
-#endif /* IS_ENABLED(CONFIG_KUNIT) */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0update_kunit_status(false);

=C2=A0 =C2=A0 =C2=A0 =C2=A0 start_report(&flags);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 pr_err("BUG: KASAN: invalid-access\n"= );
@@ -424,10 +425,7 @@ static void __kasan_report(unsigned long addr, size_t = size, bool is_write,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 void *untagged_addr;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 unsigned long flags;

-#if IS_ENABLED(CONFIG_KUNIT)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0if (current->kunit_test)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0kasan_update_kunit_= status(current->kunit_test, true);
-#endif /* IS_ENABLED(CONFIG_KUNIT) */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0update_kunit_status(true);

=C2=A0 =C2=A0 =C2=A0 =C2=A0 disable_trace_on_warning();

--
2.25.1

--
You received this message because you are subscribed to the Google Groups &= quot;kasan-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to kasan-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://gro= ups.google.com/d/msgid/kasan-dev/dac26d811ae31856c3d7666de0b108a3735d962d.1= 646237226.git.andreyknvl%40google.com.


--
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 Sebasti= an
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellsch= aft: Hamburg

Diese E-Mail ist vertraulich. Falls Sie diese f=C3=A4ls= chlicherweise erhalten haben sollten, leiten Sie diese bitte nicht an jeman= d anderes weiter, l=C3=B6schen Sie alle Kopien und Anh=C3=A4nge davon und l= assen Sie mich bitte wissen, dass die E-Mail an die falsche Person gesendet= wurde.

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

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 kn= ow that it has gone to the wrong person.
--00000000000002c57105d93fde81--