From patchwork Tue Dec 3 15:31:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13892624 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 B5D3EE64ABB for ; Tue, 3 Dec 2024 15:33:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94F5E6B0098; Tue, 3 Dec 2024 10:32:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8AE916B009A; Tue, 3 Dec 2024 10:32:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DB386B009B; Tue, 3 Dec 2024 10:32:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4E35C6B0098 for ; Tue, 3 Dec 2024 10:32:59 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0E0CB1C7479 for ; Tue, 3 Dec 2024 15:32:59 +0000 (UTC) X-FDA: 82854039912.17.C774BEA Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) by imf23.hostedemail.com (Postfix) with ESMTP id 5A67214002D for ; Tue, 3 Dec 2024 15:32:48 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=1TImmsmk; dmarc=none; spf=pass (imf23.hostedemail.com: domain of axboe@kernel.dk designates 209.85.167.176 as permitted sender) smtp.mailfrom=axboe@kernel.dk ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733239971; a=rsa-sha256; cv=none; b=FsG1UGLDItdrdaLgDtxrUC6q8mwt3TxQnmVcmQsJ2l/T4KOvD/WSNZ+KWQl++aJwA2aCJC 241cz5zI3kZX3IWEZq/VJ4iPzDo4P12xD1GBRVN0ETibdurMiQby1nERKtCUPEbbVvNqDv okGeDZJPFuMKrkamIvxM5JlFgiT4dNI= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=1TImmsmk; dmarc=none; spf=pass (imf23.hostedemail.com: domain of axboe@kernel.dk designates 209.85.167.176 as permitted sender) smtp.mailfrom=axboe@kernel.dk ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733239971; 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=99ZtQ6Npm+o/kkpmwDDPCgpJncZgiN/IMlRLftnmHuc=; b=tRmpiqTn7HVU579T2EaUhJv2IGtGSVRmVaJFPsFieOA7BR8AOtX24tIlBk6b5up1QmEoYh L+vfvKuWzWvUGE4pRKSH1MBEjZVo6yWRRkeY+MDq2GjwDNoiAUrdJ8pl/DFgW7G6kF2ksS Nyb5peGooz+bOqs0C03L1dM/OzsQoTg= Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3ea55a2a38bso3014476b6e.1 for ; Tue, 03 Dec 2024 07:32:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1733239976; x=1733844776; 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=99ZtQ6Npm+o/kkpmwDDPCgpJncZgiN/IMlRLftnmHuc=; b=1TImmsmkuy27vqjtxe8RTBh0uKldqqYlJcmBwynwiWNb533yq//HH+VflbxQsFAjtL NSV8jMw/5P4HD7R+ftzO7+F0mRkStdTfaO3PlO6vhns59kaNlvK25ahu1lTXjvAyLMwP WzATfVIMDGEeSzlnQoxdotutpWbiQasSufbhmW7ImyDTfwXPZ5yxMLAlMiAv2EwedWlU z5KnWeGwIC5hYkXc627b13KLea+dhhIRlzaXhZvSR19JT6pJotWv2aP8CHIpMTDebifC sa3G7eQUCe7FIZrZa9IdOjq3Ae5ykGdPG//8E1C1nCtCeYM0yng6ANkyYMNb5RIRzTWs oXkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733239976; x=1733844776; 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=99ZtQ6Npm+o/kkpmwDDPCgpJncZgiN/IMlRLftnmHuc=; b=nFmAPW5aJvOpXmYbgcMPK8+u65e93bqSG23c8Gg6YJ9IZaqNYS88mqdBZDyW6bOgJK n0lAsDzU/BYGWJ+BBiZK/s0e4jwX+4i5DV6YeCPyfV/Y0T2WiSm2cpC+uv6Hc3tcdWbr QNtZ/zOdsgUwbpoJ355x1rr5bWp70GIbv7TzqFGB8TGRaionySce9H+ZzhtirUeaEvhZ xxNqBsc+fsknPoTecDIad0w9Nv2zdgvUAAQ13s5wfHejV7WHrTrufz/Doi7Vpr2s2IOj dYAn/48Zl9NrdA/8GsknKwCkn2YCJarVSx6GaXUlpCDX7kETNa8em+eK807/ZWtJK3OH eRjA== X-Gm-Message-State: AOJu0YxfdRmIw4rD4QkjvpYE2PpZoOZGTlUSinJQwlYQ5UIuXfzTTf2v uULVzNk64B61/PZlrwUq7E1TFJUbNSbqcRRgNPLb556fENCyqH8v/eoQzxKxQoXfniFksKmsHNF 4 X-Gm-Gg: ASbGncsZnS/5IEM2F41cvu3t3n6MCasf0DZzekHiqIIWZctzjMI3dl3YnU2gzQ4x4TA l/+9PAsON+XLe3tS5/mPrDlqJwpn8o3WATYx+D736JqeXC39ZW6vYl6U67+2h0Pp6xu2unEo9SI Oubpsk130o7EPJhn5LpqI/wyh5W7qrHWDgrWE/LLt7ZVZ6M16IERbIpfUXofrhMFWi4DkwC3290 u8JrD+licyO377mKYhj2l3HpWq/MocbCqOwVXaaSJJOvTUcfd2HHi1AHrY= X-Google-Smtp-Source: AGHT+IHMJnWLWXZesvRG8H115i2+SnEyGT/XbMmAgLxKcYoNaa8g7OGxqlE3KOV7Yd59LM9TrdKc0w== X-Received: by 2002:a05:6808:152c:b0:3e6:14a6:4288 with SMTP id 5614622812f47-3eae4f366f8mr2926476b6e.11.1733239975822; Tue, 03 Dec 2024 07:32:55 -0800 (PST) Received: from localhost.localdomain ([130.250.255.163]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3ea86036cbbsm2891878b6e.8.2024.12.03.07.32.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 07:32:55 -0800 (PST) From: Jens Axboe To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Cc: hannes@cmpxchg.org, clm@meta.com, linux-kernel@vger.kernel.org, willy@infradead.org, kirill@shutemov.name, bfoster@redhat.com, Jens Axboe Subject: [PATCH 07/12] fs: add RWF_UNCACHED iocb and FOP_UNCACHED file_operations flag Date: Tue, 3 Dec 2024 08:31:43 -0700 Message-ID: <20241203153232.92224-9-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241203153232.92224-2-axboe@kernel.dk> References: <20241203153232.92224-2-axboe@kernel.dk> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 5A67214002D X-Stat-Signature: 8cwqd466m8ageafruju8964u1s4zzrt7 X-HE-Tag: 1733239968-838859 X-HE-Meta: U2FsdGVkX19CSCMAiDtkk/wP4+bfVMJYIUDLnmkkfeEvwJfLEprA1+LaL4zHc3jWULa+vz611uGawOO0moI++y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0/94UCX4EXA7HUgGK7yR9RZcn04MAg5ZzRKAxvdmyW3+kgc8nqclK95d/1DSbZknhO1MK3mXVnkM6MPQndjDGiAh346DabeoypBPyjBM3X/NDS3Bt2Vzhiwq+SMPPy/wKOgXtRi2AYSGxDU316JldGkS0U++nl7KFgd1sQg61+2V7Hlmi1CWdaHG2ucXNAwNoWnI88 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: If a file system supports uncached buffered IO, it may set FOP_UNCACHED and enable RWF_UNCACHED. If RWF_UNCACHED is attempted without the file system supporting it, it'll get errored with -EOPNOTSUPP. Signed-off-by: Jens Axboe --- include/linux/fs.h | 14 +++++++++++++- include/uapi/linux/fs.h | 6 +++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index 7e29433c5ecc..b64a78582f06 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -322,6 +322,7 @@ struct readahead_control; #define IOCB_NOWAIT (__force int) RWF_NOWAIT #define IOCB_APPEND (__force int) RWF_APPEND #define IOCB_ATOMIC (__force int) RWF_ATOMIC +#define IOCB_UNCACHED (__force int) RWF_UNCACHED /* non-RWF related bits - start at 16 */ #define IOCB_EVENTFD (1 << 16) @@ -356,7 +357,8 @@ struct readahead_control; { IOCB_SYNC, "SYNC" }, \ { IOCB_NOWAIT, "NOWAIT" }, \ { IOCB_APPEND, "APPEND" }, \ - { IOCB_ATOMIC, "ATOMIC"}, \ + { IOCB_ATOMIC, "ATOMIC" }, \ + { IOCB_UNCACHED, "UNCACHED" }, \ { IOCB_EVENTFD, "EVENTFD"}, \ { IOCB_DIRECT, "DIRECT" }, \ { IOCB_WRITE, "WRITE" }, \ @@ -2127,6 +2129,8 @@ struct file_operations { #define FOP_UNSIGNED_OFFSET ((__force fop_flags_t)(1 << 5)) /* Supports asynchronous lock callbacks */ #define FOP_ASYNC_LOCK ((__force fop_flags_t)(1 << 6)) +/* File system supports uncached read/write buffered IO */ +#define FOP_UNCACHED ((__force fop_flags_t)(1 << 7)) /* Wrap a directory iterator that needs exclusive inode access */ int wrap_directory_iterator(struct file *, struct dir_context *, @@ -3614,6 +3618,14 @@ static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags, if (!(ki->ki_filp->f_mode & FMODE_CAN_ATOMIC_WRITE)) return -EOPNOTSUPP; } + if (flags & RWF_UNCACHED) { + /* file system must support it */ + if (!(ki->ki_filp->f_op->fop_flags & FOP_UNCACHED)) + return -EOPNOTSUPP; + /* DAX mappings not supported */ + if (IS_DAX(ki->ki_filp->f_mapping->host)) + return -EOPNOTSUPP; + } kiocb_flags |= (__force int) (flags & RWF_SUPPORTED); if (flags & RWF_SYNC) kiocb_flags |= IOCB_DSYNC; diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 753971770733..dc77cd8ae1a3 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -332,9 +332,13 @@ typedef int __bitwise __kernel_rwf_t; /* Atomic Write */ #define RWF_ATOMIC ((__force __kernel_rwf_t)0x00000040) +/* buffered IO that drops the cache after reading or writing data */ +#define RWF_UNCACHED ((__force __kernel_rwf_t)0x00000080) + /* mask of flags supported by the kernel */ #define RWF_SUPPORTED (RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT |\ - RWF_APPEND | RWF_NOAPPEND | RWF_ATOMIC) + RWF_APPEND | RWF_NOAPPEND | RWF_ATOMIC |\ + RWF_UNCACHED) #define PROCFS_IOCTL_MAGIC 'f'