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 64F37C71153 for ; Mon, 4 Sep 2023 07:55:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE95028000F; Mon, 4 Sep 2023 03:54:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B995B8E001C; Mon, 4 Sep 2023 03:54:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A60CE28000F; Mon, 4 Sep 2023 03:54:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 960EB8E001C for ; Mon, 4 Sep 2023 03:54:59 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4437580580 for ; Mon, 4 Sep 2023 07:54:59 +0000 (UTC) X-FDA: 81198153918.17.6F3F389 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf02.hostedemail.com (Postfix) with ESMTP id 3994180007 for ; Mon, 4 Sep 2023 07:54:56 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=ZOjnzXSM; spf=pass (imf02.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693814097; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zOnx8wPwAU6ZtQY/cwgSOda0bqHjX/X+RJnXB9nkeWQ=; b=fYxUYL0jcdT/zJ9NONV62x7O7Q1+lzl0lSJoypaNzC9LcQzn/RcLiwaR4NUsKHh3EiyWyS EYPlAEH55B77SQ8l/aZUDFBzPAHCrX27AkN8FrDWWJ8dv5ogvS4pCOEeZq3tQfcebf5wgo EWvjqM0l9XblhyEMLVI9DIKnpJatCVI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693814097; a=rsa-sha256; cv=none; b=yzMKLPqab2nJB4wQ9WColaHmeL5qilOWV0Yrf32dyO+vNRYW5pl7cjmADJ3KqWtIh7QrRY tY3hfaU1fhzaNeZgiwbk9KPZ//PkF8oB5vkP+eBImAoSNlmI4zaO+94Dy1Rym2+R2JDAvR wXAqIj91kac10QUvbVvcwp8gx6Q8DeU= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=ZOjnzXSM; spf=pass (imf02.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E62CF1F894; Mon, 4 Sep 2023 07:54:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1693814094; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zOnx8wPwAU6ZtQY/cwgSOda0bqHjX/X+RJnXB9nkeWQ=; b=ZOjnzXSMw1ajlWF/XmhC/3SFT1d5SdS8SQfBbAoVNc+jGOItNFq7LD6Cp6yeh738PYwYEL d1jwA9DF774bz2mSjejWdq47ryyxONVwupslsJ4E5wmmhFrxZugad95vC8DeRWDh5rG+KY Akf9bDzkvynu2L0S5zPjCnLhehjUUmI= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C7F1213425; Mon, 4 Sep 2023 07:54:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8sy1LU6N9WQ1SgAAMHmgww (envelope-from ); Mon, 04 Sep 2023 07:54:54 +0000 Date: Mon, 4 Sep 2023 09:54:54 +0200 From: Michal Hocko To: Alexander Potapenko Cc: Zhaoyang Huang , Matthew Wilcox , "zhaoyang.huang" , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, ke.wang@unisoc.com, Marco Elver , Dmitry Vyukov , Dave Hansen , Kees Cook , Eric Biggers , Mateusz Guzik , Linus Torvalds , Al Viro Subject: Re: [PATCH] mm: make __GFP_SKIP_ZERO visible to skip zero operation Message-ID: References: <20230831105252.1385911-1-zhaoyang.huang@unisoc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Stat-Signature: uyd8upftu31n66x5767sg55jqme9yie4 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 3994180007 X-Rspam-User: X-HE-Tag: 1693814096-959792 X-HE-Meta: U2FsdGVkX1+TtEb2EmTWhJ+Zfmp6wO4aYqN09M7qst1yiZ4aC8o4wwmcpHZY9QKlfW0uJBxhbwOSi2qqn14pN+i4zXPZ2tC8DrTubCJ80aACzp7GvylOWjwetu2o9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2itGpijPLJvBryfxFZWcxLTrWqB4y3j34fOInbX5OZ05WBXaTHkssky0wPUn0yL4Vkld6k7Z5lDq71GrMk242LK0kJ+ckvp74I3N3jn6OZQROPzbT7+tyeX+1PEqvKi7DVIwYmPMCQHTU1FbyS2pGb/fxFliUMrb7k84EbLzsyfYWDC8wukdEQguZH+CP3J/VI6CGnstGgP0KPYAj0virHA4RHxADvtFtOHNl18vr3GHnsRS/vBEwI6Kxj3We9Q6ctWtBEz6g37lA1tu4+gshCod4lphoXodc5d/phbnAmDXZiYGk1NtpomSnk+p 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 Fri 01-09-23 14:55:17, Alexander Potapenko wrote: > On Fri, Sep 1, 2023 at 12:29 PM Zhaoyang Huang wrote: > > > > loop alex > > (adding more people who took part in the previous discussions) > > > > > On Thu, Aug 31, 2023 at 8:16 PM Matthew Wilcox wrote: > > > > > > On Thu, Aug 31, 2023 at 06:52:52PM +0800, zhaoyang.huang wrote: > > > > From: Zhaoyang Huang > > > > > > > > There is no explicit gfp flags to let the allocation skip zero > > > > operation when CONFIG_INIT_ON_ALLOC_DEFAULT_ON=y. I would like to make > > > > __GFP_SKIP_ZERO be visible even if kasan is not configured. > > Hi all, > > This is a recurring question, as people keep encountering performance > problems on systems with init_on_alloc=1 > (https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1862822 being > one of the examples). > > Brad Spengler has also pointed out > (https://twitter.com/spendergrsec/status/1296461651659694082) that > there are cases where there is no security vs. performance tradeoff > (e.g. kmemdup() and kstrdup()). > > An opt-out flag was included in the initial init_on_alloc series, but > back then Michal Hocko has noted that it might easily get out of > control: https://patchwork.kernel.org/project/linux-hardening/patch/20190418154208.131118-2-glider@google.com/#22600229. I still maintain my opinion. I really do not like the idea of mixing concepts of init_on_alloc (which is pretty much security oriented) and an opt out flag which bypasses it. Sooner or later this will become an unreviewable mess so the value of init_on_alloc will become very dubious. > Now that init_on_alloc is actually being used by people which may have > different preferences wrt. security and performance (in the cases > where this tradeoff exists), we must be very careful with the opt-out > GFP flag. Not initializing a particular allocation site in the > upstream kernel will affect every downstream user, and some may > consider this a security regression. Fully agreed! > Another problematic case is an OS vendor mandating init_on_alloc > everywhere, but a third party driver vendor doing kmalloc(..., > __GFP_SKIP_ZERO) for their allocations. Exactly. This allows to sniff into driver unrelated proper and allow a whole class of isssues. > So I think a working opt-out scheme for the heap initialization should > be two-step: > 1. The code owner may decide that a particular allocation site needs > an opt-out, and make the upstream code change; > 2. The OS vendor has the ability to override that decision for the > kernel they ship without the need to patch the source. Practically speaking this would require a new mode init_on_alloc_but_potentially_unsafe Another option would be to provide a simple page allocator wrapper that would allow to recycle pages for a particular user or providing a slab cache that would achieve the same thing. This would be still a bit quetiongable because the user could be seeing stale data but less of a problem than crossing propers and potentially security domains. -- Michal Hocko SUSE Labs