From patchwork Mon Aug 21 20:20:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13359784 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B4A5EE49AA for ; Mon, 21 Aug 2023 20:20:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB1E28E0015; Mon, 21 Aug 2023 16:20:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D6C8C8E0012; Mon, 21 Aug 2023 16:20:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C01D94000C; Mon, 21 Aug 2023 16:20:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7FF958E0012 for ; Mon, 21 Aug 2023 16:20:25 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 4FC0D120C88 for ; Mon, 21 Aug 2023 20:20:25 +0000 (UTC) X-FDA: 81149229210.11.3B3F283 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf28.hostedemail.com (Postfix) with ESMTP id 323E4C0013 for ; Mon, 21 Aug 2023 20:20:22 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Z2QgGOEX; spf=none (imf28.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692649223; a=rsa-sha256; cv=none; b=dBVp0bgawNHphTmO412uNLYMKKNRzRkCSXXle7T4Yxyt8b3M9LB3bxa6wP9+yieEcr97fq 5EJH1hWKsfDxuSoP3gDy5WlNx+x5Y6B/+AKytq30gLBePJUUjURQn6tEwDYTEO+ghNg0We PL/n7o3Jpl1xRg1hnPFSFxjVkkoF5sw= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Z2QgGOEX; spf=none (imf28.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692649223; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tYGfFyUq7t7eG2DfnJgfGPfrNOUqXETtillKZ2Ic8a4=; b=pz6Z//vn0K9/x7P0pyuzKunj+q+8GNnMkdh5cmxq6cx6eHSNdTiYW2LT+kMIEyEOt3SLT+ 1P7Xq2RIyDEHg6XR2AZ//ky8KgoyfymlQycj7tkXI1IGLTcGrZ9f1H/ALHdz/Thi/faniu +v2Pv6nNHD6HQ8pv6UAdxbLPlig3nJ0= 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: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=tYGfFyUq7t7eG2DfnJgfGPfrNOUqXETtillKZ2Ic8a4=; b=Z2QgGOEX+YU88go4CxiBk1uRs2 aBGSbahWb4XB33exhSqsocsfpuLMOSih/d1J+oYJPR4M7YnasVgFl4BNQxJZ+JP3WXqkD4nezXWyn ceiFlMzm9x7eRYETe01vkUIGJHoop4hUOAM7xrLUa34dPoUSs6anrg1lmyuqJAmwfFJhTWpUB1zSJ AuQjc5pru+oOvKhkaJ2jNHETW1I9Z0T1/cSuPQAhLxEyAxax34fGoaiqIzkJM5WSqTF+DfqxYX7Yk l/xIoGs8v1hwFhRuO7znM7MScBvTbAeK3zOOnEdEWye3an37pIQ/tU4wx5t0S8iesyMcE9fpzm289 j+GPvXYA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qYBNq-00CD6w-Sa; Mon, 21 Aug 2023 20:20:19 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-perf-users@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com Subject: [RFC PATCH 2/4] mm: Add vmalloc_user_node() Date: Mon, 21 Aug 2023 21:20:14 +0100 Message-Id: <20230821202016.2910321-3-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230821202016.2910321-1-willy@infradead.org> References: <20230821202016.2910321-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 323E4C0013 X-Stat-Signature: 76jn6g6s7ao36ijpzjbkt9hjzt7wi4n1 X-Rspam-User: X-HE-Tag: 1692649222-455053 X-HE-Meta: U2FsdGVkX1+ypu4MyjLG4TAW/9mG2tEgT2jKdG2UPB9fOahRTDRyCL3Cdpqc9sbMTofszWcgsrgQAArpPtrrRO9hmsR3d1rOEJ+f3I3WnIx6Yli0YQ0XUEgV/Mb7eth2++7t0LKfjJbRzKJYjW/vPQXJnK91ookVhl8gPOu4NwZ40xJ6B+NYrHFp4K4c4ulJnbOFOAJqts+awkxsc/Y04rsyddvS/xZhTRERhKCEOlVu4y5jiXlp0DqCRjc4Gb2bnWdM7zXvH3cV3aZzZrxOX80HmYsXK2xb9wnEikQxRdKz4qxYNf8W6RW4VkoIDRDXro1URS6cMk2upXkh2VWlKglXONnl5Q9JERChtGmaq8HNThzkOngvyLko3mIQD8FjrZRBLSgCCbV73OZld57SSX2fxb46h8iUiAIhknyYzPjsB/SbeAnj2jLkIEdW2EYC/vD/KmauLXNRPllysQIOgNC+1CqxWfOOGYLp/gDrBTwb3/faM6FZRcbpb+iOLIAEjn1Qpvq68EfIhX64uqIv1acQ4qNG2fX3LHD+XT1Hq72AKOb90fRfb4KUlcwoQR3dgA2V1CoVorG1qdFNR7y/rsg5o2PCKw1O/y4pWnthc42NkqIZ0SqPpr3DzEeDzFKvFjSH2c6D5T0Ot+hUT4Irz1BzTx0bbbG79uQJwo/oRd/nSFz6c5uyOL/I4bEVaqznGLR0BAmEhyYDcg6HCD7aXLYK5jsTkyaEhMPeCt+0X4ut3rqT+7736z45V/mKQAWUdwEFqNbHwTEBelQTKuCOqw1Ln7SKLII8YEgqMuoMEGFeDvw46s2SNH3Yb5Cj/ZbndIhyU2CCCO8CZkOs9WWiTbTCYscm8uId721/TPiDN3JFRn47kxxnLxM/M2jaHsvBvOeOXFDHMS1+VrS2L18Ds4pwdkMHUsJHKCuEXjFxxGD+Rf95jWOSSxp1ZkhvgnV8Gxvq6zyklz9ggk+pHmE Ro4Dy+p9 FUtWzjbF+RUAZ/mUk5mJFCNRnFb1b31bjtmHjxDlibyuK0kwUusYMZfLltGAPoa/8jGhov1zkZFpLnVew3+LxiA6ODRKb0kqxsL91bLcXmh8C5sIA3vpR/28SALo2gkSj2+QXjN+4OMneHGeCKGmntadTIbWfMsBtUTp4VAcuTKfMly0woRw+4AT3liQImRd05FSphLpuKRZ7mz7b5vC3vvDaqglNnY05tUtm+wPmrJJEd6rBY8jU9Opm1lxC1EtSMz71CRvTech3eNs= 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: Allow memory to be allocated on a specified node. Use it in the perf ring-buffer code. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Peter Zijlstra (Intel) --- include/linux/vmalloc.h | 17 ++++++++++++++++- kernel/events/ring_buffer.c | 2 +- mm/vmalloc.c | 9 +++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index c720be70c8dd..030bfe1a60ab 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -6,6 +6,7 @@ #include #include #include +#include #include /* pgprot_t */ #include #include @@ -139,7 +140,7 @@ static inline unsigned long vmalloc_nr_pages(void) { return 0; } extern void *vmalloc(unsigned long size) __alloc_size(1); extern void *vzalloc(unsigned long size) __alloc_size(1); -extern void *vmalloc_user(unsigned long size) __alloc_size(1); +extern void *vmalloc_user_node(unsigned long size, int node) __alloc_size(1); extern void *vmalloc_node(unsigned long size, int node) __alloc_size(1); extern void *vzalloc_node(unsigned long size, int node) __alloc_size(1); extern void *vmalloc_32(unsigned long size) __alloc_size(1); @@ -158,6 +159,20 @@ extern void *vmalloc_array(size_t n, size_t size) __alloc_size(1, 2); extern void *__vcalloc(size_t n, size_t size, gfp_t flags) __alloc_size(1, 2); extern void *vcalloc(size_t n, size_t size) __alloc_size(1, 2); +/** + * vmalloc_user - allocate zeroed virtually contiguous memory for userspace + * @size: allocation size + * + * The resulting memory area is zeroed so it can be mapped to userspace + * without leaking data. + * + * Return: pointer to the allocated memory or %NULL on error + */ +static inline void *vmalloc_user(size_t size) +{ + return vmalloc_user_node(size, NUMA_NO_NODE); +} + extern void vfree(const void *addr); extern void vfree_atomic(const void *addr); diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c index cc90d5299005..c73add132618 100644 --- a/kernel/events/ring_buffer.c +++ b/kernel/events/ring_buffer.c @@ -918,7 +918,7 @@ struct perf_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags) INIT_WORK(&rb->work, rb_free_work); - all_buf = vmalloc_user((nr_pages + 1) * PAGE_SIZE); + all_buf = vmalloc_user_node((nr_pages + 1) * PAGE_SIZE, node); if (!all_buf) goto fail_all_buf; diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 228a4a5312f2..3616bfe4348f 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3461,22 +3461,23 @@ void *vzalloc(unsigned long size) EXPORT_SYMBOL(vzalloc); /** - * vmalloc_user - allocate zeroed virtually contiguous memory for userspace + * vmalloc_user_node - allocate zeroed virtually contiguous memory for userspace * @size: allocation size + * @node: NUMA node * * The resulting memory area is zeroed so it can be mapped to userspace * without leaking data. * * Return: pointer to the allocated memory or %NULL on error */ -void *vmalloc_user(unsigned long size) +void *vmalloc_user_node(unsigned long size, int node) { return __vmalloc_node_range(size, SHMLBA, VMALLOC_START, VMALLOC_END, GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL, - VM_USERMAP, NUMA_NO_NODE, + VM_USERMAP, node, __builtin_return_address(0)); } -EXPORT_SYMBOL(vmalloc_user); +EXPORT_SYMBOL(vmalloc_user_node); /** * vmalloc_node - allocate memory on a specific node