From patchwork Tue Sep 19 08:07:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Kellermann X-Patchwork-Id: 141826 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3305260vqi; Tue, 19 Sep 2023 04:19:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEVLEH002lK2kVtEjlIPSL6WOz3OMmRfzI92l6BiX/f3LfLE+Z9CobWEWuCun80xs967yeG X-Received: by 2002:a17:90b:3142:b0:26f:4685:5b53 with SMTP id ip2-20020a17090b314200b0026f46855b53mr11407737pjb.28.1695122382682; Tue, 19 Sep 2023 04:19:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695122382; cv=none; d=google.com; s=arc-20160816; b=MPRud9SH7ndoY1SnxT9wvLpQvB+0h4oR8YYZ0aflQjnItJ46Jrp6eJifjIG+Xnxhu8 MqmpJCG68Zu90gY6J0Il8rIXP6K2L06Ej+4N7VuTtAG4oyH8tOmVlGd82z36Fi9QbeKs F/mS0/FF5BSaAlpGRRKhOAKroiathsp06HC0NCgKKrNowJXiiVushtRKJH60XSAp6hVm 3ufdfeSRMX1w5OxJjd308WRyj1kdHKNI+nGr02yG+bZ8CSjVtqvwT9IskI2wI/OI6/k2 zDiXWhUDEz7x1d8h+xYx1vc5MhPoXuTeYVE39Uc7uHYTIyj2rgvgRoG/Ns4s1cyHnnGB /Qqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=KauzblMbtoKORsMsCBmvlq8Rtah+B4qEiz+EyZ86dq4=; fh=lnr7yTku6JgeUD7RVg2iVpNIGCyzxEbHoqsX/RUnUN0=; b=mCtEAJuMEuESAtpFtypnRvkztpCzRunvDRdRS8JFWNOZdgYC+RIbkMViZ6Us7Qu0K6 ZdJNEwTyXO6ijCv+JE8ZyV3GwRsB5/YyqQPUB0wR6AJhgcwFWyy3qN24vJo3EMwb6wg+ tb6VaYd0DiJeKOloTa6lRd+nqDP0ykvJHFplx22oP6mQ/0yjPbh6PDc9pv7AW8HaErfS PQH+iA1xB5/gNcJvvdpz3DhNhf92eCUPTf3GFFOvjIQpiVranwMZZ1vzxDm7eVxlOu68 8xKwHgzV68d4wotsjxTa3QYNaiYA0g2G7iqzF9RCq1r0rM0Akd9dSgC59tpmmz3nj2t9 0IEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b="aej/MT05"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id x6-20020a17090ab00600b002634977e6e5si11737478pjq.142.2023.09.19.04.19.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 04:19:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b="aej/MT05"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id B3692809880F; Tue, 19 Sep 2023 01:07:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230351AbjISIH2 (ORCPT + 26 others); Tue, 19 Sep 2023 04:07:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230211AbjISIH0 (ORCPT ); Tue, 19 Sep 2023 04:07:26 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57F6411F for ; Tue, 19 Sep 2023 01:07:20 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3216ba1b01eso108920f8f.2 for ; Tue, 19 Sep 2023 01:07:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1695110838; x=1695715638; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=KauzblMbtoKORsMsCBmvlq8Rtah+B4qEiz+EyZ86dq4=; b=aej/MT05aBbrF4vhKurpilvHhgOxK4KLrHLpKyGXRu2Od0zs4a2PyIlWtaTCeWnRe7 JfAuqV3t/poDtcpGSQCQOvINRQRgYNrldOEhB2OIhJH5Y7vRXTNUpih5FIyEsVbe54oW LP307ovbi6GBUh40mqueuP+AUwYMQMESaOIuaiz0y0Tu4M/fkUxm/8x8jEPacUvzofx9 cwJqDllm1wqZmSiTHvSDrHltxLSZZ/BC+8ejWgloK+UNMoZzl6U3inV+lQb1f8TL9cPH pHOQ8wrefJDnjSo8QbEMiNX6wLfnFb6InIZaBbW1fVYLAMXwGwBWzvXix0G7VzzPM9HB mPzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695110838; x=1695715638; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KauzblMbtoKORsMsCBmvlq8Rtah+B4qEiz+EyZ86dq4=; b=dBZ/xGPhCI6pk2M3yluJ7HlxD0f+uybBOQP22nAz5YyfWDQLXjM3hxq0zy36CM/5fN crMod3eDbC3kBMm0p/WVwg+72sKeGeCDEgRDhDR8OVZcyw9Kj/B7pRW+aMFcI7wgSr1S lqxuq9KL9GAGuQipI/g4M6lI0SyvmqBq4t77YnwB9XbbOzLgC7SBPDLAM+aLfd3aNjXn M4pRr1U/QOn6qksYpnGbZ0CPl76Nqc/KCFg3LgAVFkhToa6QiVsPx+WI8mv7cepG3dMG AcWwS29yMkZpBAFlrs3+9vBG1vl5cUdjbGjhMCjpaoxJIkgp3N4GTzi5stJNzlY5zlrh vlew== X-Gm-Message-State: AOJu0Yzu53o0Kt5mQx8lHCPC+sJF3i8+vrBJkCFkBNJ+okzJrhSY7hxS Q8yUSztuNJv5F9xjg+V0/Ndclg== X-Received: by 2002:a5d:58e1:0:b0:319:79bb:980c with SMTP id f1-20020a5d58e1000000b0031979bb980cmr8726188wrd.64.1695110838407; Tue, 19 Sep 2023 01:07:18 -0700 (PDT) Received: from heron.intern.cm-ag (p200300dc6f209c00529a4cfffe3dd983.dip0.t-ipconnect.de. [2003:dc:6f20:9c00:529a:4cff:fe3d:d983]) by smtp.gmail.com with ESMTPSA id z8-20020a056000110800b0031f3ad17b2csm14772096wrw.52.2023.09.19.01.07.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 01:07:17 -0700 (PDT) From: Max Kellermann To: Alexander Viro , Christian Brauner , "Matthew Wilcox (Oracle)" , Andrew Morton , Hugh Dickins Cc: Max Kellermann , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] pipe_fs_i.h: add pipe_buf_init() Date: Tue, 19 Sep 2023 10:07:06 +0200 Message-Id: <20230919080707.1077426-1-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 19 Sep 2023 01:07:55 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777464647422636105 X-GMAIL-MSGID: 1777464647422636105 Adds one central function which shall be used to initialize a newly allocated struct pipe_buffer. This shall make the pipe code more robust for the next time the pipe_buffer struct gets modified, to avoid leaving new members uninitialized. Instead, adding new members should also add a new pipe_buf_init() parameter, which causes compile-time errors in call sites that were not adapted. This commit doesn't refactor fs/fuse/dev.c because this code looks obscure to me; it initializes pipe_buffers incrementally through a variety of functions, too complicated for me to understand. Signed-off-by: Max Kellermann --- fs/pipe.c | 9 +++------ fs/splice.c | 9 ++++----- include/linux/pipe_fs_i.h | 20 ++++++++++++++++++++ kernel/watch_queue.c | 8 +++----- mm/filemap.c | 8 ++------ mm/shmem.c | 9 +++------ 6 files changed, 35 insertions(+), 28 deletions(-) diff --git a/fs/pipe.c b/fs/pipe.c index 6c1a9b1db907..edba8c666c95 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -520,14 +520,11 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from) /* Insert it into the buffer array */ buf = &pipe->bufs[head & mask]; - buf->page = page; - buf->ops = &anon_pipe_buf_ops; - buf->offset = 0; - buf->len = 0; + pipe_buf_init(buf, page, 0, 0, + &anon_pipe_buf_ops, + PIPE_BUF_FLAG_CAN_MERGE); if (is_packetized(filp)) buf->flags = PIPE_BUF_FLAG_PACKET; - else - buf->flags = PIPE_BUF_FLAG_CAN_MERGE; pipe->tmp_page = NULL; copied = copy_page_from_iter(page, 0, PAGE_SIZE, from); diff --git a/fs/splice.c b/fs/splice.c index d983d375ff11..277bc4812164 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -215,12 +215,11 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe, while (!pipe_full(head, tail, pipe->max_usage)) { struct pipe_buffer *buf = &pipe->bufs[head & mask]; - buf->page = spd->pages[page_nr]; - buf->offset = spd->partial[page_nr].offset; - buf->len = spd->partial[page_nr].len; + pipe_buf_init(buf, spd->pages[page_nr], + spd->partial[page_nr].offset, + spd->partial[page_nr].len, + spd->ops, 0); buf->private = spd->partial[page_nr].private; - buf->ops = spd->ops; - buf->flags = 0; head++; pipe->head = head; diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h index 608a9eb86bff..2ef2bb218641 100644 --- a/include/linux/pipe_fs_i.h +++ b/include/linux/pipe_fs_i.h @@ -176,6 +176,26 @@ static inline struct pipe_buffer *pipe_head_buf(const struct pipe_inode_info *pi return pipe_buf(pipe, pipe->head); } +/** + * Initialize a struct pipe_buffer. + */ +static inline void pipe_buf_init(struct pipe_buffer *buf, + struct page *page, + unsigned int offset, unsigned int len, + const struct pipe_buf_operations *ops, + unsigned int flags) +{ + buf->page = page; + buf->offset = offset; + buf->len = len; + buf->ops = ops; + buf->flags = flags; + + /* not initializing the "private" member because it is only + used by pipe_buf_operations which inject it via struct + partial_page / struct splice_pipe_desc */ +} + /** * pipe_buf_get - get a reference to a pipe_buffer * @pipe: the pipe that the buffer belongs to diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c index d0b6b390ee42..187ad7ca38b0 100644 --- a/kernel/watch_queue.c +++ b/kernel/watch_queue.c @@ -125,12 +125,10 @@ static bool post_one_notification(struct watch_queue *wqueue, kunmap_atomic(p); buf = &pipe->bufs[head & mask]; - buf->page = page; + pipe_buf_init(buf, page, offset, len, + &watch_queue_pipe_buf_ops, + PIPE_BUF_FLAG_WHOLE); buf->private = (unsigned long)wqueue; - buf->ops = &watch_queue_pipe_buf_ops; - buf->offset = offset; - buf->len = len; - buf->flags = PIPE_BUF_FLAG_WHOLE; smp_store_release(&pipe->head, head + 1); /* vs pipe_read() */ if (!test_and_clear_bit(note, wqueue->notes_bitmap)) { diff --git a/mm/filemap.c b/mm/filemap.c index 582f5317ff71..74532e0cb8d7 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2850,12 +2850,8 @@ size_t splice_folio_into_pipe(struct pipe_inode_info *pipe, struct pipe_buffer *buf = pipe_head_buf(pipe); size_t part = min_t(size_t, PAGE_SIZE - offset, size - spliced); - *buf = (struct pipe_buffer) { - .ops = &page_cache_pipe_buf_ops, - .page = page, - .offset = offset, - .len = part, - }; + pipe_buf_init(buf, page, offset, part, + &page_cache_pipe_buf_ops, 0); folio_get(folio); pipe->head++; page++; diff --git a/mm/shmem.c b/mm/shmem.c index 02e62fccc80d..75d39653b028 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2901,12 +2901,9 @@ static size_t splice_zeropage_into_pipe(struct pipe_inode_info *pipe, if (!pipe_full(pipe->head, pipe->tail, pipe->max_usage)) { struct pipe_buffer *buf = pipe_head_buf(pipe); - *buf = (struct pipe_buffer) { - .ops = &zero_pipe_buf_ops, - .page = ZERO_PAGE(0), - .offset = offset, - .len = size, - }; + pipe_buf_init(buf, ZERO_PAGE(0), + offset, size, + &zero_pipe_buf_ops, 0); pipe->head++; }