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 X-Spam-Level: X-Spam-Status: No, score=-10.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B056C47082 for ; Wed, 26 May 2021 12:36:31 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id CA4BD613D6 for ; Wed, 26 May 2021 12:36:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CA4BD613D6 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CCNJ+6WxWUh6MPOji9j5COePm1VTRaRJXb6sq/ZSLMI=; b=vu0LqO1hVtgChR 2rH1HrQ2oDzoKKyAfCkG93CXWS3LjQtxOQkjlOErjGw/4+YXxNpSR/fGlkC25nb+CW8CpizxVFXCK 1h1aEFKs+ededH7xWGSdf+9urnBg83o2d6tJxt1a9e1rSUI4kREATq2BU8nwgd3Cxg1zOFDWIGT8V +EqXKvuyWwwNSUhBVfv9pbNSDjxuQ72s3T0Sxz0pk69TWOZhoVp06z6FQO4waPv2FabCbHbJJFBEB 5/PkrY1ITPJQFsk2Jrig0qatQhpGfl+2MDLbSnQ9A9QWo7ZWRh80cJfu2rlnggp0oPB+4Ia/gsgGh 8Ux4L0hdS1RMsqKuXxcA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1llskL-00E1VU-KT; Wed, 26 May 2021 12:34:50 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1llqWd-00D7Oa-HS for linux-arm-kernel@lists.infradead.org; Wed, 26 May 2021 10:12:33 +0000 Received: by mail-wm1-x334.google.com with SMTP id o127so382761wmo.4 for ; Wed, 26 May 2021 03:12:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ORUbrgb2hImgyzC/Ql6sac6MWYkFqD0t9FCM4LD49w4=; b=l6C2fhuJmUKv63+BBXr0nJgy6CTe7BixGMgvwO9M2FRsv/OGGMz3hPT4rjDoLbtClq yBRC1nQ5wDggGwN2vcXtatvWJXMvWUUxGuUefkCGRYehOWz9YofyfHhdXN+F9NReEO0P /MOJXRK2qbTcngPNpmoEN348bXWjTMvcLbNDL1rAAUr1RxdBWDr/uvb3bG7bK1TsMQX8 ne+Y101/EDeEqPzSKfQXZ/cM+k+Ua54k6+bchRTMmuE8UyBVVIvBBIoiOzGzucIPpDF4 5Y08lckwHE9bE7wzSzzjCzDw6FPh3S+yCZ6rG5GE6w3wnD9HivMewszPb4xTd7t+UXNI fvHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ORUbrgb2hImgyzC/Ql6sac6MWYkFqD0t9FCM4LD49w4=; b=k0w6iYmA52yZxoX8kSj4CLLaQtJmoRUA4sDB6/j4ifQ0T1iixlYPS7l0fR+3arHLnk JtaJmer75POoKjVVT02Ee7wmIaS7pQadrFXiLRNEhaNPsLb0b/EIhyCb7OSi11/obGE9 pHIpbeDLTHso53KUkDsr+aAWYBhI4OAJAodYxQqPSvPy7VKyDSnRAkTIcFSYKkE+Gqr7 kwuM35/3W6CFJmKlxGme4odftmcn2kdab9b4RXiR5zXiV6+nW/RO4Hl/20BbXXnQ2gMT b+0VOdzFkCCjwSEtevKuLIpomgmpaGuNF/9LQrvd5RWmd/cjfl45YseAHuQvaEuAlmAb 9iAw== X-Gm-Message-State: AOAM533EDTpz/HQGoYAT4+I4Muj5zIcaWTGdTZa7nOvtGvpTiEAkXLFU yv6KJ0i0+h9w5t6F68lKpgeDnQ== X-Google-Smtp-Source: ABdhPJyfuVgkBn3qeKPgc7SD6M3E3x6Ghl2Mu01ryqrvqMyzTQhWBOMMhCyvFTQ8mtzo5Vanus/3Mw== X-Received: by 2002:a7b:c446:: with SMTP id l6mr2541346wmi.75.1622023949427; Wed, 26 May 2021 03:12:29 -0700 (PDT) Received: from elver.google.com ([2a00:79e0:15:13:cd98:de82:208c:cbdb]) by smtp.gmail.com with ESMTPSA id u18sm6717455wmj.15.2021.05.26.03.12.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 May 2021 03:12:28 -0700 (PDT) Date: Wed, 26 May 2021 12:12:22 +0200 From: Marco Elver To: Peter Collingbourne Cc: Andrey Konovalov , Alexander Potapenko , Catalin Marinas , Vincenzo Frascino , Andrew Morton , Evgenii Stepanov , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, kasan-dev@googlegroups.com Subject: Re: [PATCH v3 1/3] kasan: use separate (un)poison implementation for integrated init Message-ID: References: <78af73393175c648b4eb10312825612f6e6889f6.1620849613.git.pcc@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <78af73393175c648b4eb10312825612f6e6889f6.1620849613.git.pcc@google.com> User-Agent: Mutt/2.0.5 (2021-01-21) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210526_031231_645264_20789056 X-CRM114-Status: GOOD ( 22.71 ) 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 Wed, May 12, 2021 at 01:09PM -0700, Peter Collingbourne wrote: [...] > +void kasan_alloc_pages(struct page *page, unsigned int order, gfp_t flags); > +void kasan_free_pages(struct page *page, unsigned int order); > + > #else /* CONFIG_KASAN_HW_TAGS */ > > static inline bool kasan_enabled(void) > { > +#ifdef CONFIG_KASAN > return true; > +#else > + return false; > +#endif > } Just return IS_ENABLED(CONFIG_KASAN); > static inline bool kasan_has_integrated_init(void) > @@ -113,8 +113,30 @@ static inline bool kasan_has_integrated_init(void) > return false; > } > > +static __always_inline void kasan_alloc_pages(struct page *page, > + unsigned int order, gfp_t flags) > +{ > + /* Only available for integrated init. */ > + BUILD_BUG(); > +} > + > +static __always_inline void kasan_free_pages(struct page *page, > + unsigned int order) > +{ > + /* Only available for integrated init. */ > + BUILD_BUG(); > +} This *should* always work, as long as the compiler optimizes everything like we expect. But: In this case, I think this is sign that the interface design can be improved. Can we just make kasan_{alloc,free}_pages() return a 'bool __must_check' to indicate if kasan takes care of init? The variants here would simply return kasan_has_integrated_init(). That way, there'd be no need for the BUILD_BUG()s and the interface becomes harder to misuse by design. Also, given that kasan_{alloc,free}_pages() initializes memory, this is an opportunity to just give them a better name. Perhaps /* Returns true if KASAN took care of initialization, false otherwise. */ bool __must_check kasan_alloc_pages_try_init(struct page *page, unsigned int order, gfp_t flags); bool __must_check kasan_free_pages_try_init(struct page *page, unsigned int order); [...] > - init = want_init_on_free(); > - if (init && !kasan_has_integrated_init()) > - kernel_init_free_pages(page, 1 << order); > - kasan_free_nondeferred_pages(page, order, init, fpi_flags); > + if (kasan_has_integrated_init()) { > + if (!skip_kasan_poison) > + kasan_free_pages(page, order); I think kasan_free_pages() could return a bool, and this would become if (skip_kasan_poison || !kasan_free_pages(...)) { ... > + } else { > + bool init = want_init_on_free(); > + > + if (init) > + kernel_init_free_pages(page, 1 << order); > + if (!skip_kasan_poison) > + kasan_poison_pages(page, order, init); > + } > > /* > * arch_free_page() can make the page's contents inaccessible. s390 > @@ -2324,8 +2324,6 @@ static bool check_new_pages(struct page *page, unsigned int order) > inline void post_alloc_hook(struct page *page, unsigned int order, > gfp_t gfp_flags) > { > - bool init; > - > set_page_private(page, 0); > set_page_refcounted(page); > > @@ -2344,10 +2342,16 @@ inline void post_alloc_hook(struct page *page, unsigned int order, > * kasan_alloc_pages and kernel_init_free_pages must be > * kept together to avoid discrepancies in behavior. > */ > - init = !want_init_on_free() && want_init_on_alloc(gfp_flags); > - kasan_alloc_pages(page, order, init); > - if (init && !kasan_has_integrated_init()) > - kernel_init_free_pages(page, 1 << order); > + if (kasan_has_integrated_init()) { > + kasan_alloc_pages(page, order, gfp_flags); It looks to me that kasan_alloc_pages() could return a bool, and this would become if (!kasan_alloc_pages(...)) { ... > + } else { > + bool init = > + !want_init_on_free() && want_init_on_alloc(gfp_flags); > + [ No need for line-break (for cases like this the kernel is fine with up to 100 cols if it improves readability). ] > + kasan_unpoison_pages(page, order, init); > + if (init) > + kernel_init_free_pages(page, 1 << order); > + } Thoughts? Thanks, -- Marco _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel