From patchwork Tue Nov 13 05:52:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 10679677 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 7FEBD109C for ; Tue, 13 Nov 2018 05:57:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6ED8429FAC for ; Tue, 13 Nov 2018 05:57:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 630462A264; Tue, 13 Nov 2018 05:57:07 +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 B9EEB29FAC for ; Tue, 13 Nov 2018 05:57:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B44C76B02A4; Tue, 13 Nov 2018 00:57:05 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AF1756B02A6; Tue, 13 Nov 2018 00:57:05 -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 96DA36B02A7; Tue, 13 Nov 2018 00:57:05 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by kanga.kvack.org (Postfix) with ESMTP id 50BD26B02A4 for ; Tue, 13 Nov 2018 00:57:05 -0500 (EST) Received: by mail-pf1-f200.google.com with SMTP id a72-v6so9573021pfj.14 for ; Mon, 12 Nov 2018 21:57:05 -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=tF2sOgqTTtf23IsObTuFdWR8R11O/EQfQPFMPT2uhd0=; b=HSK5bynFSwHhNpNGQ8vpTeVztrEdnelQ+SUHUxGuBiHa+A4YELN86BYx92OzRiPAVK 6xnOImDnzU8a4G8rIg336c9zf+4UyWkgWZzRc8mitXiCS9ldsAPaQ0eW/o1PVdy7MhXB 51U8Eqk6+V52/23iz5y1nIYYpPeMK13KqZfYjvtCL01RG64yVbuNhpPhzvZ4iBNtuLvg GJRbiHRPvmOkFdX6sMS8X50q1bw2A2KLJ2OqS5px3lGaqwfhnZP8vNG8NK+5ZXsIwuJa V8LBofnPNWZGMN0OylzQFbvjCcFCa/sAqF6ySFkYeKfiWEvfc2ro2qG5TXhLM9cIYpqA Vn9Q== X-Gm-Message-State: AGRZ1gI8Mt2uzkWA2wzYV3mUuW/hihqjQ9syMmzKz/i2UkekaLkfEHXr 3BxmFKIEU/4eTdcn5Ex/gWGTBRu+NKK62LwEpqVUctuGrgf0EVnxnabWAtGQ2Unghw73BnJh8mC a//o+5zyp02JAVq36DzFExn4/e5zmp7VPOGlNsqBWsUUlLvvn9gd8pTwJF9mByuyqqvoUz6dQtD X6K9Ap8ztX1BVPf7aEuvkO2kk4SHq00qFDkNZT1lRJDF4TLfIgmV8hCKfPf5XvKi37cvaFKu8dq gaG6bvDHMkS3Miq/DFesfm0EfGULVF1e7gUtaajhMD0alztPHvzIQ2Ge59gJOFZQiELBN+iQKbe b4xY4d7D0hOpolXje0wqXpI1z1mZpG1avCfTSwOHjHWT/Ble7SG1ny/vMTL80zmnTcFifTlhWAL R X-Received: by 2002:a17:902:544:: with SMTP id 62-v6mr3539275plf.73.1542088384873; Mon, 12 Nov 2018 21:53:04 -0800 (PST) X-Received: by 2002:a17:902:544:: with SMTP id 62-v6mr3539267plf.73.1542088384749; Mon, 12 Nov 2018 21:53:04 -0800 (PST) X-Google-Smtp-Source: AJdET5fS0RnSKhk+byP2yV7dscPV2qjKZiOqwsVSyrf91os4fQLenWzK5D7/JiHbNdBt6NvJi1Hv X-Received: by 2002:a17:902:544:: with SMTP id 62-v6mr3539220plf.73.1542088383643; Mon, 12 Nov 2018 21:53:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542088383; cv=none; d=google.com; s=arc-20160816; b=EG9HnoXONYUsDN2n6ec80In6GpcaJSzxl1ffRdurna9p2oh5E2Q/zKYrtPPAwDqtIj /kll0c67MJIENImWlOYzH7G6oJCvzxo63Ig21Gl7kGm65yCP16UkO3A+MWep77HbfJH0 rUPNlPpn+ylNa0BAoEapdDby5+Q/u3IOK+c4mCxtE/3nIDM7pd/HZSHfrOeTN+OwIZXp Qifnks5RO2J8ML2C/RuKRIbtIwrgBSn60SoHTowdjea8W+s4IkQNOGxpqRV3Sfk81nGP Rxx9GSHcp13fXbPuHIJUbCZuAuCERYlR31WebIPLQ8NnVRxjeG0DsJQQ16l9J4tlnuVc xMuQ== 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=tF2sOgqTTtf23IsObTuFdWR8R11O/EQfQPFMPT2uhd0=; b=rrTIReYQcne5fOq1vhb/9HYnOIyTCkcwMyzKOLTcnsd3U7QvPt+MxcrOqRUdyHU23l Owb069b1jMs/ynAxZp5S8C71D2SWIsI5mUj/zH/SXvSKvJ05/59EOM1dCOwwgXQl0Viy dejTsRKymX/+qBIMbR0CfSuAfzjb+47q2enqVJbQyIUWZERG9Zwy5kGWK90erILlorFD Bf607JwjxMNQbSccmwFoqBV8F4N0eMolW8CxZz8qXcxl9fbmHS8Di6E0U6DopPMOrU1K vrFJ/CcjeJd/ZmALhxiaJGvIj5XjEkWtMKwY5KB/a6ew/EeJLlqpm/4lb8DeAvfP16jw 27Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=su9rMUoZ; 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 x16si18382845pga.407.2018.11.12.21.53.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 21:53:03 -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=su9rMUoZ; 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 283C422520; Tue, 13 Nov 2018 05:53:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542088383; bh=KOhqBvlnJ4r2HHtNKM4xp1EZPdIZoiatRSG29taCjCc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=su9rMUoZ5vqx070BOgUiX55inootisEZUUzvzwir0J3ECAsWxkEMbw2jUVrOqOD/g nJXuKf/PsdFc7GVlS7p1Bcc4tTRqaOFiV9iw2kRs6agi/s47BeDCYwTrlpRtZKifbi l4TvzdLwvLHo6Vuj17tbEMx47J4oFdGEDTNwp0qY= 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 3.18 9/9] mm: don't warn about large allocations for slab Date: Tue, 13 Nov 2018 00:52:52 -0500 Message-Id: <20181113055252.79406-9-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181113055252.79406-1-sashal@kernel.org> References: <20181113055252.79406-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 b7f9f6456a61..0b8ff2152f60 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -3465,6 +3465,8 @@ __do_kmalloc_node(size_t size, gfp_t flags, int node, unsigned long caller) { struct kmem_cache *cachep; + if (unlikely(size > KMALLOC_MAX_CACHE_SIZE)) + return NULL; cachep = kmalloc_slab(size, flags); if (unlikely(ZERO_OR_NULL_PTR(cachep))) return cachep; @@ -3497,6 +3499,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 dcdab81bd240..d8489833d423 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -653,18 +653,18 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags) { 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)))