From patchwork Wed Oct 19 08:24:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4590 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp206109wrs; Wed, 19 Oct 2022 01:51:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5MF/dgaUTHxFLen7ArxTNEckZ9cNjw6UAAWvg6ZZnY3+Rydz5zmhS7psi+P2+fDkGxR2bu X-Received: by 2002:a17:902:8698:b0:181:f060:7133 with SMTP id g24-20020a170902869800b00181f0607133mr7503452plo.1.1666169495858; Wed, 19 Oct 2022 01:51:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666169495; cv=none; d=google.com; s=arc-20160816; b=T2ME53gnhttOVm/bFjIjfWseRfe2U4RYTX6eCdUc7WPiGscv/iHEMmeI/DAGIdX8Ra axSt8sLSVWye8T8qe1V2RqW+Q3pYMLD9mVfPN+QlL5fC7J6orpet0S5HyeOKeI5d14D8 yzn7B53NH0sgr6rA6o92pdydM9oTbgc0y819BhNuXjGQ1zCB6gE9wqwwI7UDQO+dEAGp TlrB41KCnNVX4viDN2SJnnidfS7qSY0OmAVQWaEMn0AYm84idrelPeXt0c9HG64G2RYG aN/HBKp8Q/I4vJrvEiSw/1qpzPnsCAjRDHy03j4pIyDDqAi+X6ob4HYi8gSBnUwp99TM K5XA== 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=y9yzAIWNNuhVv5FuC4VJWtp6Cz4kMPKpUnXBWUB+jP0=; b=XTAOEFlE4IIZO7UOxeyQjytLSAkOOygJwsWsjGfGXu73hsB0PlY4I6lE0ObHV1oQ+J r0t5OB82SXC7Kt1ZqEmk/VbUECAgn3+s2ApRYYILwWnSIv11txS9qoaR6LqLDxn9CboW WWHFk7oHFObcvf7U7aWVqWcl+zppUD5WROJ0SsAZlOh9qMEP33eQkLhtr0pbXt6mEKPW FMAWjXM8WasaY8Atn7P8JsyGq5qOTsaUXtLRtF+XYzIdJPa+r53gzGbv5t8yb8OSI71f dorTYUGOZ20zX/kSVicA1y6MtY5hr+UeaNiOSiZ04dD41VUdu1RmYREpA4/RpzwRvSVY Lr/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TdEO1GpD; 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 kb6-20020a17090ae7c600b001fe1c9436b1si21055903pjb.86.2022.10.19.01.51.22; Wed, 19 Oct 2022 01:51: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=TdEO1GpD; 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 S231615AbiJSIvA (ORCPT + 99 others); Wed, 19 Oct 2022 04:51:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231657AbiJSItA (ORCPT ); Wed, 19 Oct 2022 04:49:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D061814C0; Wed, 19 Oct 2022 01:46:51 -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 17E5B6183D; Wed, 19 Oct 2022 08:46:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D08EBC433D7; Wed, 19 Oct 2022 08:46:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169201; bh=b8MlR2uiSgcn2sfEO2O+eztyP0E+QW2yZ9/nitKtF8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TdEO1GpDwPg7DlGi5O4JVH3GJpvjeLcb5Z742a1W8BVjwUUn66/EPknkecp/0Fcmg r3B3ReEM401ifl9g2jCcksacK+O+n1Mg4UfOyvTACSiPtwYdNCbMHQhZUatx0NFvXJ 82DDpqiHy6wNZxmq5DExJWxR+y2BOZb9cQ2N23Lw= 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 6.0 155/862] ring-buffer: Add ring_buffer_wake_waiters() Date: Wed, 19 Oct 2022 10:24:02 +0200 Message-Id: <20221019083256.828194839@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747105345500900060?= X-GMAIL-MSGID: =?utf-8?q?1747105345500900060?= 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 @@ -413,6 +413,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; @@ -925,6 +926,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 @@ -939,6 +971,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; /* @@ -957,6 +990,7 @@ int ring_buffer_wait(struct trace_buffer work = &cpu_buffer->irq_work; } + wait_index = READ_ONCE(work->wait_index); while (true) { if (full) @@ -1021,6 +1055,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)