From patchwork Fri Feb 9 04:05:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 13550845 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 DCF9DC4828F for ; Fri, 9 Feb 2024 04:06:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71BD46B0085; Thu, 8 Feb 2024 23:06:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CB8E6B0087; Thu, 8 Feb 2024 23:06:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 545EC6B0088; Thu, 8 Feb 2024 23:06:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 415A86B0085 for ; Thu, 8 Feb 2024 23:06:34 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DE561802DE for ; Fri, 9 Feb 2024 04:06:33 +0000 (UTC) X-FDA: 81770928666.10.CEE06D9 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf23.hostedemail.com (Postfix) with ESMTP id EE5AC14000A for ; Fri, 9 Feb 2024 04:06:30 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AZ1NeioH; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707451591; 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=8KvQuM8OQ/k4hdbGFhyp69M4b0glecGcjvBA4TzLzwQ=; b=4XAq38QhCIo/VXi8v/Iel8nuYpoBf0wo8KD+XGJheAaT2iRS7JoGvh0ePcG20V7f1nSr9u UfRSMuk9fzFhHHkeXnjhTKpLMA7E5wC70SXww5h//CNdCz9tdxhNHj4hHAfCi9e9abqT9u fug3uaJJrGh/xAbP8g566iDzjm78pLU= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AZ1NeioH; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707451591; a=rsa-sha256; cv=none; b=deUUK6dKhHphXSoJQ5xJNkYrEeIW6CMpWS0W8ttghpSaZW05SopWEmZbvMnoZkjFJ5nhHM ObkTAzjhYgZCJYf08iBK06NjaancTvUj0OtkxsEw0J/FwFRCWMCD124eP8SRMTAtqQdSLt wcZPh/nGOE/ZTtTPm+FcIb+AapIRQ3U= Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-6e065e5f721so372771b3a.3 for ; Thu, 08 Feb 2024 20:06:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707451590; x=1708056390; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8KvQuM8OQ/k4hdbGFhyp69M4b0glecGcjvBA4TzLzwQ=; b=AZ1NeioHPp1J2nGZG5aagPUgUMJLm91rL3pdl4wkDO8z2fYxzpaEVjxqhA3ckwyejv Bbqx1iqbjyQU/AUmVF39OtX2wQCbWqdSrhAdeuePk8oONrcunlS3O3iuVopMQ9iqG7FJ vMCtQudUIKtVLLjoNlkKhAqv5YnPlSALRlm3hFV76JwOiX4+IHWgNDxX8G7mD4dL486y STy3vpJjlrxJLpiQidXXGIdpXlnmI9tHjRgB3xvGUhy4twpYJVkYe0OA82OVeLpYbVWq t/0AIHU7FWlfnJBaEZ9X9nZS9KDVnyrlKUaZWJd5PvElUWav9YYb9gXEkQwVCqzE/2QM sMtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707451590; x=1708056390; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8KvQuM8OQ/k4hdbGFhyp69M4b0glecGcjvBA4TzLzwQ=; b=vxTnbDI2a4ZQcgaekeZ43LUf+Q4XU2fZVpOGmBbuiFn5vUU8I9a2/rWgj3uCSLmwrk VERGN0TK92uC+8MgYIwmQ0+JWDYoWXeSuAGINECq7UrJpiZiYx40INt6ROS0b6cHytGn XIyt42BXrHiGeMMiX1l82sA2Hi0Eo9gLB4wBvjzuJjAbXhYK2UDftRTvvXnANYYNianO mdOh3m1mJBDrN16/r5vOHFCCkYnoG6FPAwW8nUKdWPFgfFhVD3OIx/dn9gz6HdDP3KSU 3nUW23+zbXOTfmCJYlT9yYNVCzzpEjZvktCBGXA8wG4erdJP77ZjtOd92bvvXpQrE1Ig iawQ== X-Forwarded-Encrypted: i=1; AJvYcCWEXP30p2nzVhSgf0Cf4EdkZPwry0r79IXFwR3NBSGZkjAkfc0UJMOFlS4hKgnkn95lgSeOFkmADrNufVCY9fs9Lx8= X-Gm-Message-State: AOJu0YwfzIFu4DejgfokUb6/x7+vOTjn6X5IIMW9xIf0i3f028GIBCau Vkg8zISHPmb9ItH4cToyHVv1MfCO2N9j+kSd7UR4zukzxp0lMs/Y X-Google-Smtp-Source: AGHT+IGQBdQ96AWfRShK3THRmZ/s+UP/PKdWL9/0jO8LeSeDC7xm1ls7NjuGAIDwxkvXo++YHCAN4Q== X-Received: by 2002:a05:6a00:bdc:b0:6df:e85e:ecc6 with SMTP id x28-20020a056a000bdc00b006dfe85eecc6mr521111pfu.3.1707451589662; Thu, 08 Feb 2024 20:06:29 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWdg8hv5XdH6EKCu1LTwjNtjdDavpVVV78qHLOLm6RZihoGfapXop+ABS9UTa9kAd3MiFUVzdXtkUDGGX96nIPHXik+Vtby1jDoxmr93Sadbon7ZAQZgHUtdc4jR8uEEianIkut2yaoRtShsOlvTSBLyu6qrKADVSDnSWmXWKw7Z+GYkTkVIxTMwWhVUkuQ3tyuAMr64xwMkrKnAnn2HdWivAzaIpaikmZVk5QXlulka1ipuvoCbLwhJ/vJd7n5LB6etkbgJ2LbWrom4JWoyjucVlWdpM7pX6nH6nTuIfGVEzy5qQr/g6YbNCh7o033IAymJ/6+pJsAzwh3lWNBTSOlquwUKBcGvK083zCJn2ES30w86coAEg== Received: from macbook-pro-49.dhcp.thefacebook.com ([2620:10d:c090:400::4:a894]) by smtp.gmail.com with ESMTPSA id x29-20020a056a000bdd00b006e0418993cesm591583pfu.8.2024.02.08.20.06.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 08 Feb 2024 20:06:29 -0800 (PST) From: Alexei Starovoitov To: bpf@vger.kernel.org Cc: daniel@iogearbox.net, andrii@kernel.org, memxor@gmail.com, eddyz87@gmail.com, tj@kernel.org, brho@google.com, hannes@cmpxchg.org, lstoakes@gmail.com, akpm@linux-foundation.org, urezki@gmail.com, hch@infradead.org, linux-mm@kvack.org, kernel-team@fb.com Subject: [PATCH v2 bpf-next 04/20] mm: Expose vmap_pages_range() to the rest of the kernel. Date: Thu, 8 Feb 2024 20:05:52 -0800 Message-Id: <20240209040608.98927-5-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240209040608.98927-1-alexei.starovoitov@gmail.com> References: <20240209040608.98927-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: EE5AC14000A X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 9m8xzpzosw4w9ak39ayxkbztx4y1cntg X-HE-Tag: 1707451590-353151 X-HE-Meta: U2FsdGVkX19JpV6UDbxqlnT+t+ZQJje4noN0GITxFPLrNZvtB98BgEp4dKFpJaq3U45iBtZmubMWLAAeDuKQiKo3fexWX2pXRdf5reBF/rltTDIMD6Nsop6Ynb9HB8Sz+GnUMdYfXWkeI2qk5B2H1RkHx9fglPQR/WiS/1os/6R89n6Zq60PhG/1hI0eQbt1Ll+NY1xRmdLJvD0RSs0ONyqaU6cDtD8Zz3I7HL0v170Od6Es/2EhnKF7IFpZlzrWX8IlkQKKO6UK2ovvPEh2o/r0DP0j/AHBngixtWPg2+FBEVHq+VKnrUHeVfOkk3yHjc8ZtTz+i1NtkXLuBzXMFB8iYQ3qFBqyP0Ebv4ax9L0rsj3W4+L0BHxOpSNOHvVPuMLlvC5L8WhfocYNxEFL2RWfTPwPxV8SvjH1rxiB6NPtr0OC1rue8VAfw5CteJm3U1X2Un8Suf2wbMFesBQP2hILgjcNxMY/IwJT3zD33/AIIL3wpZLUQJ6B1RcxiNMByBsL4Fmf0R5qBCuVSqg6hQIWU8aUlDb4EGFl45TNMVBMReFw6yJCiOFj0sLLBsBQ4ghfBzF6jDb4+j9NmG8NCk+Ab5AbTWtvin3fzchY9FgazJ7lPqEsQiWEcK69UPunLS3fqZP6HzZ9ggVv4RlztEOOwJfuFHkeZE48yeHBRjFHu5DZlj+VFCQTaqBjxDX7701ec463IkCw9ql4QZquCdUTHpXWzz2ZjPkMFltuTgpPJ+bap6ONlDQ2EU2pwCUjwoV0YK1/NDFKFNuj5w04yriEUmj8GtxCGzPPdpdeOPXuqYyDxGTT7oTdJsyxMCFyHObg4pjDS1qthRRpeT8wP08xJFPc6PCiBSNSVNZnz0iWNjh5AZn4Y/9ToH/q1Tdx7UWJXsn4fhNorp4EOnGbvo4tz06eDro1jBJpkbSosLinwi5pfZmhML5+eYq+p+xpjAkEI+LnT8iYKNjX12B XmJMn0xZ ijc6aDqfCtKlnz1dtCNQgedOAhhc/xy4JQ7I4US4RQsPm85Aaej4EsA7kMq7xI40KR8qcoYyxh3+E6OxGZWowmIuNSIzVYsNMEpb41fxt1mcpiSOIvsE7B4unL1Hfri5ms3NovffihQRNSl9sbBbLwgHyRsFHjckKIiA5YSW4fiHUmynxzCKQJuCsolhqxOO/mj2IE4mP2kmlk0lCcPcrdfDceeYOBY/teqpZ2TvNS0peDbgYZdQ0UmBJ1TW/s6qc32KhRNoFOOvQ3AhdIqztd9gcq2Tw0w2BzHBRvAx1EARP2JZeSquwBd9rui8lEZ3AtlO3+f1WoKmZxhFgcxzIgIf/Cx1J8wImPo/IS7NN88ZlHp57heGJTiWlLi5cDwx2ySgE2hQSl2/PVd6zmrDcPCORAzuoGSJKQIo6UnIuyQWS5XFOiHOuGvU9zvi7kGe0qvw1JGtLpQfm8rUqkv/nzs7DVL+T/GYHMpnD7RxyI2UBLDbKbX/JvDs7Hp6g/+jQuYIZeCAZToFnePWhK9oWa2/7pze8CHVdCFiSoZy1iCkqfKiSV7niI6tIe8qXOPqjmK/wh/zzdfIid8GX6cBQp4e5kF0JJ0AZylhq 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: List-Subscribe: List-Unsubscribe: From: Alexei Starovoitov BPF would like to use the vmap API to implement a lazily-populated memory space which can be shared by multiple userspace threads. The vmap API is generally public and has functions to request and release areas of kernel address space, as well as functions to map various types of backing memory into that space. For example, there is the public ioremap_page_range(), which is used to map device memory into addressable kernel space. The new BPF code needs the functionality of vmap_pages_range() in order to incrementally map privately managed arrays of pages into its vmap area. Indeed this function used to be public, but became private when usecases other than vmalloc happened to disappear. Make it public again for the new external user. The next commits will introduce bpf_arena which is a sparsely populated shared memory region between bpf program and user space process. It will map privately-managed pages into an existing vm area. It's the same pattern and layer of abstraction as ioremap_pages_range(). Signed-off-by: Alexei Starovoitov --- include/linux/vmalloc.h | 2 ++ mm/vmalloc.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index c720be70c8dd..bafb87c69e3d 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -233,6 +233,8 @@ static inline bool is_vm_area_hugepages(const void *addr) #ifdef CONFIG_MMU void vunmap_range(unsigned long addr, unsigned long end); +int vmap_pages_range(unsigned long addr, unsigned long end, + pgprot_t prot, struct page **pages, unsigned int page_shift); static inline void set_vm_flush_reset_perms(void *addr) { struct vm_struct *vm = find_vm_area(addr); diff --git a/mm/vmalloc.c b/mm/vmalloc.c index d12a17fc0c17..eae93d575d1b 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -625,8 +625,8 @@ int vmap_pages_range_noflush(unsigned long addr, unsigned long end, * RETURNS: * 0 on success, -errno on failure. */ -static int vmap_pages_range(unsigned long addr, unsigned long end, - pgprot_t prot, struct page **pages, unsigned int page_shift) +int vmap_pages_range(unsigned long addr, unsigned long end, + pgprot_t prot, struct page **pages, unsigned int page_shift) { int err;