From patchwork Sat Sep 30 20:32:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 146977 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp569372vqb; Sat, 30 Sep 2023 13:38:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFgqUVqncFDcapdIpCjQ3YwsYoGS2pGEPJ2DC/lV7rtqehN9/mv3Zg8DLJ97LiUikAdUzOF X-Received: by 2002:a17:90b:4c4a:b0:273:efde:2ea4 with SMTP id np10-20020a17090b4c4a00b00273efde2ea4mr6716296pjb.42.1696106320212; Sat, 30 Sep 2023 13:38:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696106320; cv=none; d=google.com; s=arc-20160816; b=zJ1oWjuantNx+e2gpWG5LGzpHNjjzj5GCvBqFXsEw08pfUQ25/OJdVwJWOiQUQvd9W b3xG+9sM/cJDQYKxSHWLGwHNri5OYAYlZ5qfAAJDZdkmYHpK/I+EM0UBdYgQ7lUW7+k5 XNwutRkHmcN2YNXx0Y+wh8I+QsZ8VHhJMDEJQjz2QNHKcUK4onVHPozqgmJp1ejMsDOh Yp6mEmvLJ4B93W8V5OZpJ94rTm7twjAI2CXlRNuCvYv1MixHkZlr3GdAPCMDzq+5Rm9w dw68vO2l10XYiyBDL8TmITKhPH1/jw6xaNGxUfHVq528g0O4QH9+2nNN5kJMb7D4I0Vd JUKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=kldgyzaCek9nwUwTqSzYWVDTNuNSkRelAk/WG2ywv2I=; fh=ApwHQaseK1wNew8Vzvpim8knOZ6RyBZxIjOlq0ALTzk=; b=UNQgxO5M33VJ1gvjBjceYKLQ7jrR6kl+DLq4IcbtVhmiQKvMduma7n9glqHDQPlXR9 w0sHjEmQ2/HG72nQBOUu7gPWo/L+VIg9Ib3OVgpQFZFndRPiqWLn8URc2jUE8XJTnwRv cE8nB5JkIw2hk6THlMre94PMerrjF1HARVIy4U9RwXigCR7jhpfzVLb1d3+pHZV8M8M+ qYRbyJcYXG7F/aW4aVEszNcTplbmdmdWF2PHuJIJ9bkjnBkcsiusTGZ+iaKgMpHIjzai Wv3+7zE2WtFOIu5vjzucrO4wvYLlKUfCd/bFnx1Czwv0OwSWvwoJoqLXSmwBgIUI5OFl mc2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id gv20-20020a17090b11d400b002773f96df0esi4053488pjb.3.2023.09.30.13.38.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 13:38:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 27572805ECD6; Sat, 30 Sep 2023 13:37:34 -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 S232658AbjI3Uh0 (ORCPT + 20 others); Sat, 30 Sep 2023 16:37:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230516AbjI3UhY (ORCPT ); Sat, 30 Sep 2023 16:37:24 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B35FCA; Sat, 30 Sep 2023 13:37:22 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DC9EC433C9; Sat, 30 Sep 2023 20:37:22 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1qmgjF-004MzV-1y; Sat, 30 Sep 2023 16:38:21 -0400 Message-ID: <20230930203821.422832821@goodmis.org> User-Agent: quilt/0.66 Date: Sat, 30 Sep 2023 16:32:14 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , stable@vger.kernel.org, Julia Lawall Subject: [for-linus][PATCH 1/4] ring-buffer: Update "shortest_full" in polling References: <20230930203213.826737400@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS 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]); Sat, 30 Sep 2023 13:37:34 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778496380747924318 X-GMAIL-MSGID: 1778496380747924318 From: "Steven Rostedt (Google)" It was discovered that the ring buffer polling was incorrectly stating that read would not block, but that's because polling did not take into account that reads will block if the "buffer-percent" was set. Instead, the ring buffer polling would say reads would not block if there was any data in the ring buffer. This was incorrect behavior from a user space point of view. This was fixed by commit 42fb0a1e84ff by having the polling code check if the ring buffer had more data than what the user specified "buffer percent" had. The problem now is that the polling code did not register itself to the writer that it wanted to wait for a specific "full" value of the ring buffer. The result was that the writer would wake the polling waiter whenever there was a new event. The polling waiter would then wake up, see that there's not enough data in the ring buffer to notify user space and then go back to sleep. The next event would wake it up again. Before the polling fix was added, the code would wake up around 100 times for a hackbench 30 benchmark. After the "fix", due to the constant waking of the writer, it would wake up over 11,0000 times! It would never leave the kernel, so the user space behavior was still "correct", but this definitely is not the desired effect. To fix this, have the polling code add what it's waiting for to the "shortest_full" variable, to tell the writer not to wake it up if the buffer is not as full as it expects to be. Note, after this fix, it appears that the waiter is now woken up around 2x the times it was before (~200). This is a tremendous improvement from the 11,000 times, but I will need to spend some time to see why polling is more aggressive in its wakeups than the read blocking code. Link: https://lore.kernel.org/linux-trace-kernel/20230929180113.01c2cae3@rorschach.local.home Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Fixes: 42fb0a1e84ff ("tracing/ring-buffer: Have polling block on watermark") Reported-by: Julia Lawall Tested-by: Julia Lawall Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ring_buffer.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 28daf0ce95c5..515cafdb18d9 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -1137,6 +1137,9 @@ __poll_t ring_buffer_poll_wait(struct trace_buffer *buffer, int cpu, if (full) { poll_wait(filp, &work->full_waiters, poll_table); work->full_waiters_pending = true; + if (!cpu_buffer->shortest_full || + cpu_buffer->shortest_full > full) + cpu_buffer->shortest_full = full; } else { poll_wait(filp, &work->waiters, poll_table); work->waiters_pending = true; From patchwork Sat Sep 30 20:32:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 146976 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp569192vqb; Sat, 30 Sep 2023 13:38:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG6YqQWZtQLhFSRN22p6whse18bkDRoil/u+WOUUMi0Q0yiJ+lox2zc/GtljYlmKlR88dgb X-Received: by 2002:a17:903:2344:b0:1c5:6dbc:7938 with SMTP id c4-20020a170903234400b001c56dbc7938mr7887679plh.69.1696106287874; Sat, 30 Sep 2023 13:38:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696106287; cv=none; d=google.com; s=arc-20160816; b=kluweUIshz+0KgTPDc+3DcmuMxbRXHb/0Bs1rTTrWT7h6sLOb4ekFDCg72BnRe5vYn UEI4ETgsHTT2PUK90dTOvLFHf0MM74C+ZpDYeiiUWgSDwgakaVh1vk4kG8XXY4fn4p0D cmIe4LVZ4FkIPxNYdwIDd491pk5RhJthze60tUuj5+scr7Uvo2QAQYzQV2RRiVwO+EJI gZ7aanJkrW8qF7T2mqJxYj2x7cVd6w+xmw4cQ+xLj/azBuAnj1h68kAR2VwNbAWqY+cA la2NsaVnjYPsRwSS23hzrB/MW5ibO/qThA24MQi0IzMcIjyODtOPdI11auD4TIzLkWH5 SWQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=9dx9ob0UtuTq07HubdoYyEvBfvwiZEmoVdd0gkvkpM0=; fh=cY9HGbp9RiQ9xCYqjybSe1/cIiXVFs0Cn9z6ge1iyyY=; b=atvj7nI5P1BSvLZftwiPsdGtUEtdVCA/ZOv7ofMk5JnDoXGI67PNo/+HAvO9rK8uys uoMZ+NfvZQoTGZq9RsZuhUqh17Sjd/eAF3dPnbFojISRFewVQHn9aa4QSuKvStmp8ZAd QJKOKFVABI0I1zb6kkUgoA7XPPAv07UIeZDqpUnV4aCNJuJD6NPPxo0v2Nctbl4cv4C7 XQdFCPQDJxeLtJrGc7HFdXPmGZu1Elpi27Z1LD4kUJ4FfZV8hF2NztwUbEExzcuA3+Ad X6MatRQFnr99LPURK+TWn1rKpg0HgUOmTR6kkAuMb+L/6MApg+t7yrjCGAoPtZkg23q5 kb8w== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id ky16-20020a170902f99000b001c5fea1bd8asi18035806plb.567.2023.09.30.13.38.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 13:38:07 -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; 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 Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 5A20C8243BD3; Sat, 30 Sep 2023 13:37:43 -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 S232878AbjI3Uh3 (ORCPT + 20 others); Sat, 30 Sep 2023 16:37:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231779AbjI3UhZ (ORCPT ); Sat, 30 Sep 2023 16:37:25 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DFB8EB for ; Sat, 30 Sep 2023 13:37:23 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC8DAC43391; Sat, 30 Sep 2023 20:37:22 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1qmgjG-004N19-0l; Sat, 30 Sep 2023 16:38:22 -0400 Message-ID: <20230930203822.053304721@goodmis.org> User-Agent: quilt/0.66 Date: Sat, 30 Sep 2023 16:32:17 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton Subject: [for-linus][PATCH 4/4] eventfs: Test for dentries array allocated in eventfs_release() References: <20230930203213.826737400@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS 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]); Sat, 30 Sep 2023 13:37:43 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778496347122407727 X-GMAIL-MSGID: 1778496347122407727 From: "Steven Rostedt (Google)" The dcache_dir_open_wrapper() could be called when a dynamic event is being deleted leaving a dentry with no children. In this case the dlist->dentries array will never be allocated. This needs to be checked for in eventfs_release(), otherwise it will trigger a NULL pointer dereference. Link: https://lore.kernel.org/linux-trace-kernel/20230930090106.1c3164e9@rorschach.local.home Cc: Mark Rutland Acked-by: Masami Hiramatsu (Google) Fixes: ef36b4f92868 ("eventfs: Remember what dentries were created on dir open") Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/event_inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 5f1714089884..8c8d64e76103 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -421,7 +421,7 @@ static int eventfs_release(struct inode *inode, struct file *file) if (WARN_ON_ONCE(!dlist)) return -EINVAL; - for (i = 0; dlist->dentries[i]; i++) { + for (i = 0; dlist->dentries && dlist->dentries[i]; i++) { dput(dlist->dentries[i]); }