From patchwork Thu Sep 21 07:57:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Kellermann X-Patchwork-Id: 143076 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5264170vqi; Thu, 21 Sep 2023 18:56:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFdnEUOIU+UTbMISt2SehYmfyAGG43WZnilYe6euEPMIHqK9rypf8n0dqc/DzOEO+tCSvAB X-Received: by 2002:a17:902:f80a:b0:1c5:deaa:d72e with SMTP id ix10-20020a170902f80a00b001c5deaad72emr1568582plb.30.1695347783676; Thu, 21 Sep 2023 18:56:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695347783; cv=none; d=google.com; s=arc-20160816; b=Qi9W3OABc7wOdWB9CNCtvy0qDpdWfOArCfgQHafRboPKoFDiU+D/AT7siN73IolVse +uyZ0Mglnh8OFikH5n8JG9wqcbglNnGFuJgb2gECIRauhGJSx9i/d3Nvm7fgG0DPxIaR 3mXRx9uIb2sM3qHzEzXnGtIU2s25d7UAo581chjOwkhCemLtbIvnpmP0+V8tNHWJ6miv HtWT6xPdJFYPB6J+daof9oyaGf4um1MseDXqaWRkdCXug7ShAXJf+FwytCzMgRTaGXxH /cWZicN9UzrwEKBQ0sDwSsY+T0XHlUeWPA2q+4keBXUn6zj9sCTgqotevKJxQ6ZVCwE1 Bjxg== 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=uXl3XjtNY+qQUGAfKFbAOhIfMu203xufyzo0Jfa0XyY=; fh=/mmUFS5s71yRsPeN08HF9rYndG2tJREJfMy47/3Il/c=; b=uNF7nKqRdV7D7UiBM5BN+RLA8Rtv+tKqkta9g8GnWkI4s89hLoPf19ZwB87EMAARfk gW4fHhQv0q9QGxHO2WaeKB4mesLfHkalc8ydxwMbyAY3gGylXfWsO91+2ga22V2PxOJA 8eKjcyH0+AHVMVzYGC+H13ciF84C2xZwHUgz7x1r1tv6uN46ed4SuOoI0Fsh7kgP6G3g Y5X+KZZzaX1NKavjcNktz/hFarcGF7n3gCrYqRSuzmGqJQCnhWqU9LPXs3fRr3qpjMcg /Y4QRUbuXp+S8PLRsI8RKS79JO5q68e0uqFd8bInXD1s+gAtR4rbhFYt70jfkx2U26lx S3cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=iRPclcbE; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id l16-20020a170902f69000b001c5e0672f53si1493978plg.466.2023.09.21.18.56.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 18:56:23 -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; dkim=pass header.i=@ionos.com header.s=google header.b=iRPclcbE; 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; 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 snail.vger.email (Postfix) with ESMTP id 5127C82AE2D5; Thu, 21 Sep 2023 12:45:11 -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 S231171AbjIUTpJ (ORCPT + 28 others); Thu, 21 Sep 2023 15:45:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231395AbjIUToq (ORCPT ); Thu, 21 Sep 2023 15:44:46 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46A1510D76C for ; Thu, 21 Sep 2023 12:31:20 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-4053c6f0da0so1640145e9.1 for ; Thu, 21 Sep 2023 12:31:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1695324664; x=1695929464; 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=uXl3XjtNY+qQUGAfKFbAOhIfMu203xufyzo0Jfa0XyY=; b=iRPclcbEziiuXphFxRjzycEIzgzVvfixovnnY4z5rMoA8nZQhVSi2TzjFvZhuYnott F1ZFDsMMxSO4O99WzxyJDTcpo4zhddeK3Q0OVoDfH/ypn6AdIdHlwqmlkxqkLp5B5q5w QolScV9TwCk/GfZ8CelkWOwX7wqK5Hd60a2nzZnX9XrFQfi089RIYsnxhgoUiubdtu1M fYrd7hOnuxK14aKZyIBbRtuw1/1Ck3zFJRyJElwQ9rqKV6Kt8iWTdnfDCjW9BIx7q2ds Fvwenutawy+gAoF8SGE8c1XYI3Wt2jp6gs/TxVghZX4jDiHEHmDJJHFoQ1xqpUakJpqV Q3ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695324664; x=1695929464; 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=uXl3XjtNY+qQUGAfKFbAOhIfMu203xufyzo0Jfa0XyY=; b=EIomeeeB/V89W4OcanAsjfM9p/vo8KY8X/uxW1l6z+fg5Z6QZssFj/uG5h0HGklT0T ErRZbMDaHRZl/WP7FSLPF710ZaPHBt2aKs454kkUxCYUWiM9orlaNooNKbV9CF+gdvvs 1xf8zs5WGdzPZktVo63EumdLGtbJvy4quInL1n2WtVWrgjCRC3+dmE+HZFjU1Hsi7qvZ TNiGOiX6jP4ohe3fwFL13C0KkpumwIopf2AQrXDlQssCZlVmVfXJvs3AJTYyUnEWDhIJ kKeC93b5rHCPx7sg3McEvk2H0dvnlXNuIjTtR2KNLfth/JorlVN2+6LmQyr/IfP3Bjhj 2J9g== X-Gm-Message-State: AOJu0Yy0Utwjs//cQhKMjUEySipkhjZ5/2x0BwDCQkw82qw6Absw4fvz 9+rKgIVA9XsOwsCicZL+qlxAQkfRJa7vRBCPFPI= X-Received: by 2002:ac2:44ce:0:b0:503:f:1343 with SMTP id d14-20020ac244ce000000b00503000f1343mr3999054lfm.19.1695283079562; Thu, 21 Sep 2023 00:57:59 -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 v4-20020a05600c214400b003fef19bb55csm1151252wml.34.2023.09.21.00.57.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 00:57:59 -0700 (PDT) From: Max Kellermann To: viro@zeniv.linux.org.uk, brauner@kernel.org, howells@redhat.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Max Kellermann Subject: [PATCH 1/4] pipe: reduce padding in struct pipe_inode_info Date: Thu, 21 Sep 2023 09:57:52 +0200 Message-Id: <20230921075755.1378787-1-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=unavailable 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, 21 Sep 2023 12:45:11 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777689869494391157 X-GMAIL-MSGID: 1777700997284563914 This has no effect on 64 bit because there are 10 32-bit integers surrounding the two bools, but on 32 bit architectures, this reduces the struct size by 4 bytes by merging the two bools into one word. Signed-off-by: Max Kellermann --- include/linux/pipe_fs_i.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h index 608a9eb86bff..598a411d7da2 100644 --- a/include/linux/pipe_fs_i.h +++ b/include/linux/pipe_fs_i.h @@ -62,9 +62,6 @@ struct pipe_inode_info { unsigned int tail; unsigned int max_usage; unsigned int ring_size; -#ifdef CONFIG_WATCH_QUEUE - bool note_loss; -#endif unsigned int nr_accounted; unsigned int readers; unsigned int writers; @@ -72,6 +69,9 @@ struct pipe_inode_info { unsigned int r_counter; unsigned int w_counter; bool poll_usage; +#ifdef CONFIG_WATCH_QUEUE + bool note_loss; +#endif struct page *tmp_page; struct fasync_struct *fasync_readers; struct fasync_struct *fasync_writers; From patchwork Thu Sep 21 07:57:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Kellermann X-Patchwork-Id: 143485 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5634953vqi; Fri, 22 Sep 2023 07:47:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEr/FjWk1BpRsVJpVpXKsFRueYb8Gzmy7F5ZRdFCUq4MCOfqi0e8lBBmZ0KgWs3Q70ud+2V X-Received: by 2002:a9d:730f:0:b0:6bd:c7c3:aabc with SMTP id e15-20020a9d730f000000b006bdc7c3aabcmr8365323otk.19.1695394042073; Fri, 22 Sep 2023 07:47:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695394042; cv=none; d=google.com; s=arc-20160816; b=rxhUpQIANwgyaBd3w+SinG7wHc4XDL4z9zKdKdfweFYbbLYZifiRdLb3QjJpQRfBpT zkrcUJLDnPZmVKDAp9kXIXt+hQmnQOj8Wx4gKL3ASIZN2UcuWCvr3CsO6cMrTI5i/et7 NZ00Yf1PrltPNr71BS4xUGM5ipfPzkCJ8W8LuM4fVvPVTU6CuucZnj2/q0KCLwwl/ZmC Z4MfbmOxhVkX0IPGGuJKOO/wOBJbQGIIzUE71bLaVdH6smx22N4APoNLeM332RADX9wC 67+xgptAgn6Hjrje1LIubqEjBGZHjLYTMISuXFTTdXv3JIGe1t4p+yvqLJoDtnOsn6q4 RJXg== 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 :dkim-signature; bh=exindjDRedXgd3Z4uqnR6aLnmaUK9oSQ00jryr/8dkk=; fh=/mmUFS5s71yRsPeN08HF9rYndG2tJREJfMy47/3Il/c=; b=XY07piteXCGR8jAK0geMpe7qr2PfQrDHfzzKkdM1VImLhG8MpaXCvQQxgvys9UnOHP +41GwWg7DdR4uwLxFdKwI8L2saXAljXYED7/NNtv97Vplp0vCi4sMJwUFFpEKJYIP0O5 +wMOYJUHfDwdxSJbvRxuZA+EFvqs9mUFv7xrCGAVyFxaGjrTCCVhWl4rV8ZFpsKYQEo0 Xo7d05oW9vVXgZnuzQbQ7n8dKVS/XyqmOseihBu9vuqZZ+uWdoyTxF3ROOlLxjCXafZ+ 7vz2Hbm4U3HYHE3YkKlKGpNNdeIzp0VIsVec/jmhPeW46aaS6Ypj3fMXc3XB0AIKImY5 G+3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b="c2fwadW/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id a5-20020a655c85000000b00564bcae8b64si3655032pgt.846.2023.09.22.07.47.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 07:47:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b="c2fwadW/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id BAE9684D572F; Thu, 21 Sep 2023 16:00:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231925AbjIUXAr (ORCPT + 29 others); Thu, 21 Sep 2023 19:00:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231646AbjIUXAg (ORCPT ); Thu, 21 Sep 2023 19:00:36 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 396898A203 for ; Thu, 21 Sep 2023 10:40:29 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2c00b37ad84so22335401fa.0 for ; Thu, 21 Sep 2023 10:40:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1695318027; x=1695922827; darn=vger.kernel.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=exindjDRedXgd3Z4uqnR6aLnmaUK9oSQ00jryr/8dkk=; b=c2fwadW/bxkT2mvxY06pYDFleUPJ6t9rsbDH/sy+z7l+nnQC7aJZB4qTFpHtVV0hTh 10KEl5kps2ChhyFkt+IfPA7+jgu8AIVqfMERwclqAwWZUX16ZKoWbAvuHx/ryzQQKlG3 u3fHkaI3RzRHQMuzKa7s+y4BLtwdUeOAcNU1ZNZM7iVROQkp8yAqQKRjKhlEBOzW0kxs aoYhwEGTg1SoTv1SXozK7ioYt0CiKuGi2x9Ebrz/jMHbDZm3siNU5CWxki1XiPKjyb7p 388ZZRx1GTibwL/j6ABRDrQxlTX5dloByrlQoMVY5fGilZoPMoRop+AAl0Aeh/IwgUfk WhYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695318027; x=1695922827; 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=exindjDRedXgd3Z4uqnR6aLnmaUK9oSQ00jryr/8dkk=; b=edCefjok8/MEZx3xSJ6MVfzI/Y1nifqxWlXT4lQyVVk5B7TwdzZo8mXrLmt1EGfnyR Gc9caQQK5XSK9eHDjet7uMHn30snsCzht8bObQwcjwlCXupVaAEXlAvYEwGFFEZNAKZa ShvdxJgHxBlQ+EwfzNMmADdrl0GkymhM3EdTN1X3zmMlgknrOCJGPsI9PUKRWIuUDhIv Je09nZl+wd/CAkmqcz1o8WgDL9bc8C9Vm3rIP8Xu67sLWKkevaiUhJVyHY/hwXtNNr6v wd01i+eWJXw+JlJYJQDonXRqHtE7Msj03AupUNixX2kdTEBz3oDRSM6kuEQtkpSNQeWN IwjA== X-Gm-Message-State: AOJu0YyES0pxTHsGx0I6xl50ItVs1p7Mzi4u3Qafb+mW6gNpxakWdvGs aUNM6PiuyUZhuhbCaGxFTDkjU763u+TGmAhS0VQ= X-Received: by 2002:a05:600c:2109:b0:401:bedd:7d42 with SMTP id u9-20020a05600c210900b00401bedd7d42mr4517741wml.13.1695283081746; Thu, 21 Sep 2023 00:58:01 -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 v4-20020a05600c214400b003fef19bb55csm1151252wml.34.2023.09.21.00.58.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 00:58:01 -0700 (PDT) From: Max Kellermann To: viro@zeniv.linux.org.uk, brauner@kernel.org, howells@redhat.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Max Kellermann Subject: [PATCH 2/4] fs/pipe: move check to pipe_has_watch_queue() Date: Thu, 21 Sep 2023 09:57:53 +0200 Message-Id: <20230921075755.1378787-2-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230921075755.1378787-1-max.kellermann@ionos.com> References: <20230921075755.1378787-1-max.kellermann@ionos.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED 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 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 16:00:50 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777749503139940548 X-GMAIL-MSGID: 1777749503139940548 This declutters the code by reducing the number of #ifdefs and makes the watch_queue checks simpler. This has no runtime effect; the machine code is identical. Signed-off-by: Max Kellermann --- fs/pipe.c | 12 +++--------- include/linux/pipe_fs_i.h | 13 +++++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/fs/pipe.c b/fs/pipe.c index 6c1a9b1db907..6ecaccb48738 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -437,12 +437,10 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from) goto out; } -#ifdef CONFIG_WATCH_QUEUE - if (pipe->watch_queue) { + if (pipe_has_watch_queue(pipe)) { ret = -EXDEV; goto out; } -#endif /* * If it wasn't empty we try to merge new data into @@ -1325,10 +1323,8 @@ static long pipe_set_size(struct pipe_inode_info *pipe, unsigned int arg) unsigned int nr_slots, size; long ret = 0; -#ifdef CONFIG_WATCH_QUEUE - if (pipe->watch_queue) + if (pipe_has_watch_queue(pipe)) return -EBUSY; -#endif size = round_pipe_size(arg); nr_slots = size >> PAGE_SHIFT; @@ -1380,10 +1376,8 @@ struct pipe_inode_info *get_pipe_info(struct file *file, bool for_splice) if (file->f_op != &pipefifo_fops || !pipe) return NULL; -#ifdef CONFIG_WATCH_QUEUE - if (for_splice && pipe->watch_queue) + if (for_splice && pipe_has_watch_queue(pipe)) return NULL; -#endif return pipe; } diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h index 598a411d7da2..699507c52b72 100644 --- a/include/linux/pipe_fs_i.h +++ b/include/linux/pipe_fs_i.h @@ -124,6 +124,19 @@ struct pipe_buf_operations { bool (*get)(struct pipe_inode_info *, struct pipe_buffer *); }; +/** + * pipe_has_watch_queue - Check whether the pipe is a watch_queue, + * i.e. it was created with O_NOTIFICATION_PIPE + */ +static inline bool pipe_has_watch_queue(const struct pipe_inode_info *pipe) +{ +#ifdef CONFIG_WATCH_QUEUE + return pipe->watch_queue != NULL; +#else + return false; +#endif +} + /** * pipe_empty - Return true if the pipe is empty * @head: The pipe ring head pointer From patchwork Thu Sep 21 07:57:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Kellermann X-Patchwork-Id: 143438 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5580287vqi; Fri, 22 Sep 2023 06:37:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEEMMGks7/tmb1RKMhtgNf+0gvNHpkAYVa8yU8zSCdsGz9NVk5wO8cVS45v7rOokGsc+rtA X-Received: by 2002:a05:6a21:78a7:b0:136:e26b:6401 with SMTP id bf39-20020a056a2178a700b00136e26b6401mr9781138pzc.16.1695389845242; Fri, 22 Sep 2023 06:37:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695389845; cv=none; d=google.com; s=arc-20160816; b=Gx5lurPoV/Boh9kCb11qh9XtLHeeTAiVfOY85Qq0XwS0qRS9lk0mA2QH5Q/gfriWGq CDU37xzVDSs4/hRGIEBKp+MRUkKzVlWBPucyrlACELMfmdQ/wRDiYhUQSUgB6DuAs9/7 h5XiI/oZxN4hJywaxS2EKm5AbPQnlL6G/ePjfy4QbUStrK51h7L+XJhC2S5m7FLyFXFb 5/GOKpROrr8egSz47Brt0Vj5fN4ePH96fJsbnaxBUQkHIfQhaS+F8bGVHrPwb+dKIaMK xJm/luAei4m0fmQrwB2fgtpyr+bMZeD6IwMuK8D1iRD6lXFYZjnXWbpibxob3c6TygSo 49Lw== 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 :dkim-signature; bh=08cpvcrCpdCUD29e4UfDmA8S+Uy08AnVrTRRsGrC/bY=; fh=/mmUFS5s71yRsPeN08HF9rYndG2tJREJfMy47/3Il/c=; b=S7wqmEtbaFvCk0mFZRCix9Vus1rUvX3IPj48yVLqge4YuPxnipQ5WskkgxsD5izkQM Cie8athDHNu9J+b6DXHQ+QeEDCFYtCDbLMLEe4CaJ/2qzLzRhk9R3jjJpNdWvqWy99SJ g35f+vl4PQQlF8IyDAyh9lv+ggog5B1rRBSAldWm10issJOuT2jaN2UBLUaWwOqxrEuo VWgbxRy2dWbJWuvPFb1XLqO8wGYwDa3gh57p1U3wmD1xZ7hCgBkdV+yDa6eGEYjO97Xw 3bA5f9+ML1tBV+bcklK4hXFOqtP0T9XRXGu52lHbA8P6nvQit4DoM3LhigYXT3x8MSPx n1mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=HSIHYQK5; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id eb17-20020a056a004c9100b00690158afc78si3820754pfb.284.2023.09.22.06.37.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 06:37:25 -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; dkim=pass header.i=@ionos.com header.s=google header.b=HSIHYQK5; 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; 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 snail.vger.email (Postfix) with ESMTP id B044C82F34BB; Thu, 21 Sep 2023 14:02:35 -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 S232440AbjIUVCS (ORCPT + 29 others); Thu, 21 Sep 2023 17:02:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231517AbjIUVBw (ORCPT ); Thu, 21 Sep 2023 17:01:52 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 943DF580B1 for ; Thu, 21 Sep 2023 11:12:15 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-404fbfac998so14743435e9.3 for ; Thu, 21 Sep 2023 11:12:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1695319934; x=1695924734; darn=vger.kernel.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=08cpvcrCpdCUD29e4UfDmA8S+Uy08AnVrTRRsGrC/bY=; b=HSIHYQK5bawTfqMQGWEK07nFoZMPZTh0XmGRrXdx9dibJr5ATt03wbQx7pdZTRXxbW 9fdMrlWf4VfH6IKxHV6N5C6bFDVbHDGJLhlmY+KrruiA3dbXOVIC26B19PSE7WHMsGy4 cP3I4Snm14Pid2nDj0++/MLW5LtBfKrBiNJZM8qFNnlNcWmBJ1M3sJo02nwRJVQZgIg0 dbox8VpfRu/QQc377XXSYdhvyycnICd813pKUP9GjzenCDAk2HE0W47G3XLfq6XoNiAK TVfvZcKXiUjMbAJKa0ajq2ryJx4BO6TLUFlCYuVPqWxhu32gyLWUrctQWTzBfKwKggts m6oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695319934; x=1695924734; 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=08cpvcrCpdCUD29e4UfDmA8S+Uy08AnVrTRRsGrC/bY=; b=RF7846pSWoY5aUfU3k5dJZXCEIc7jIJs23pOu/dmBGiHX0lvD6aWqbdYtwtAwwfxrY 1Pf8xyEqGg5jn0ZcqrmEFzl4vAqUFxKqIbX9OFV20Q1zGW4kjfZhDjvbDbb/kQOdaKHZ UNrrAOYYso6GBPxeZ4z+KcJOUbRlKP+R97Ciuf7lWtBzHaH5SCiPIPt+yiWvMSvlFza4 S/RYqxp2Hha4PeZAdG/5JzdDobIwsFUitxYhc2WzyJo1CXlst5cMRvunS4oQXuiZBhsA kJeAoBAwF16LKot7vDt2wPx3dLC6BmLKlJebehWhEDOeAp3FravtJmMJSDuNMuMhSJKo Jx/A== X-Gm-Message-State: AOJu0YxmY58AFwWJgmF7khush1p0eayzqgbD8DUaebBYGRUhdc+G7uKX 9ArQYHysnl1up+//+In8P+YNcw9W5SurWBS9NlY= X-Received: by 2002:a05:600c:21ce:b0:401:519:d2 with SMTP id x14-20020a05600c21ce00b00401051900d2mr4093726wmj.23.1695283083252; Thu, 21 Sep 2023 00:58:03 -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 v4-20020a05600c214400b003fef19bb55csm1151252wml.34.2023.09.21.00.58.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 00:58:03 -0700 (PDT) From: Max Kellermann To: viro@zeniv.linux.org.uk, brauner@kernel.org, howells@redhat.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Max Kellermann Subject: [PATCH 3/4] fs/pipe: remove unnecessary spinlock from pipe_write() Date: Thu, 21 Sep 2023 09:57:54 +0200 Message-Id: <20230921075755.1378787-3-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230921075755.1378787-1-max.kellermann@ionos.com> References: <20230921075755.1378787-1-max.kellermann@ionos.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED 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, 21 Sep 2023 14:02:35 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777745102210151791 X-GMAIL-MSGID: 1777745102210151791 This reverts commit 8df441294dd3 ("pipe: Check for ring full inside of the spinlock in pipe_write()") which was obsoleted by commit c73be61cede ("pipe: Add general notification queue support") because now pipe_write() fails early with -EXDEV if there is a watch_queue. Without a watch_queue, no notifications can be posted to the pipe and mutex protection is enough, as can be seen in splice_pipe_to_pipe() which does not use the spinlock either. Signed-off-by: Max Kellermann --- fs/pipe.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/fs/pipe.c b/fs/pipe.c index 6ecaccb48738..939def02c18c 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -505,16 +505,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from) * it, either the reader will consume it or it'll still * be there for the next write. */ - spin_lock_irq(&pipe->rd_wait.lock); - - head = pipe->head; - if (pipe_full(head, pipe->tail, pipe->max_usage)) { - spin_unlock_irq(&pipe->rd_wait.lock); - continue; - } - pipe->head = head + 1; - spin_unlock_irq(&pipe->rd_wait.lock); /* Insert it into the buffer array */ buf = &pipe->bufs[head & mask]; From patchwork Thu Sep 21 07:57:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Kellermann X-Patchwork-Id: 142986 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5190992vqi; Thu, 21 Sep 2023 15:58:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEncLUr/+EgN565yIqsjy4cNVR99+nIyyPNccuMhV9sQ9VTbSDisg/PliWblQ6gUFv6c8Si X-Received: by 2002:a05:6808:234d:b0:3ad:29a4:f560 with SMTP id ef13-20020a056808234d00b003ad29a4f560mr6204991oib.34.1695337082066; Thu, 21 Sep 2023 15:58:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695337082; cv=none; d=google.com; s=arc-20160816; b=C3eKuQ2UwCt7RZ8fqyG7iYF5U0/urwaDItc8xEO5+0HhUF4HGRbplQkCKbMHVjmdfW g3tGJlLtLLxskFo3fMq3fZglUni0Je9E5VYNPULWSlvcir/5fl8LrCfJcJo52OmtXDD5 JYBhZbWew5dGapIGgRcqjNhTwDOdZV6T+BY4fPoSBiIgGVFiP87wGbLPjBx5SNk+jl1n Ydl0P+RnqJyo61eSeVxGUj3YI2SeBkEIFWjVpH3LPhsXV6s/W8J9DQiOIUH7GO0exhXi q0va0HwvwI4I7peN4ADtWHlkdjbH0n9HdjUK+tc7jQFx0TrgnApLFcfwBgGNV2AXVv4y W/xQ== 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 :dkim-signature; bh=Ln8pAXov2i3W9jm1L6DymijJbQvZk3PVbO+zm8QE4Tk=; fh=/mmUFS5s71yRsPeN08HF9rYndG2tJREJfMy47/3Il/c=; b=Ll8NYY+684+txbN+v/1vXMktk+QH20y7yW6EXjF2iXt1L5sUA441g7WYGopo3Sb2lt J04iSyQxsUDzD5H8iHu0fea/ewH8HQuoWPq8yHaTkthOkTrqRh5VwECjOv/wzEEAxMYv jNXvDf7TfjhZL+08NA2+OCOIGW+GJycmL4neOL7dwYV0jipzVAujx7KxDJCWDS4pTtP6 Jpr0/CsNQWfOW3g8mh6YkRZ/nZ4YF930bwRWZERPuTW9k2C9uYxXe5HE5l3XyYbAYu9d tEluZiwlGaSnnh+/KkwXmBbr0aSf4UxC4VDhMWhvEEecamjrS9TY5+RzpFnMvwEwQU1f 3mcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=S373tAqM; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id k124-20020a636f82000000b0056b0b30d05csi2258897pgc.245.2023.09.21.15.58.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 15:58:02 -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; dkim=pass header.i=@ionos.com header.s=google header.b=S373tAqM; 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; 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 morse.vger.email (Postfix) with ESMTP id 3EB4983470F9; Thu, 21 Sep 2023 12:37:38 -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 S230394AbjIUThS (ORCPT + 28 others); Thu, 21 Sep 2023 15:37:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230385AbjIUThB (ORCPT ); Thu, 21 Sep 2023 15:37:01 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49C41FBB33 for ; Thu, 21 Sep 2023 12:12:33 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-9ad8bba8125so172000466b.3 for ; Thu, 21 Sep 2023 12:12:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1695323552; x=1695928352; darn=vger.kernel.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=Ln8pAXov2i3W9jm1L6DymijJbQvZk3PVbO+zm8QE4Tk=; b=S373tAqMm0OSLe8ccVaqtclKSPf62bjkwoM5pxazLkqmEKdxhANXGyVBOnJ7cl67qI uKgX5YBDYRB52PJeAvKAnzl47FChzi1EfnmrOlgAm0hTPJ2WXUBzPYbAoQSoHMtczQqL 4Pl7/deynA/1c9WoEHSFX+9WsBnSFV7mzyi6deZkdVOWpmB1NNL3nLt1IxON6QR5hnb5 Nye9kUbKCHU1XH+0eVRxFe0P9XIVUpEqRO4MF+RjURkWSWTurYab3OeWtoIKVXvTZ7EE 52kqwsVEGbb8+UC0oLuVKRHSm3WnFm5c9pxyfg6lazHyYOlmSYQrPNt63lwWPUy0QKOO domQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695323552; x=1695928352; 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=Ln8pAXov2i3W9jm1L6DymijJbQvZk3PVbO+zm8QE4Tk=; b=YaYHJXVwHgS2LbUv+i3zzpKgKpnjCBNNySNSD/PwLDMC6CmzQhQaiVIUXCysVHfVKU VgyErS/Qi2VCyKr3WwD5ZuzEarecTHrPlXMhCSpzhZ9UyQUf06Yot7kW56QfjS5ziuNZ mqs7EGG7qRsf/RRLCxvWnvqbRLFkCbSWxiJp1Xwbow94fHtq76sVv9rQbYmNtmT7ZuB1 u1l5ksi0MdiivoAkfCRm10UOPlowMgGi5psjDiQhFE8smawWkwttSWrU0RItCLotevxA 4LPlSyCihl/rYRqjKdbk6kjApX2YC5WB/qvMejus5E2xuIElYsQtvPmE0OEgyXoEE/pd JhIg== X-Gm-Message-State: AOJu0YynWRxy//oE23VqrT5VZltlx/O2lsfP5StkclBZQGLrd+Mzf38a dfONiusWyToYWSXvA+6587uUVg2m/zLnc0l/Rvc= X-Received: by 2002:a7b:c3cf:0:b0:402:f536:2d3e with SMTP id t15-20020a7bc3cf000000b00402f5362d3emr4452684wmj.14.1695283084637; Thu, 21 Sep 2023 00:58:04 -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 v4-20020a05600c214400b003fef19bb55csm1151252wml.34.2023.09.21.00.58.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 00:58:04 -0700 (PDT) From: Max Kellermann To: viro@zeniv.linux.org.uk, brauner@kernel.org, howells@redhat.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Max Kellermann Subject: [PATCH 4/4] fs/pipe: use spinlock in pipe_read() only if there is a watch_queue Date: Thu, 21 Sep 2023 09:57:55 +0200 Message-Id: <20230921075755.1378787-4-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230921075755.1378787-1-max.kellermann@ionos.com> References: <20230921075755.1378787-1-max.kellermann@ionos.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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, 21 Sep 2023 12:37:38 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777689776273566473 X-GMAIL-MSGID: 1777689776273566473 If there is no watch_queue, holding the pipe mutex is enough to prevent concurrent writes, and we can avoid the spinlock. O_NOTIFICATION_QUEUE is an exotic and rarely used feature, and of all the pipes that exist at any given time, only very few actually have a watch_queue, therefore it appears worthwile to optimize the common case. This patch does not optimize pipe_resize_ring() where the spinlocks could be avoided as well; that does not seem like a worthwile optimization because this function is not called often. Related commits: - commit 8df441294dd3 ("pipe: Check for ring full inside of the spinlock in pipe_write()") - commit b667b8673443 ("pipe: Advance tail pointer inside of wait spinlock in pipe_read()") - commit 189b0ddc2451 ("pipe: Fix missing lock in pipe_resize_ring()") Signed-off-by: Max Kellermann --- fs/pipe.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/fs/pipe.c b/fs/pipe.c index 939def02c18c..da557eff9560 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -322,14 +322,34 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to) if (!buf->len) { pipe_buf_release(pipe, buf); - spin_lock_irq(&pipe->rd_wait.lock); + + if (pipe_has_watch_queue(pipe)) { + /* if the pipe has a + * watch_queue, we need + * additional protection by + * the spinlock because + * notifications get posted + * with only this spinlock, no + * mutex + */ + + spin_lock_irq(&pipe->rd_wait.lock); #ifdef CONFIG_WATCH_QUEUE - if (buf->flags & PIPE_BUF_FLAG_LOSS) - pipe->note_loss = true; + if (buf->flags & PIPE_BUF_FLAG_LOSS) + pipe->note_loss = true; #endif - tail++; - pipe->tail = tail; - spin_unlock_irq(&pipe->rd_wait.lock); + tail++; + pipe->tail = tail; + spin_unlock_irq(&pipe->rd_wait.lock); + } else { + /* without a watch_queue, we + * can simply increment the + * tail without the spinlock - + * the mutex is enough + */ + + pipe->tail = ++tail; + } } total_len -= chars; if (!total_len)