Message ID | 20240731000155.109583-1-21cnbao@gmail.com (mailing list archive) |
---|---|
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 DE9CFC3DA7F for <linux-mm@archiver.kernel.org>; Wed, 31 Jul 2024 00:02:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 582596B0082; Tue, 30 Jul 2024 20:02:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 532AC6B0083; Tue, 30 Jul 2024 20:02:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D2696B0085; Tue, 30 Jul 2024 20:02:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1DFFC6B0082 for <linux-mm@kvack.org>; Tue, 30 Jul 2024 20:02:46 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 902B340163 for <linux-mm@kvack.org>; Wed, 31 Jul 2024 00:02:45 +0000 (UTC) X-FDA: 82398096690.15.B5C7CAB Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf13.hostedemail.com (Postfix) with ESMTP id C080F20005 for <linux-mm@kvack.org>; Wed, 31 Jul 2024 00:02:43 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=I7Obx2S5; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf13.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722384102; 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=V7XE31Xnis95FwL0BCSpbXSmWoexmbCjdp1JCCxsjbA=; b=vg27BB/3uLqkdjUBJo/QU2He1UKrGqNTbe5EVvIseKpoBIpmptl0GlWnqSnfVvB5D1VDOd jkktK9aljKxeo+S/WJAtaJfqWKI6hVb5SLMk16jPmcroqY7cNtbwR6wJ3Wd3cZq26e+EFz 8Yop0oePbu0mBckGpf8ADPqKGNXrYhQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722384102; a=rsa-sha256; cv=none; b=5ukGhK8ADeNT53JY9izEA1O6PQ4UjqkrkpxDRn/75c0vatVWvh9txT6YZ62gAe36AywR5d WUge6y5ttxW/sbY6PwTJFQF5YooE9nGKRdL0G/h23G+WuHSW5wdP0INV5iHz/mUra+uQMF hYzdy5Cuxn/VDSzjSuVVvrlciI0QlBc= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=I7Obx2S5; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf13.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=21cnbao@gmail.com Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-70d2d7e692eso4135673b3a.0 for <linux-mm@kvack.org>; Tue, 30 Jul 2024 17:02:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722384162; x=1722988962; 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=V7XE31Xnis95FwL0BCSpbXSmWoexmbCjdp1JCCxsjbA=; b=I7Obx2S5IGZrY4/pv0BlEuNoIA8icy0tRloJ+3viwiHc/S89AJG5NC98bXsF4V5Icw H7MOKpGi05F1ENkSMsXAjDN5YZodPPI/G1Bnjeyksk0MXwBGPWfcmc1U/bv0oD4y0RK5 VvA1YCMlwji4x70H43huIvTlHILi7KNDHhVZ4VJBt5IdLC0xJc4QkL09WwPjeQoPiezm QdJ1o0X2SCxy4ZgoYzTlBqhAdYbPsowq9/nKM3/FXn6L0q8eL5jd9uwQiQEA1b7GkBGk 7fB36objtMfjxTENSjBH1FhSgMrLjmoROC2wJQLy1iTvNyeFJ5GbuyrQnv/WuFC2Fzl3 7FOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722384162; x=1722988962; 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=V7XE31Xnis95FwL0BCSpbXSmWoexmbCjdp1JCCxsjbA=; b=Swp75xOUFFZAX7Lf4fIsUejKnXB8Txo2UVlYIUFinAB3e+9C7haJ2pmalY0azyr/+Q DEB2olgqAQH7s3ez7uMc2CRiHWfqw5Uk8Cp+l7FZYau2jWper+n5SuSX9LQo5MD2mjzd fQyKJuHqRR9/4jPStAB/uzMG27aIx25N5CjjrKe84LN1X5W1ZtLHuAPrHc5rGy0oK7OI J/AJ2dHvw4HCruiAvb32lh5Rh8UbL8tEhjv18JqgyWuX0vLsP2bTCkaN3FCcCvW6qjSx COZJGzw9nOBwI5eRjoLYlch2nWxrhwSawe8UfIdpMEYEi6V6N3eLtNVoGsyMKiZk8JW4 Ttxw== X-Forwarded-Encrypted: i=1; AJvYcCW7DIEab1wkrDMmtIJm0XZI0AwZysb1f/LCUc2GKnDXzYo+bLczhntlsMwpYe49KKmojTqsHyr2XClfp5lNEC/mDQU= X-Gm-Message-State: AOJu0YyRwxUo8748Sw/B/NSKAJSXmmr1KQpPEsIL/g/WJ+7sHGhKFmZ5 8eFaxCKr7W+G+KHXV0r08dGgfhl4PWGMD+BUQ2rHnJVW44Jve+tF X-Google-Smtp-Source: AGHT+IH9TIr1BjC9Dxmz8MIiv0IdQXYIX1RAmPY4wZlrTUPpc7c4xiWYuzvWLtqwXFXiJrYxGHZFWQ== X-Received: by 2002:a05:6a00:4651:b0:706:34f3:7b60 with SMTP id d2e1a72fcca58-70eceda1d57mr10958031b3a.23.1722384162173; Tue, 30 Jul 2024 17:02:42 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead6e1a2asm8871689b3a.23.2024.07.30.17.02.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jul 2024 17:02:41 -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, lstoakes@gmail.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 v2 0/4] mm: clarify nofail memory allocation Date: Wed, 31 Jul 2024 12:01:51 +1200 Message-Id: <20240731000155.109583-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C080F20005 X-Stat-Signature: t98sup1hsq16dk4jx4rq31w8za6ns4gg X-Rspam-User: X-HE-Tag: 1722384163-946341 X-HE-Meta: U2FsdGVkX1+AOEprxJwQK14Fm44MX8NzrUgGBNEKcT/cKrnFSBLup9e2meGSlTfx/CvUJXQczsaljgUdGCF9veDENb39Qkr/fAZZHoT6n3qpbyM9rmjFOCznAJAo21oGlzDPJAveq3hnwDIPzfvEQ+EtZ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ZFAF9KyX61Bpbvqdftsc0vdFobzz26K4m+qxHJc59ZjYzaWLMvCa7DcImtNN+It4hIR80tHna5kkLKMxcqLSXEG/S7gKZtjtkzYcwUz/S+mO/eVFeIhWO9PxqjF1Poynb+0eGZ0ZymywvY1n+IXhC+JMIZdRtxaEHGnC2NX6AY9S65/KZ5nDiz/NuTDFVym0lMW9tFOEh8nOqw1419UneUPaGiNtrAjRr5Sp/FDTEtd8Xw0zcJz5lyVpLzol7nLnJr3rVHfPjoCiWva1tdkegwS5RvEzGPDiYsST9g+r/SZWnOmToVJRzlSmTSUalile2wJlcp6djBkUYsAdfsx6Q== 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: <linux-mm.kvack.org> List-Subscribe: <mailto:majordomo@kvack.org> List-Unsubscribe: <mailto:majordomo@kvack.org> |
Series |
mm: clarify nofail memory allocation
|
expand
|
From: Barry Song <v-songbaohua@oppo.com> -v2: * 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 (4): vpda: try to fix the potential crash due to misusing __GFP_NOFAIL 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 drivers/vdpa/vdpa_user/iova_domain.c | 31 +++++++++++++++++++++++----- drivers/vdpa/vdpa_user/iova_domain.h | 5 ++++- drivers/vdpa/vdpa_user/vduse_dev.c | 4 +++- include/linux/gfp_types.h | 5 ++++- include/linux/slab.h | 4 +++- mm/page_alloc.c | 14 +++++++------ mm/util.c | 1 + 7 files changed, 49 insertions(+), 15 deletions(-)