From patchwork Tue Nov 13 05:52:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 10679669 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 0058D13B5 for ; Tue, 13 Nov 2018 05:56:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E298C29FAC for ; Tue, 13 Nov 2018 05:56:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6B752A264; Tue, 13 Nov 2018 05:56:45 +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 4634B29FAC for ; Tue, 13 Nov 2018 05:56:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DBC56B02A0; Tue, 13 Nov 2018 00:56:44 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 488D76B02A2; Tue, 13 Nov 2018 00:56:44 -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 32B8B6B02A3; Tue, 13 Nov 2018 00:56:44 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id DF61F6B02A0 for ; Tue, 13 Nov 2018 00:56:43 -0500 (EST) Received: by mail-pg1-f198.google.com with SMTP id q62so6007777pgq.9 for ; Mon, 12 Nov 2018 21:56:43 -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=zuQPdsDPXCbo+Uo4hKVYxA7KU6CtPFJlnlj+4TAb2ng=; b=NmK7Mqmdr2eo+k6jcZF2Q13z+0KCqC0mk4iSMlGxejavjx0oMU6zRZTJoe57WERqF6 jPoOvRU2YoKH2wkp3MC2/TtoPt0LJ9GlXZcMgIUT+NPPilnWMvhnScCblyRn47zds9z/ p/jiQFeh3rTx+tQtbk4HhvtOQqwCu8301KLKcwrYJuLFVjXFidJupd/VWqQDADQL4BVi D1HNu/uY6t87yIk69QFGFQxztHhtzYWPs1tsDe0r6IsXW/dWXhbpRKvgxZmbdI3IJ+iL o9taRdWaWm4EHPomtSD6LbqHmFzevDiyl72dizeJ5tDGygpIuCEP6GfbK0nEdZTQBtKa 3dOg== X-Gm-Message-State: AGRZ1gIUKQRTL/v1HJT5OkyjKT/JKzlMO6C7rJ/Xcr5Y89DGcmMo1Tz/ Bok/XlP+x7F7Y9+ZCEcjFdO1YhMAckV/AEdxySWAeVgJ5yOZYiB534NcaEFk380jm0L+duJZNCO pPI3mw1HdIks9blB68tWhxOssaJITLGI7H6i14vBYBNJwiGJ5jc2W/0r6iR7Kp2X3Sdm/X7AscQ EzaApY0lGM+xWwUl3Nw0icjAE+7lAQ/T6bMxXaBhb8DekhFLacg7Zhp3nTHcdKBBR3b8Wgu8bBF qVIOWAHF6eXeb4XDEHuEK1n7J/AiV/OvygADxkK4MPZwAXk4DpStA+jcE/T6nGzqcPQOgUWweO/ PYhGwf8kpfetdolWkVOF1ZkgIfIh0AByaOq5BXg+RGwpHY/Ol+Iqr/EMGmebfTQBVh6yArjImzY g X-Received: by 2002:a17:902:76cc:: with SMTP id j12-v6mr3783670plt.339.1542088363454; Mon, 12 Nov 2018 21:52:43 -0800 (PST) X-Received: by 2002:a17:902:76cc:: with SMTP id j12-v6mr3783665plt.339.1542088363332; Mon, 12 Nov 2018 21:52:43 -0800 (PST) X-Google-Smtp-Source: AJdET5fSlel7HSeVgHwGb2X+o8igrdoHaUjnRCUAcDRLR3SpuThd9ulRnxTCfoRGbXtypMmanmCo X-Received: by 2002:a17:902:76cc:: with SMTP id j12-v6mr3783608plt.339.1542088362074; Mon, 12 Nov 2018 21:52:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542088362; cv=none; d=google.com; s=arc-20160816; b=eKqMrZz+CIYkZQw39N8VhGjqQwXdM/LTwtwSYDdCa8Lh8m/8nLA3PfHNFfk/1rwL2s KkyFRmqC2GOgImkp9oxXcxLV1i7/mcHIbFMSLyi8UVU7G6NnwtyL1mrnsc+yYT3lDqEH oFX/XWxhIeaiSt/ds1oAA7ZjBF3RFuT4i88oK4xC4gMEIzzfSwMhx9fxeVjWQ8IV0Xkg ojb4x74x/dFRwgy2/qjbAQURkmLaexrNVymX75Aju2IzGkFDFdOrBB98TkAuGtrTXmJ4 rraSYfyccf9I3wwxyma9BWksAqSmsE/jRgLMz78XbUsD3GU3Ve3OD7eyqjTXeeaINv1H y5Kg== 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=zuQPdsDPXCbo+Uo4hKVYxA7KU6CtPFJlnlj+4TAb2ng=; b=cXVoFXKgSI61rdfV1hK19DN7XBIvJYsV47kKSvj+qJw7ysj2bSPImodNrOE4c24/8i 9z7PRD6plq9Q0Peh7jUFii48pM1+cGMhkhXZZWnlOXmF25R+BtX3OtMKZ4uO9HthkFb5 eHiYvrvJSrphWMNU9QOGNNsXJ6XRQj4tcIl+vrAEj4AfDEFfFMit80rT4Yc9nAHd8tsS HzcVsIipEmFGUyqelPZzi4lGg6l2ToRdBB0Z9Cnis9XVy6nXTGmLEO9Id1i+SjT9pz8e oWaLly+57pSEoc+EmI/M+87tNxsJvL5/aj+LTxrP+UDiCmp97F0Ww8ncGYJdU2S4RxCx OW1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wge2nkRb; 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 k13si13373990pgb.343.2018.11.12.21.52.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 21:52:42 -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=wge2nkRb; 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 9AA9C2251F; Tue, 13 Nov 2018 05:52:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542088361; bh=UeyeAhZLNpqh0cMAYMGzyy2/lL7C+oynF3ZSNb/JERY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wge2nkRb36lj+V6VNIUrgkpzSIjMA3mU/2WKrFn65bnk4HXLMPAu8Ol0JEPEgLmMi /NCBueTpg78f4NxyfqvTjHM3jHTPr2Yohcs23+mTGt1C+YJM4UZhrUjgh2nDrqPkR5 rp38TYTN0MJ4RoeebDsaAQO21glk3FWm+ZM9q/VM= 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.9 17/17] mm: don't warn about large allocations for slab Date: Tue, 13 Nov 2018 00:52:23 -0500 Message-Id: <20181113055223.79060-17-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181113055223.79060-1-sashal@kernel.org> References: <20181113055223.79060-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 c59844dbd034..263dcda6897b 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -3690,6 +3690,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; @@ -3725,6 +3727,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 622f6b6ae844..13f1926f8fcd 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -883,18 +883,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)))