From patchwork Fri Feb 9 04:05:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 13550844 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 89924C48297 for ; Fri, 9 Feb 2024 04:06:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 152346B0082; Thu, 8 Feb 2024 23:06:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E20C6B0083; Thu, 8 Feb 2024 23:06:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E94F76B0085; Thu, 8 Feb 2024 23:06:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D2B8C6B0082 for ; Thu, 8 Feb 2024 23:06:28 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8DB1AC0291 for ; Fri, 9 Feb 2024 04:06:28 +0000 (UTC) X-FDA: 81770928456.03.2CB779F Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf02.hostedemail.com (Postfix) with ESMTP id BBBCA80013 for ; Fri, 9 Feb 2024 04:06:26 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LxrBm5w1; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.179 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=1707451586; 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=6BMTbGEmBryFuIGcZHloqpvwHOH0k2D5DfDjYGSWlIg=; b=OHi/Tr/HRrJB7qCNiOhjj7fWS3cru98w6O3gFfsr7s4e7cQD9HGTqmkm+nSkEJM2+pZbqD UPxlH82zv6K0SC0lzSgjHXG6eLRVw9M+T3iUmv3YS/VlkoJWIeqGNxy1wImGdj1I/k/Yln 7CERASEq/t09UvYB7POC5xtIOlVm8QQ= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LxrBm5w1; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707451586; a=rsa-sha256; cv=none; b=79YeVPvGnk88eL2C2WoZlYEO9hT1ktBFRRR0v9kDSM+Q2ajl1MHXM/dgmkun/iNW/+I3I6 M/88YC2zdEHtQI+kHCWQXaMBb3+903/jnju0ihVnPoSHTfnVwBatRRXAYg+UaiLUT/BJbU lZTGBJGpmtDMN4YMCkZCAHwvwyvqlCA= Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1d8ef977f1eso4579015ad.0 for ; Thu, 08 Feb 2024 20:06:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707451585; x=1708056385; 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=6BMTbGEmBryFuIGcZHloqpvwHOH0k2D5DfDjYGSWlIg=; b=LxrBm5w1BL65KktdysnXPhif0cH7DvqEWvLipSmVVvECNcQnZMAMOUE0PwT/oJUf/N xlamza0a+dSwrpyU+ZUztyk5WsZCcNTIl29BS5e8fzrVmKHnIRQ+zNA5zg8NuuiSOjPJ 4JFAuGX1yEs4VOxBpFCpekhNZLmP6/7gLlRvr/NngSWzDDApRUni68t+vqzjVHkIWVgx JKIh0Nl9/DYDnOwMeF5fj2xwazQt69Q/QfIIQeyKG7MuVm2XbGVBBbpNEy2TMrjJt9BJ l1BrCpgi9W1uyBNW2LgLSqhWFqCGzBPCX6uFfJ0m0Rj2QHanT27kHKskJTUOf/Lh+3LU Jxzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707451585; x=1708056385; 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=6BMTbGEmBryFuIGcZHloqpvwHOH0k2D5DfDjYGSWlIg=; b=ry4F/NSjzQfk+y92v4Aq3ilHrMYqO9JUumNWz6htlUGgU+5DQ2p8whmBUhwPaf2Ln2 RYR0awiwPoP3apKTOb+GN0lCZZfMcPphSpzrMPS+AHCrohfSKPR0Wf3YWqUC4duEK1pN nNyQtkP9JDPM8CYIzbEhpLiUmbPcIBUn5DRIb7y1ZAHO5J3WIX8E/jLzl8nu1iQ2ghPR 6R/pq7+NFpUHtgfv9Z5iWBAKmglqYzvWe6nQCu9CQFetU8Kqeuh0z6OzAsHm1rP4SKBv XwJIsIMPm3iHfjQYC9KR6Tpe16+p78W21ECUIrQl4WxVah8eI3Wc8Z6cciGcBJ5YO48u WKRg== X-Gm-Message-State: AOJu0YyDjWnzpSNqMipnOgzyhf4XGrZo7uK/bKcjHGqs4+7yRVVumCSD 8GXDjG/EazmYTq2fcbEkS6A44J7FarbFD3zSFslAMaJ8RfRHQ2wK X-Google-Smtp-Source: AGHT+IF5Mfq/bPHfBQYoGGtl+p8BmK45T13+kVLjl6HOkUeWFmPC1hzclwCAAHXTr58YrlBe4W+2VA== X-Received: by 2002:a17:903:40ca:b0:1d9:5f11:d018 with SMTP id t10-20020a17090340ca00b001d95f11d018mr520921pld.1.1707451585566; Thu, 08 Feb 2024 20:06:25 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCU+VQojeGmZnI/6ZKbMA4QjC6Z7cs8p2E3pelD8tmw/+rxHsyJp+sHxsISw306bbIwagnzXrqksuerDCdyJyzHnkQ8d3DIm2mi1k1zoOdJMP/wTNoNNR5ir3f4CT7VEYkubNEGmEnkgZRPf9eGmcjXs9cZMp9inOKRZV5yXU3IAzhgmqi2+d2s8sfmHKBYfLJ0cTlhfgPzGfXc6HritoDUz+EJpKOETMg/w/f5tKSmrToubP2DeHNnK+Nb6neWYKAOjYI7Nbtm4Q637JP9enCDVLsNvdrPpk40p+0X64NQlSkbO6KUf1lMsM+50n70zWLAH4TkyqwOFm/a4C0sXyAEf8d77rzbEMPOXScNRvVSW7DsnXrjq3Q== Received: from macbook-pro-49.dhcp.thefacebook.com ([2620:10d:c090:400::4:a894]) by smtp.gmail.com with ESMTPSA id ki11-20020a170903068b00b001d937bc5602sm544378plb.227.2024.02.08.20.06.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 08 Feb 2024 20:06:25 -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 03/20] bpf: Plumb get_unmapped_area() callback into bpf_map_ops Date: Thu, 8 Feb 2024 20:05:51 -0800 Message-Id: <20240209040608.98927-4-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: BBBCA80013 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: gcfoh1j7j336shmmttte4spuy7r4teap X-HE-Tag: 1707451586-616659 X-HE-Meta: U2FsdGVkX182MFdoYyRCiiM5Oygi7D9qdxy7Vl6RMyimfBLcKkN4gk6Rq/RqT9M0FJ2ebKrjm8vIB063JUA03zSaFvY9iDU4ih5X7Z/vzlq4Wvw6PpZjf4mSHf4UqvFltQRCQ8ZjtBiaod7vYonr4CCI8VQH3vmCUDFdviuR5WtpylNDOWdLeaZFGcrXh3FLIGps4fmbth5+XSBun7RzK6ze9BKa5P776Nv9CUmQllmaPIAPXlWTnKR35Z+/HNaRXIxLTey8fUKieTK4BMOid+oViGQXFN3ruuFBqTDmDzneptVYz6TjejkE3vfXKWNO8nMDQy5KyrFYKgi/vBHiqC3RFC9pclHWNJUKsDQh6I50J4qc9V0cprAEBzfhFKu2iJdpJcsYmQvD/FmEbGwiGWknMw1tGv27GWX+VlrYuAash3lvuyCgzi9I/j+2AGgTF1Ii1XH3ElzXeGeAcjR2vWKom5y0237+vTSD35ZVF9+56KMaPnxJG2HfqH1g8rG3s7fozQexL6GJEHMClj2l7sopxc6m+2Szjcxp4F0hQGc5PDgxtxiDBQV+MURSNM+fINKqEzzaSoetMQW7DO6K2Jm1eUaC1i0t66jfS00TVDkA726+edzBt1hbCisdNE9YtpUYU0vk9IKjk7ePvopNuzYf1nSIXw43Xq6NuRUIdtCLyGzHdAoJzGnNGdIBlVRoEMqxrr3HBq8hUZbVuRl4mx9oF6h9J7mcBskOIMmBv41gVPkPdWEG937EOG/Gv2AJGRjRLKap6fK5PLSUFudoZWqXCsj0bWA7fT4lb20L9Dj1PjzWZfVTRfZsWuCqWMlkpDQAUVZyLNvpPovpx2rUJXdjEjrl1/Mb718eH4Ok6lTAMzqq1h44WOywHTnrmEaxxSOSH0zfXYuTtaEx4TaKyNDn3PT0JAQp31oR5a5CZN3crs9OePzLIERWupYbirHZrZrWvKL9J5s626UPQK7 t0/IArdH KGWdAHUlr6N0rzzoVQLt+jGrH7pHrLx5B5CiGAtsW4SQ4ZBbMLLRRlG4fvx0aen+cCqxuzYT5Ydl2HbHMdS+UpAXxIUSBz/dCy1GviYUrTJv1huDp0xk+dlzMNRF0AxzQ9BDW1mnBfun8dQmd2S1JFBBWLrX1QyS9Qc/Bz0GSwsyObdAHQw5T4sNvq+CaHgm5W0der+K4UrqU+eSM6AUW+y62+2Kc3Cg+LtRtSRG80Adatz18dg+5cdKPmdH1aYHwvG8WNmnsuZWXJa4rVu1/a+l/p1CU1LhYMibs5rcyGEneP/LfLvBlH/rQdg0mReE5gaqayxQYGcE1/mYULL1xdMzz0Kmo1KEi5HrrssdO9JVySgabWMTi1dzGeqwn+7YYc4RKLquEqN4xYZlPl9/vNolzXkU5vxn1sqx1D73ZYqJyI2eYlqcwyuGRZ4NqDTOjEsxBa2K7vhRdvwiJYmdbiKFF8A3oqsPFCVw12fgMl2xViwSo2pHDnr/cQK+sjkP6Z8tCEPVn2bu346bd28zAYynmhJUZgJIBc40BSy5B6YKHtJZ7X1uu1dEhCgzp00UK0nptlH4Z32K+v0yLmK2ev6O2FBnvZvvYoBLW 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 Subsequent patches introduce bpf_arena that imposes special alignment requirements on address selection. Signed-off-by: Alexei Starovoitov --- include/linux/bpf.h | 3 +++ kernel/bpf/syscall.c | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 1ebbee1d648e..8b0dcb66eb33 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -139,6 +139,9 @@ struct bpf_map_ops { int (*map_mmap)(struct bpf_map *map, struct vm_area_struct *vma); __poll_t (*map_poll)(struct bpf_map *map, struct file *filp, struct poll_table_struct *pts); + unsigned long (*map_get_unmapped_area)(struct file *filep, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags); /* Functions called by bpf_local_storage maps */ int (*map_local_storage_charge)(struct bpf_local_storage_map *smap, diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index b2750b79ac80..8dd9814a0e14 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -937,6 +937,17 @@ static __poll_t bpf_map_poll(struct file *filp, struct poll_table_struct *pts) return EPOLLERR; } +static unsigned long bpf_get_unmapped_area(struct file *filp, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags) +{ + struct bpf_map *map = filp->private_data; + + if (map->ops->map_get_unmapped_area) + return map->ops->map_get_unmapped_area(filp, addr, len, pgoff, flags); + return current->mm->get_unmapped_area(filp, addr, len, pgoff, flags); +} + const struct file_operations bpf_map_fops = { #ifdef CONFIG_PROC_FS .show_fdinfo = bpf_map_show_fdinfo, @@ -946,6 +957,7 @@ const struct file_operations bpf_map_fops = { .write = bpf_dummy_write, .mmap = bpf_map_mmap, .poll = bpf_map_poll, + .get_unmapped_area = bpf_get_unmapped_area, }; int bpf_map_new_fd(struct bpf_map *map, int flags)