From patchwork Mon Nov 11 23:37:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13871490 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 E913ED3ABFA for ; Mon, 11 Nov 2024 23:49:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A6A4E6B00DD; Mon, 11 Nov 2024 18:49:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9CB806B00DE; Mon, 11 Nov 2024 18:49:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 845F46B00DF; Mon, 11 Nov 2024 18:49:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 633556B00DD for ; Mon, 11 Nov 2024 18:49:02 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 25D03141B16 for ; Mon, 11 Nov 2024 23:49:02 +0000 (UTC) X-FDA: 82775454468.17.C717F36 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf23.hostedemail.com (Postfix) with ESMTP id EDD9A14001D for ; Mon, 11 Nov 2024 23:48:32 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=uMhKMlfR; spf=pass (imf23.hostedemail.com: domain of axboe@kernel.dk designates 209.85.210.180 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=1731368886; 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=BpaeGG8sCxZf4JRh/p7NGjZl2gbHvBRPjf0TUvSvRrE=; b=toOS87bljX8vLheymARaYmeCIVvV8JLgGBnlgwBZvn2RBDJXfO+rJ/U9ccgHTlyofu/KOs 1IJ0GBaL4Fl3LY4l2OMbCdiUkEJloBnNPGPgeJWQrn3y8ejSfGTPKoxftaxBFCagT/Lk+4 1QTBhXC+5lFxCfTV1D7WtfijD5IpGR8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731368886; a=rsa-sha256; cv=none; b=49FZaJTBofBOuga5GL7uCLEOydU3i6EB09fTPQkiVWA2AKnIxKvMd7KeRnW4WOE2fq9IFi FKRYlP+N02rtS33bwKH8b/POqpYY30YNKBzX14p+K4xcDUqHr/1RI/yuHigZw2hRngO9u8 HST9g8IASfOX8BQcRHaAMNnH3HQFi1I= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=uMhKMlfR; spf=pass (imf23.hostedemail.com: domain of axboe@kernel.dk designates 209.85.210.180 as permitted sender) smtp.mailfrom=axboe@kernel.dk; dmarc=none Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-71e61b47c6cso4610836b3a.2 for ; Mon, 11 Nov 2024 15:48:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1731368938; x=1731973738; 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=BpaeGG8sCxZf4JRh/p7NGjZl2gbHvBRPjf0TUvSvRrE=; b=uMhKMlfRjFv6IrcoY7XmipOmpT5ovpaZ5vbWZByyJSYlxOhWO4KpFXQ4ZuG8P+CjJm 80fscvJFfITmaEen8/DIHPeuBDOcy/bnsNYjPO+4W1e1aTk8o/L0ivR3wpP5f8cgt1NG wVB6L6wcBmqT+zunqiOyvU7TDSQqx+LqkS7J8YyJjwSlEn9Cj2tuuJL7A/6dOEevt1BG itWVji5BnEYqHa7MZo/za7GvHjtIjXRc2pt0V2qzDoSCYm/uRf3tOUlLF0QrEc8qzg3t 9R1n/xfK+6726UCwj6HulbKHtIENgbuIFBIsis8phuP4AJ8/k+WDTgcmUPpjxJwYW78c emcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731368938; x=1731973738; 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=BpaeGG8sCxZf4JRh/p7NGjZl2gbHvBRPjf0TUvSvRrE=; b=Zuzou/NAEie/swegocvsDlMu8TIaivdsf7xtuL1Q4rHhfKiOo3NKlVxoaA+yT3sFid aNOLdY0fhjF5SaBfDLkvyEymc7wYtWLmIfVJ0qyQJMCvQL6Yzut6H1dr5M8Wr4GkEma2 Sv7a67Ip9SxR9vgehPQH4MkBDQi1HqLaQC3YN/VPunBaH4/M6nZ0nGAN28bYkHA9J+tJ +3LU2xkf8xf6m+gfcgY7iW3XGyntrLetEBGYTEwgD2BnnVPH9zdAI/oFWzTX9LLBUt2E 3XxJOSy10cVyRDn4Be6D/R8G3fP6VrzZVAOj8TOCQcsfkoOF3KNZZ0XFIKpLCELqiBl1 7C6g== X-Gm-Message-State: AOJu0YxwUpRujm4tN1AEr9YxAUwzelKq8omlpe50zLdIULNfW7/Pf4lS yM+wwfA9737j4RPBj5VbaSL2GcZor+8oB1LZ9e0JlpsBoThYPkYIuMZ8VOPPVmEwJIVv4Ty5Tgo iaAY= X-Google-Smtp-Source: AGHT+IGZeOeX13AG9u0SljALCGlqZd1HzXcprLCQtKHVA2LyzBnUVzw9lDFogBpMHW34whNWJjJhLg== X-Received: by 2002:a05:6a00:3a28:b0:71e:7846:8463 with SMTP id d2e1a72fcca58-7241334a3e2mr19790618b3a.19.1731368938117; Mon, 11 Nov 2024 15:48:58 -0800 (PST) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724078a7ee9sm10046057b3a.64.2024.11.11.15.48.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 15:48:57 -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, Jens Axboe Subject: [PATCH 07/16] fs: add RWF_UNCACHED iocb and FOP_UNCACHED file_operations flag Date: Mon, 11 Nov 2024 16:37:34 -0700 Message-ID: <20241111234842.2024180-8-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241111234842.2024180-1-axboe@kernel.dk> References: <20241111234842.2024180-1-axboe@kernel.dk> MIME-Version: 1.0 X-Stat-Signature: 9qaa7b9rm16gcqcwk6f66to7kuy9sxdn X-Rspam-User: X-Rspamd-Queue-Id: EDD9A14001D X-Rspamd-Server: rspam02 X-HE-Tag: 1731368912-768588 X-HE-Meta: U2FsdGVkX18dvnbHQlfT4WjKJsD/8c9cXZlPuy2XKsQ/0NdUYgm1Y33B0CMTGALLZBxnRiZrhK/jEnuWp8htxpfe2Nz9ae6FUn5De6OQMYy4Pz0q+Tq7f0QDXpmlRQypus9Jy/Qs3X+4qc6no1P75F2xfA1Vqq+cE2+L3Ig43JTe+LODL34pUadcm0I5RJKFzxE6AllOXSn0UVY6n4/SGZOoyOFzIffexjdZW1KuBwdgfE8pM8t5UA39m2mhclfHZeAZdtaTeHSXh0WKdMdlWHBoURhoogv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ity=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 | 10 +++++++++- include/uapi/linux/fs.h | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index 3559446279c1..5abc53991cd0 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,10 @@ 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) { + if (!(ki->ki_filp->f_op->fop_flags & FOP_UNCACHED)) + 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'