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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8372AC433F5 for ; Mon, 6 Dec 2021 21:09:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350134AbhLFVNU (ORCPT ); Mon, 6 Dec 2021 16:13:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229795AbhLFVNT (ORCPT ); Mon, 6 Dec 2021 16:13:19 -0500 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16C22C061746 for ; Mon, 6 Dec 2021 13:09:50 -0800 (PST) Received: by mail-io1-xd33.google.com with SMTP id p65so14606790iof.3 for ; Mon, 06 Dec 2021 13:09:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=r9EatIR8zw0uiCmcjCpN5nb99oEeaRmy6PPAXAHDInU=; b=d8LJ0GCx9BppTTQuyCnfWdUbOS18FiLlkBaZqlZTqBPzEHiMZPEL9ZSdj556Eah2XI 8lLBlM5ZcDf5e3zcahr/GkNISYRLmFIVViussCMRxJROiCzyAVJK8ARmHICXD1JOa5nd uOd5D4yyl+L1scbBv41ckD+qezDn72yyT8oxZXVdmIcWyTdQsKEuhPBZJtXIpEPYENed fIDdIqWEnSGpeGhLDP76V4Qm5nkp0KQUN1XDAdB2aoYjYWSDMRVh2Cw/BwsNaElENZqo xcK7JplojrsWLqrzyxdiHLahfo/Cn/3no775T5dAgOEBPSw22VUPN3e6Gi3EWyzSjFHe TLug== 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=r9EatIR8zw0uiCmcjCpN5nb99oEeaRmy6PPAXAHDInU=; b=XOSFMqQxi26MEBC4r/+s4xAvolSusdlVRzbVbNbOqdhM00USg+o/0/6f2O4nTnNExY GVJmWTRgjTmM9U+9uUt40QrB3uiIwcRp2WkhwzaM50Pml14FZDAZ6pwBc2OfOsU71QM9 CT5LYLuD2UArxKVU2umh+/vB/8IeYmhxs45ve+E/yjVAG+4KEV7BKjudx+8JxLOJTWwr JTAqQ3z9dNfrlhgrs0gZ+iFoAmAsWshcQi3YVXBen3lnzaUAsacj3u/ALCourXwlr38f xsNG/8+8T/7WkDGaG3Ypu06odo2mquo6+RMbe/3YAPzFbbzb8rOid3kW7Ud5iX+LSi0q Orzg== X-Gm-Message-State: AOAM533LH4r/wkMnqE9Usu+plGlqbSQvYkuA7tjmFvIebF1gOVZZwBnZ RnDCWD35trLf589uRLPbVUW7mtzqXhcRMfimPmE= X-Google-Smtp-Source: ABdhPJy1cQs9Bcx2KLI7O1M+hytgLnfpb9EsS+I497WYYRltPdfjm7tK2yK47FJ6xYP2uGNfp8KkeM4MOGQqJfGHuqw= X-Received: by 2002:a5e:9b0e:: with SMTP id j14mr37680837iok.127.1638824989563; Mon, 06 Dec 2021 13:09:49 -0800 (PST) MIME-Version: 1.0 References: <984104c118a451fc4afa2eadb7206065f13b7af2.1638308023.git.andreyknvl@google.com> In-Reply-To: From: Andrey Konovalov Date: Mon, 6 Dec 2021 22:09:38 +0100 Message-ID: Subject: Re: [PATCH 08/31] kasan, page_alloc: refactor init checks in post_alloc_hook To: Alexander Potapenko 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Thanks! 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 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 A0D12C433EF for ; Mon, 6 Dec 2021 21:12:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qZahib0GLVWgCfZ1rp2Cx1dt2vsrVccHMyybY62AMSg=; b=z4pOtmz8EnUT81 y2YEjhKwL5zr25CDOrtiKCRkleWvwsUGW1HKuMwdk1JZvTybfq35dZA4nUysMrGTRqZyDfwJ0LsVd mTLhaKipkV9lN1FX3BxyOOCMxppIC0Mgkr/jiW3uLQscSJQdVsh18lynUHamgXfUcDUcacXSeurok Frb8khsz90QkTLzrEcR7YrnztHwYaOrZr7E25ABBr2FvVJMTImK7t5M2eRyrnvI+fDn3Xjy2jmb6u AddmRn0nebHN4L0dVDfxQAmXDVu8n+JxXrwSDDkH3o+GdEdx8GlRTE6DO3Eam87Og6A6K5B0pmvLn PSfVdM2rFPIbC4knQV1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1muLFX-005khT-LF; Mon, 06 Dec 2021 21:10:16 +0000 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1muLF8-005kVf-PM for linux-arm-kernel@lists.infradead.org; Mon, 06 Dec 2021 21:09:52 +0000 Received: by mail-io1-xd32.google.com with SMTP id k21so14574038ioh.4 for ; Mon, 06 Dec 2021 13:09:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=r9EatIR8zw0uiCmcjCpN5nb99oEeaRmy6PPAXAHDInU=; b=d8LJ0GCx9BppTTQuyCnfWdUbOS18FiLlkBaZqlZTqBPzEHiMZPEL9ZSdj556Eah2XI 8lLBlM5ZcDf5e3zcahr/GkNISYRLmFIVViussCMRxJROiCzyAVJK8ARmHICXD1JOa5nd uOd5D4yyl+L1scbBv41ckD+qezDn72yyT8oxZXVdmIcWyTdQsKEuhPBZJtXIpEPYENed fIDdIqWEnSGpeGhLDP76V4Qm5nkp0KQUN1XDAdB2aoYjYWSDMRVh2Cw/BwsNaElENZqo xcK7JplojrsWLqrzyxdiHLahfo/Cn/3no775T5dAgOEBPSw22VUPN3e6Gi3EWyzSjFHe TLug== 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=r9EatIR8zw0uiCmcjCpN5nb99oEeaRmy6PPAXAHDInU=; b=Owz/Igxqr6JV9OcSQcqcFyMq5D1xxnhOKVHb++YT+omMQQDP4zY1a07cP2lPcDINHO VgPxqCxd9QhqXTDWLE0lsRTSINc2WNID7A9aAPSMD06kZ9UOAS6JRzkfD4UzPXupo2O/ 0/l3cpuIeWFt8BPKaInvgVxhB9LAhqe53x8uCAJ8vzVWxvA8d458IrMuWpbFMCi1MMsm VsEU/1vRYNift4PFkSSmaZIRvwPQZkn4qy5+nyuBoJE0TFAGKWVX1zRfsiAi4UI3ZF02 HxELtxV/E+CgwBBug3QvlSjvTb6BAHk0xoc3JrpFs8du8MTAhxTq1DaJRivqbQz4KLaJ bZ2g== X-Gm-Message-State: AOAM532xYcGOfNbvtrje51EjmBSGrkilZdUxwDr+P+bIO7FqZiKLeuA5 L20CI9irZhs9iUZUDj0cyqJJTdFwMl0GPAF7qd8= X-Google-Smtp-Source: ABdhPJy1cQs9Bcx2KLI7O1M+hytgLnfpb9EsS+I497WYYRltPdfjm7tK2yK47FJ6xYP2uGNfp8KkeM4MOGQqJfGHuqw= X-Received: by 2002:a5e:9b0e:: with SMTP id j14mr37680837iok.127.1638824989563; Mon, 06 Dec 2021 13:09:49 -0800 (PST) MIME-Version: 1.0 References: <984104c118a451fc4afa2eadb7206065f13b7af2.1638308023.git.andreyknvl@google.com> In-Reply-To: From: Andrey Konovalov Date: Mon, 6 Dec 2021 22:09:38 +0100 Message-ID: Subject: Re: [PATCH 08/31] kasan, page_alloc: refactor init checks in post_alloc_hook To: Alexander Potapenko 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211206_130950_874061_5E852611 X-CRM114-Status: GOOD ( 25.79 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. Thanks! _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel