Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp19267lqz; Fri, 29 Mar 2024 07:20:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV9tFqgrub0Ewt4bA9CvyldBxJ6zZY8P165/F3VjzSRl60iqIb6+mSgpBGkyHunIq5uzvr4GATIS8/ZhicFUB5/GfpEiuACuo4WxZYD/Q== X-Google-Smtp-Source: AGHT+IG+kZ1K6yewnbvTs7M51no7YtLU49Ctb8LGZ2+GPjDFBlebOc7KQxjFXwchHeNnP2PKTptT X-Received: by 2002:a05:6359:4c02:b0:17f:58cb:2d3a with SMTP id kj2-20020a0563594c0200b0017f58cb2d3amr2619417rwc.19.1711722038744; Fri, 29 Mar 2024 07:20:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711722038; cv=pass; d=google.com; s=arc-20160816; b=VMtUK60Z9PHniHmiFA7jxUHyYdcntx832kVn7imNZo86EiUhA0D1Bz6Rc7NiJcdab3 GV2xLGt8jSaJvc6LyMdAY8myF2EWXgUQ5pHaZXK1eO1mlzc2U/hfDo9c8TZjhCsJqgS4 ZXsadx7e5QJcz1V/2ug3MTj8Fchp00qdruS7cHotjcHBIIZwoL3wwE5yrR4beeu8bofq IFOvpQTNcW6hxc+t6svGmzI9Mrv51QArH75GZzhZ/OUDh+wer9195gYNc9NyaU3C2ahv xP4LOt52ntN0+rG2m31YlONJHCviOMUny+f25fQqUb3sljiSKRg8GBw3aB8pL0KfQX79 unMA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=EFplLyKUXidsZDHWW7MP023Wrh8lGpxyMJReNa5eQMc=; fh=jbdL9yezZGWeougVM/WPqEp5A9C+xom9Xz1v2qFq9CM=; b=gq86XEVFt6B2Mya23MRw/Mckm4xj08J6SgBTs5+9rmWPKFVdMXrX7QMxl7ilZFpyT3 izq6MPi3A1LsYeTY/siiELuwYiOZkRjJqiSpLx1spNO+VQJXk2hoAas9eELqVHy/NHeL 4RH5JRUjBm30A8M0syecRSrAKhq2eS6nrDqq15eik7PidvKI3CuKbAgJtkVKZxaVhdIu 71jTl4F2qIvsGHf5W+ey81uEJMi6WrQvxY3ZVEaZsTa5nIP9vXiKlq4rF/cQee4MfD5g OalaJQkXXQ8o4xiZ2UfvPkZHjswQZvl0Gh7Rt8aDfcgUSiy7Mn01mp3sytuUPsx1libd rAPw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NAKG0q8S; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124809-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124809-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id k10-20020a633d0a000000b005dbcff42ee2si3681696pga.536.2024.03.29.07.20.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 07:20:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124809-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NAKG0q8S; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124809-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124809-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E7B73B2B197 for ; Fri, 29 Mar 2024 13:57:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E477E199EA1; Fri, 29 Mar 2024 12:42:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NAKG0q8S" 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 AEEE6199E8E; Fri, 29 Mar 2024 12:42:52 +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=1711716172; cv=none; b=OsMdZlYDTrWrNm+MPZgRRYi2Lpk+V6/NfYKN3pqed3VMvm3TJV1/CWnfOD4FJpLDF9psVWjhYB4dbonAZSWXV8CsuIfsZ9+oneKDGuFPt5dCPMyBgnK4jCp866kIunWVQ7i2OBFr1+quc1FxkQKvVY586/68N539t2qRxycJDTQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716172; c=relaxed/simple; bh=cHQxS9eKOaxd8Sh2UiR3ItlynHa0OS46OHcIPltCVeM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZLx7VOpFGQvkdQ29Eor9H2lnmMSqdEXzA5nW2bLMs+H049N6+2kKjzdK+/pVSSd3EyQ+3RmuXSKHt5B5T6o7Wj14oNDH+DyYRdKkx5pNFisMXFRHIzAZc2LpkzEol2G50Bxzh9ZQTZJzNrZVsetut/Jb0SuqayHSJjWaBZqmze8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NAKG0q8S; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC108C43399; Fri, 29 Mar 2024 12:42:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716172; bh=cHQxS9eKOaxd8Sh2UiR3ItlynHa0OS46OHcIPltCVeM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NAKG0q8Sjmjfsl+b1D2/nIaVHURz/wo5LLe6LtEuQLxrkZUaivpxqfdXMDhsI18su 3PIe4JpXZ28qu9Ve4nH7sU4oOcgMD0EfpP4mger6C77UV7tOe2uc7uSGZyRfC7pANn AN36698+VQNxxoRfTi3A6KKEH6964g/0rwvKsc4T18Naryv3h3BN9/tHKMi6dhNI9l ns/az+xG5bMVePP+NOXhklUGJOPvADLrRj5i9L7pNvLGPWJIJn9PoMoCboznqTPwUz 1n2QnlSFJr3k735NTlDxDjDOG4urplGFzJUWe3XJ2zrW/JvPlyDL12l8xetasguyg3 UlUeG5hJJIdTg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: linke li , Masami Hiramatsu , Mathieu Desnoyers , Steven Rostedt , Sasha Levin , linux-trace-kernel@vger.kernel.org Subject: [PATCH AUTOSEL 6.8 98/98] ring-buffer: use READ_ONCE() to read cpu_buffer->commit_page in concurrent environment Date: Fri, 29 Mar 2024 08:38:09 -0400 Message-ID: <20240329123919.3087149-98-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329123919.3087149-1-sashal@kernel.org> References: <20240329123919.3087149-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.8.2 Content-Transfer-Encoding: 8bit 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 aa332ace108b1..54410c8cacbe8 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -4350,7 +4350,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