From patchwork Thu Sep 28 16:17:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 145851 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3154411vqu; Thu, 28 Sep 2023 01:23:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHUS8q3ymqN8WxfVujVBz+c2Ix8xN9lx8TuJiq07WgFhV8b4Vpv25SeXAE0MjWuBPD4QQJx X-Received: by 2002:a67:ebd3:0:b0:452:6465:4a35 with SMTP id y19-20020a67ebd3000000b0045264654a35mr478034vso.11.1695889412685; Thu, 28 Sep 2023 01:23:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695889412; cv=none; d=google.com; s=arc-20160816; b=fhyPNylEnYCWtP3iknXVVTIivRx2dGAKy+Dbc6UlEA8rWhjpDZIB55duHa+JIN3YMA P78TmUHZnY+QtCcvgnRLqp35mhCHg5I25K1tp3QaPZQ40wsK1W1pYbRtQffDz6861acA OzSWkhnq+ze7A6ekXtAWc5XFuNmloknQtAO/5Qu8kgp1k+sIgIv13s6pIos81p3crEF6 YgH0QuHvPqJxOv/7QP4Xnid2gYh12E5RX1UWHCrCGxDlMUiLuO9UojhmtT7Kx++RTFWl sgBzYGqR5bSrxP+JKsCepuZ9dLd26Y+O/DeqC7eQeyOHQDJJUvWZ+q1Nz1ML5txZ1F2s kveg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=HPXRe2ci5bibplOuMtpQ+mvHTUIvpWj4ufHHQ182qEc=; fh=sVO6dZaz2MjOMYYQUXK0Jk+arht08gyUXlIvEKWSH7U=; b=Y9pMJRtWj7qitxA68gDa8UF/H2cg4SJM3JpVS0tJy75xAeyXXBpUCvRQ8vDZ0yPsNP /WoNKqkW4Dc/wCSWozRlFF2RFGAoVjMsuefLNQTJsdBeyjhjb9a4XumnjMB+GVv/isXX hzvLCeH0OJMmCWcNV719f/UNIhSDCRI7Br7SsgZCNid2fb/VrIlSCS3owN5UIq0k6s48 r/Bm+9FaJNQmgSbP7WkAtzzcHPLnKAciLnA7REfefeZ0WdjLoz79cU1l78a2nVTZ5MH/ v6JxmSGvhcWmd8UujXBzj5d55PFLoLDA9z8//EroR4sKEkxy4kaigJeBK2NOJfzKXlbc O9hA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id y5-20020a63ce05000000b00573fc71f6d9si18069086pgf.64.2023.09.28.01.23.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 01:23:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 5457481C99BC; Thu, 28 Sep 2023 01:19:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231276AbjI1ISn (ORCPT + 20 others); Thu, 28 Sep 2023 04:18:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231200AbjI1ISi (ORCPT ); Thu, 28 Sep 2023 04:18:38 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37538B4; Thu, 28 Sep 2023 01:18:36 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.169]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Rx5w66rfSz4f3m7f; Thu, 28 Sep 2023 16:18:30 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP3 (Coremail) with SMTP id _Ch0CgAngVDXNhVlhwUABg--.50964S3; Thu, 28 Sep 2023 16:18:33 +0800 (CST) From: Kemeng Shi To: viro@zeniv.linux.org.uk, brauner@kernel.org, dhowells@redhat.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] pipe: remove pipe_full check with wrong head in pipe_write Date: Fri, 29 Sep 2023 00:17:51 +0800 Message-Id: <20230928161752.142268-2-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230928161752.142268-1-shikemeng@huaweicloud.com> References: <20230928161752.142268-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: _Ch0CgAngVDXNhVlhwUABg--.50964S3 X-Coremail-Antispam: 1UD129KBjvdXoWruF13Cw1xAr45GF1xurWDXFb_yoWkKFgEka 97CFn3ur43Jr48Jw17CFnakryxW34Uur1UZrW5Ar9xJF1kWr98u3s5W34DC34UZ3Z8tF9x C392van2vr1fWjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbfkYFVCjjxCrM7AC8VAFwI0_Gr0_Xr1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l87I20VAvwVAaII0Ic2I_JFv_Gryl82 xGYIkIc2x26280x7IE14v26r18M28IrcIa0xkI8VCY1x0267AKxVWUXVWUCwA2ocxC64kI II0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7 xvwVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2 z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4 xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v2 6r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x0EwI xGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480 Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7 IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I 0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUxsqWUUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=DATE_IN_FUTURE_06_12, 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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 28 Sep 2023 01:19:27 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778268936954561727 X-GMAIL-MSGID: 1778268936954561727 In pipe_write we have: head = pipe->head; if (!pipe_full(head, pipe->tail, pipe->max_usage)) pipe->head = head + 1; /* write data to buffer at head */ /* supposed to check if pipe is full after write */ if (!pipe_full(head, pipe->tail, pipe->max_usage)) continue The second pipe_full expects head after write but head before write is used. Luckily, we will call pipe_full with correct reloaded pipe->head in new loop cycle and stop writing correctly. Remove wrong pipe_full check and simply continue to first pipe_full check after write done to avoid unnecessary check. Fixes: a194dfe6e6f6 ("pipe: Rearrange sequence in pipe_write() to preallocate slot") Signed-off-by: Kemeng Shi --- fs/pipe.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/pipe.c b/fs/pipe.c index 2d88f73f585a..b19875720ff1 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -542,10 +542,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from) if (!iov_iter_count(from)) break; - } - if (!pipe_full(head, pipe->tail, pipe->max_usage)) continue; + } /* Wait for buffer space to become available. */ if ((filp->f_flags & O_NONBLOCK) || From patchwork Thu Sep 28 16:17:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 145862 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3165374vqu; Thu, 28 Sep 2023 01:53:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHVuxeR0x0wZJAkR1+lM5J2ShwkOVx6XHD3aL3mQuqBP+rPT4NfQQOMdV9a9+FRmmFNEAM3 X-Received: by 2002:a05:6102:3a76:b0:44d:590d:28a6 with SMTP id bf22-20020a0561023a7600b0044d590d28a6mr539590vsb.27.1695891181604; Thu, 28 Sep 2023 01:53:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695891181; cv=none; d=google.com; s=arc-20160816; b=hV0j9oBkY9bypHnDdiXzZghS5w9ZmvimGFjVIUn4dBI3kKpMUmhqG3NaMM+W6QckDU N+sIm3ZGX/Awv+Oo/ToS7ofykX4Si5Z/6TEXCg/DfBVYu4rZwI1bdWG5fJ+K136NPtp+ SE04vBsTX+t2AGZUdUnvh7dX7ZdD+mhELrV3IhQS4nk3vfHmXJhMq4TymGBiKaWrJW0G EP0q2OMq4JTeu8nwZAEOr00Kg+0xfkKiOrsZ8GOX9Yvf5voTzi/JB+u9BDll+TpO5a61 BGN01/c7rOryKn5ZZjkSdZR1AE63f7lLY6L5mAbpb76AOgCn4EPKWRjj+UdIIFpTMp+r DLdg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=vwbBA1BJuyLwNvFcOc3pD0Uw5qE3TLWcglXed98JqCU=; fh=sVO6dZaz2MjOMYYQUXK0Jk+arht08gyUXlIvEKWSH7U=; b=RY6RFcs5iO2jNYX7NnCuMQuy/pX+VNwoHE1bok16e4QJVUj/yBJDUGtoy8M2rnHJTq JPQUR/sCn8dfpBSpG8RFWjzleLapSM9p2GGvgVIiKFKrm2U0g1j7QThagZ7idll7AcXa GFYB5fwoSVVhnC8/xu4ZCGGGfRnUaZCytbPlzhQkDVyVPIkXXV2JamaLJ6mkp3b39ZnO KVIq42rDxExsPG4R2dQuZ3DELqyAG3hUbHldRaHPmGCDc1sMFP2GchRjhtDO3FOM2a28 DI1NGgtcbH0wX+N76yCA+lu+Bt9OYqlSOmKaDU+rM7bp9MEmHeVd/Yota5YkHjjY4fRI Codw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id c3-20020a6566c3000000b0056534300dc2si17634521pgw.247.2023.09.28.01.53.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 01:53:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7D58080A73FB; Thu, 28 Sep 2023 01:18:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230338AbjI1ISi (ORCPT + 20 others); Thu, 28 Sep 2023 04:18:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229539AbjI1ISh (ORCPT ); Thu, 28 Sep 2023 04:18:37 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E90B8B3; Thu, 28 Sep 2023 01:18:35 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.169]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Rx5w71sVyz4f3mHZ; Thu, 28 Sep 2023 16:18:31 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP3 (Coremail) with SMTP id _Ch0CgAngVDXNhVlhwUABg--.50964S4; Thu, 28 Sep 2023 16:18:33 +0800 (CST) From: Kemeng Shi To: viro@zeniv.linux.org.uk, brauner@kernel.org, dhowells@redhat.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] pipe: avoid repeat check of pipe->readers with pipe lock held Date: Fri, 29 Sep 2023 00:17:52 +0800 Message-Id: <20230928161752.142268-3-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230928161752.142268-1-shikemeng@huaweicloud.com> References: <20230928161752.142268-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: _Ch0CgAngVDXNhVlhwUABg--.50964S4 X-Coremail-Antispam: 1UD129KBjvdXoW7GFyDJF1xZrWxCw18WFyxuFg_yoWDtwbEk3 92yF1rWr1fJrWxXa17CF1ayr4UuryDAr17Zr1Yyr9rGF18WryDu3Z5ZFy8AryUXan8GF9x Ca9Fyr9rJr1xCjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbfAYFVCjjxCrM7AC8VAFwI0_Xr0_Wr1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l87I20VAvwVAaII0Ic2I_JFv_Gryl82 xGYIkIc2x26280x7IE14v26r15M28IrcIa0xkI8VCY1x0267AKxVWUCVW8JwA2ocxC64kI II0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7 xvwVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2 z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4 xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v2 6r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x0EwI xGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480 Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7 IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I 0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7IU0TrW7UUUUU== X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Thu, 28 Sep 2023 01:18:44 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778270791362076018 X-GMAIL-MSGID: 1778270791362076018 Change to pipe->readers is protected by pipe_lock. Only recheck pipe->reader after relock to avoid repeat check of pipe->readers with pipe lock held. Signed-off-by: Kemeng Shi --- fs/pipe.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/fs/pipe.c b/fs/pipe.c index b19875720ff1..e9c63f66d1c7 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -479,13 +479,6 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from) } for (;;) { - if (!pipe->readers) { - send_sig(SIGPIPE, current, 0); - if (!ret) - ret = -EPIPE; - break; - } - head = pipe->head; if (!pipe_full(head, pipe->tail, pipe->max_usage)) { unsigned int mask = pipe->ring_size - 1; @@ -573,6 +566,12 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from) __pipe_lock(pipe); was_empty = pipe_empty(pipe->head, pipe->tail); wake_next_writer = true; + if (!pipe->readers) { + send_sig(SIGPIPE, current, 0); + if (!ret) + ret = -EPIPE; + break; + } } out: if (pipe_full(pipe->head, pipe->tail, pipe->max_usage))