From patchwork Mon Oct 24 11:27:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9259 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp461717wru; Mon, 24 Oct 2022 06:44:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5yvF+wUTpN98eRZBNkpcX0TIYqg31HJOLZopx3moDOFmyh74353btgNzRj9bdDvivo6omI X-Received: by 2002:a17:907:2c75:b0:78d:c201:e9aa with SMTP id ib21-20020a1709072c7500b0078dc201e9aamr27729480ejc.235.1666619073422; Mon, 24 Oct 2022 06:44:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666619073; cv=none; d=google.com; s=arc-20160816; b=Rqjre/rKzsnvTN96JJcCsKCap3hx12OmrmkSslGX8xM0PH8JMWeyz/T1SeFBBGnFrE jErlr7t1RbG8Ydnm2/R4lQJH+GW8HA2LUpwQfYdWyf10ntCGk+ATqsxRqOuk2SlWiIM6 lnxuMdUjgHvoLyv5b+LtKmIkR1wIh3som9ZAV3xUADmEyP9oM8ZKjt3M8hto6aTtwZJ0 OVm3VsDeitK5lfgguXYXWQ8QP8lXav0qWjW0O4keXrOqiNK287ebpX9Sl8HYCZISCeM/ 4o1dp1rIL2UTuudZQG10rQ3T78fU31baIMafk2l8iBKiOPCKckaWc+uW2Mqw5dAMpVwh 00Uw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=p2EPIk5y+Phlf0/1XdjE+2Ma30jtsmbq+IJGQgQi4WE=; b=tSTJmOBnFfx5fkV/059TmQsJ5yRpZ80jAkGzkWL5rIzQYCv+EqO0Gvqjq/vkOolltx caF/oERE9Pha7d1Z4E5/5Bv2TPJJuJrKRiKInWvDtEoEjTox4NzUiDGrJ9MzezJPdUWX ust8aPUnSvYWM9On/fs6ZsR9y7kVe8Yz4r3zH02vVE8wSlFJyjNXkQGODlzuKZ+CBGDu KPzMo0flhtXP7hAGFZqjPe0a8IVPsH9pAQlRJBi2AhaKX1gXo2rcx8pdtlq5MHSYknKg eA6vhutIUjBSEz80qT5U9x377hrRd2RwSXwDAx/3bxq01+NRocVM/ObgfZtgjjnM/WUR 8GjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cmzeauQd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb7-20020a1709077e8700b007721f88d3e0si28483444ejc.554.2022.10.24.06.44.09; Mon, 24 Oct 2022 06:44:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cmzeauQd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236097AbiJXNmb (ORCPT + 99 others); Mon, 24 Oct 2022 09:42:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236687AbiJXNlE (ORCPT ); Mon, 24 Oct 2022 09:41:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B0EE895D5; Mon, 24 Oct 2022 05:38:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9D43D612F4; Mon, 24 Oct 2022 12:37:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF334C433D6; Mon, 24 Oct 2022 12:37:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666615065; bh=DW7fMcNbVUcJAVYBNxb1tue/4JtMbn4dGrsZ3o/tHhU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cmzeauQdSO7PzWT/IKcSDgb0Ix9afAL4YyR6x9k1GJPqYBhlEXv0m/4s1Qai5//TK /InHeXzpfgFPAQuC39RKVLXyxH3i6o73o93Bdr4sj9tjSyR35QV6Qo0rW64uFLFslh ycWab2tBuK+jY4aYBkNSJoLZiDTG4+fOqnExnleo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ingo Molnar , Andrew Morton , "Steven Rostedt (Google)" Subject: [PATCH 5.15 109/530] ring-buffer: Add ring_buffer_wake_waiters() Date: Mon, 24 Oct 2022 13:27:33 +0200 Message-Id: <20221024113049.953720243@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747576761444636568?= X-GMAIL-MSGID: =?utf-8?q?1747576761444636568?= From: Steven Rostedt (Google) commit 7e9fbbb1b776d8d7969551565bc246f74ec53b27 upstream. On closing of a file that represents a ring buffer or flushing the file, there may be waiters on the ring buffer that needs to be woken up and exit the ring_buffer_wait() function. Add ring_buffer_wake_waiters() to wake up the waiters on the ring buffer and allow them to exit the wait loop. Link: https://lkml.kernel.org/r/20220928133938.28dc2c27@gandalf.local.home Cc: stable@vger.kernel.org Cc: Ingo Molnar Cc: Andrew Morton Fixes: 15693458c4bc0 ("tracing/ring-buffer: Move poll wake ups into ring buffer code") Signed-off-by: Steven Rostedt (Google) Signed-off-by: Greg Kroah-Hartman --- include/linux/ring_buffer.h | 2 +- kernel/trace/ring_buffer.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) --- a/include/linux/ring_buffer.h +++ b/include/linux/ring_buffer.h @@ -101,7 +101,7 @@ __ring_buffer_alloc(unsigned long size, int ring_buffer_wait(struct trace_buffer *buffer, int cpu, int full); __poll_t ring_buffer_poll_wait(struct trace_buffer *buffer, int cpu, struct file *filp, poll_table *poll_table); - +void ring_buffer_wake_waiters(struct trace_buffer *buffer, int cpu); #define RING_BUFFER_ALL_CPUS -1 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -405,6 +405,7 @@ struct rb_irq_work { struct irq_work work; wait_queue_head_t waiters; wait_queue_head_t full_waiters; + long wait_index; bool waiters_pending; bool full_waiters_pending; bool wakeup_full; @@ -889,6 +890,37 @@ static void rb_wake_up_waiters(struct ir } /** + * ring_buffer_wake_waiters - wake up any waiters on this ring buffer + * @buffer: The ring buffer to wake waiters on + * + * In the case of a file that represents a ring buffer is closing, + * it is prudent to wake up any waiters that are on this. + */ +void ring_buffer_wake_waiters(struct trace_buffer *buffer, int cpu) +{ + struct ring_buffer_per_cpu *cpu_buffer; + struct rb_irq_work *rbwork; + + if (cpu == RING_BUFFER_ALL_CPUS) { + + /* Wake up individual ones too. One level recursion */ + for_each_buffer_cpu(buffer, cpu) + ring_buffer_wake_waiters(buffer, cpu); + + rbwork = &buffer->irq_work; + } else { + cpu_buffer = buffer->buffers[cpu]; + rbwork = &cpu_buffer->irq_work; + } + + rbwork->wait_index++; + /* make sure the waiters see the new index */ + smp_wmb(); + + rb_wake_up_waiters(&rbwork->work); +} + +/** * ring_buffer_wait - wait for input to the ring buffer * @buffer: buffer to wait on * @cpu: the cpu buffer to wait on @@ -903,6 +935,7 @@ int ring_buffer_wait(struct trace_buffer struct ring_buffer_per_cpu *cpu_buffer; DEFINE_WAIT(wait); struct rb_irq_work *work; + long wait_index; int ret = 0; /* @@ -921,6 +954,7 @@ int ring_buffer_wait(struct trace_buffer work = &cpu_buffer->irq_work; } + wait_index = READ_ONCE(work->wait_index); while (true) { if (full) @@ -985,6 +1019,11 @@ int ring_buffer_wait(struct trace_buffer } schedule(); + + /* Make sure to see the new wait index */ + smp_rmb(); + if (wait_index != work->wait_index) + break; } if (full)