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=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 6E07EC4742C for ; Wed, 11 Nov 2020 09:58:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AA55420639 for ; Wed, 11 Nov 2020 09:58:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AA55420639 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 08B8A6B005D; Wed, 11 Nov 2020 04:58:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 014506B006C; Wed, 11 Nov 2020 04:58:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E202D6B006E; Wed, 11 Nov 2020 04:58:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0172.hostedemail.com [216.40.44.172]) by kanga.kvack.org (Postfix) with ESMTP id B39186B005D for ; Wed, 11 Nov 2020 04:58:16 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 6303B180AD802 for ; Wed, 11 Nov 2020 09:58:16 +0000 (UTC) X-FDA: 77471686992.25.ear36_26109f1272fc Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 2F9AE1804E3A0 for ; Wed, 11 Nov 2020 09:58:16 +0000 (UTC) X-HE-Tag: ear36_26109f1272fc X-Filterd-Recvd-Size: 4034 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Wed, 11 Nov 2020 09:58:15 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 04BB2AC23; Wed, 11 Nov 2020 09:58:14 +0000 (UTC) To: David Hildenbrand , Michal Hocko Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Alexander Potapenko , Mike Kravetz , Mike Rapoport , Oscar Salvador , Kees Cook , Michael Ellerman References: <20201110193240.25401-1-david@redhat.com> <20201111084738.GT12240@dhcp22.suse.cz> <4ebc711e-7fbc-62aa-b88f-3d6ffa9379ff@redhat.com> From: Vlastimil Babka Subject: Re: [PATCH v1] mm/page_alloc: clear pages in alloc_contig_pages() with init_on_alloc=1 or __GFP_ZERO Message-ID: Date: Wed, 11 Nov 2020 10:58:13 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <4ebc711e-7fbc-62aa-b88f-3d6ffa9379ff@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable 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 11/11/20 10:06 AM, David Hildenbrand wrote: > On 11.11.20 09:47, Michal Hocko wrote: >> On Tue 10-11-20 20:32:40, David Hildenbrand wrote: >>> commit 6471384af2a6 ("mm: security: introduce init_on_alloc=3D1 and >>> init_on_free=3D1 boot options") resulted with init_on_alloc=3D1 in al= l pages >>> leaving the buddy via alloc_pages() and friends to be >>> initialized/cleared/zeroed on allocation. >>> >>> However, the same logic is currently not applied to >>> alloc_contig_pages(): allocated pages leaving the buddy aren't cleare= d >>> with init_on_alloc=3D1 and init_on_free=3D0. Let's also properly clea= r >>> pages on that allocation path and add support for __GFP_ZERO. >>=20 >> AFAIR we do not have any user for __GFP_ZERO right? Not that this is >=20 > Sorry, I had extended information under "---" but accidentally > regenerated the patch before sending it out. >=20 > __GFP_ZERO is not used yet. It's intended to be used in > https://lkml.kernel.org/r/20201029162718.29910-1-david@redhat.com > and I can move that change into a separate patch if desired. >=20 >> harmful but it is better to call that explicitly because a missing >> implementation would be a real problem and as such a bug fix. >>=20 >> I am also not sure handling init_on_free at the higher level is good. >> As we have discussed recently the primary point of this feature is to >> add clearing at very few well defined entry points rather than spill i= t over >> many places. In this case the entry point for the allocator is >> __isolate_free_page which removes pages from the page allocator. I >> haven't checked how much this is used elsewhere but I would expect >> init_on_alloc to be handled there. >=20 > Well, this is the entry point to our range allocator, which lives in > page_alloc.c - used by actual high-level allocators (CMA, gigantic > pages, etc). It's just a matter of taste where we want to have that > handling exactly inside our allocator. I agree alloc_contig_range() is fine as an entry point. > isolate_freepages_range()->split_map_pages() does the post_alloc_hook > call. As we certainly don't want to zero pages during compaction, we > could either pass the gfp_mask/"bool clear" down to that functions and > handle it in there, or handle it in isolate_freepages_range(), after th= e > ->split_map_pages() call. Whatever you prefer. I'd rather not put it in post_alloc_hook() where the bool would then get = checked=20 from allocator fast path as well. Maybe split_map_page() then as it contains a for-cycle already. > Thanks! >=20