From patchwork Sat Aug 17 06:24:45 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: 13767001 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 17E6CC52D7F for ; Sat, 17 Aug 2024 06:25:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 65B216B0408; Sat, 17 Aug 2024 02:25:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 60AF66B0409; Sat, 17 Aug 2024 02:25:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D2736B040A; Sat, 17 Aug 2024 02:25:09 -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 334A26B0408 for ; Sat, 17 Aug 2024 02:25:09 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B3245160500 for ; Sat, 17 Aug 2024 06:25:08 +0000 (UTC) X-FDA: 82460749896.27.E13B94C Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) by imf20.hostedemail.com (Postfix) with ESMTP id EC22B1C000F for ; Sat, 17 Aug 2024 06:25:05 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iq9ZcjfL; spf=pass (imf20.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.43 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=1723875832; 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: references:dkim-signature; bh=fghbe/uTAWmKHUS8am3aPE9oJQfSOdjuZEbStAX9aZE=; b=pwQWsHahNJUTUswviolu6YmoDevYGEl9Zaq/Ke/CmUHvk4nfcEUvOKagGZhpeGWrOE0YWW 1SK65gl3YW4eO+oQLxSyDwTysntUst55aGhwq14tTOp5b9v2dOoTYu+80Y+hE/tLLK1t9p us9ToJY2sKj+RLnQmnRH+dYzDvGRY1k= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723875832; a=rsa-sha256; cv=none; b=AOFSDL8yD69yUstKdKWLUhIXAPXBbh3t2lxARfTj/Ah2ij07PwylOGfMff83T7z9HfwlBh 6+dFjtS3fFgC1uH5OwJVN0UGX/jW2BXRwWIV0mTz28i5uofenMqlC0GYL90WdU1I4+cN1Q cy9IXcE3o7/sbJ+kkUKeZN868NxGmok= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iq9ZcjfL; spf=pass (imf20.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.43 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-2d3b595c18dso2220579a91.0 for ; Fri, 16 Aug 2024 23:25:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723875904; x=1724480704; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fghbe/uTAWmKHUS8am3aPE9oJQfSOdjuZEbStAX9aZE=; b=iq9ZcjfLIt41aQGDG1+uHERjz4vXzxxoYpspUf/+1PAz2HNhFKlAScjNmE5RHdUq8y t+fu6P1tNgYvtfV6PC8GPG+nbaBYR+wHgjvj/sDRSV4hzxhNUvuP7CenWAyO6anTnPDK Epf/YUIX+dlOGmOd6GB8dLpImi1zIGOoZVx1elvd1RCLTdPDMMcGahXFgZaWmpxwW7oy uJGtUZYjQzq2S1WzhvSJ8whqL3wY1bPWXlu+T0xJOz5S4ward4lr6zQox1HuKi1sRFgf zJFOic+suoOULX7Xv+HyLWIhs9ZfZDN21oGbxDlREwvF/zm4cqzkCTKSJ2q3CEL3Rg/M WJtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723875904; x=1724480704; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fghbe/uTAWmKHUS8am3aPE9oJQfSOdjuZEbStAX9aZE=; b=clamCJbKIhA9TMtCXEmxvQpBR23uz+KmVIOa8/n6CLjh2jqDoDQSfITfXG3/nT3cQA fvjUJEErnc9vqj5+gynD649AcZtmX/YuArR2hBfqNQaNOJgCwRYPae5W5rp3z8h+HFo5 eVDOgQpSrHAu/k6jAMeoUOlKL/UukuvK+djVYbf/COdlO6DKrkdFHWtZa11v8ay1McxH XhCUMhSNBwqb4KAEVfC2y5q42FaNylNLXpCrSrfi15h6CxGzrlGgge419B2/TrZwgG+Q Vwhm6SZlgNHeVeEjD3e4lx6fOkeY78Shq1w41D4BR8NepeYGpBAnwxoqQbRtgXTNJzeK cIqw== X-Forwarded-Encrypted: i=1; AJvYcCWUiAA9PdUzwsbJnRsIOwabhrDvTZ/2vJ1+Cd6WmItDkeG451MtHRRWmOpzzHcE2CGh2DHPlXkDzEuPAyoky3STzy0= X-Gm-Message-State: AOJu0Yye5XXecuFwPfiS/77KMvRg21l09FzxF7s2pxUvUAbVS9AF4ZmC Ot4i1p0d+0DoFQ1NVZdUO5iAun0DA2vauq44NGUwDPv0t5NJ4WBo X-Google-Smtp-Source: AGHT+IGsKQP7phlZrMQES1TfZT80/j8UfqPE65YWyVkI9qgq9GoOjg8IBWskUSJYiyrWCebaEF1qxw== X-Received: by 2002:a17:90b:3597:b0:2d3:d79f:e8b7 with SMTP id 98e67ed59e1d1-2d3e4537f86mr7473378a91.5.1723875904457; Fri, 16 Aug 2024 23:25:04 -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.24.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 16 Aug 2024 23:25:04 -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 Subject: [PATCH v3 0/4] mm: clarify nofail memory allocation Date: Sat, 17 Aug 2024 18:24:45 +1200 Message-Id: <20240817062449.21164-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 X-Rspamd-Queue-Id: EC22B1C000F X-Stat-Signature: jnx7aa85ghd4e4aeo3y1qxm1a5g6hnaw X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1723875905-784359 X-HE-Meta: U2FsdGVkX19eiDj1mI4TjRxEwDSaC/TfzdVEencg4eVw4Qj8BFj+zN2KYtzGB3NE7+s+UqLvzMAM2JUUcikaE8fmuz4kZKkgh3pcnW9gMjB+oT692ZC/va1i1nmk4WImIRS5T+oABvJUfy7V3q06uB3YzPGehNQidvXPGygAFWWx48uS63NnrlyMzixvwfK/yx+QEfIrnkNH5W6QiQgM2oS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36q6RHX6C/qC2JqbvoCV/GqHqoqHTPriSL8twEdo7+YLieAZ27BarcD2Q5bvOzd5opH1NAktE0Aha+QAD9gqA7E0/AkAX0nCAlNBfaaq4VEPIF+o2lf7eqvSF6MAfLyS09kE7gPqpaThiepnT0MnfT/AZp/PLqzYOATs/eIrznR5IzjEhgvcMuAbpwhGZ0bA39b+Eq6xoKjw0Ow7xEQFyin+0kXxt9kGg2b+oaiItnDnucKkOYQU8JK+OghdzdPAxaqS5dQj+tDWg/hNBubs= 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 -v3: * collect reviewed-by, acked-by etc. Michal, Christoph, Vlastimil, Davidlohr, thanks! * use Jason's patch[1] to fix vdpa and refine his changelog. * refine changelogs [1] https://lore.kernel.org/all/20240808054320.10017-1-jasowang@redhat.com/ -v2: https://lore.kernel.org/linux-mm/20240731000155.109583-1-21cnbao@gmail.com/ * adjust vpda fix according to Jason and Michal's feedback, I would expect Jason to test it, thanks! * split BUG_ON of unavoidable failure and the case GFP_ATOMIC | __GFP_NOFAIL into two patches according to Vlastimil and Michal. * collect Michal's acked-by for patch 2 - the doc; * remove the new GFP_NOFAIL from this series, that one would be a separate enhancement patchset later on. -v1: https://lore.kernel.org/linux-mm/20240724085544.299090-1-21cnbao@gmail.com/ __GFP_NOFAIL carries the semantics of never failing, so its callers do not check the return value: %__GFP_NOFAIL: The VM implementation _must_ retry infinitely: the caller cannot handle allocation failures. The allocation could block indefinitely but will never return with failure. Testing for failure is pointless. However, __GFP_NOFAIL can sometimes fail if it exceeds size limits or is used with GFP_ATOMIC/GFP_NOWAIT in a non-sleepable context. This can expose security vulnerabilities due to potential NULL dereferences. Since __GFP_NOFAIL does not support non-blocking allocation, we introduce GFP_NOFAIL with inclusive blocking semantics and encourage using GFP_NOFAIL as a replacement for __GFP_NOFAIL in non-mm. If we must still fail a nofail allocation, we should trigger a BUG rather than exposing NULL dereferences to callers who do not check the return value. * The discussion started from this topic: [PATCH RFC] mm: warn potential return NULL for kmalloc_array and kvmalloc_array with __GFP_NOFAIL https://lore.kernel.org/linux-mm/20240717230025.77361-1-21cnbao@gmail.com/ Thank you to Michal, Christoph, Vlastimil, and Hailong for all the comments. Barry Song (3): mm: document __GFP_NOFAIL must be blockable mm: BUG_ON to avoid NULL deference while __GFP_NOFAIL fails mm: prohibit NULL deference exposed for unsupported non-blockable __GFP_NOFAIL Jason Wang (1): vduse: avoid using __GFP_NOFAIL drivers/vdpa/vdpa_user/iova_domain.c | 19 +++++++++++-------- drivers/vdpa/vdpa_user/iova_domain.h | 1 + include/linux/gfp_types.h | 5 ++++- include/linux/slab.h | 4 +++- mm/page_alloc.c | 14 ++++++++------ mm/util.c | 1 + 6 files changed, 28 insertions(+), 16 deletions(-)