From patchwork Mon Oct 24 11:27:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9997 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp615939wru; Mon, 24 Oct 2022 12:27:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4u7qeEYruIj4dS7rumVfem50Woy23AMVnamfwGL9MljId2hY7zbdBv90ZhFTsyUUwqRUPY X-Received: by 2002:a17:906:cc0d:b0:78e:2c06:8e70 with SMTP id ml13-20020a170906cc0d00b0078e2c068e70mr28292961ejb.732.1666639655951; Mon, 24 Oct 2022 12:27:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666639655; cv=none; d=google.com; s=arc-20160816; b=tyhuQplFhqP8dyNftQz4UkwEDfFV3/mDXE6PLOXIHQpvRcU3DaP4wJFfOHoCdwpwtp eLHEc5c3MOeVTPKten9uTLMht82QGXCfiY4VX3SF9KqifaSX3iRni/ags6FiPtCQjvRu mdNwOf8I2LL0auOApIwv4T2aO11fZ8dXZ1RdnFkdsnEwHlsPPkJdE6D7oLwBOMJnWamK LtVP2zu0baym9kOQKilcKf8F3mdL9YegJswKN5azPqpCaCermlMeOKGcmFIVunUgYIkx 2NMFYKuJEyVkutB2bVuh4GQBNn+jUN1e7Gtn7dTZmoDZ83uOGvyB1Qc5IgLqh51k+ufK lAGQ== 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=/TJKSuJOWF9B9/v5cVmfC9VqNccdQxFkNoy64Rx1hso=; b=DKVW1DPkjtEmsoDXNAv8cy+VIEy4ydIAHuFvGQQGeW4PEFoVYaznzb1DPuJiG/xFDr ntxHv2Qpk2cS8F0TPl1chA89UdLE7qSmJ6QVIinusivaAH14+8PR+gB/f2J4qYI9mH2o NB13E8Yqai6AhF7g8zvlkbcys0gVAZuQNap4CSyGWAytjmNu9NdI6ljVJydX2c7uM8/K IuHS7BA1NcLYfSgibBQejZyVzP0J2URI2kEmEZJut8LodctdzrixVgNFcywWmR80UOrJ 1VdKW16sZF0PYlKMVuDpgVTO5mkGXmu3tNzEcmH6tbWjyA1wDMotOxFaFOc3YruZ1Hq3 G0gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XVMPVI8o; 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 f18-20020a170906391200b007806c141214si537249eje.153.2022.10.24.12.27.11; Mon, 24 Oct 2022 12:27:35 -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=XVMPVI8o; 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 S232403AbiJXTZa (ORCPT + 99 others); Mon, 24 Oct 2022 15:25:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232082AbiJXTXK (ORCPT ); Mon, 24 Oct 2022 15:23:10 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEB1317FD4C; Mon, 24 Oct 2022 10:57:57 -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 sin.source.kernel.org (Postfix) with ESMTPS id 80BC5CE1366; Mon, 24 Oct 2022 12:19:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7192AC433C1; Mon, 24 Oct 2022 12:19:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613952; bh=Y3eT2xE4uYU2PLlz1rAVKbLGZkqNAWjS8soALy34X1Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XVMPVI8obe3lCWzdsiR/nvFUR/+LREElt2+6QoRGpGlznSg0a00a4cRR+kJQR33Qr uB71FzPyQvaFinPN+2+WQHjx8KQyRe9sjLNsviuJ9xtDmfQmXDT8WCeE19FPIH0c++ QACBTCXdz0ApkT50R3sC1T6bQICbZYUv96DcT/7o= 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.10 076/390] ring-buffer: Add ring_buffer_wake_waiters() Date: Mon, 24 Oct 2022 13:27:53 +0200 Message-Id: <20221024113025.849362575@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@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?1747598344267845025?= X-GMAIL-MSGID: =?utf-8?q?1747598344267845025?= 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 @@ -100,7 +100,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 @@ -414,6 +414,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; @@ -802,6 +803,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 @@ -816,6 +848,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; /* @@ -834,6 +867,7 @@ int ring_buffer_wait(struct trace_buffer work = &cpu_buffer->irq_work; } + wait_index = READ_ONCE(work->wait_index); while (true) { if (full) @@ -898,6 +932,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)