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 C70CFC433F5 for ; Thu, 16 Dec 2021 11:00:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F3F46B0083; Thu, 16 Dec 2021 06:00:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 57C366B0085; Thu, 16 Dec 2021 06:00:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41D336B0087; Thu, 16 Dec 2021 06:00:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0105.hostedemail.com [216.40.44.105]) by kanga.kvack.org (Postfix) with ESMTP id 3264C6B0083 for ; Thu, 16 Dec 2021 06:00:26 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id CE3C6181AEF09 for ; Thu, 16 Dec 2021 11:00:15 +0000 (UTC) X-FDA: 78923363190.10.21AF235 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) by imf07.hostedemail.com (Postfix) with ESMTP id 506474001D for ; Thu, 16 Dec 2021 11:00:15 +0000 (UTC) Received: by mail-qt1-f181.google.com with SMTP id p19so24941978qtw.12 for ; Thu, 16 Dec 2021 03:00:15 -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=KnBQJR/TMzh78I8yqUIjs7VdtqfCQRZRo/Chv253Z68=; b=GezK35ONVgcuhJJR9plrCRkI9pOw0Cz7eqzaOyGvWHp2KW/HeY8FI+58hNZJdGmiVi uzKqtD7F7sqrVEgZMi43OW6jV0Fj9RM+U+DKg9M5Peq0VTr4Z/X5SKfUgLOHOm8EW7MD 3aFfiV+PrYPhedbM60AhoGMbEOTGcEInQBdFToAUkh4HTWe+i0Asn6HI7LZEzLxfZdLX k3+n2HGRq8+XcluqX9Zw1i3LIIVb/Z7N2CuybxnhpO4UkyHZAIki8aLBv9hiK5ny9wm0 yOvL40sCuQRP4gPVu/QOgCMHIHx3SAB63AORfTMtqrbTVKGTJQcoGOKBUSgEojKM/nbc Qlzw== 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=KnBQJR/TMzh78I8yqUIjs7VdtqfCQRZRo/Chv253Z68=; b=U2hweV9Z8UHWl5wSXN0NK3caMgHWCHHLTJ9blPLs8b5XSeAdhfM2YUl9LcVRjgS4l9 VLybTTYMLxqFiHR7DnWEIa4kdjJ9rKGL06bcZIIm1Hi21Ar3hJHeYKZ/zCUOWERfOw0b PNjiWY+BU8uWaq0ogfT1mQALCvpSGV5Tyd04jG5zoqhOxMidhot54bIn6npMr9FgiNy0 3+8OrwHr+CIijcxb1XRQ9BB6rQAKRK5QYemOS1gcTMqXWXmniSuxGkDT2wNCcUX6R4Kk Z8AvlGA/Uo1lV1+pFGlBSns1wGJ/tzGaCqtWUmFXOEBpMX6TThRsBOgJxqkU3enMMPCp /RrA== X-Gm-Message-State: AOAM532ziIev3kXoyNwyUX76OlnJhqYoIoBCcHvZtvZfXBJYLf+jmyd+ dxJZFkuy1f6yBMAn+uJySwzvT04SZdBVn7esTFgrww== X-Google-Smtp-Source: ABdhPJwfGfQGB0BT1ZzJnkSVVFHCTAY13k5P2iioommCl//Y954NEMtEyBrfWxsiHxd16//ozpaMeZDMNAqUuXtQyJU= X-Received: by 2002:ac8:4e56:: with SMTP id e22mr16609220qtw.72.1639652414512; Thu, 16 Dec 2021 03:00:14 -0800 (PST) MIME-Version: 1.0 References: <984104c118a451fc4afa2eadb7206065f13b7af2.1638308023.git.andreyknvl@google.com> In-Reply-To: From: Alexander Potapenko Date: Thu, 16 Dec 2021 11:59:38 +0100 Message-ID: Subject: Re: [PATCH 08/31] kasan, page_alloc: refactor init checks in post_alloc_hook To: Andrey Konovalov Cc: andrey.konovalov@linux.dev, Marco Elver , Vincenzo Frascino , Catalin Marinas , Peter Collingbourne , Dmitry Vyukov , Andrey Ryabinin , kasan-dev , Andrew Morton , Linux Memory Management List , Will Deacon , Linux ARM , Evgenii Stepanov , LKML , Andrey Konovalov Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 506474001D X-Stat-Signature: c7f3akrq3rhw4ty3b8qh51str3o1u3ab Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=GezK35ON; spf=pass (imf07.hostedemail.com: domain of glider@google.com designates 209.85.160.181 as permitted sender) smtp.mailfrom=glider@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1639652415-30048 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: On Mon, Dec 6, 2021 at 10:09 PM Andrey Konovalov wrote: > > On Thu, Dec 2, 2021 at 5:14 PM Alexander Potapenko wrote: > > > > On Tue, Nov 30, 2021 at 10:41 PM wrote: > > > > > > From: Andrey Konovalov > > > > > > This patch separates code for zeroing memory from the code clearing tags > > > in post_alloc_hook(). > > > > > > This patch is not useful by itself but makes the simplifications in > > > the following patches easier to follow. > > > > > > This patch does no functional changes. > > > > > > Signed-off-by: Andrey Konovalov > > > --- > > > mm/page_alloc.c | 18 ++++++++++-------- > > > 1 file changed, 10 insertions(+), 8 deletions(-) > > > > > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > > > index 2ada09a58e4b..0561cdafce36 100644 > > > --- a/mm/page_alloc.c > > > +++ b/mm/page_alloc.c > > > @@ -2406,19 +2406,21 @@ inline void post_alloc_hook(struct page *page, unsigned int order, > > > kasan_alloc_pages(page, order, gfp_flags); > > > } else { > > > bool init = !want_init_on_free() && want_init_on_alloc(gfp_flags); > > > + bool init_tags = init && (gfp_flags & __GFP_ZEROTAGS); > > > > > > kasan_unpoison_pages(page, order, init); > > > > > > - if (init) { > > > - if (gfp_flags & __GFP_ZEROTAGS) { > > > - int i; > > > + if (init_tags) { > > > + int i; > > > > > > - for (i = 0; i < 1 << order; i++) > > > - tag_clear_highpage(page + i); > > > - } else { > > > - kernel_init_free_pages(page, 1 << order); > > > - } > > > + for (i = 0; i < 1 << order; i++) > > > + tag_clear_highpage(page + i); > > > + > > > + init = false; > > > > I find this a bit twisted and prone to breakages. > > Maybe just check for (init && !init_tags) below? > > I did it this way deliberately. Check out the code after all the changes: > > https://github.com/xairy/linux/blob/up-kasan-vmalloc-tags-v1/mm/page_alloc.c#L2447 > > It's possible to remove resetting the init variable by expanding the > if (init) check listing all conditions under which init is currently > reset, but that would essentially be duplicating the checks. I think > resetting init is more clear. > > Please let me know what you think. Ah, I see, so there are more cases in which you set init = false. Fine then.