From patchwork Tue Nov 13 05:49:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 10679645 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF893109C for ; Tue, 13 Nov 2018 05:54:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9999929FAC for ; Tue, 13 Nov 2018 05:54:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CE192A264; Tue, 13 Nov 2018 05:54:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCF0229FAC for ; Tue, 13 Nov 2018 05:54:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CA4706B029A; Tue, 13 Nov 2018 00:54:54 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C2C246B029C; Tue, 13 Nov 2018 00:54:54 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ACC2C6B029D; Tue, 13 Nov 2018 00:54:54 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id 67EC56B029A for ; Tue, 13 Nov 2018 00:54:54 -0500 (EST) Received: by mail-pg1-f200.google.com with SMTP id r13so7359652pgb.7 for ; Mon, 12 Nov 2018 21:54:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=lJoup+4NDZD4AsOOaATFOKwdwPjtOOPxQJpxr0dlKJU=; b=AnQ7G0BPiUucCmnnDYde8kNDnQDEXMk36mMeQ+2ta+9+74U03b1qmeloLapNkGkWuL k6qpfb/5048STkege9HQ/gth979ulWwbiKZE2/8mbfYxXGxVGBy6roRWkN3pyeh2bVk5 M9EU2o2RYtgdQXX14SJ8/RRt38M2UgeeNInqtLcAQs7N5oC15KKwDsjQnm+E2V8+J72u JkyrxyonTeWH6B0GIcdFrwAi7U4mk/paL3ch4zceEdzXl7rb3LHEN+LgvaLw+IwcWWuO LpQdhCUNB3IX5Q3YNGqHKETlfpIxNVpm2ek1+9ZUbDFFeJwE94eaiKhMKQunqZs4am9S fP3Q== X-Gm-Message-State: AGRZ1gIvGitxtM62paE9hpRCFDPuwBbirg95WUbtJmmUdaUJhDbCGZeF rpnYSNJNrg84AkRioi/mmyXGQ2Q96Z19b60WO/qVaJYXQvbKgGrDYM+jcRKHU1WCJYZE3SmtrqG iSI7226sDqsyXkq+L/B864EhkUQvXqUFblqOOHYo5xToOFdQgYOzZ1EcYCatiA1qE44QQf7KUFt kbf8g04ZfSBhZHXeJnujBimWs2R/Xk5zYLYhnvbsu4aX++a3NeJApJ4HTsfyttCyB8TDaBLcvRr BD+dFKWJjFoyQZH2dZj4Sck+W+wvJa34mshVdH4UhNXDTemqh+/agDyKWCUz5UU47lGWEr/yome 3PCP+4S+cpnATp7cT1hNT+m2/j+SED7+YR/Jr7ss5JjcU7VGShFyXbCmYFJC++NUu9eLM3veiOD 1 X-Received: by 2002:a17:902:a40f:: with SMTP id p15mr1624100plq.286.1542088254745; Mon, 12 Nov 2018 21:50:54 -0800 (PST) X-Received: by 2002:a17:902:a40f:: with SMTP id p15mr1624093plq.286.1542088254625; Mon, 12 Nov 2018 21:50:54 -0800 (PST) X-Google-Smtp-Source: AJdET5cZgO0LBQwH7vE6Mkll4vUjoAFOwk1AHoHn9ZKfpuuB0qWk90FMZIr/tJ8j3B4pJo/TxFNS X-Received: by 2002:a17:902:a40f:: with SMTP id p15mr1624055plq.286.1542088253535; Mon, 12 Nov 2018 21:50:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542088253; cv=none; d=google.com; s=arc-20160816; b=GExjfeAfe17vdLxibXY7cyH3IUJc914GsDbI4ZkpOMaLLxvGy8ZfDfp3WjLZU+8XK6 TpGcXK9mjUFfsrBx4ldiftytMq5ZdgfYd2led2eQHR2jcXgzMS1FjhBJYCZXQJcjM8Y/ rTlfQG8akFRxXs+4YLDyH5dHcpMakwQaRUcysVxY6m1QAFvffbn4m9nLMOdTG5KUt2YQ fPj+e6IWAZsz35cfJmsw36iXl9i0d3Dst3X4F1TPQ75WX22KWq6ut+o0Zsi5AkBDQRDa tUgsHTNNaBV+nrVRtgWGfOvMZicQPtWVd/3zSzxUjkF8RHZqCTFEM0E/cSDxuBqHPlQt C5Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lJoup+4NDZD4AsOOaATFOKwdwPjtOOPxQJpxr0dlKJU=; b=LBYcV/mi2Py7EaBsdeEgcCLcrRakxHvKkNOfg4GdS3on9/smmoDm5DiQMe8mnRasva DfqR8v2CMDsZT4xSiayo+H+K58Zd0j+8eBVKCui/r0l0v7uogqEOK08dGvwzs2MfZ3m8 yHxs2Le2hFIbn0WvP0rIRS3ozIt/OxWIedK1NSdQJRNDBL7tRQntkrjVj676CnT3oYCe ymQXJsao0biWMEjDqq89fodpkXVuxCIXvNddIW9z0B0A1fapY0da0K65+ZCGAB2067Lx b5BQu9vIJnpIjyZfrmNg6EwkxKHF/Q6zEO0L5W+nxIzFIk+9YJpLaMNq0lPY+ztNE8FX IDzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Vxojw30r; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id g13si18325824pgk.165.2018.11.12.21.50.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 21:50:53 -0800 (PST) Received-SPF: pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) client-ip=198.145.29.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Vxojw30r; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sasha-vm.mshome.net (unknown [64.114.255.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1730E2251C; Tue, 13 Nov 2018 05:50:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542088253; bh=2/QX0btORBDgnTEIH7KoPpLIqiZPGQBd0g8YV15QEcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vxojw30rfT2xVucovt21hAQcox63gLY1aoinmLA7ktOju+6jjiwAjQMMXnz6rQAk5 eh/nnY8yN55vbvHGaXiuqbJQnd8YOsJxhoMoki9e64iibKvKyae4/n0bcUdOAIJJn+ j1G6IdZSW8xdXGB6nEGGA+IHIFKcJVxRDYckzuo8= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dmitry Vyukov , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.19 44/44] mm: don't warn about large allocations for slab Date: Tue, 13 Nov 2018 00:49:50 -0500 Message-Id: <20181113054950.77898-44-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181113054950.77898-1-sashal@kernel.org> References: <20181113054950.77898-1-sashal@kernel.org> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Dmitry Vyukov [ Upstream commit 61448479a9f2c954cde0cfe778cb6bec5d0a748d ] Slub does not call kmalloc_slab() for sizes > KMALLOC_MAX_CACHE_SIZE, instead it falls back to kmalloc_large(). For slab KMALLOC_MAX_CACHE_SIZE == KMALLOC_MAX_SIZE and it calls kmalloc_slab() for all allocations relying on NULL return value for over-sized allocations. This inconsistency leads to unwanted warnings from kmalloc_slab() for over-sized allocations for slab. Returning NULL for failed allocations is the expected behavior. Make slub and slab code consistent by checking size > KMALLOC_MAX_CACHE_SIZE in slab before calling kmalloc_slab(). While we are here also fix the check in kmalloc_slab(). We should check against KMALLOC_MAX_CACHE_SIZE rather than KMALLOC_MAX_SIZE. It all kinda worked because for slab the constants are the same, and slub always checks the size against KMALLOC_MAX_CACHE_SIZE before kmalloc_slab(). But if we get there with size > KMALLOC_MAX_CACHE_SIZE anyhow bad things will happen. For example, in case of a newly introduced bug in slub code. Also move the check in kmalloc_slab() from function entry to the size > 192 case. This partially compensates for the additional check in slab code and makes slub code a bit faster (at least theoretically). Also drop __GFP_NOWARN in the warning check. This warning means a bug in slab code itself, user-passed flags have nothing to do with it. Nothing of this affects slob. Link: http://lkml.kernel.org/r/20180927171502.226522-1-dvyukov@gmail.com Signed-off-by: Dmitry Vyukov Reported-by: syzbot+87829a10073277282ad1@syzkaller.appspotmail.com Reported-by: syzbot+ef4e8fc3a06e9019bb40@syzkaller.appspotmail.com Reported-by: syzbot+6e438f4036df52cbb863@syzkaller.appspotmail.com Reported-by: syzbot+8574471d8734457d98aa@syzkaller.appspotmail.com Reported-by: syzbot+af1504df0807a083dbd9@syzkaller.appspotmail.com Acked-by: Christoph Lameter Acked-by: Vlastimil Babka Cc: Pekka Enberg Cc: David Rientjes Cc: Joonsoo Kim Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/slab.c | 4 ++++ mm/slab_common.c | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index aa76a70e087e..d73c7a4820a4 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -3675,6 +3675,8 @@ __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); if (unlikely(ZERO_OR_NULL_PTR(cachep))) return cachep; @@ -3710,6 +3712,8 @@ static __always_inline void *__do_kmalloc(size_t size, gfp_t flags, struct kmem_cache *cachep; void *ret; + if (unlikely(size > KMALLOC_MAX_CACHE_SIZE)) + return NULL; cachep = kmalloc_slab(size, flags); if (unlikely(ZERO_OR_NULL_PTR(cachep))) return cachep; diff --git a/mm/slab_common.c b/mm/slab_common.c index fea3376f9816..3a7ac4f15194 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1027,18 +1027,18 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags) { unsigned int index; - if (unlikely(size > KMALLOC_MAX_SIZE)) { - WARN_ON_ONCE(!(flags & __GFP_NOWARN)); - return NULL; - } - if (size <= 192) { if (!size) return ZERO_SIZE_PTR; index = size_index[size_index_elem(size)]; - } else + } else { + if (unlikely(size > KMALLOC_MAX_CACHE_SIZE)) { + WARN_ON(1); + return NULL; + } index = fls(size - 1); + } #ifdef CONFIG_ZONE_DMA if (unlikely((flags & GFP_DMA)))