Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp25238lqz; Fri, 29 Mar 2024 07:31:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV0jOp2xqt39mWZx/EepXsFCfmUInp2JkKx56XGVnY9/Vcsm+VNqMAr8CFhc2ablv/mCS8LgHGZyTCpAUCpX/M1VkoX8FZwdTQ0deoNKQ== X-Google-Smtp-Source: AGHT+IEhxWFggNPS/tgD6Ji70ciEMQJrV1Xx7uogz9rDU2uJnE5BHn1AkXvvH8BZLh+whyGvtVv1 X-Received: by 2002:a05:6a21:9212:b0:1a3:e4fe:f6f1 with SMTP id tl18-20020a056a21921200b001a3e4fef6f1mr2224197pzb.58.1711722665741; Fri, 29 Mar 2024 07:31:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711722665; cv=pass; d=google.com; s=arc-20160816; b=ZnQ54LR6mvXMGYc41kWTFfK0juGKQODtWg81y1/dEoUkXTiauU1qvnO5HzG5YrOO2k dZ5/RwXB69/sngoGzGlv70pVm8CaAEp8a2QlY7C+FEbJ8BV3B2FqGptPRWBK50Ddzt52 kRpWjVHRTyDlq0J/Wy0BNG4mpZQ/YlXc3/3fzaxwXg9RImM6NvnpW7v9mPr9VN2pX3tM lT8loo2d+ztcF9euN/wbV/MJFPblGUQiA2YJ8S48j4+g5m3tWqt5mTHQ10kRkUyBnnsl FVcS1IJiysmQjiv4TENapGxAPCw24etKXeVmppfZrFvQzIPXDgdk+JOGn4sBzss62amo HtzQ== 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=IvO/3EiM+oST9Ljtxd1wMgVCmiPadkvFEEVKwd3EHTc=; fh=jbdL9yezZGWeougVM/WPqEp5A9C+xom9Xz1v2qFq9CM=; b=ra905SMzNQV3ctR+k0OLh+7g7XuZnBIRfBdHv8s3AdfOkFszQkk/RLP+h4GhdKRfJm kKAK7j1uz+s8wYn78cjpjvd/LqzcAlXZvDfpIwUwSaBCNtq9aau+DuJrbM0udMJYBubc UEJij62bKyYWg5wI7l8QQP8R6fNUcCAlQ/nKrqudCSMIayp+ehZvmSIjTZ5meq7bOybm HMInZS3zYFB8IhQzHOP/8epHwfPU5cbYtivU7PrQvBFotEBINyOskbUKpp8VC2nUFO9/ 2zUTIUbKPv/1RI7YWeHKvNxEOQKozBs6t4QqcOpgUo5OtYHcgbp39PMTm4qwZZwV7C8L imig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NjMNluy3; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124936-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124936-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o4-20020a63e344000000b005e4b0710537si3778866pgj.562.2024.03.29.07.31.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 07:31:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124936-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NjMNluy3; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124936-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124936-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 68D7528694E for ; Fri, 29 Mar 2024 14:31:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B6D111A5D9C; Fri, 29 Mar 2024 12:47:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NjMNluy3" 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 CDED11A5D7F; Fri, 29 Mar 2024 12:47:33 +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=1711716453; cv=none; b=umSM+1WCyiBxbFgk6gMKHU8kHFW6BGwAEDQHCLXsjMbgjZAwUt9yYQEXIHJhO6tXC7uX101hISLBOVuu9d7s2aQpbd95ci+wFQ0f8Geo4uxo4V2biNBUdAx6GsOxR8OlX8O9a6onFdaMTmnc0wBf9/6uPM9XQUaUrXSnlgU9rR8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716453; c=relaxed/simple; bh=/mV5g2u4Bgi3sJcKcC/duOfJ8yg/8UzMmXb6B1zUg2A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qsqXANjWCWVbKauEP3hEzP09J4g8Pp5PDKbGB0WIQF3sxxBmOk/vE/8rbQEE37+88AMWsvr7VTjQRVYzXWwm+X49JJB9WAx9G+sS6i8d5U1rCT73XqDEacKt1Jjp0ECcUTX6nZ45yOqYkJrHWpk4mYd2MqEFAYc0PsCq7Qpm49s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NjMNluy3; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8640C433A6; Fri, 29 Mar 2024 12:47:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716453; bh=/mV5g2u4Bgi3sJcKcC/duOfJ8yg/8UzMmXb6B1zUg2A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NjMNluy3d7NUA4pQVabD7zH6NDiqg6NQGA751XNQxFs/fDKhPYsdLcoyH2jXA2OwO XCHxkTnTJRuCm2MZp5GFCVci9XjdggJNLOG09exBYaJ7x0nZOw+BqKH6g72Tm2y9cJ mTbgfcG58KuaRaRKxh3IYC74SBRsYaopKh66gohXGDt6u+V+eNd+O2R1N1zwZ47aZ1 iiBvxSkkQ1qd3OGDxHSrV9tAmijHbpMqoenWkLhTPMZLVLUcbF76M2I5FxSufGu1Qy 0JlbROIYLTmOCg1pCsHSC2+ps22D65T1f6c/JMACPFhzMkYmUZUNv35LSACCTw7DI3 FAdKTHA3NttoA== 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.1 52/52] ring-buffer: use READ_ONCE() to read cpu_buffer->commit_page in concurrent environment Date: Fri, 29 Mar 2024 08:45:46 -0400 Message-ID: <20240329124605.3091273-52-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329124605.3091273-1-sashal@kernel.org> References: <20240329124605.3091273-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.1.83 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 e019a9278794f..7ed92f311dc9b 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -4384,7 +4384,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