From patchwork Thu Dec 2 02:06:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bixuan Cui X-Patchwork-Id: 12651461 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 EFF1BC433F5 for ; Thu, 2 Dec 2021 02:06:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 589F86B0072; Wed, 1 Dec 2021 21:06:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 512456B0073; Wed, 1 Dec 2021 21:06:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B2916B0074; Wed, 1 Dec 2021 21:06:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0213.hostedemail.com [216.40.44.213]) by kanga.kvack.org (Postfix) with ESMTP id 24E3A6B0072 for ; Wed, 1 Dec 2021 21:06:43 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D099C8249980 for ; Thu, 2 Dec 2021 02:06:32 +0000 (UTC) X-FDA: 78871215024.08.3701EF1 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by imf08.hostedemail.com (Postfix) with ESMTP id CDB1A30000A9 for ; Thu, 2 Dec 2021 02:06:32 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04395;MF=cuibixuan@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0Uz7z7hl_1638410784; Received: from VM20210331-25.tbsite.net(mailfrom:cuibixuan@linux.alibaba.com fp:SMTPD_---0Uz7z7hl_1638410784) by smtp.aliyun-inc.com(127.0.0.1); Thu, 02 Dec 2021 10:06:28 +0800 From: Bixuan Cui To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org Cc: leon@kernel.org, cuibixuan@linux.alibaba.com, akpm@linux-foundation.org, w@1wt.eu, keescook@chromium.org Subject: [PATCH -next] mm: delete oversized WARN_ON() in kvmalloc() calls Date: Thu, 2 Dec 2021 10:06:24 +0800 Message-Id: <1638410784-48646-1-git-send-email-cuibixuan@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: CDB1A30000A9 X-Stat-Signature: p4i8s3wc8a1xd31s7c8pw9h36cw8ai7o Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf08.hostedemail.com: domain of cuibixuan@linux.alibaba.com designates 115.124.30.132 as permitted sender) smtp.mailfrom=cuibixuan@linux.alibaba.com X-HE-Tag: 1638410792-549892 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: Delete the WARN_ON() and return NULL directly for oversized parameter in kvmalloc() calls. Also add unlikely(). Fixes: 7661809d493b ("mm: don't allow oversized kvmalloc() calls") Signed-off-by: Bixuan Cui --- There are a lot of oversize warnings and patches about kvmalloc() calls recently. Maybe these warnings are not very necessary. https://lore.kernel.org/all/YadOjJXMTjP85MQx@unreal The example of size check in __do_kmalloc_node(): __do_kmalloc_node(size_t size, gfp_t flags, int node, unsigned long caller) { struct kmem_cache *cachep; void *ret; if (unlikely(size > KMALLOC_MAX_CACHE_SIZE)) return NULL; cachep = kmalloc_slab(size, flags); mm/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/util.c b/mm/util.c index 7e433690..d26f19c 100644 --- a/mm/util.c +++ b/mm/util.c @@ -587,7 +587,7 @@ void *kvmalloc_node(size_t size, gfp_t flags, int node) return ret; /* Don't even allow crazy sizes */ - if (WARN_ON_ONCE(size > INT_MAX)) + if (unlikely(size > INT_MAX)) return NULL; return __vmalloc_node(size, 1, flags, node,