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: 13394506 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A869EE7D0A7 for ; Thu, 21 Sep 2023 20:22:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231739AbjIUUW4 (ORCPT ); Thu, 21 Sep 2023 16:22:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230290AbjIUUWf (ORCPT ); Thu, 21 Sep 2023 16:22:35 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3FA4D6068 for ; Thu, 21 Sep 2023 11:26:32 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-32157c8e4c7so1296080f8f.1 for ; Thu, 21 Sep 2023 11:26:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1695320791; x=1695925591; 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=AQyqw2hmtvETPkConD+HqIROJDoLoeYUUTKSVHkSRChKrZKZqoM0fSc4Tptwg5X2g6 hajOmARPPIea4P+eu5IAMb4/1uerV1LomVWMNW9np1zLTXV1DCnF+ejH0x9Nan2exwru wFV0u2q6Xc/5tYZi5RsDGrE+m9K8KH+UH6BS7f5RVgpO4UeyEvLSMZ/3PLAqwdUzvQYI 8HImRxLF1GVWsV4vJOyF4CNYTkDS0ex8isFW43OqYM90tWTTTcQM/sY9pNxPN/lUxuXm 7yem40xKM7Aq31jfizI7YYQm0mDDGM/BurmvtymsMqKA2ee7stnTe7jSHITD6zD36hJI FZkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695320791; x=1695925591; 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=PngcV0a+w2iPchygNd7SskyxRCQAHMMZrxECFo2dcDDKDWIeMD7PxC0T3DD9L+L3vn e9HDvaAn0ZsVzZ1EK0hmca9la+7TIAjPa579DNJ4x255tTWlL/CHxyUTx0HO+AwW0Ujp oHNvRNZKI+6gYqWVCu1DCRU4TR3Z/QtNZSd3iN6t0XsBfK1MAZtZI92WS3s/sc1DULnA /w1uaaQFBxrseJUBvZsU358q7yekS/mWkOWZI6/EQ+i1rQfI3/iZwdp8t92V08KSSpQE EoLl3G0e8KSwn3XwtM98vJbu2e/9ixT0dR06uYjXFbnupohMxJrGO5cSY/FUxt3Bj/OD EUEw== X-Gm-Message-State: AOJu0Yx79PCZcE1bnAFEA9Q5fVL1oRIAoZ9k+Up7xD8B5f39Acie7tai fhYDvM/ouBAEcmkWXvG4w29U3gp7AkAffPRSCd8= X-Google-Smtp-Source: AGHT+IF1pBtqoHJupqJB89JDTv8U2tPiwASllgBiXga49KhWXGoCCYdQLyGMzig5D0GLqGXQxvk2QQ== 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 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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: 13394416 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EED3E7D0A6 for ; Thu, 21 Sep 2023 19:42:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229993AbjIUTmq (ORCPT ); Thu, 21 Sep 2023 15:42:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230519AbjIUTmc (ORCPT ); Thu, 21 Sep 2023 15:42:32 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FDE3C6 for ; Thu, 21 Sep 2023 12:22:25 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-503056c8195so2179236e87.1 for ; Thu, 21 Sep 2023 12:22:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1695324143; x=1695928943; 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=ctPjk+OJw6+tnp2fWURX4aNmHGoYzrYgmIvLIuZCMqiY0gkrETO7GlnvM6MveKnJb6 EXIVYhOscKMSpdPXB8On/TUeDMEzKyaMTExIAw12Gre9yC2YJrztw60/GPtrH/9CQgz6 hvkpRw2/seTMHycezVJbRiDWgPY0QzorPub+hSPxEzUT2HRZ+FFs0M4fJsjbev6rLq99 1NuYTFk1B3pNVcahJr6UVDwc7thBG25cPf/nZ5xclOj8SoJKFhVudoD1iCvxkU+nmuq2 jyCriGjJTGgUXU7N9Yl+bsIG42/GZ+gjNk2qu0jjEY7dSa8lqTIVl8MGlSkhRen4dMJR gfsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695324143; x=1695928943; 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=whudk9ng0bCc9HfCjFPg4H/6Vsvf3SkSRVolHozT55oYvcZZIci5ilrSFsclwYjcTu YI0Th4+m9NNjyx0/XBd8ya1uOu7iLD96iJZkbmCaMKp/+NmPoDweknmvDVFIdDAwkByv szbVHTAwb5HnUYiZSpT5+r3gAUe2aKWqoWMw1I9sHKtjp2U124uRIzECiZ1vbXKFW1lF BTtZCwGJw5ajq8JaklxBjhAyROCruIuCqvDyP/WjhgKbv45Ljwnupik4YNUiqKWHZbYy w85VRQQyneIQCorfrpMq+cB7qopM/CLhTwf4cYjnSgVpLHBi22oLcHxPFBvC6VOQ23CZ MgmA== X-Gm-Message-State: AOJu0Ywe0L6VIpTysCn6ZvV3QB1LwS3BaCC8f4qR4Qqa3RC1LGnzQMO0 gvVRkRFzLt01Wq1UYaCwgwl2GxsTt1Ha+/NejYk= X-Google-Smtp-Source: AGHT+IGgD2cpMGXUp64ky7Z5KuE2s5kxlCzRjSWpVK8NceErhc6QZfb9I2OKWDGSASGhoo1owTOA2w== 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 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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: 13394318 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5D08E7D0A5 for ; Thu, 21 Sep 2023 18:53:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229712AbjIUSxj (ORCPT ); Thu, 21 Sep 2023 14:53:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230141AbjIUSxS (ORCPT ); Thu, 21 Sep 2023 14:53:18 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BD2FDC71D for ; Thu, 21 Sep 2023 11:42:25 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-307d20548adso1147558f8f.0 for ; Thu, 21 Sep 2023 11:42:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1695321743; x=1695926543; 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=AYijfl6k6J2ERfSsntSWD/cCf7Dbh74z9oDKCg8BN5sZd0deFtXoR2x+/76b2WzsTz 9Hdjio12Y9naVVUiP3nEADiUuGXduFkxYkH2X6/nwSg7uHeARMNXTDuw0IpLO6jtJjnK W1DCf1lNWJv9igzpDapHQprMv8U/tVrnE9yPJ/GM9nS6nqxuRyuHUiT8D78ZeOLSSJSl jP9ttYV+6YnXN3qFo+SnnPhhzKHipQrLRn+sdX5gFWWnO6jmu2wESQrbvGsu9BS8rVEs CZVgoINpyTaBAszv6MKeQxtwCzCPd4/TToj7N00PNeA5NpoKrunbMYt4eKFatioiR93S z6Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695321743; x=1695926543; 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=KOWDgUrs+GYL4w/nwRMslI1/8y0ImhAatp6ozJ/kquOH8OKxImD/q4udooq/AFhyvq /dd2YFookz0cSnCXUu4M+5EJEIeKVWwCaHfCu7wyQETE3G8XWSoQMYnkic3UTqgnJEnW CN8Hs3aVrCopooqnrl1UyTmtvNcnoDM1glmM27PMRUK7VpUqi+vonp6Q6RcSvhKwV5E3 GjkxhrC3tvKb9v0FE1Z5xzY/TWMKsl+eSRSzvNaqcJY15bUl1j7sOm5FN4/Vj52KXv+D BxVNuMViALoYxZ03fzX0xzA7clqmYAFC/exlI9MFw6qhtG9r6DrP6ui6/5j4FhH8aTtJ uxAQ== X-Gm-Message-State: AOJu0YyDWn/bkgLS9TaOBS999do/hbP10r5LakBF6D24yNhVkVCblHOo qz/r1+90GC18M8v/Y/RRqtKgpcS3yhHasiBtraI= X-Google-Smtp-Source: AGHT+IHKMTqeR6eWT3SKwedq8Ouyyzy3Vjxtlx04nLKDFKoBcTp5eNB7RjdnrInQXt2I0atyD2orOQ== 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 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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: 13394307 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8E11E7D0A5 for ; Thu, 21 Sep 2023 18:48:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229692AbjIUSsP (ORCPT ); Thu, 21 Sep 2023 14:48:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229944AbjIUSsK (ORCPT ); Thu, 21 Sep 2023 14:48:10 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA6AFEE86D for ; Thu, 21 Sep 2023 11:48:00 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-53348be3fe1so1030833a12.2 for ; Thu, 21 Sep 2023 11:48:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1695322079; x=1695926879; 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=DedfHSMxJ4pHtOAMAtM3nfFWfK2RG7tFJfneIdcg8oTu0AddooUpsUyKZr59ohIgOj GwEDF5oHQOqlWiv4GUHX+0etOxpJaB1aIq272k+qheq3F1xA/y54RIrTXSP7WEeDJqsj CgSODq8EsVMe4v7Ryl5RSSCwVTLPZcPITFFzu6nBm7gSfb342sN2LiOE+SNbuVdUEUkz E1bS87Egu6kt4W7lORwpK1jTL50DaCLr7Q7Du0ockkm1+dBkf8Y7j8bVJm7u0qPqlWBM /jhd4WtEU8v8vPwoExrLd3xaduVi2p6BtdSfEjxRS6bZycSkuR2TLIt92PhOerpaK//Y kmiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695322079; x=1695926879; 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=jrRAI8pdgDmqTw6yvC3+oGKJ0Db7kNIs/JwkMwl00hGhEt9L2Syayhaaiw0OxhVJxy vRy996H4oVgq0ZxDUhLLk98viJhSgcrJI0Lja9gJNNmKOYsHv+Qbg4PqVJnOSBwaGXGv nXGu134Ulbr+yvZW8rNxuFhNE9ew1aU2XsiwWTOKcYsYYVGjvs2m1d1yTrOwVphjGjoi DjtKZFST8WwGG+gpHT1UK9eyfwR+SE9BtR8bNWxDns4V0wAeKCtDgfQtnnWGqPmcv5Or wfrOzoreDvbR/zDxJ2z87QvkX28Kbm5L9vDqmDgFdfCP1LcLBN2Uxp8LAw7mMoccM0tk 2LOA== X-Gm-Message-State: AOJu0Yz9JFdD2pzVn17VTdg2DyzgQifvwxTm/Rbc4bCly17rYIflFU8T d3c3pWqsqij571aLIM2OiPaNHANRD4gRIU0aD8k= X-Google-Smtp-Source: AGHT+IHSDm/lGTyJTnqjqg3B4/6aDvlgdKLxA2WrrHf6uT8+eulEAGpPC8J4aUHwdlDrn7eA8iqZAg== 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 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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)