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: 13390923 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 A3254CD54A4 for ; Tue, 19 Sep 2023 08:07:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 34DB56B04C2; Tue, 19 Sep 2023 04:07:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2FDFE6B04C4; Tue, 19 Sep 2023 04:07:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 19E766B04C5; Tue, 19 Sep 2023 04:07:22 -0400 (EDT) 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 0B32C6B04C2 for ; Tue, 19 Sep 2023 04:07:22 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CE3FCC0B61 for ; Tue, 19 Sep 2023 08:07:21 +0000 (UTC) X-FDA: 81252617082.17.D0B2216 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) by imf10.hostedemail.com (Postfix) with ESMTP id E154CC0016 for ; Tue, 19 Sep 2023 08:07:19 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=JbF3DuLG; dmarc=pass (policy=quarantine) header.from=ionos.com; spf=pass (imf10.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.221.49 as permitted sender) smtp.mailfrom=max.kellermann@ionos.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695110840; a=rsa-sha256; cv=none; b=oUQFXwQjFB9tVyQ5e01gOPqCjTe4bnxgJhai0A0R1Pn4agu5xhxzc7dsMXV2C4HCHVrniZ dYQNBDbNAhB2zMJLEhDd8GR0lT9+yLM0eFJNIsvNZnCFM73aO+7y31F17IMdYy5iDXTQDZ 1M1k+0ivJB58OhZfBWrD6eIXLLwoI84= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=JbF3DuLG; dmarc=pass (policy=quarantine) header.from=ionos.com; spf=pass (imf10.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.221.49 as permitted sender) smtp.mailfrom=max.kellermann@ionos.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695110840; 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:references:dkim-signature; bh=KauzblMbtoKORsMsCBmvlq8Rtah+B4qEiz+EyZ86dq4=; b=3nrQ8Pfiu0P+N6VqUE1G1ExSGG8AqJT9GebO4UTT9U4PWW1GXEsRcfqE4LsP5AfLkhKEyW xwje4JiJ/SDuxxos3Klu+YLkcJuMgBvVvWbDa00BRFPmSwcrZiMrb1f3JE4rLwLOPZ1mcv I4n4fkf8Skvwfp7KOZ46xkoI9eK+pBk= Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-31c5cac3ae2so4811972f8f.3 for ; Tue, 19 Sep 2023 01:07:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1695110838; x=1695715638; darn=kvack.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=JbF3DuLGx7B/eDngOuShhKP+koCnNk/+NaoBCcqbLAkE6Wqdnr31jfvWLxf2HV6Uw7 PgtUlGZT4Oa7NmTutZL7PTZCmQhIJf+lTSObW3MPhTZ2KJQSlXGmknRHjHmEODe3zZAf 4LbZFyIe/0hAPY+HtB5VPEVe48zyLIc0eKUD84YYgrm/p3iIoYZ2JFhb7G2y8orrGk4j cfN+QnGOmayMknQmZEXHaP/i8bFytDg2JmOMSUeob96Umq0pbEbrVt21ybTzFlFPg7S3 3bWflWZtT8PEExXVzvnm3lX1jjgrmQZnU5K76c7EPuR0msdnxHKhpDOj5nuKGq/cvLc3 23hQ== 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=ZmXQ8DSGg/F63lJthxgGT4H3IclqCxzkNbjDUH29YaWTEoZPgOzomIuwoyV+vAhvDZ KYiYzdcbzZqDDuCclO6Ybc7eK33dGZ1EGTB+qhquWvmmDTNKUEb8yyRLI78xv266c0KT 3+lcdpOaS3COkJVvsOMDjIEfIIl9XygGPiJI9G16xsKz235VcB8aWLhtpVVgBvtHyPmq fkKiXZOXWkdt+ONiyEduVXGsYrem+NQo0MPFs7cUshz1UmB7+mXIk+xveHPy5iRju9lM h4smMvXjQYZaJQuaXrsp66kzcSNrdSlO81XgVuE2aQ1QEXqYc1ERJr7lWCGxGjakCY+v xvPg== X-Gm-Message-State: AOJu0YzoyjWkDG+YIFWiFvYUzhVXIfOU7gWs5kEzK/sgdunkEQdGVvOh 2+tVP4IuH/FTRYy8g5B95i3I8A== X-Google-Smtp-Source: AGHT+IE8qi+dsghdzDbTiwa+G9WSy2YkcwrfbpN6ruotbQOOULLulDuGSAZEVLhxEsDuDDNXa2JYcA== 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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E154CC0016 X-Stat-Signature: yowpntkckni34nsawnm18xqgmuj3zzb3 X-HE-Tag: 1695110839-583477 X-HE-Meta: U2FsdGVkX18vIv9Yfl9qmej/vQuwBgdULOoBi0HB6CI/1HKG/Xia7eBJGqM2wdqKrYj4D0GhNoSjFpY5ScJZlfQq+d2AK4kx6mQTz8Bc3jR3v0nAoPT6QihEVF0Me55PHrnwNQ/1lbBDL+lKuOFmO2RT+r2WECa4G/Lh33UqRZ9e4vQHFFMta7affu/I1DGVGY7ML3C+M9ExeG/EM+mwMeddpnFBgNQysmI067OuTjMIXXzbiypcRIIqwIpxgz1EJ/ciC80IA0fbgQYranolC9jbHj7cwEldlqm0+pZ2j5B1h96hnmpytU7FgHnuPiSWO1WM5xStIO1loWuE5OoPeL9NEiS06YYpzoNq1SzzZnSI4DAeR7BXN/KfZ7GR23q7gaA12gEUoRaQZugyfC/3QUnXL3hStgOcdV/KpB9xFLVyqt3j3N+RICyFKyLS7Kyfl1N7WMpKuVSs7hoqTEzFMZAeYIXA2R02/vUwaCcIDTjuNXhNjda9AAW7IafFraHrs6Jrb1TgH8dhN9hBYphql0ABFdnPu0mOV3eR8yj6btCWDMX6uf3lpi9XZL+xPMFwE8OqA1LHdbP/V8h8AkifKwfqjkupV1tF8fYcdsN94zX2PqhXNxiFKCn6SJwXb1fCJFcD8aNIin6rrqOJlb7OCGJ9oDfbeK3PiQEI8Ikk+Zw871tchiv75TMeWGnUGNkL93UJWxDULm0i48N8agQvyYUC5BU+F5EOwsi0wrnDGFUEaPGgETiGt6mJ1lQTi1AeZ2tN5cNJ/7nTkMsMgHXFYMkGLWkFAV/JOaM+9mMZCgIYdDBYbyBz1Qyg87hnymcDLWhi/f8CT/ku15kqWALHXxDUVhT+5a2WrQJAxRaiYfe66v1TTkG68qmRfbj/Xc5tKtWlCl0JaPrOYAswMHNDZf/Sx0Mkr9tfHbmRSfjewMyr0snJZmKhgqmAti93PWsF7a88qUKmPgxcAeldGgE ZXd7dYlA IQsr69RsSWQON0z220QAmA5pX1Do2p/WwAYqitVkG+VCFFr7ggyilcpEd9zAzacsghTqONpwR9lyMgIf7rVvgEJh235eWn4DJ3IaKG3kVUItzBIy6xOMC3DEhwgiOZvo4Nc3tVImUJItalt0qGffoPU0OOkQ0QKHmhpOeuXYKy8SxIezuCNNa+yODcnzB8MVgsYdLhZ7W4biUUiMc1yV1M3l6azLlrxR2MhlE+fB7l4RmDoExc+4VQFlx2+a1hIIdoGP04o1bQcwF6n3NTxOIFY47u0xf4+WHm3EMDAfPkvJ76oCqAAXQhZF5BVV10yucFV08GZCkSgTtIJYL7aGv+v51dA== 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: 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++; }