From patchwork Tue Jun 18 22:45:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13703115 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 D3E18C27C4F for ; Tue, 18 Jun 2024 22:45:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5AEDF8D006E; Tue, 18 Jun 2024 18:45:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5374C8D0066; Tue, 18 Jun 2024 18:45:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3627F8D006E; Tue, 18 Jun 2024 18:45:54 -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 137708D0066 for ; Tue, 18 Jun 2024 18:45:54 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B7166A0ABF for ; Tue, 18 Jun 2024 22:45:53 +0000 (UTC) X-FDA: 82245493386.24.6457290 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf30.hostedemail.com (Postfix) with ESMTP id 6465F80014 for ; Tue, 18 Jun 2024 22:45:51 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=h+7m1+Mf; spf=pass (imf30.hostedemail.com: domain of andrii@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=andrii@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718750747; 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=+BHFCISMLwJKW22QX58L7fMOjU5YYBLJsv1sprYhrVQ=; b=G9f7KgS8JKzs1Xw5m0o8mX8fvYdZjuZ6nqUz1ZjXQ/cr4L+cc65YYK6zXKiDmEmH+ghCKL NWsPTF34Wcs9s+TMXFG+X/AM4s5wUZnKWJVSgKFEa1AV3PKDuKORYOdgi9n9ThB11T7Ge/ TrHtbRsvTyFU1v6jodrhGKkdFxwNse8= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=h+7m1+Mf; spf=pass (imf30.hostedemail.com: domain of andrii@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=andrii@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718750747; a=rsa-sha256; cv=none; b=7ZtK30l6XYEW8pdKAsvS2mMgjESIBiqXPzeCtP6zUw4NgM0/GvzykcAUdgT2WoL6/3yAtV QNcnqjblW/bV74QNmGeb3Q6OkST7rqbBN+0Ee6rqNsDeA2U3BxjwPklBOTCQHEwGnCMxm6 OioNB+zX9PR4fGNXoIDpEAWcNMLyigE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id D8BA5CE1BAC; Tue, 18 Jun 2024 22:45:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0592AC32786; Tue, 18 Jun 2024 22:45:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718750748; bh=BRYHJjN55WzCmrelJcd8JVcPZniK31ZSH/3ppJflWBk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h+7m1+MftxjtctKSgK+ErwiEiUuKyGqmCNL+qDMH6l5ecOdq7PogE8ZeY9/wQDkWz yaB4VZX+sao0OsXy2X3rmy+7mqsMauaYi9vEVXYvwzl1lOeK631bUfPUV5yIpH4dv+ Pg1sTWe842h1BzI3FOevUeMSseDIShK6pHN7HYXZenyQIJhcb+9jy67xmMOq81DPRH ElfNqsmCu/VRajWHgAkegR7UbM2In+9u6yIFvHXyO/ptL+oBlvujZbqJimkz6L2QLd JMaW5qvY4WeDV3opbnev60+toF+pj5/fzA13ywqOkNHJxp0yh7UnpYoEtJ3Bo2s9kr r4EdVfrIUNf/A== From: Andrii Nakryiko To: linux-fsdevel@vger.kernel.org, brauner@kernel.org, viro@zeniv.linux.org.uk, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, gregkh@linuxfoundation.org, linux-mm@kvack.org, liam.howlett@oracle.com, surenb@google.com, rppt@kernel.org, adobriyan@gmail.com, Andrii Nakryiko Subject: [PATCH v5 5/6] tools: sync uapi/linux/fs.h header into tools subdir Date: Tue, 18 Jun 2024 15:45:24 -0700 Message-ID: <20240618224527.3685213-6-andrii@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240618224527.3685213-1-andrii@kernel.org> References: <20240618224527.3685213-1-andrii@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 6465F80014 X-Stat-Signature: 88j33j7ta4ibogs77axfo9dig37ba4dr X-Rspam-User: X-HE-Tag: 1718750750-452663 X-HE-Meta: U2FsdGVkX1/JdgKbt5v0VCa8bJxOpmEbV0Bmr4LRSanQm7PJTOEuG10a+6lh1iPDMGnTfGx4E81+a7eOiHvdoJFYM4qa+q1TZieq9wGrWfmO+L17tlbvphrsw8zrkk8znp/SKYsEvCDKnqARojUwe/zCDl94pnuIdcs8F2S3d9zjhaqNrRYXfJmU3MmK9Nzqx/b6j49dGLE/dzBQO4zCqQJPmyzawpkemV5yuW7w/PyNEGqm3xl84SIDN1tU2KUP8441ffMNSSrUJtdQIwsaQpMQ8deYxcqJAYBMAsQ3CiBE3NxuRdQDIuKk4/lyd6yMxrLOFVBeFgSjFFPY3h4G7t+iSaPOImoB6oHo0igCqhbSWvtafUbd0KH3Qb1qePu6kvzyXLo9QtgqA6s8T7y+ZyuTAuyH7YQUoX3VVWV9waP7m8GBosS8vjA+dKvYu3sOTyKSBQdvvIz0uc6v/PhTxVegJWEBHWnDLaA9urFHanYXl8rDdNqYNIBJNWLtwCueTsy7Wu9/ZvwO/oFZqMdlBTGbo6uA521B9mDShbyvL05hFXlYrBQfnM8yFs+V7TWkU37kML1p7lFd7XWpOVatg+o1id1qXHFD/4+7SvB68INGx5Y9FLVsiIKTkfx8RMjnXjQF8LZTTFWXbwDIYDoszWWTweqEWXMM0RslDeQ4aIGq4gD7UdlGfTj/6y7Pj8KyXS9WNgwRIWs+bGtQBqBbNbDMp2w8IUn/YWZ2wyxdwC8WNce6CG/2hNTiHkgbcRvhtCzVTE50XhU8BM0sUXQmt+yLHLrRCek462/gNDRf1ZRAmUB2P56nNf1w6M+i/eKLxAD5Jj+7uMubeSZoSuoOj/aRzLVZi2I8QTwmwCYglzbEbK8SC27reZsFBAqfG5mn0e31YjEnkQZxt8j/nmzlUOOtdQ8PEMKC/d6gtC05WPAMKJHugrvIhJvUkvHIocytFw5Pga6RAl/fh19kNl5 sEfsxW2i iZxlMlhVVll0N0gcSSY178wqmbZdEs34EpwFD+YPR7sRhIBanph224x16PNJzj6YkVqelAqhdDonE8X6AZ/h/TlIxEBGN7RpDR/LaB6/7l/6kqFBYWFGPbLzdPD0lCDDO7gmWpWmJcGKAMyN7aWpXAs2HrXnKXsA+v1q9EFzQ+ZRejwVrH4hMpwCTFgtWluYnPWgZ741a8lcavEU3f/vDiCeZMqqYs+ABy1vVWpfHrho7lkY= 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: We need this UAPI header in tools/include subdirectory for using it from BPF selftests. Signed-off-by: Andrii Nakryiko --- tools/include/uapi/linux/fs.h | 184 +++++++++++++++++++++++++++++++--- 1 file changed, 172 insertions(+), 12 deletions(-) diff --git a/tools/include/uapi/linux/fs.h b/tools/include/uapi/linux/fs.h index cc3fea99fd43..cad6375044bc 100644 --- a/tools/include/uapi/linux/fs.h +++ b/tools/include/uapi/linux/fs.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ -#ifndef _LINUX_FS_H -#define _LINUX_FS_H +#ifndef _UAPI_LINUX_FS_H +#define _UAPI_LINUX_FS_H /* * This file has definitions for some important file table structures @@ -13,10 +13,14 @@ #include #include #include +#ifndef __KERNEL__ #include +#endif /* Use of MS_* flags within the kernel is restricted to core mount(2) code. */ +#if !defined(__KERNEL__) #include +#endif /* * It's silly to have NR_OPEN bigger than NR_FILE, but you can change @@ -24,8 +28,8 @@ * nr_file rlimit, so it's safe to set up a ridiculously high absolute * upper limit on files-per-process. * - * Some programs (notably those using select()) may have to be - * recompiled to take full advantage of the new limits.. + * Some programs (notably those using select()) may have to be + * recompiled to take full advantage of the new limits.. */ /* Fixed constants first: */ @@ -308,29 +312,31 @@ struct fsxattr { typedef int __bitwise __kernel_rwf_t; /* high priority request, poll if possible */ -#define RWF_HIPRI ((__kernel_rwf_t)0x00000001) +#define RWF_HIPRI ((__force __kernel_rwf_t)0x00000001) /* per-IO O_DSYNC */ -#define RWF_DSYNC ((__kernel_rwf_t)0x00000002) +#define RWF_DSYNC ((__force __kernel_rwf_t)0x00000002) /* per-IO O_SYNC */ -#define RWF_SYNC ((__kernel_rwf_t)0x00000004) +#define RWF_SYNC ((__force __kernel_rwf_t)0x00000004) /* per-IO, return -EAGAIN if operation would block */ -#define RWF_NOWAIT ((__kernel_rwf_t)0x00000008) +#define RWF_NOWAIT ((__force __kernel_rwf_t)0x00000008) /* per-IO O_APPEND */ -#define RWF_APPEND ((__kernel_rwf_t)0x00000010) +#define RWF_APPEND ((__force __kernel_rwf_t)0x00000010) /* per-IO negation of O_APPEND */ -#define RWF_NOAPPEND ((__kernel_rwf_t)0x00000020) +#define RWF_NOAPPEND ((__force __kernel_rwf_t)0x00000020) /* mask of flags supported by the kernel */ #define RWF_SUPPORTED (RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT |\ RWF_APPEND | RWF_NOAPPEND) +#define PROCFS_IOCTL_MAGIC 'f' + /* Pagemap ioctl */ -#define PAGEMAP_SCAN _IOWR('f', 16, struct pm_scan_arg) +#define PAGEMAP_SCAN _IOWR(PROCFS_IOCTL_MAGIC, 16, struct pm_scan_arg) /* Bitmasks provided in pm_scan_args masks and reported in page_region.categories. */ #define PAGE_IS_WPALLOWED (1 << 0) @@ -389,4 +395,158 @@ struct pm_scan_arg { __u64 return_mask; }; -#endif /* _LINUX_FS_H */ +/* /proc//maps ioctl */ +#define PROCMAP_QUERY _IOWR(PROCFS_IOCTL_MAGIC, 17, struct procmap_query) + +enum procmap_query_flags { + /* + * VMA permission flags. + * + * Can be used as part of procmap_query.query_flags field to look up + * only VMAs satisfying specified subset of permissions. E.g., specifying + * PROCMAP_QUERY_VMA_READABLE only will return both readable and read/write VMAs, + * while having PROCMAP_QUERY_VMA_READABLE | PROCMAP_QUERY_VMA_WRITABLE will only + * return read/write VMAs, though both executable/non-executable and + * private/shared will be ignored. + * + * PROCMAP_QUERY_VMA_* flags are also returned in procmap_query.vma_flags + * field to specify actual VMA permissions. + */ + PROCMAP_QUERY_VMA_READABLE = 0x01, + PROCMAP_QUERY_VMA_WRITABLE = 0x02, + PROCMAP_QUERY_VMA_EXECUTABLE = 0x04, + PROCMAP_QUERY_VMA_SHARED = 0x08, + /* + * Query modifier flags. + * + * By default VMA that covers provided address is returned, or -ENOENT + * is returned. With PROCMAP_QUERY_COVERING_OR_NEXT_VMA flag set, closest + * VMA with vma_start > addr will be returned if no covering VMA is + * found. + * + * PROCMAP_QUERY_FILE_BACKED_VMA instructs query to consider only VMAs that + * have file backing. Can be combined with PROCMAP_QUERY_COVERING_OR_NEXT_VMA + * to iterate all VMAs with file backing. + */ + PROCMAP_QUERY_COVERING_OR_NEXT_VMA = 0x10, + PROCMAP_QUERY_FILE_BACKED_VMA = 0x20, +}; + +/* + * Input/output argument structured passed into ioctl() call. It can be used + * to query a set of VMAs (Virtual Memory Areas) of a process. + * + * Each field can be one of three kinds, marked in a short comment to the + * right of the field: + * - "in", input argument, user has to provide this value, kernel doesn't modify it; + * - "out", output argument, kernel sets this field with VMA data; + * - "in/out", input and output argument; user provides initial value (used + * to specify maximum allowable buffer size), and kernel sets it to actual + * amount of data written (or zero, if there is no data). + * + * If matching VMA is found (according to criterias specified by + * query_addr/query_flags, all the out fields are filled out, and ioctl() + * returns 0. If there is no matching VMA, -ENOENT will be returned. + * In case of any other error, negative error code other than -ENOENT is + * returned. + * + * Most of the data is similar to the one returned as text in /proc//maps + * file, but procmap_query provides more querying flexibility. There are no + * consistency guarantees between subsequent ioctl() calls, but data returned + * for matched VMA is self-consistent. + */ +struct procmap_query { + /* Query struct size, for backwards/forward compatibility */ + __u64 size; + /* + * Query flags, a combination of enum procmap_query_flags values. + * Defines query filtering and behavior, see enum procmap_query_flags. + * + * Input argument, provided by user. Kernel doesn't modify it. + */ + __u64 query_flags; /* in */ + /* + * Query address. By default, VMA that covers this address will + * be looked up. PROCMAP_QUERY_* flags above modify this default + * behavior further. + * + * Input argument, provided by user. Kernel doesn't modify it. + */ + __u64 query_addr; /* in */ + /* VMA starting (inclusive) and ending (exclusive) address, if VMA is found. */ + __u64 vma_start; /* out */ + __u64 vma_end; /* out */ + /* VMA permissions flags. A combination of PROCMAP_QUERY_VMA_* flags. */ + __u64 vma_flags; /* out */ + /* VMA backing page size granularity. */ + __u32 vma_page_size; /* out */ + /* + * VMA file offset. If VMA has file backing, this specifies offset + * within the file that VMA's start address corresponds to. + * Is set to zero if VMA has no backing file. + */ + __u64 vma_offset; /* out */ + /* Backing file's inode number, or zero, if VMA has no backing file. */ + __u64 inode; /* out */ + /* Backing file's device major/minor number, or zero, if VMA has no backing file. */ + __u32 dev_major; /* out */ + __u32 dev_minor; /* out */ + /* + * If set to non-zero value, signals the request to return VMA name + * (i.e., VMA's backing file's absolute path, with " (deleted)" suffix + * appended, if file was unlinked from FS) for matched VMA. VMA name + * can also be some special name (e.g., "[heap]", "[stack]") or could + * be even user-supplied with prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME). + * + * Kernel will set this field to zero, if VMA has no associated name. + * Otherwise kernel will return actual amount of bytes filled in + * user-supplied buffer (see vma_name_addr field below), including the + * terminating zero. + * + * If VMA name is longer that user-supplied maximum buffer size, + * -E2BIG error is returned. + * + * If this field is set to non-zero value, vma_name_addr should point + * to valid user space memory buffer of at least vma_name_size bytes. + * If set to zero, vma_name_addr should be set to zero as well + */ + __u32 vma_name_size; /* in/out */ + /* + * If set to non-zero value, signals the request to extract and return + * VMA's backing file's build ID, if the backing file is an ELF file + * and it contains embedded build ID. + * + * Kernel will set this field to zero, if VMA has no backing file, + * backing file is not an ELF file, or ELF file has no build ID + * embedded. + * + * Build ID is a binary value (not a string). Kernel will set + * build_id_size field to exact number of bytes used for build ID. + * If build ID is requested and present, but needs more bytes than + * user-supplied maximum buffer size (see build_id_addr field below), + * -E2BIG error will be returned. + * + * If this field is set to non-zero value, build_id_addr should point + * to valid user space memory buffer of at least build_id_size bytes. + * If set to zero, build_id_addr should be set to zero as well + */ + __u32 build_id_size; /* in/out */ + /* + * User-supplied address of a buffer of at least vma_name_size bytes + * for kernel to fill with matched VMA's name (see vma_name_size field + * description above for details). + * + * Should be set to zero if VMA name should not be returned. + */ + __u64 vma_name_addr; /* in */ + /* + * User-supplied address of a buffer of at least build_id_size bytes + * for kernel to fill with matched VMA's ELF build ID, if available + * (see build_id_size field description above for details). + * + * Should be set to zero if build ID should not be returned. + */ + __u64 build_id_addr; /* in */ +}; + +#endif /* _UAPI_LINUX_FS_H */