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 08FA279FD; Thu, 11 Apr 2024 10:50:56 +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=1712832656; cv=none; b=kK2zzlN82elZuEf+X7/WQi+ad8rG6gozGVsfkupmokbAVXXYwNItDPzPDBrFvFJ29gASeb2wP9UITgRmNjFE8pm0qZ6RrJ4RlisQLIKOm8OgE0hseoM8+exxCy41RLtvMxfzLcKO5pR/cG9k33GxgMiI7xprCt5nMfaSHzQG0Cw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712832656; c=relaxed/simple; bh=4WLhnnN7zXJnW96NHYfMXDRH0rXtlTnqy1l03eQ7mOM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jluxnswJZS8EMk2ekQEXmQOWWqc4tKON8E/8Pii1P6OyKPfJcHEmNwk9HdhJblIrnwbvntDLkNsie/2Ndxj12YXubUGEx8R3WU4n23M4IshbVZJRPtcgSBymuV4G9VjYQNFqpS1kdk/CPP7qWV/+97Y1bJF+SVgO7lUoF02W/pg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=szQwIFn6; 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="szQwIFn6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E965C433C7; Thu, 11 Apr 2024 10:50:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1712832655; bh=4WLhnnN7zXJnW96NHYfMXDRH0rXtlTnqy1l03eQ7mOM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=szQwIFn6tnaitGVx51Y8WJnMGD3QkWWcZN34ba6UXLL7b+wn30OGhFfDFYMORuQzj iPD0Ze/2QfieR0xz8ESEbJHbDYnl6ttBSprpKTkaUEQyZhUP80ehbAhNukPj99myMj cW97enF5MZfZBfjQ+hJKEvEw3vjR/RuX7VEl8VnA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Masami Hiramatsu , Mathieu Desnoyers , linke li , "Steven Rostedt (Google)" , Sasha Levin Subject: [PATCH 5.15 38/57] ring-buffer: use READ_ONCE() to read cpu_buffer->commit_page in concurrent environment Date: Thu, 11 Apr 2024 11:57:46 +0200 Message-ID: <20240411095409.144537496@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411095407.982258070@linuxfoundation.org> References: <20240411095407.982258070@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 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: linke li [ Upstream commit f1e30cb6369251c03f63c564006f96a54197dcc4 ] In function ring_buffer_iter_empty(), cpu_buffer->commit_page is read while other threads may change it. It may cause the time_stamp that read in the next line come from a different page. Use READ_ONCE() to avoid having to reason about compiler optimizations now and in future. Link: https://lore.kernel.org/linux-trace-kernel/tencent_DFF7D3561A0686B5E8FC079150A02505180A@qq.com Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Signed-off-by: linke li Signed-off-by: Steven Rostedt (Google) Signed-off-by: Sasha Levin --- kernel/trace/ring_buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 80ec515ae81e7..c6bcb80785d8f 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -4390,7 +4390,7 @@ int ring_buffer_iter_empty(struct ring_buffer_iter *iter) cpu_buffer = iter->cpu_buffer; reader = cpu_buffer->reader_page; head_page = cpu_buffer->head_page; - commit_page = cpu_buffer->commit_page; + commit_page = READ_ONCE(cpu_buffer->commit_page); commit_ts = commit_page->page->time_stamp; /* -- 2.43.0