From patchwork Thu Nov 14 15:25:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13875216 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 6DE3FD68B30 for ; Thu, 14 Nov 2024 15:28:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F6286B009B; Thu, 14 Nov 2024 10:28:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A6076B009C; Thu, 14 Nov 2024 10:28:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36D556B009D; Thu, 14 Nov 2024 10:28:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 168856B009B for ; Thu, 14 Nov 2024 10:28:15 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C8C68121230 for ; Thu, 14 Nov 2024 15:28:14 +0000 (UTC) X-FDA: 82785080406.24.7C459DD Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) by imf14.hostedemail.com (Postfix) with ESMTP id BF84C100006 for ; Thu, 14 Nov 2024 15:27:23 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=qqgMJeSl; spf=pass (imf14.hostedemail.com: domain of axboe@kernel.dk designates 209.85.161.42 as permitted sender) smtp.mailfrom=axboe@kernel.dk; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731598004; 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=LyRvRhMBG1NsG1pjAu7RsorwHLATahyjt2W9R5OMw+k=; b=gzSogBsS6Z+QWyRX1hDahG04qonJ565KuuhEoLe1ojZ+RaJizf7Y9VgDC+a+fswJvYrKpl s4qf3E1XioWMGKToOMm549pGj/GtnshKCd3O1susuGhcOV7GzXbJyY7Sqoz4SMeLdnNgLb oC29PFyT4Om9rY6g59e80dPlgpIyHCU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731598004; a=rsa-sha256; cv=none; b=Cuf2ACFL8unu6amHvRuyzbaCfWWdLqLkB5pUFXw3M0Xmw4O3s7y3TTEDGMFfpnDkDQCewX nL9cHNRSBSSAwJLhepyah8Dt4OArpgyVdbJKi8tdDp5RCLLnJgDPACNfl0ajJHSN6kVyY9 qrSCqfnJTV1C4qX7oJSt0tproGRA37k= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=qqgMJeSl; spf=pass (imf14.hostedemail.com: domain of axboe@kernel.dk designates 209.85.161.42 as permitted sender) smtp.mailfrom=axboe@kernel.dk; dmarc=none Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-5ebc1af9137so297638eaf.2 for ; Thu, 14 Nov 2024 07:28:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1731598091; x=1732202891; 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=LyRvRhMBG1NsG1pjAu7RsorwHLATahyjt2W9R5OMw+k=; b=qqgMJeSleBTzV7yoPOt574T0qTMvDRcio0ANw2tmkUDACEtojwxJ2zTKvqcUv4oZ+/ xoBPwUheCzEdanKzJQs0nQfdn3CKrKRUksT+HHcIgEIZk5QTfLZwxxgzceJooKBUBZcb aQMRkV6p4tBv48V9iKekbqFYR5BdnRUH4IQuqtgoK9Zk0m49/KTP1ydLcx3wm5ap2LXZ v0FDee36eq4z3XAE8oieSSFZeUoOENAc3PMqa+9cb5e5gV1A2pg/RvEWCCWl88ogktrT g7eKEj8mM9LrGnvkvKpmL6TzRxMwOQa4tIUEgldj/wCvSBRT/ByxSI+oU00Se+7JjbH6 cWUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731598091; x=1732202891; 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=LyRvRhMBG1NsG1pjAu7RsorwHLATahyjt2W9R5OMw+k=; b=u15JovT45oe8o1Kjoz5Dtj/Nvo021Hv2Y8bk58d/rViy79ckFomdwZJOfBsetK2sjT ceoK1QD3jOl4Vrx6ocOHmIMTSwHVxJnjDhWPJPyQIAIIJsdI6riBwxUv0Rq6CsyULsCo bi0uototNK3iFT0B82jAhOc4V15/uZCHEkUvOqE1Db9P1wt/eadLbUQJVvxD4vKolDG+ 5vxYtHt9dyFKQ/S75h6kqL9Ix8aaTpnzKqeMqkMZ2PeNA6OzsG4Jj3fjSxLz2iND8QAj 99tDtrnr/c40S9hRChT8N+zEOSi1HLe1KhtNh55exNp5epGJ9ZOWjuHYprhuim7SrYKx 9l5Q== X-Gm-Message-State: AOJu0Yw6839VfT/8A056BxMBoLEDbxZCWHv24pPvOVeyl6Oo2Df+vClh BqEujX2eHAweSDm8MTGIjzix03ZZP8aT4M628jAt3pqM0tab+BuSiewcuyMcw7lgQrwUQVP5YH7 Kujc= X-Google-Smtp-Source: AGHT+IHQ/GenKedH6rwQd+su0Ph/MRWIuzytWarVEOsqT+imV9hIASvSe13ZVKnr0H0iVbl20zcXwQ== X-Received: by 2002:a05:6820:4d06:b0:5ba:ec8b:44b5 with SMTP id 006d021491bc7-5ee57c4397bmr19027877eaf.3.1731598091501; Thu, 14 Nov 2024 07:28:11 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5eea026eb41sm368250eaf.39.2024.11.14.07.28.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 07:28:10 -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, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, bfoster@redhat.com, Jens Axboe Subject: [PATCH 07/17] fs: add RWF_UNCACHED iocb and FOP_UNCACHED file_operations flag Date: Thu, 14 Nov 2024 08:25:11 -0700 Message-ID: <20241114152743.2381672-9-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241114152743.2381672-2-axboe@kernel.dk> References: <20241114152743.2381672-2-axboe@kernel.dk> MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Stat-Signature: pjomoq9nn77uo5i4puounbw68yct9gys X-Rspamd-Queue-Id: BF84C100006 X-Rspam-User: X-HE-Tag: 1731598043-585705 X-HE-Meta: U2FsdGVkX1+UXrtUFrTfEkvH3eYmd7x3CeCXXEyukujCOc4lfkxKrwe/Yk+e1uBwTBH3jWluBXej9qwlu7mfIFMj628MTRub5naeHXEspSPD1Ik/OSwGWtpR52AOJ0qAKvudODj+Qd8CN1uZnhJ+G+pCOsbIDaV21Q9DuCBnkhZf7WL38UAvbvrsfXPbETy+bBhFVjjxEa9R9ILc57bm3VXmzaENp5+NjFhOUvs2vZhBRZvh37N95xJlDielCEH8pyhtqCgdbdF2naZvKVk11DuPypRvIwJcKgzs5YFuKUuYEFImydb1BvcUCDc6rPcCyGV4g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: 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 3559446279c1..45510d0b8de0 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -320,6 +320,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) @@ -354,7 +355,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" }, \ @@ -2116,6 +2118,8 @@ struct file_operations { #define FOP_HUGE_PAGES ((__force fop_flags_t)(1 << 4)) /* Treat loff_t as unsigned (e.g., /dev/mem) */ #define FOP_UNSIGNED_OFFSET ((__force fop_flags_t)(1 << 5)) +/* File system supports uncached read/write buffered IO */ +#define FOP_UNCACHED ((__force fop_flags_t)(1 << 6)) /* Wrap a directory iterator that needs exclusive inode access */ int wrap_directory_iterator(struct file *, struct dir_context *, @@ -3532,6 +3536,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'