From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2D511CA8F; Mon, 1 Apr 2024 16:26:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711988809; cv=none; b=s96GnloMZcGtqgTwdFqSuu/APF6v5x+GhdPHvmmnDfwxo9/SJfXpMqJaob2PiPtz966NKJ+hHcD+ZZB3iReEVZGCaqqlJPP6erxx0qIYSQYZQlXhb0q73lX0res9Ezj8U7ohKUVlNunnF8P0T9Rkx8xdSEViFGgrQ0eoyil8ZJw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711988809; c=relaxed/simple; bh=cLAowEEi9oWf+P/LpieyxnexaZDZoQKCSYuG05cFJwY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IydpjoJ7ls6gIdxDs0R5EjMvWTVDq1g+oc6OiilKEpiGh7lyklEWqSHVu/h9uPp9DUiXH8GZNn+wZJ9VLx4DMqXtr4/Cgeg3zbKGUEgHoFLBJ8WHVxP91DddDbWcbqA1esW6fci8FC69gqMUy010QnFdXCmee5/8vbkTvy98Ock= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=1ncAIs0D; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="1ncAIs0D" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A64AC433C7; Mon, 1 Apr 2024 16:26:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1711988809; bh=cLAowEEi9oWf+P/LpieyxnexaZDZoQKCSYuG05cFJwY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1ncAIs0DWhtnFIJ1uDzm8Rn8NsHGi1fuQv29axMSoAtkzKQ5NDcqdL621EQQlOgAv 7MFY6J4gBRvRJ4IZEthzvc8XQIKX1SzcQRGNG3oPGhwn2qbDEOyAHmr2CYlxOWuujI AyHM0g4ZrfVoCEmMlyKqqdHZSwv+nJzLPnKtmefY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Linus Torvalds , linke li , Rabin Vincent , "Steven Rostedt (Google)" Subject: [PATCH 6.7 256/432] tracing: Use .flush() call to wake up readers Date: Mon, 1 Apr 2024 17:44:03 +0200 Message-ID: <20240401152600.776960881@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240401152553.125349965@linuxfoundation.org> References: <20240401152553.125349965@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.7-stable review patch. If anyone has any objections, please let me know. ------------------ From: Steven Rostedt (Google) commit e5d7c1916562f0e856eb3d6f569629fcd535fed2 upstream. The .release() function does not get called until all readers of a file descriptor are finished. If a thread is blocked on reading a file descriptor in ring_buffer_wait(), and another thread closes the file descriptor, it will not wake up the other thread as ring_buffer_wake_waiters() is called by .release(), and that will not get called until the .read() is finished. The issue originally showed up in trace-cmd, but the readers are actually other processes with their own file descriptors. So calling close() would wake up the other tasks because they are blocked on another descriptor then the one that was closed(). But there's other wake ups that solve that issue. When a thread is blocked on a read, it can still hang even when another thread closed its descriptor. This is what the .flush() callback is for. Have the .flush() wake up the readers. Link: https://lore.kernel.org/linux-trace-kernel/20240308202432.107909457@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Linus Torvalds Cc: linke li Cc: Rabin Vincent Fixes: f3ddb74ad0790 ("tracing: Wake up ring buffer waiters on closing of the file") Signed-off-by: Steven Rostedt (Google) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -8352,6 +8352,20 @@ tracing_buffers_read(struct file *filp, return size; } +static int tracing_buffers_flush(struct file *file, fl_owner_t id) +{ + struct ftrace_buffer_info *info = file->private_data; + struct trace_iterator *iter = &info->iter; + + iter->wait_index++; + /* Make sure the waiters see the new wait_index */ + smp_wmb(); + + ring_buffer_wake_waiters(iter->array_buffer->buffer, iter->cpu_file); + + return 0; +} + static int tracing_buffers_release(struct inode *inode, struct file *file) { struct ftrace_buffer_info *info = file->private_data; @@ -8363,12 +8377,6 @@ static int tracing_buffers_release(struc __trace_array_put(iter->tr); - iter->wait_index++; - /* Make sure the waiters see the new wait_index */ - smp_wmb(); - - ring_buffer_wake_waiters(iter->array_buffer->buffer, iter->cpu_file); - if (info->spare) ring_buffer_free_read_page(iter->array_buffer->buffer, info->spare_cpu, info->spare); @@ -8582,6 +8590,7 @@ static const struct file_operations trac .read = tracing_buffers_read, .poll = tracing_buffers_poll, .release = tracing_buffers_release, + .flush = tracing_buffers_flush, .splice_read = tracing_buffers_splice_read, .unlocked_ioctl = tracing_buffers_ioctl, .llseek = no_llseek,