From patchwork Fri Dec 13 15:55:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13907404 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 4617DE7717F for ; Fri, 13 Dec 2024 15:56:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 158866B0096; Fri, 13 Dec 2024 10:56:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 043C46B0098; Fri, 13 Dec 2024 10:56:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB29B6B0099; Fri, 13 Dec 2024 10:56:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A7A836B0096 for ; Fri, 13 Dec 2024 10:56:16 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 4C9EE120749 for ; Fri, 13 Dec 2024 15:56:16 +0000 (UTC) X-FDA: 82890387048.11.B87DFCA Received: from mail-il1-f173.google.com (mail-il1-f173.google.com [209.85.166.173]) by imf19.hostedemail.com (Postfix) with ESMTP id 43DD11A0019 for ; Fri, 13 Dec 2024 15:55:47 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=Lk5MRJvQ; spf=pass (imf19.hostedemail.com: domain of axboe@kernel.dk designates 209.85.166.173 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=1734105362; 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=GSkw2O9MvlIqrpnaZu3vqR/UQkDcssp7vRMzGlrmmEklnTv6TtXzvkaQperayVcoSYyRm3 EpTVqrld2ptYXfP8ZRCIG2Zr4eWlrJzjwD8qXsT345yajpPK1gSt45GHCZdoMsjMwmILCt ATuWKa/+QsuWiM/Iexn2UZB8PiHAooU= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=Lk5MRJvQ; spf=pass (imf19.hostedemail.com: domain of axboe@kernel.dk designates 209.85.166.173 as permitted sender) smtp.mailfrom=axboe@kernel.dk; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734105362; a=rsa-sha256; cv=none; b=kKHKwlIQaJlb5PZOYkQphr3ugQ89BX+WucglNESJDSh6/LRgpJfsfnYjyD/7aoS70siQIV Wna1qTMS1Ml6a9DLPg4VPDfQTLdPx8i7hmlxjMNt922yDw8fLr4IgUu89W6+a5HhUFpY/5 JTcrSTqMlge3dZGSUM+2wV3VrMYtNqs= Received: by mail-il1-f173.google.com with SMTP id e9e14a558f8ab-3a9cdcec53fso15576795ab.1 for ; Fri, 13 Dec 2024 07:56:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1734105373; x=1734710173; 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=Lk5MRJvQ6nwCRts6ZvYIxtXHFLNasFEM0Cz4VNebMjXYYpea9uikTLAaM9BlClDA1w zFJAz4OVQsT8JxFfFdMzHcnMXAMfs70oEjgMnBo1WDaLmQyMH228PJkZR4C8V06vSa+p a+gz3rH55K0LV4BkkP+O+tQnglZElcEaS5fYnkK/9KDSKHGXT2D1rzwHm2YI+8qrVuHo CIcukBrMquc9JlVCYOeiHVNY8rlfP6CSs5uVPAzFKmG03vSeI3ZAJQKsSwCcB5zbFSXE uzG4uErfknVujBLD6bEy9xws0DVH5WBW6xKXe3tTs3V3BLzOc3NGwDxd49M8eWguvFhA KNtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734105373; x=1734710173; 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=gPCyqpzlRYvi9dURpnAZAL2oZLjUScWu937kUIzmhnr11SHEYkTgu1NSz+SwXEeOrj mR+e6Ut01DqSOIDbB2gsdepdQ5Y7Y/jYSHgKC9ORR1MOFwY4VQbCRBo0CvI/E0J87Vre 44GSoJ2vAdd7aRnoigLZKLAu3tl58x1qSlQ/XDgRy9gfV4PfFoo2cymziEd/f9hzeRZY AHSKWCrKB0IIs08opOMySciZrJ8+KlaiVUfcdiSV4E9gvyBQHntN4/gfyL0HCmw0/Q8b De5w3fvgfu0l4tfq+FCkZnskMM1R0sfWz8o1sOYxwPWw3RwMoV/lfx0z/VuXfXBuaVfA c6dw== X-Gm-Message-State: AOJu0YxUvzWUEjVNd2Eu0i/zDB971EsBc+IjMff0mO9U9aGXcTNlyJ4n YXjNZkLjsADMAD/VALNdUXCNL536YhPUfuYCC5eNudfCuBbjct/pe+gsfOAzzVcMK19JBPh9Chg x X-Gm-Gg: ASbGncvYUap6TcP1GXww23lU6AlMoKp9TMzz+wY1OuKUVGXCef9GekBOMSKk+nPie/T BoUPUa6PXlCoR/f75jO577/7MxlKV/UNkrAWio2B+qPVsE/9EpQysbWqT7F3YXggIDCY6M04qpg eLXiKMxdjpZsHcRJO4GzzCR9OeeUjvcYSZeeTeC1kQpblwJuimfNOqEf8oH8QPc5rOJ47CMVEvT igFf7gCSVqs4YCknVgip+iNYM1TNowKPWJGYRTytQSHV7nCdDAt1Rs8hqoT X-Google-Smtp-Source: AGHT+IHLruDe6Zg9uYRMCFFj0re5LQoOZLn3MM3DvSbmN1NLcJuI0/2En87svfvn51ITwB5/NqHQ+A== X-Received: by 2002:a05:6e02:3042:b0:3a7:8720:9e9f with SMTP id e9e14a558f8ab-3aff4619d10mr35119105ab.2.1734105373195; Fri, 13 Dec 2024 07:56:13 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3a9ca03ae11sm35258405ab.41.2024.12.13.07.56.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2024 07:56:12 -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/11] fs: add RWF_DONTCACHE iocb and FOP_DONTCACHE file_operations flag Date: Fri, 13 Dec 2024 08:55:21 -0700 Message-ID: <20241213155557.105419-8-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241213155557.105419-1-axboe@kernel.dk> References: <20241213155557.105419-1-axboe@kernel.dk> MIME-Version: 1.0 X-Rspamd-Queue-Id: 43DD11A0019 X-Stat-Signature: ip96stfysg19fy456wj43f64594yo46w X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1734105347-828786 X-HE-Meta: U2FsdGVkX19dX9v2wjP6mtpK+Rotngc5FUlQs9X2Dp//7lfKED0XZZpfkcmuBKdg6L6uHt8Mvaqb4WuIaXIu5+qS5z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ZiOeewF98IqZEUxF5AKsBKWAs37ApJSfjIBX5nysobmmbkzhlmqoHG2ha5Ad1cbXEu7pk5f3e7mwF1Qx4T1wnSlP7s5LmmvYpfIThD8ITOBk8aGwDJq2TwcIxD6WXWyQJKlQC8EpVQV6XdHFKqmWfC0uWbxBr0Py2xcYKSMuvXMMaiSYSU5b 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'