From patchwork Tue Jan 31 04:38:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rishabh Bhatnagar X-Patchwork-Id: 13122226 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 837DAC38142 for ; Tue, 31 Jan 2023 04:39:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F2A596B0074; Mon, 30 Jan 2023 23:39:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EB45C6B0075; Mon, 30 Jan 2023 23:39:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D2CAF6B0078; Mon, 30 Jan 2023 23:39:02 -0500 (EST) 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 BEAD06B0074 for ; Mon, 30 Jan 2023 23:39:02 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 86F9A1C6121 for ; Tue, 31 Jan 2023 04:39:02 +0000 (UTC) X-FDA: 80413839324.18.859F320 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by imf05.hostedemail.com (Postfix) with ESMTP id 83C5D100007 for ; Tue, 31 Jan 2023 04:38:59 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=jED0HrnI; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf05.hostedemail.com: domain of "prvs=3885f9781=risbhat@amazon.com" designates 72.21.196.25 as permitted sender) smtp.mailfrom="prvs=3885f9781=risbhat@amazon.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675139939; 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=KzxtKnvbi8Q7EeBQQOVpXwZCQQNURGL1YCOaytw/sBY=; b=zmnZO5kEyEkp2flCGNGgGXO1wedhzmV5Wf2td4A5blFPTKBu1JC7i9+KsoJnA0r0h7pf3k gGvpY2BJ+TwgI36vIALQDAYSGXTK08ZLkDDEO6AhyjeLzc2GPwylddqzPhK7qTnENlYW2i 5QurTjvEbDMXNjDaEdWalpk5qm9pqEo= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=jED0HrnI; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf05.hostedemail.com: domain of "prvs=3885f9781=risbhat@amazon.com" designates 72.21.196.25 as permitted sender) smtp.mailfrom="prvs=3885f9781=risbhat@amazon.com" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675139939; a=rsa-sha256; cv=none; b=EFPrsKF72vR+TTl+XfzFPUn6t5qaPFm/Qdehtq17AAs1DOQsjzBCpETA6AyuJQz7wzh/kh VstLXVFKyIE2yCdWDH2qk4/+er8GFr8DjL22BDVuvThC7/F9tKdd7eQgySNAMO8LC/5dsj Hb+AVdb0Q1Sd9G3ok1RW4CQL3UTyOGc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1675139940; x=1706675940; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KzxtKnvbi8Q7EeBQQOVpXwZCQQNURGL1YCOaytw/sBY=; b=jED0HrnIRKb4aH5qkNnQCPTd6JofJNViJdyugWtAsxceKpTQ1DR8tvHY 2aUzJqQMPkgw7OkwiO6nvKPNbKjoOQcvRv3L0BnRUID1bfJq8wo5xO35o JgPX7lHhVjYcw+STTtISsu1L2PclW55bFMcWTa8h4EDtjDEs+PqYqnYTe c=; X-IronPort-AV: E=Sophos;i="5.97,259,1669075200"; d="scan'208";a="287996743" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1box-1dm6-7f722725.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2023 04:38:59 +0000 Received: from EX13MTAUWB001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1box-1dm6-7f722725.us-east-1.amazon.com (Postfix) with ESMTPS id 388A89ACF7; Tue, 31 Jan 2023 04:38:58 +0000 (UTC) Received: from EX19D002UWA004.ant.amazon.com (10.13.138.230) by EX13MTAUWB001.ant.amazon.com (10.43.161.207) with Microsoft SMTP Server (TLS) id 15.0.1497.45; Tue, 31 Jan 2023 04:38:57 +0000 Received: from EX13MTAUEB002.ant.amazon.com (10.43.60.12) by EX19D002UWA004.ant.amazon.com (10.13.138.230) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.24; Tue, 31 Jan 2023 04:38:57 +0000 Received: from dev-dsk-risbhat-2b-8bdc64cd.us-west-2.amazon.com (10.189.73.169) by mail-relay.amazon.com (10.43.60.234) with Microsoft SMTP Server id 15.0.1497.45 via Frontend Transport; Tue, 31 Jan 2023 04:38:56 +0000 Received: by dev-dsk-risbhat-2b-8bdc64cd.us-west-2.amazon.com (Postfix, from userid 22673075) id 9D103271E; Tue, 31 Jan 2023 04:38:56 +0000 (UTC) From: Rishabh Bhatnagar To: , CC: , , , Michal Hocko , Linus Torvalds , Tom Herbert , "Andrew Morton" , Rishabh Bhatnagar Subject: [PATCH stable 4.14 1/1] mm: kvmalloc does not fallback to vmalloc for incompatible gfp flags Date: Tue, 31 Jan 2023 04:38:15 +0000 Message-ID: <20230131043815.14989-2-risbhat@amazon.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230131043815.14989-1-risbhat@amazon.com> References: <20230131043815.14989-1-risbhat@amazon.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 83C5D100007 X-Stat-Signature: x4cuarp1pzp7in967qhrrxk97z6n48qk X-HE-Tag: 1675139939-73290 X-HE-Meta: U2FsdGVkX189jRjEeQxCLku1VyCFUkHK0I1dNxzyxy1QYaAHCiBbVbeP6WD6z9i2BrgkoN14Kx8wEllBeYeQ814ascwdS24rbsgmgUISVjJw9bvEFgfwoYv/UgvNsYVuULTDHG6BIzayCr1a11VV33vBu8g01Nwm5vADA0pKyMcfsSYxqU6Oi95uprrf9OlRagxkEEeRgOnzYMEeAD8+vSuo/+kFs3bfkpZEeERMwyJYJf5AEqtUQHvPjuIXNEEu2Q5FzU+bTlFdVunDIkKdmfzdbgIS9lb5TVbN+wbgWHUSoqpsqXdo5Lvbj898zGFt86N1Hf11VDXONgeWIc5OwejyBqJQ0edNR2/PojQHawAkCpS8CTUh8c2k5nReVbXwSWLsr07y+K4oB9n7wd5dcfJjwOlC+8lqM41m6EObZRD9E4qLpNUDZS2MvAd0J/LhmQJNi6+UOcAIQ9KGrJfddyyV5LQvE3TkdA0lMiC+tusG9bc8dwAVN8TW6Vsoc0DH9Vkw6XkyYESHMFuXq18mmwG+yHnqFHYReMquWvTjY3XQA06o6I0B7zS+7kqx/nPr9eYgTaufKXIuiehhpOU2IKoJvcLWWwqCIUp7BYAec8WuVn+eY0rygjrqmqSbCZmVBMec6mpFkMxU3oJhdPIHaIrID8Ri5Kh1mG/w7wjmyXHf+u8pji/Vl8WorPbleAHoy3Cfs2N1ZWPsZ6SzIf0mjoaSbndyQnMtb4tTiCsjOqROzTKhS5Ca4uuglzCA9xGicklX6qw2hG2YPoXV9GpGJ6MRZGjJVJypa2yAJ7f3Y6JoHRrgEOyaTg2SqOJvQi10NcwB3TMARc0/ln4SlqP6YADNSWOj0iqcBcncxbPAwRre+HfzmQYdxBZcmJtA2BSLf1/gWnMJvSJyxoRh/CEpMPoGK+1LIw1W/apwBj2PFvH4K0wSK4XHcTHGmRYjz85zo2k9WbTOkYCmpHV3sUt rDQ38R6u 6T0Y3HuJRgTPCdktP6w903Lo8Iq1vkm+6td1ZA38mOS0zKPLSFWeoN+Knwm1XqW+5jZdRL1WlgGUrkVYeDfWB1mhTjYQ7UzZEqqPdL7SpQDAGcNbnqj3jclNEuwD4w+GKvuWncKqfGV95wZ8p06QJc0YPexXeobxvo6ETAm3UDTgrIb/KvlK4JTbOa5UVzVYVUf2cvyNuoS6jM2NLWmE0NmQ4SQNI9NFScLjxtwSrhHdx8luU/9/8vuKTDT6tlhC5rTCuYo+2hQjRCtRAq5BTGcU4Iid0VMuioRKzuoa7gsnG5JgOXNCSjGqpLlq9DTMXwPqhL2JtAS1hbsy0ETgeu+DBZi0eTliU1EiPqlcgR4YAQNvAStuo6toyQg== 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: From: Michal Hocko Commit ce91f6ee5b3bbbad8caff61b1c46d845c8db19bf upstream. kvmalloc warned about incompatible gfp_mask to catch abusers (mostly GFP_NOFS) with an intention that this will motivate authors of the code to fix those. Linus argues that this just motivates people to do even more hacks like if (gfp == GFP_KERNEL) kvmalloc else kmalloc I haven't seen this happening much (Linus pointed to bucket_lock special cases an atomic allocation but my git foo hasn't found much more) but it is true that we can grow those in future. Therefore Linus suggested to simply not fallback to vmalloc for incompatible gfp flags and rather stick with the kmalloc path. Link: http://lkml.kernel.org/r/20180601115329.27807-1-mhocko@kernel.org Signed-off-by: Michal Hocko Suggested-by: Linus Torvalds Cc: Tom Herbert Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Rishabh Bhatnagar --- Changelog: - Removed lib/bucket_locks.c diff as not present in 4.14 mm/util.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/util.c b/mm/util.c index 84e775f5216f..7d80c8119dce 100644 --- a/mm/util.c +++ b/mm/util.c @@ -400,7 +400,8 @@ EXPORT_SYMBOL(vm_mmap); * __GFP_RETRY_MAYFAIL is supported, and it should be used only if kmalloc is * preferable to the vmalloc fallback, due to visible performance drawbacks. * - * Any use of gfp flags outside of GFP_KERNEL should be consulted with mm people. + * Please note that any use of gfp flags outside of GFP_KERNEL is careful to not + * fall back to vmalloc. */ void *kvmalloc_node(size_t size, gfp_t flags, int node) { @@ -411,7 +412,8 @@ void *kvmalloc_node(size_t size, gfp_t flags, int node) * vmalloc uses GFP_KERNEL for some internal allocations (e.g page tables) * so the given set of flags has to be compatible. */ - WARN_ON_ONCE((flags & GFP_KERNEL) != GFP_KERNEL); + if ((flags & GFP_KERNEL) != GFP_KERNEL) + return kmalloc_node(size, flags, node); /* * We want to attempt a large physically contiguous block first because