From patchwork Sat Aug 17 06:24:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13767003 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 0B64FC531DC for ; Sat, 17 Aug 2024 06:25:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9262C6B0410; Sat, 17 Aug 2024 02:25:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8CA786B040F; Sat, 17 Aug 2024 02:25:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 792046B0410; Sat, 17 Aug 2024 02:25:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5F4766B040E for ; Sat, 17 Aug 2024 02:25:25 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0DA9914054D for ; Sat, 17 Aug 2024 06:25:25 +0000 (UTC) X-FDA: 82460750610.09.C482145 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf07.hostedemail.com (Postfix) with ESMTP id 31FDD40014 for ; Sat, 17 Aug 2024 06:25:22 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Da+bphgy; spf=pass (imf07.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.44 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=1723875847; 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=friTy/DcHRUPotFFxFEVr/8PnCHtLs9nrIthUQvrKhU=; b=jzmU7ktFxkZskkXdgY8ERc6nUZ/4xP9RysiGt5U93IGyjZWLpHWJwXj9zmFQ+QC2d22Ui5 mff+aHLBBoszYhc/o226+D8vzZDUAXJVAdYBaohX1Xiaxad9qUM8CGwSJz114PNMkVPkwI S3rilVk9g/OigQN9okfrRVBFjJNFL18= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723875847; a=rsa-sha256; cv=none; b=jqP1qVVcwa9V1F0ZOqLMEav5D5DBzc4XTXAfUtPKYohZ2DNGZ5KYaj9GbBbyRvRsGN4Q7H G3welDpMDZ9354wunj0LfaM0qLWDxjRYd8+Xau1CP2F/BKX8H3D55uTxqtW7N/hbfpEvsl bYRpCWBoSU8axPX/SoNC4dJomqCLn68= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Da+bphgy; spf=pass (imf07.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-2d3bae081efso1982847a91.1 for ; Fri, 16 Aug 2024 23:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723875921; x=1724480721; 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=friTy/DcHRUPotFFxFEVr/8PnCHtLs9nrIthUQvrKhU=; b=Da+bphgyFfhSpbYST02f5rlIJKYzKadBsV+U61qp/eB/EpU+2k+kInqPtwPTrGmpWX 0KoIwg447LBLthvmBJHkH+pCbvlH2Z4E0jUw1SldNqHlyVkm/HMFAR0+1I+P3mx0+FoH pjz3XgWtIyldzDbiv5REWieJp4He/VOjNeX0tlf+CbftMWnpPBgiWqyKwQG234DiRpMQ P7kXkUXLV8D1pwa8OxXBnRqaZt05sOxQHgPqAEIC9MDZ5mx1RfOFzSvS/G0/IH3IJ62Q YuO1/BHZTTsWMrwd22YWmdcRlNfHmCaJGs7Govi3DsGzj5z2ceNYhrPFE1p08bgy65ji CUlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723875921; x=1724480721; 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=friTy/DcHRUPotFFxFEVr/8PnCHtLs9nrIthUQvrKhU=; b=IJA6buLfzD7moPU2JpGtFwBwTj4o9NsL5NknN3lSxuK3a3anljF/u+wq04qlaoYU0I TRSCHcA4jY4f51nFHDEnjs41UeNtl4yd2+shj9opU27hD1HFzOTGxnl1pmtPV9RkjAb7 p/D1s2jTbpd/DGCZv/B2j7ogD0AzbOwurOUSyp6I+HIr4GXYY+A21z909XBhiuCFcl0D ZAyQAKSAfrZzofJHEIAC9XhBGvXWkB2mvvsJO8LKpfIC6hGlSQPaXk5qgUiTzgES04Vv hrywnwDuzj8ztAQJ2t3AkEPnij0OXssseG/bFCjna8TMo1e/gAkukNAJTTOxt3+NcqKN ShGg== X-Forwarded-Encrypted: i=1; AJvYcCUuVKJqbP04gr/S8VEtUFvjXzg0YC8R+kFRP4RgysHaSSBuDuRahzz2UdsDq5UdBqUWVVrxKorNs3e2puQAqiAL8es= X-Gm-Message-State: AOJu0YzIzRPD7eSlINOgrxTd51GrVDYRgfuRcQdcraURNUCWKYslpIbc JDIxws8cyMpdMCiClUbTrqXQwtkfPa/1Vld/F2EbaVTVySd08J90 X-Google-Smtp-Source: AGHT+IGbImbwpzZFycRBvwd+gSXhiD/E6qOTGdZAld/gNp5VVNETMnD4+Zd4mdJ5MJXaEJz/V+vFEQ== X-Received: by 2002:a17:90a:c915:b0:2c9:7e9c:9637 with SMTP id 98e67ed59e1d1-2d40556d433mr2122285a91.13.1723875920984; Fri, 16 Aug 2024 23:25:20 -0700 (PDT) Received: from Barrys-MBP.hub ([2407:7000:8942:5500:fd84:292a:c6d0:8b67]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3ac854f3bsm6768404a91.51.2024.08.16.23.25.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 16 Aug 2024 23:25:20 -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, hailong.liu@oppo.com, hch@infradead.org, iamjoonsoo.kim@lge.com, mhocko@suse.com, penberg@kernel.org, rientjes@google.com, roman.gushchin@linux.dev, torvalds@linux-foundation.org, urezki@gmail.com, v-songbaohua@oppo.com, vbabka@suse.cz, virtualization@lists.linux.dev, Christoph Hellwig , Davidlohr Bueso , =?utf-8?q?Eugenio_P=C3=A9rez?= , Jason Wang , Kees Cook , Lorenzo Stoakes , Maxime Coquelin , "Michael S. Tsirkin" , Xuan Zhuo Subject: [PATCH v3 2/4] mm: document __GFP_NOFAIL must be blockable Date: Sat, 17 Aug 2024 18:24:47 +1200 Message-Id: <20240817062449.21164-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20240817062449.21164-1-21cnbao@gmail.com> References: <20240817062449.21164-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: s7m8obm8dgy7g7q55puxkxcta7ynadef X-Rspamd-Queue-Id: 31FDD40014 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1723875922-719090 X-HE-Meta: U2FsdGVkX1+IJ+9M+c1TgPlC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RzqfcrM3bMxpQNVT+Hk4zNphZz1Gl8HlV4VtkDLC8Q7EzD6I1nKR2D91j5bdnoUEku02zEVjKjl4QfdiYObdk9PsJZRYy81geIUh/HNKlofLKJKUJ3TLhRPy2NzASt7TXKhAe0JczQ1arGKEDh7XgO5m5GMUGMgXTKSF4sNXfqlA3Sl1KjpRln5fM4BXkzsCuRJlKkSiDIX+8SyvGm7x6uTBM/lLZrDZL5E6PFRwmaiYP7vRZPUdiFwMhPeksHosotBvIxU3M8hlhUzupNwSBJ7fEje5rbzzKB2Xs1/deeRCFNgLi4NmuI4ic2BTH3l87sY+tj578U1M2+MCEMcmIIo4um3LQ/GLOihpwhX1VZyMFv3p2OZuDCnMBcG6A99zpAnfkfrUJKvIFWTuNVL8Qhma0k1AIEYYPcGWB+PaPK7mMlQAWhQwvLs8/CthpVXAMZGZgj0Rc1kMCeHFTQXqsY6mC/pl76CpNnQEnSAWfKbIWA//EfsSH7yr5zO7rkVqd8YDIYoQm5c03cntfbJcuKRYGl/9CAyErsJGa2xGqKvTWDT0LVLjNAZ3kyelDnELMlboskZhFMZnPtj5jmeTqFWF9pzTWfIoloIVdiJdeO7UQh1S9N33iSImGEccoWl5wMFEwBMi/cLslkBNkxtWeFxZ82++48nX1nEDFYKb6YAe/TpuEe4squ/WPK4RaBxbcu4SsoDLMcrkFYW/YbHWQI/Tb94e9Rv4qBaTJTGwTwbFFQhHkaMZa0DyCPAD7q0FfcNC7RvhQuEXaul8Hja9RXbAeAwRcfu59YDdvia6ZDU92+D+8v2MTK4ecGF8JpYVs5RDTlPzf1uUzscnk9yW0kIoBANMUaQrgxYN0ljs9btALy+uY8Kdf7 zuwTasmy uySDF2QueCqbvG9ya/1JRimOzwcWGHcYy0D+dr6//ik= 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 Reviewed-by: Christoph Hellwig Acked-by: Vlastimil Babka Acked-by: Davidlohr Bueso Cc: Christoph Lameter Cc: David Rientjes Cc: "Eugenio PĂ©rez" Cc: Hailong.Liu Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: Jason Wang Cc: Joonsoo Kim Cc: Kees Cook Cc: Linus Torvalds Cc: Lorenzo Stoakes Cc: Maxime Coquelin Cc: "Michael S. Tsirkin" Cc: Pekka Enberg Cc: Roman Gushchin Cc: Uladzislau Rezki (Sony) Cc: Xuan Zhuo --- include/linux/gfp_types.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/gfp_types.h b/include/linux/gfp_types.h index 313be4ad79fd..4a1fa7706b0c 100644 --- a/include/linux/gfp_types.h +++ b/include/linux/gfp_types.h @@ -215,7 +215,8 @@ enum { * the caller still has to check for failures) while costly requests try to be * not disruptive and back off even without invoking the OOM killer. * The following three modifiers might be used to override some of these - * implicit rules. + * implicit rules. Please note that all of them must be used along with + * %__GFP_DIRECT_RECLAIM flag. * * %__GFP_NORETRY: The VM implementation will try only very lightweight * memory direct reclaim to get some memory under memory pressure (thus @@ -246,6 +247,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