From patchwork Mon Nov 11 23:37:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13871495 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 083FBD3ABFD for ; Mon, 11 Nov 2024 23:49:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D43D6B00E4; Mon, 11 Nov 2024 18:49:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6EA3F6B00E5; Mon, 11 Nov 2024 18:49:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 512566B00E6; Mon, 11 Nov 2024 18:49:12 -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 276E46B00E4 for ; Mon, 11 Nov 2024 18:49:12 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A1C36C1A21 for ; Mon, 11 Nov 2024 23:49:11 +0000 (UTC) X-FDA: 82775456862.18.45B9729 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf09.hostedemail.com (Postfix) with ESMTP id 6488D140006 for ; Mon, 11 Nov 2024 23:48:41 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=OS6IDF2T; dmarc=none; spf=pass (imf09.hostedemail.com: domain of axboe@kernel.dk designates 209.85.210.170 as permitted sender) smtp.mailfrom=axboe@kernel.dk ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731368887; a=rsa-sha256; cv=none; b=2EqyqvQ+USECkfVCiVREhxgVwRByv29J2XDCc4JOCb4llEK+PhobiWC9Nnm+KsGhrInF79 B1wG+3BjqCpix4rvwZ5KmRV9CbmL1Ld8ibHHxFKA5SMo/zb4P7jGBCG/11TseHj0Ue7WKq n4tJVf0LVZxwx6xHvFj3lGxiRJqucLs= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=OS6IDF2T; dmarc=none; spf=pass (imf09.hostedemail.com: domain of axboe@kernel.dk designates 209.85.210.170 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=1731368887; 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=QHHnA1NsQjr1van9cnJ+PQRWRXhY+a6ETIPA3kXFfjk=; b=vPbpy7utgf5O8nMsL0Y5VpdqCxa+1ty1v9Sn5QB1UtjpmWlcukx2a32AsLapve9guyzX22 nmCyyg1oxvqnlH6BpMfFMlu89gr9RlqvfrFCoaGnZe3g4tZbo4DGf01lloqNELk6Ah2RkN L6fTjH6I4KBeLgMAJgIGE9OkaiWYggY= Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-7240fa50694so3694862b3a.1 for ; Mon, 11 Nov 2024 15:49:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1731368948; x=1731973748; 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=QHHnA1NsQjr1van9cnJ+PQRWRXhY+a6ETIPA3kXFfjk=; b=OS6IDF2T2YecJ3Ua2eCHf5/FzcQMorYmvaxLMmDlIevNirs5I3DXFwAClyeEfZzxMt +AiB9WLEaxaXEadTCsb7L+LcH2YFiAIOMkXYh/Ze8uQwp8nrzNbmkzm7cfHPS7itOMUb o5UpYWiRUKQxPJUeInRArEu+wQV+cRiotDWiAyCLfa0hvogLqTk4Gk4BeXdSJt+Apd+Q l25eNZ2Jk8ZDc93gUWHMxfb4USYAHOSYSzsr0iQVKo4ofQUy3QljQLyFv6EAgSAOq1/2 5OEEK4gPGwsPhcwIeTShmWlXD6fBI2qVmQuDAUTQ/5p4bg5Pip0Xz68gM4p0kOKIs69P PBQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731368948; x=1731973748; 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=QHHnA1NsQjr1van9cnJ+PQRWRXhY+a6ETIPA3kXFfjk=; b=NB31gYvYbN68nFyZcQAYDaLDCoQk8e8kdcsHvopWrtI7p8A5ujC/t116UqiIBNfQt1 DI/DKBsdzkJ5twKuviJU/45nRVYfUVSWGqaAht1zBCVTGZzqjf4HD7Tc50NnEHZEQg24 UV3t8mN6LqjrlJR++HVegAWVtzYJ9M28uEHHU9isBFh7bkhru1PcqHRTCOuvLtknHV4m 4+mhy7q5pFFkxyKnTend/k1GY3rhbUrLPFHeeELRBalg37PJkzZcKeVINDaPnhYMNtk6 YGt2WkO9q1l+CKEY+a2dLAiZecrobQHLhK81V4oTu/CVkvBkMzr/gjH2h1hL7pfjBlCO yoTA== X-Gm-Message-State: AOJu0YwPQWSynT8ePbuvsZ/RbZ5VteIxC1vMOEEwIIS9DXzFLR7hGGCg vfyHGmgoZ7P5w7+25n9UgrhoPIpbWcUkqTGiFGHQ8i6oVhE58ocKhjmO3sj2JWiKNioS4fC4FTj rp7Q= X-Google-Smtp-Source: AGHT+IE+DUrjoGziw6EjyU9hF9MosU8fZ1F2/8qqkRJb8RqY6XTyhSKojrzpZHSNP9ce3wMHzfWwwA== X-Received: by 2002:a05:6a00:181d:b0:720:aa27:2e45 with SMTP id d2e1a72fcca58-724132c535bmr19020120b3a.14.1731368948118; Mon, 11 Nov 2024 15:49:08 -0800 (PST) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724078a7ee9sm10046057b3a.64.2024.11.11.15.49.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 15:49:07 -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 13/16] iomap: make buffered writes work with RWF_UNCACHED Date: Mon, 11 Nov 2024 16:37:40 -0700 Message-ID: <20241111234842.2024180-14-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-Rspam-User: X-Rspamd-Queue-Id: 6488D140006 X-Rspamd-Server: rspam11 X-Stat-Signature: upa11tow3iu6qc4wkchpkjnw5gepbp1k X-HE-Tag: 1731368921-460131 X-HE-Meta: U2FsdGVkX18cVOgnc3eG1+v10G/vHq8aFH4Ha+3N79AbnJhvEWIVu3CmgFrVWQdRacgfSGs4oXcMS5X3Ki9+vFNC5u6hMkpaF0cN/ump7ArI/g44d8zXWIqOjmFgYNpES/xlvkpBG9fykWiDeMUHG+Hqa7UXPWZhAHjJ7QWqwA0gtFIowCXKxJcjevFcxzzd4BTw6bvkCgMSGcvrjTGzK4Yau7V2FPkbo177Qu+tCv+t/qt8YYxlLkuxMQP9rfppAq18LwO/ZLmgmqmFoWGyEx8ZMqbBFwjA/zbOq4QWmF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 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add iomap buffered write support for RWF_UNCACHED. If RWF_UNCACHED is set for a write, mark the folios being written with drop_writeback. Then writeback completion will drop the pages. The write_iter handler simply kicks off writeback for the pages, and writeback completion will take care of the rest. This still needs the user of the iomap buffered write helpers to call iocb_uncached_write() upon successful issue of the writes. Signed-off-by: Jens Axboe --- fs/iomap/buffered-io.c | 15 +++++++++++++-- include/linux/iomap.h | 4 +++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index ef0b68bccbb6..2f2a5db04a68 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -603,6 +603,8 @@ struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos, size_t len) if (iter->flags & IOMAP_NOWAIT) fgp |= FGP_NOWAIT; + if (iter->flags & IOMAP_UNCACHED) + fgp |= FGP_UNCACHED; fgp |= fgf_set_order(len); return __filemap_get_folio(iter->inode->i_mapping, pos >> PAGE_SHIFT, @@ -1023,8 +1025,9 @@ ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i, const struct iomap_ops *ops, void *private) { + struct address_space *mapping = iocb->ki_filp->f_mapping; struct iomap_iter iter = { - .inode = iocb->ki_filp->f_mapping->host, + .inode = mapping->host, .pos = iocb->ki_pos, .len = iov_iter_count(i), .flags = IOMAP_WRITE, @@ -1034,9 +1037,14 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i, if (iocb->ki_flags & IOCB_NOWAIT) iter.flags |= IOMAP_NOWAIT; + if (iocb->ki_flags & IOCB_UNCACHED) + iter.flags |= IOMAP_UNCACHED; - while ((ret = iomap_iter(&iter, ops)) > 0) + while ((ret = iomap_iter(&iter, ops)) > 0) { + if (iocb->ki_flags & IOCB_UNCACHED) + iter.iomap.flags |= IOMAP_F_UNCACHED; iter.processed = iomap_write_iter(&iter, i); + } if (unlikely(iter.pos == iocb->ki_pos)) return ret; @@ -1770,6 +1778,9 @@ static int iomap_add_to_ioend(struct iomap_writepage_ctx *wpc, size_t poff = offset_in_folio(folio, pos); int error; + if (folio_test_uncached(folio)) + wpc->iomap.flags |= IOMAP_F_UNCACHED; + if (!wpc->ioend || !iomap_can_add_to_ioend(wpc, pos)) { new_ioend: error = iomap_submit_ioend(wpc, 0); diff --git a/include/linux/iomap.h b/include/linux/iomap.h index f61407e3b121..2efc72df19a2 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -64,6 +64,7 @@ struct vm_fault; #define IOMAP_F_BUFFER_HEAD 0 #endif /* CONFIG_BUFFER_HEAD */ #define IOMAP_F_XATTR (1U << 5) +#define IOMAP_F_UNCACHED (1U << 6) /* * Flags set by the core iomap code during operations: @@ -173,8 +174,9 @@ struct iomap_folio_ops { #define IOMAP_NOWAIT (1 << 5) /* do not block */ #define IOMAP_OVERWRITE_ONLY (1 << 6) /* only pure overwrites allowed */ #define IOMAP_UNSHARE (1 << 7) /* unshare_file_range */ +#define IOMAP_UNCACHED (1 << 8) /* uncached IO */ #ifdef CONFIG_FS_DAX -#define IOMAP_DAX (1 << 8) /* DAX mapping */ +#define IOMAP_DAX (1 << 9) /* DAX mapping */ #else #define IOMAP_DAX 0 #endif /* CONFIG_FS_DAX */