From patchwork Tue Nov 13 05:50:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 10679655 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 D54F2109C for ; Tue, 13 Nov 2018 05:55:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3D0929FAC for ; Tue, 13 Nov 2018 05:55:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B712F2A264; Tue, 13 Nov 2018 05:55:53 +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 DA16129FAC for ; Tue, 13 Nov 2018 05:55:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF1C26B029C; Tue, 13 Nov 2018 00:55:51 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C78DA6B029E; Tue, 13 Nov 2018 00:55:51 -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 B1B4B6B029F; Tue, 13 Nov 2018 00:55:51 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by kanga.kvack.org (Postfix) with ESMTP id 6AF296B029C for ; Tue, 13 Nov 2018 00:55:51 -0500 (EST) Received: by mail-pf1-f198.google.com with SMTP id 129-v6so9545305pfx.11 for ; Mon, 12 Nov 2018 21:55:51 -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=awUPsRmGv7aD/Cg9oCyKAUsZoVxKMnOuwQoRAGhNkxk=; b=ZadbvwFnzzwNDUnrARmRcEbELqm75IOigy3eyXd0CoIRaq1aEmAHJ5cO4cm7aR7iia wwrDWwSJKIS7xUnTGEV8xYWodljUocCKE4G8oGQTiBZOTZnu/K8XeyVvAiFm6L3S8A6b BEEP1Sq9VD8RaNPIjT4J0T1OQCZGlsLyCzEn93cveupa1eKdY0+DY3OyM9GfRK6DxgCI frRj4pEBsnobay+JZFP/UUaIgJlpzaFagae1+JoAbL9GrZ6tQiXMyXL0q/flDLCzFcBC Q5gFoyEhr2dYvMguVyMPSkje29vuD1jXqdgBCtsgOD6eGYe7cr1qfC8DXibCfCipEXKm FXlg== X-Gm-Message-State: AGRZ1gIbxMEI2qrExaiWzHMERTxU5F5iGLexXNRqJMRSYYHglrxlLcuI IMUA140yfTcJhYzVpSXFsTvOaGUPL7pXIroWQhhVUboIyIG1A1gP9n8NSnjCpGl8rxvhLqUQ6N+ /wXLwxR0iQeSdOOLj6W+fDJInK/o62Z3114faLu47R0gNoM6XLYIbEBkQqZgK1RF2ZfWOy8S4fN 1in538Swq1nkzj5pCQ9Yfa3gCN3JzRevljN2DNVwGxmqPPYJDDtI9xjdEPqHevkZq17VI1iTmzE 1yHdLdwcNoNEb90mXiEn451EjKS4i15y5tnMMtSsDVMfmY65xnGEgorsPzhIA2aiVyuqCkqZXxu k0uri7Ru98abDBXGg4YX4HbfzTayhLnO7w0jJATAkOjfCL/Z436JlVvTPQqMqBdRLUkgiluMNTb Q X-Received: by 2002:a63:ae01:: with SMTP id q1mr3470259pgf.402.1542088311846; Mon, 12 Nov 2018 21:51:51 -0800 (PST) X-Received: by 2002:a63:ae01:: with SMTP id q1mr3470252pgf.402.1542088311723; Mon, 12 Nov 2018 21:51:51 -0800 (PST) X-Google-Smtp-Source: AJdET5eUlH5v3k3IYIUxGjBB+FDHKqdjVOImsHdnK48LU69WOU324GKBRHzuWTofmyIGBC08pO87 X-Received: by 2002:a63:ae01:: with SMTP id q1mr3470211pgf.402.1542088310561; Mon, 12 Nov 2018 21:51:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542088310; cv=none; d=google.com; s=arc-20160816; b=E0nswGeZDpNqx8jApDGoLdEhSQYLmJEb6jX8+5UN+qDy9mOz1NJZqOwCAWhkHslagD Swy/cEREYbhI2ld82N/4uVM9NPkJ7czWj+wOv8jSQn+QLdnnxg0pXW2Xzt9iE/ukt5Yk /Tzg83s7Dm/7glS/JfRUMYkN3T6uVZc9CVMYqvr4egRAJV+pANJErgR0Npxzk+YxOmaZ 26ZblBdKBs9SRGdtPHcLERlXSkDRMjI1UG6AxD8d7FW3U50BYTnzRk0OXaDTGlSCt+10 PTEhDQGLjST09kavLxGd3RCzbhDziS27BdAJ41vUJdPf2RwgEeKj3lm0xuVOODoJREnS FjKA== 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=awUPsRmGv7aD/Cg9oCyKAUsZoVxKMnOuwQoRAGhNkxk=; b=fKGm/jol2H4ggul2v5kMouuz3Jc50d9oe+N3E7IlCdAhyc3LRN0+Xf1zdDdcLLTqmQ L3fytOetX+l+fr619HadveEnfmidMDJY+FKrFIN7FwQ1ixsrE2vKubQoCXS2r3PX6rEt CXjDNJ+kHg9POluLPp70wmEROch4alDiqMf/SXYz8o6rHnlvOQ2jFuN95NiZ7h1MkgVq uE2/2zFGNuxQKYIXeOduFDjpwfdmz3fe/zFS2hFxdvjxANZn8gRDVoDulKgQmu5K1E/+ BRndndjgcBZmddGKd250lMZw1Axc8ebRkCGD570aHRze+W/AoDBUFcTamV7TSBLyYSMj BOrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hagp5elB; 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 j7-v6si18831404plt.349.2018.11.12.21.51.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 21:51:50 -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=hagp5elB; 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 0AA4D22510; Tue, 13 Nov 2018 05:51:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542088310; bh=Lpm7SHpu7WLq7xIwdN24+tKRdX4Rqfv+5SIwBwozd4g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hagp5elBRNonOsJVyZAlAzUnNHNGCgcvywZn4gEFF24NSfDgeKru3jbC8/la1b888 058SDH8NXHGDslcHDIoXHFQ/iHLh6ezctN6DNC3sT4DT3g0eM1Wars4V/94VZU+5F3 mfT4n54aQ2jm99bJoSsvfDj0ihnmftdsMg2/pvLI= 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.18 39/39] mm: don't warn about large allocations for slab Date: Tue, 13 Nov 2018 00:50:53 -0500 Message-Id: <20181113055053.78352-39-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181113055053.78352-1-sashal@kernel.org> References: <20181113055053.78352-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 2296caf87bfb..8a0fba22c910 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)))