From patchwork Tue Nov 13 05:51: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: 10679665 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 E8F96109C for ; Tue, 13 Nov 2018 05:56:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D811129FAC for ; Tue, 13 Nov 2018 05:56:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC0492A264; Tue, 13 Nov 2018 05:56:26 +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 3F15A29FAC for ; Tue, 13 Nov 2018 05:56:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B2636B029E; Tue, 13 Nov 2018 00:56:25 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 462A96B02A0; Tue, 13 Nov 2018 00:56:25 -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 305656B02A1; Tue, 13 Nov 2018 00:56:25 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id DB7086B029E for ; Tue, 13 Nov 2018 00:56:24 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id 94-v6so8779808pla.5 for ; Mon, 12 Nov 2018 21:56:24 -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=QIvKUw06n8Jw1tPXgvlWbpq7rNpI7b9HD6USl64l0qQ=; b=bZp8+R9j171/TDnJiUTG+hKkLISdB7lxfgVdz/npE2JXlmLrxhPUyCbmiDO1A1iGPi jUCPyQM3AayeJ7AtlfP3lF8CfbB3vwZeFFbkRZFEUQymlnPEQfCdXIU9hKh/ISMsxLiM neZx/UB3SuY7XYdvKQ7dZeyKzet8vQqvk4Ij4izUkRwSuTjlojDcahSrlYq54wPQc93C XsfPGns6ecEFR2GnJr4U0rrl6xw528z6j7Rf78wPNPCEZgc/J3NpQydE6eYo7vg8RX/a UfP+MjuaGSG++Wbv4BtvWP7XJDO7/YbDOjxrMZvvfgiZZAZvcaDyY0jywxkgXwJIDnE5 coQQ== X-Gm-Message-State: AGRZ1gIyjouKClLQ/+XNw7zq2Rqa5x4beNjS5mXvFW8Tnau6aDv3c8aV YewAhkbY8wjtT3CaL3GlGUFYP8bAL+x70hz3CPYEq+b0shVhyGZJTK/n9/kWyH8tPRThTV7TFGP lbekfBfdIOjTrgAGf9+siMYwx1qhHR4KZ4+ES5eVBDbYUnPkFsVpUV5UcZK2HbdkQSUtyoONOhU H1aU/gVVohHUWPl3xQ+n7H9YfXj4eWxOCiPgMnXAMVWLDrHlEalOJGR8T1MOv5LzgPaijVQ/GXj 83+QQvdZqLWgJjPlC23axaeB419aqvEquQUaGxCVdMdMDI140UjihxCMYWmAZjng0vQ8yWjxg7s Cd1hN0uPh+R67uK4OTJxUvbVBXCxcE7UKUKIOLNiPq1Ro3vCmPAEVe7OCpA1T7RABEPC+Dj0I3v l X-Received: by 2002:a17:902:1123:: with SMTP id d32-v6mr3746309pla.62.1542088344305; Mon, 12 Nov 2018 21:52:24 -0800 (PST) X-Received: by 2002:a17:902:1123:: with SMTP id d32-v6mr3746300pla.62.1542088344151; Mon, 12 Nov 2018 21:52:24 -0800 (PST) X-Google-Smtp-Source: AJdET5dkpvT32pUNjz7CmD7vcrasdjUzGttav/jqKX4eAr/wJG8AmLPD5TtmyXQpNDb73qpdb3zI X-Received: by 2002:a17:902:1123:: with SMTP id d32-v6mr3746257pla.62.1542088342925; Mon, 12 Nov 2018 21:52:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542088342; cv=none; d=google.com; s=arc-20160816; b=E95lMnh8fkib2iLdj3iCr/JXZXlofKz7nVBPMA51pOEr9GRYC2V28NR+dPJEloNwDe hKtzqyBEzNfVqqCk5sUI+9cfz/0hgknkaCgCdZNuPUFtRig5LZ/h+b4aJimgdDUHCkIc A94XQgCSDC+XQ2axbiHl5WLRYGQ79L54lXL7wfkXYfOdzEdc0FdQdJaESGI4lfU9uMfL 8P50FcVfqOtfptT44nZs44FYNU+z0dOU5mF7fgpChEhu+TKa3DOTBskKjgJYNtPSnDt6 QEMSiynmmujpAZ20Juc2W7HITANnrMSwNnfBWGd50JPoxCENV4QbgYycloP3oO5bjyqn nacw== 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=QIvKUw06n8Jw1tPXgvlWbpq7rNpI7b9HD6USl64l0qQ=; b=vn8TIiihpMjtblRsxAudGQdCTIlpN+Lk25e+1b1CjAoWfTotpbCtwZ7AacTky5PTm4 xuiY9+c72kQL8yXb+vPHDw6OQVD2BWSgoJwixw9W5ODyJAqtPTB/fOW5ECKZjkrFiRIm AUo+aCOZ3dDprI1QzcC2h7dErdG17XSGm0YpAk47T6JD7/n4YX0vZjpz6GwLLtqtHcw3 7IyEw1SQqantPwZm0yLNxXjiUfM4Ys6t7oU6wMD4NCkajjaDgxQNbMvR1n48OZ38/0N9 3XJUgJcqzBDFbr2A/cXX7O+q7PB3DEZtbAaN/AucUbjbPzzIY6Uh9NvEj0Z/8OgbJwId zw5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XDsfCc2Z; 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 e68-v6si21220794plb.172.2018.11.12.21.52.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 21:52:22 -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=XDsfCc2Z; 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 790552251D; Tue, 13 Nov 2018 05:52:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542088342; bh=g4oRi6iD6jYnZXzqC9XJfHAoZ363ncG3WwRFG+WbXic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XDsfCc2ZNmxw7TtGqMCssYA0xyyGlF3io9ukb5dYHvkl2W1v/KTNRuyTUUg5Km6hI WuDKeMjwXnQVZZ9oHcaG/wD85scaq9ktUdogQzilGUvLzvkZQ8iHrsmUsLYzVQwAuf 69mUtuLEig7x+tY3BK08RLSpYJTFNJb+U7SxFxig= 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.14 26/26] mm: don't warn about large allocations for slab Date: Tue, 13 Nov 2018 00:51:50 -0500 Message-Id: <20181113055150.78773-26-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181113055150.78773-1-sashal@kernel.org> References: <20181113055150.78773-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 198c1e2c5358..68ab88e2920e 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -3670,6 +3670,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; @@ -3705,6 +3707,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 91d271b90600..f6764cf162b8 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -971,18 +971,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)))