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 E06A7C3DA5D for ; Fri, 19 Jul 2024 07:42:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E59D6B0082; Fri, 19 Jul 2024 03:42:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2960E6B0083; Fri, 19 Jul 2024 03:42:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 136986B0088; Fri, 19 Jul 2024 03:42:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id EA7636B0082 for ; Fri, 19 Jul 2024 03:42:07 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5D9DC1C0ECB for ; Fri, 19 Jul 2024 07:42:07 +0000 (UTC) X-FDA: 82355708694.16.162B64A Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by imf27.hostedemail.com (Postfix) with ESMTP id 3F53F4000D for ; Fri, 19 Jul 2024 07:42:04 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=suse.com header.s=google header.b=Y8QmFniD; spf=pass (imf27.hostedemail.com: domain of mhocko@suse.com designates 209.85.167.42 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=1721374870; 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=uUjOkBb5OMiI3jA6TaZk4RFWIP6X8+yma9jsNYjN6Ro=; b=i/MQ+LrLlOwE6S+MVgb6EHPk1nMxmfSqcIYtJWKkOcCurHxBA90ZGEdUthnY7n0CSO2Wfo V8iZjdI61eEJ4vD3AFCgppylJVaV614QoxOMnV14SBlhtQiy+E5EnJ8Sj0j8ku9flHOBXQ 2lOtHiW8H58Q4xiYycHhzxjTJQUvhcI= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=suse.com header.s=google header.b=Y8QmFniD; spf=pass (imf27.hostedemail.com: domain of mhocko@suse.com designates 209.85.167.42 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721374870; a=rsa-sha256; cv=none; b=68arKsrQJffg55jFmg0l21Of6xXvL75ZI1bYg6o3kR641m34vN22b7hKlHeNO9/bZprqz3 YmpXDm+XXFNcqrSJKlIWoo27XXSFu3fCx9eZzAZyc0k3W5tezUWq1+ZTQ3R5qy08pYr/GO G+hplbt+sFlrUL86Agr6N2RCWu0zVtY= Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-52ea5765e75so1723970e87.0 for ; Fri, 19 Jul 2024 00:42:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1721374923; x=1721979723; darn=kvack.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=uUjOkBb5OMiI3jA6TaZk4RFWIP6X8+yma9jsNYjN6Ro=; b=Y8QmFniD5ntCh3qltGTCHu82v0CZowtee7iq0FmbD2pqCdy0Z6DE1vvD/GpQMrvVdP z2Ak0x58yZILfyUmXTF9l97hpKoG9jwbMKFMeUFVbUS+oMeAN825P973BAufrnbeQvJL XKh3YKQLezleDR2Lpf8NF50XUHfpmjZBAxr8NkA7EkuhyruD8IXf2orKa2YjB4BjPA9H T+tdFWCJq2j092xwlQSUu7cV+F5d5bnuxbcwEUJ3LFapqvOcvN7Ds1ZrI+s0F46NL74K +KoDe5ULWiuOSPLpcrIsXsVayJuEKwLdvc3vw/xvyATJ5We4AYC28LNQnGJN1k9emTKI EOTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721374923; x=1721979723; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uUjOkBb5OMiI3jA6TaZk4RFWIP6X8+yma9jsNYjN6Ro=; b=nalw2nwX4McuSwYQJw8CtM04g6e24fH/Nhz9PKvMmEKtWhWUBFq+4vi7LRdHaZvTY+ mtnF2TZW8wRFQoCHFcm3uWPeD7mMDIBadtop1yJpVTKaQviajQ0M/YmdK9sjm+pun1NE nwtCXLMzxyyKNMSTaBw+N/4nGHsqDWMmjD5eiWt2mxzzoF1XaNMCHl0wrjZ4f2evrm6r anw1ObCEAZFG8RLet3vJbiK5luhPCEqbmqXSnGYfSrf48At0apja2piFG1ucofQDSV+i 2FfddFnSWCXS4XGnmRxZxgpl0GiUtjbe3KBX4XgwOF/uE62IeGxH/lYV+YEIvnhHUgAE IvFg== X-Forwarded-Encrypted: i=1; AJvYcCWcNSy149o9//2qMVVHhM3OQX9r+fP7ECK9amrZlbls1UU1whTAVvPK5uUJKHlpvpw8cjB4AJetKBTM2AJ0Mbogiuw= X-Gm-Message-State: AOJu0YxZV7t+EatFWM4GrcXnn6fQuP5fNDVGPwiqKanHGVORC2gHFYYS X9AomLYn90AODE5Od3emIc+J1yaH/R5wpO93SMqHwsOzJxrQ/NwUNJlhr/k/qq8= X-Google-Smtp-Source: AGHT+IHqIs8+nZ3uoHqGkMJGAWZChZScZEg1cc+L7EnZG/BY/8s2F8/0MdlJ37qCn5jXWO2sCB89/A== X-Received: by 2002:a05:6512:3f1a:b0:52c:dbe7:cfd5 with SMTP id 2adb3069b0e04-52ee53c974fmr4998591e87.32.1721374923412; Fri, 19 Jul 2024 00:42:03 -0700 (PDT) Received: from localhost (109-81-94-157.rct.o2.cz. [109.81.94.157]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a6e91fsm41293895e9.23.2024.07.19.00.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jul 2024 00:42:03 -0700 (PDT) Date: Fri, 19 Jul 2024 09:42:02 +0200 From: Michal Hocko To: Barry Song <21cnbao@gmail.com> Cc: akpm@linux-foundation.org, linux-mm@kvack.org, Barry Song , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: Re: [PATCH RFC] mm: warn potential return NULL for kmalloc_array and kvmalloc_array with __GFP_NOFAIL Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3F53F4000D X-Stat-Signature: 7szz99xc87wdofz4npotzim6sqohf4up X-Rspam-User: X-HE-Tag: 1721374924-688332 X-HE-Meta: U2FsdGVkX19fwLJn5MkERXefbdcQJm0K1Iz/pzA07zAitlBORpzZV1eU4vFeSjDQvfIa6zBRrK9cjWhwVOacazNy1T8S9d4KeE8WODAbmbuCZKPdFDBDrL+zPh15dx0O0nHF6vKRDQYOrWKuyoKOnZgnE6MKjeVqTJKLBOzOqBnEaev2gyWnAWkYwOBDiewXslYCbTMAkauXDrCqOvTQ4nuimGZtILCiNA2hODf88UhU/7q+3Sv6lK8OkjF2oGLQJd2K7gINYy79PdoVCtw6hTw0OYJiLTK2/NMFwD+WSYUF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1Ue0yrPbqonKYLqQw/19NJwr/4Ze60XhgTRj1btAlykJ+SpJpp+av2QlCeqKJdaWe+zP2Yc6wDWZpirpSOysH62tiwSVV5m0iSiporkcDhPJo= 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: List-Subscribe: List-Unsubscribe: On Fri 19-07-24 19:07:31, Barry Song wrote: > On Fri, Jul 19, 2024 at 7:02 PM Michal Hocko wrote: > > > > On Fri 19-07-24 12:35:55, Barry Song wrote: > > > On Thu, Jul 18, 2024 at 8:50 PM Michal Hocko wrote: > > [...] > > > > Yes, those shouldn't really fail. NOWAIT|NOFAIL was something that > > > > should never happen and I really hope it doesn't. Others should really > > > > retry but it's been some time since I've checked the last time. > > > > > > > > > I assume allocations directly using alloc_pages() might not respect GFP_NOFAIL > > > and violate the semantics of GFP_NOFAIL. > > > > What do you mean? > > I mean, if we are using wrappers like vmalloc (GFP_NOFAIL | GFP_NOWAIT), > though alloc_pages might return NULL, vmalloc for itself will retry. vmalloc(NOFAIL|NOWAIT) is equally unsupported. This combination of flags simply cannot be delivered. > but if you call alloc_pages() directly with GFP_NOFAIL | GFP_NOWAIT, > alloc_pages() may return NULL without retry at all. I believe alloc_pages() > is also wrong. It cannot reclaim itself and it cannot sleep to wait for the memory so NOFAIL semantic is simply impossible. We have put a warning in place to catch abusers but apparently this hasn't been sufficient. There are only two ways to deal with the failure. Either return NULL and break the contract and see what happens (implementation now) or BUG_ON and blow up later if the the failed allocation request blows up - potentially recoverably. Linus tends to be against adding new BUG() calls unless the failure is absolutely unrecoverable (e.g. corrupted data structures etc.). I am not sure how he would look at simply incorrect memory allocator usage to blow up the kernel. Now the argument could be made that those failures could cause subtle memory corruptions or even be exploitable which might be a sufficient reason to stop them early. You can try that. I do not see a saner way to deal with this particular memory request type. Unless we require all __GFP_NOFAIL|GFP_NOWAIT requests to check for the failure but this makes very little sense to me. -- Michal Hocko SUSE Labs