From patchwork Fri Dec 20 15:47:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13916938 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 347C3E77188 for ; Fri, 20 Dec 2024 15:48:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CEDB6B0098; Fri, 20 Dec 2024 10:48:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E3046B0099; Fri, 20 Dec 2024 10:48:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F03076B009A; Fri, 20 Dec 2024 10:48:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id CFAC46B0098 for ; Fri, 20 Dec 2024 10:48:47 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 92878AEEF3 for ; Fri, 20 Dec 2024 15:48:47 +0000 (UTC) X-FDA: 82915768698.19.A3336E7 Received: from mail-io1-f42.google.com (mail-io1-f42.google.com [209.85.166.42]) by imf20.hostedemail.com (Postfix) with ESMTP id D89451C000A for ; Fri, 20 Dec 2024 15:48:09 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=uvGsjowN; dmarc=none; spf=pass (imf20.hostedemail.com: domain of axboe@kernel.dk designates 209.85.166.42 as permitted sender) smtp.mailfrom=axboe@kernel.dk ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734709693; a=rsa-sha256; cv=none; b=pT12vSWdOhMd2OteW66Kft0/GnHSHPEf2i71AV1BkkbEVMfOz2Tkq5QtgcM44WmAPN1d9j 5glS7cj4vS6abtH+8dm6D/jHZNWMKtWKrFzOgRCZcbK02ZRC2KsXSuZxOjnsMcIxbEpnxW X0MimRAg4EpL01eL8NeLyWwDVMVeIUU= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=uvGsjowN; dmarc=none; spf=pass (imf20.hostedemail.com: domain of axboe@kernel.dk designates 209.85.166.42 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=1734709693; 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=4w74VD3kuQguRINknUSjUP4VNHVLoGClDPYL5LdL0oM=; b=LbafXs5kS9xH53BRsUlC23/QyztJelE/n/gaKisYPdzo7k1q7Lu6sQExARIoS2FHsnzNLY Y/pOMiALdEc27kyMrfDkXNY+3VBTrO7oHTssfWmcimqhRUoYQcUISOJ0DIg492xufB0g3j BBF3QTF7j5nUh/eISYcFb2n+H6qJEH0= Received: by mail-io1-f42.google.com with SMTP id ca18e2360f4ac-844ee15d6f4so158514039f.1 for ; Fri, 20 Dec 2024 07:48:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1734709724; x=1735314524; 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=4w74VD3kuQguRINknUSjUP4VNHVLoGClDPYL5LdL0oM=; b=uvGsjowNZMOEk+83jamCcivzA+PkvKh+SdrUHOWbEWOtShT9S9+IvYvByWCP/nKQ++ CPtAGyPG7TPBS/ZInEspiSMMdCx+ZQBaIi8kAy2a4X/Vpr85xO3uEN9X6mxckUCEcz+9 wIGPJ9UF+ODbQCE6rYa1673FNcb1lMU7mHIPFCrUowlJCedGWz0JBKBiMA+YAIiYIUEy nNflkRKmmcZbpHN/o/BszjNHJykvEG1yfr0turPFKQ1F2dhqE4F8HHAMstDXhvkGgh6C 2jvTKHSIG41fYr1b6a1naoeBs3RYm7x55wGRaHXEzhOAQozWSr+pVwNlHIWKXCXQYxoV lNEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734709724; x=1735314524; 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=4w74VD3kuQguRINknUSjUP4VNHVLoGClDPYL5LdL0oM=; b=u0onHsZY7xDOQ8bez1UCAjeT5AkN86PPDYTpIkIXQIihrlC62v6JhOuW+++TTAMKH7 qy0JqJ/ZquRI4xHHIEGASe+ShOIG/9Aw2ZgIReqxTDeB5K3v6vRM2YoCuffLnuyXWhYd /CHqE8tBWlt8BMX0dXbCYxF/vx0fT5JB0ZK5p9XtTSV29K5wJ7EV+YK4WDr9CrYGrWWm OoxS7n20llP0alL2gCmam3RifIgtDUlq/TfIzi0//UQpqfNP4J6uETuvjMrYEmqjVCKH IwfLUXv3Ayb8p9QoLoPM8JZw1pHNYp/d2fa5ITJ1GXKtklOJ8AkwuiZV754AOe5tHoxn ivnA== X-Gm-Message-State: AOJu0YwZw/f7muSzRtR0tvxFBDccH5E78/LcY8sFG04Czk1fempbtSN1 uVuS0Y1V09zblu0eo9gxAJBTWuaLWqOtBaoANGz8UYPD4Blo/3HKa1I6KA6lC4267R6gV1N8gRC o X-Gm-Gg: ASbGncuclhv6lEC6OplUG3/Kx/dXivnjcv7OVEfO5wCfDGhldyhlLX/5zJz+MF0BZmY amMpdUoVEzDHCvco42DyBZs1ds+ZELjydiLzt3ABhsj8T8irNqhgHlS4qI4jZ9YZdh6Wh0EnK/D 7aIUv3tM31c8tT/+tAwuhLbxFNi47ZLfOcgleWglrkMPiS+TXExKLOTAS1KYYpk4qa9tlkrNd/H 3LAuVH7fPT0ov4xUcYu5rT5nKkLSXAy8BfNIRsYIBSTMaRMD3DBwVtzaD/R X-Google-Smtp-Source: AGHT+IERkjVXfRiBHnc8FlfnVZJTgamzH1zCvDow9NijC4/j/GJhywdFRh297ssQYYJsqQo3rjiWFg== X-Received: by 2002:a05:6602:60c6:b0:83a:a746:68a6 with SMTP id ca18e2360f4ac-8499e4d888bmr383870539f.5.1734709724489; Fri, 20 Dec 2024 07:48:44 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4e68bf66ed9sm837821173.45.2024.12.20.07.48.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 07:48:43 -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_DONTCACHE iocb and FOP_DONTCACHE file_operations flag Date: Fri, 20 Dec 2024 08:47:45 -0700 Message-ID: <20241220154831.1086649-8-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241220154831.1086649-1-axboe@kernel.dk> References: <20241220154831.1086649-1-axboe@kernel.dk> MIME-Version: 1.0 X-Stat-Signature: ieyrdiat5yr71nnieyrkuirw19pwhx83 X-Rspam-User: X-Rspamd-Queue-Id: D89451C000A X-Rspamd-Server: rspam08 X-HE-Tag: 1734709689-316975 X-HE-Meta: U2FsdGVkX1/Tw7L4lv3bdUe26Wnn2ck59VhTRFtC7szDpPHWL9Ox3hJwVc3G3/OcxB6AdwdZkcic7psBz0DeCKtJau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/Y5gt4ksacVwW0K5dfNlZVYDczGE1pcfTZz26L3lagEBjqdLix/CrwAG6GtDBc83iop5GcppYl28sBxTwS4hyz6MIY5RH+W3ECEGkn2JoRQUD3WbMSXASBMp68ZTR43MoKDLMBh1Ej6r/2bRIgbuBwjuwiFV3w+L1eNbE9hVP93DHllp2AFkRudIYjC 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_DONTCACHE and enable support for RWF_DONTCACHE. If RWF_DONTCACHE 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..6a838b5479a6 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_DONTCACHE (__force int) RWF_DONTCACHE /* 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_DONTCACHE, "DONTCACHE" }, \ { 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_DONTCACHE ((__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_DONTCACHE) { + /* file system must support it */ + if (!(ki->ki_filp->f_op->fop_flags & FOP_DONTCACHE)) + 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..56a4f93a08f4 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_DONTCACHE ((__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_DONTCACHE) #define PROCFS_IOCTL_MAGIC 'f'