From patchwork Wed Jul 24 08:55:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13740694 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 0606BC3DA63 for ; Wed, 24 Jul 2024 08:56:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 853F36B008A; Wed, 24 Jul 2024 04:56:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 804536B008C; Wed, 24 Jul 2024 04:56:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F2A56B0092; Wed, 24 Jul 2024 04:56:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 517596B008A for ; Wed, 24 Jul 2024 04:56:20 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1A7D5A3654 for ; Wed, 24 Jul 2024 08:56:20 +0000 (UTC) X-FDA: 82374039720.15.EDB99C1 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by imf29.hostedemail.com (Postfix) with ESMTP id 211BF12001F for ; Wed, 24 Jul 2024 08:56:17 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=C1qnctWS; spf=pass (imf29.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.180 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721811331; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=R/Cn9Fke+io3lF3O4J0LET8eDbs2QZYmqd+T1evqSS4=; b=4YqMl/h5rqS4DvAD0nERG9uXFc5eSGGbt/PFyq4jTCtIZy8cK2zX3GRgAkYHQyXbZIXjkm pWIbKTNHnVjRot+oyKbbUT3HEFZCaw7XCCmlxq/vDtodC5vQPJBVzt68mHcSQGcVfSzOLr glYdB6bIZ8p+UpUjjxrSgQFiQYGifWk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721811331; a=rsa-sha256; cv=none; b=BEN2ks3GGj5jrd9/ZkO6ORR4POyZWrFai7louuJKTVNwId++LjK6VjjbCcKKvtKq5TJUeG KSA3BfpmMliaIQsizb/qSmxKpPeMJ0K/1HdDjTpyO0n8BYXRKu/24q//4PWfmKdrLXex1d KPRu/RNUOWNEfDLYWEZ6oUacECXOF48= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=C1qnctWS; spf=pass (imf29.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.180 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1fd66cddd07so14344625ad.2 for ; Wed, 24 Jul 2024 01:56:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721811377; x=1722416177; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=R/Cn9Fke+io3lF3O4J0LET8eDbs2QZYmqd+T1evqSS4=; b=C1qnctWSQmxDZpje6KbDo3VWGQRQ2gl2FMXJrscc1Mgu/OB0E5d/U1RDJpCn3ijCO+ 8nVL4uuNkkadFv07R4XW5AUwrNgl0iCAjeUwukQ4U5ITDAVEuIX/InHI+6dqNjNOTYFH VdlT5JIBYkyfUd80MIKh8XpXtbJL5tTKyDet226pzt5Uzj0jMw7xsrwczpBA1aIoNKTm erhf+ECot3MkyWV+IvDoVitFkDOeZmWbR8WYq9IdXDYQasGvBoF5oyIS0OXcbzFZxKgk oK+QYc2qbSU590PuXBfY5F/rCScJ5CslEm1JmTqOPZ4uMpXAmBnbxjCfTo8kqnK5tYls 2v2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721811377; x=1722416177; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R/Cn9Fke+io3lF3O4J0LET8eDbs2QZYmqd+T1evqSS4=; b=HSJUfms4F8l2kZbtoFztoZQVAsQLPpQMuPNdPReVlpbFyGobvTsop+hT7NbLo4tMo7 PhT3Cs1WDmTnbkoWTaQ4cPXgHxsthJhV0WqqXc91S5CkjD8Pr6EbG7er3AU6oKtrSfxr Dq3i7GvuEDmUSBkx5nUl8G/CqpfqOzT36IuMC3VYbzD6Rc/XObVIa3I7r7Ur7uganA27 oioVU/wZDxDArniIoIEl58O5c3vpriNDnZ2nJdlELvtuOB5ryHIln3nE/qYZ/0+1VDJm lkzQ3Z5vgo8OsUP+wVRHiFrgx5Nz3Q/uOywkA5Ir0m7kCccXdTwrA8eCENZv0ewi4D3R 3umQ== X-Forwarded-Encrypted: i=1; AJvYcCU6cSAzSN+PQLPCXuus+luwS8d6y1lvAW3Xo5RZxNLFNVJFt1tlL6UCNezJCvpbnS4m0pbqdt21gmWlxbQ5EaH+aos= X-Gm-Message-State: AOJu0YyI89nnClYdkjEp1WKHk61FwfE958lj6DILnfGaxc18+4Y1Oo0M bSrUB3ugXPIlQKTVoAGc0IX5od+e9AHbRfC4In4R7cn/GPR5xYag X-Google-Smtp-Source: AGHT+IGIkVhFAMakU8DpVXwg17zUus/la2WxZ7dCaBvOhapjR8YXaE6IfX0kCgLDUKxL5Byi3m8WpQ== X-Received: by 2002:a17:903:22cb:b0:1fb:8cab:ccc9 with SMTP id d9443c01a7336-1fdd558a23fmr18290925ad.45.1721811376865; Wed, 24 Jul 2024 01:56:16 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fd6f31855fsm89021895ad.156.2024.07.24.01.56.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jul 2024 01:56:16 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: 42.hyeyoo@gmail.com, cl@linux.com, hch@infradead.org, iamjoonsoo.kim@lge.com, lstoakes@gmail.com, mhocko@suse.com, penberg@kernel.org, rientjes@google.com, roman.gushchin@linux.dev, urezki@gmail.com, v-songbaohua@oppo.com, vbabka@suse.cz, virtualization@lists.linux.dev, hailong.liu@oppo.com, torvalds@linux-foundation.org Subject: [PATCH 2/5] mm: Document __GFP_NOFAIL must be blockable Date: Wed, 24 Jul 2024 20:55:41 +1200 Message-Id: <20240724085544.299090-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240724085544.299090-1-21cnbao@gmail.com> References: <20240724085544.299090-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 211BF12001F X-Stat-Signature: nzf8sxcuz579hd5bp76pkoa1fz1wcjqb X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1721811377-955813 X-HE-Meta: U2FsdGVkX1//SEr7qvmeWPJprzTUG1YW0cBB+fiuXHy54uEYu1ZFIvh1st4hNG6TbAih1pQOOVE2nesZQlMYu2dnki06XPyi9LvexVqa7NaC0wDcygq4Enm8reeSU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u28culIq/IBIrvQhTNytDy4C2EtVscr+mcdpqITfv6B6Zo+UcR2dVca+wYywu4p/CChrcbyuwMuarqTdqqNpYj2U5WM5GaD6Antu7cKM5k3kptlHN4AnFTzyLvvXal7j6h16Wk2+jCpptuA7q1dEUPFZT2TK9hRWc8dvnFDa+I6wxPYF+LsqPflX2JFiCbQJKuNfsiKnbJDFcESeQnp8LSLT2g1f826Z8Dn9W47C/fbD2lPZVxAcbQg1zEeFitKZ9tESI/rosvxy1SJdSLvSRLilizb4C6KYhFGsHRN2kgO7/4/VWQn6TirSte+9g/kxe/dSD4kqi+Dm+wYTwIGw= 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: From: Barry Song Non-blocking allocation with __GFP_NOFAIL is not supported and may still result in NULL pointers (if we don't return NULL, we result in busy-loop within non-sleepable contexts): static inline struct page * __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, struct alloc_context *ac) { ... /* * Make sure that __GFP_NOFAIL request doesn't leak out and make sure * we always retry */ if (gfp_mask & __GFP_NOFAIL) { /* * All existing users of the __GFP_NOFAIL are blockable, so warn * of any new users that actually require GFP_NOWAIT */ if (WARN_ON_ONCE_GFP(!can_direct_reclaim, gfp_mask)) goto fail; ... } ... fail: warn_alloc(gfp_mask, ac->nodemask, "page allocation failure: order:%u", order); got_pg: return page; } Highlight this in the documentation of __GFP_NOFAIL so that non-mm subsystems can reject any illegal usage of __GFP_NOFAIL with GFP_ATOMIC, GFP_NOWAIT, etc. Signed-off-by: Barry Song Acked-by: Michal Hocko Acked-by: Davidlohr Bueso --- include/linux/gfp_types.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/gfp_types.h b/include/linux/gfp_types.h index 313be4ad79fd..0dad2c7914be 100644 --- a/include/linux/gfp_types.h +++ b/include/linux/gfp_types.h @@ -246,6 +246,8 @@ enum { * cannot handle allocation failures. The allocation could block * indefinitely but will never return with failure. Testing for * failure is pointless. + * It _must_ be blockable and used together with __GFP_DIRECT_RECLAIM. + * It should _never_ be used in non-sleepable contexts. * New users should be evaluated carefully (and the flag should be * used only when there is no reasonable failure policy) but it is * definitely preferable to use the flag rather than opencode endless