From patchwork Tue Jun 22 21:57:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 12338659 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68DB9C2B9F4 for ; Tue, 22 Jun 2021 21:58:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D998360FDC for ; Tue, 22 Jun 2021 21:58:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D998360FDC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B40E46B006E; Tue, 22 Jun 2021 17:58:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ACA196B0070; Tue, 22 Jun 2021 17:58:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 944A96B0071; Tue, 22 Jun 2021 17:58:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0054.hostedemail.com [216.40.44.54]) by kanga.kvack.org (Postfix) with ESMTP id 568576B006E for ; Tue, 22 Jun 2021 17:58:47 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 980AD10FF1 for ; Tue, 22 Jun 2021 21:58:47 +0000 (UTC) X-FDA: 78282725094.35.0C5F8E5 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP id C33CDC01C091 for ; Tue, 22 Jun 2021 21:58:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=INWpsc1UVjms1eLYsvuvGZc0zD9LX7V0xGiQqg6km1o=; b=e7r9sbUnAb7gN7BztF5Nm75xsK cWpyUXRPWmVUSimdR6iL03cJaLBr1u9OQczRskBllHFSi+GLUa66pqpPPm057WMR+XePc3B91ZGCZ S1Y+1tc7b7CmqotwQnaTFC2Iabs5ZFExciQnZJkytuhtJYuBaK2hctXqyzzWiYudxG6qPJfEIJMjQ /kJd6RBzAwYy1wAHg401NGgJEel0m+Y71xpkbdug3dYUhzVYO+JWfKiLQ2U5gIbbPiJeWlfkqj0ac kEB676HDG2h3ENilpBMO5o5/A2vTzm8artM24Y+XWK1WQb+8U5bk9Fn5wEHiNZtAYVXmWnQbaXIBJ MuRaCCTQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1lvoPA-00EnBm-NH; Tue, 22 Jun 2021 21:58:11 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Vlastimil Babka , Joonsoo Kim , David Rientjes , Pekka Enberg , Christoph Lameter Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH v2] mm: Move kvmalloc-related functions to slab.h Date: Tue, 22 Jun 2021 22:57:57 +0100 Message-Id: <20210622215757.3525604-1-willy@infradead.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: C33CDC01C091 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=e7r9sbUn; spf=none (imf14.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Stat-Signature: o6mqdptgozx7jna37t964urcapdj5z8p X-HE-Tag: 1624399126-489403 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: Not all files in the kernel should include mm.h. Migrating callers from kmalloc to kvmalloc is easier if the kvmalloc functions are in slab.h. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Pekka Enberg --- v2: allmodconfig revealed someone calling kvmalloc without slab.h. It doesn't include mm.h either, but clearly it's being included through some indirect path. drivers/of/kexec.c | 1 + include/linux/mm.h | 32 -------------------------------- include/linux/slab.h | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c index f335d941a716..b90660c05f30 100644 --- a/drivers/of/kexec.c +++ b/drivers/of/kexec.c @@ -16,6 +16,7 @@ #include #include #include +#include #include /* relevant device tree properties */ diff --git a/include/linux/mm.h b/include/linux/mm.h index 8ae31622deef..750a6f227ec7 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -798,38 +798,6 @@ static inline int is_vmalloc_or_module_addr(const void *x) } #endif -extern void *kvmalloc_node(size_t size, gfp_t flags, int node); -static inline void *kvmalloc(size_t size, gfp_t flags) -{ - return kvmalloc_node(size, flags, NUMA_NO_NODE); -} -static inline void *kvzalloc_node(size_t size, gfp_t flags, int node) -{ - return kvmalloc_node(size, flags | __GFP_ZERO, node); -} -static inline void *kvzalloc(size_t size, gfp_t flags) -{ - return kvmalloc(size, flags | __GFP_ZERO); -} - -static inline void *kvmalloc_array(size_t n, size_t size, gfp_t flags) -{ - size_t bytes; - - if (unlikely(check_mul_overflow(n, size, &bytes))) - return NULL; - - return kvmalloc(bytes, flags); -} - -static inline void *kvcalloc(size_t n, size_t size, gfp_t flags) -{ - return kvmalloc_array(n, size, flags | __GFP_ZERO); -} - -extern void kvfree(const void *addr); -extern void kvfree_sensitive(const void *addr, size_t len); - static inline int head_compound_mapcount(struct page *head) { return atomic_read(compound_mapcount_ptr(head)) + 1; diff --git a/include/linux/slab.h b/include/linux/slab.h index 0c97d788762c..ee676de68afe 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -697,6 +697,38 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node) return kmalloc_node(size, flags | __GFP_ZERO, node); } +void *kvmalloc_node(size_t size, gfp_t flags, int node); +static inline void *kvmalloc(size_t size, gfp_t flags) +{ + return kvmalloc_node(size, flags, NUMA_NO_NODE); +} +static inline void *kvzalloc_node(size_t size, gfp_t flags, int node) +{ + return kvmalloc_node(size, flags | __GFP_ZERO, node); +} +static inline void *kvzalloc(size_t size, gfp_t flags) +{ + return kvmalloc(size, flags | __GFP_ZERO); +} + +static inline void *kvmalloc_array(size_t n, size_t size, gfp_t flags) +{ + size_t bytes; + + if (unlikely(check_mul_overflow(n, size, &bytes))) + return NULL; + + return kvmalloc(bytes, flags); +} + +static inline void *kvcalloc(size_t n, size_t size, gfp_t flags) +{ + return kvmalloc_array(n, size, flags | __GFP_ZERO); +} + +void kvfree(const void *addr); +void kvfree_sensitive(const void *addr, size_t len); + unsigned int kmem_cache_size(struct kmem_cache *s); void __init kmem_cache_init_late(void);