Message ID | 20230408052226.25268-1-Tze-nan.Wu@mediatek.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp691039vqo; Fri, 7 Apr 2023 22:36:31 -0700 (PDT) X-Google-Smtp-Source: AKy350bIgHsDPBFgLVzwqiO4+QV1pzHSYF+NiAB5oIrIcUkTAnyniygvpW2A+YjvDrqiAOypCuxt X-Received: by 2002:a05:6a20:4a1b:b0:d6:17fc:9f66 with SMTP id fr27-20020a056a204a1b00b000d617fc9f66mr4642352pzb.18.1680932191586; Fri, 07 Apr 2023 22:36:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680932191; cv=none; d=google.com; s=arc-20160816; b=RRjpRqYeX4z+UiWKDfrJoopKoKZLAYEze1qFyRYePMgvCqOvEH9KoIAjKujjElOHEG 3wHKvuACewQbron1oeUDkodmjlpmKcu+j99GyMgdEomPJkr0A6mIhyM13h9RTHEhS9xH aePQ61QAWl0vDLvWzjVkzC8p5XqTlhxC1r0IrPKyltupOyx97B1CvvmKajQjxZeauNCo WJw+l6UJ2TaBZHgmm4dVJag3dBhq+xR63uajIFjbA/v6uRRLTNkhkFty9EQjwPqqcxK5 4/eNkAqW7Z/EE2ddc+1uZOQQCW/476xgCBZhzWnQxUd1MCgtPKkRdCszwCe6jD4Ar3vR qYQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=Wdlz1937eg98NYAB81abic14zLCB/RzHOwbInQ9humY=; b=BMQ3ospqtpPwCR9yCh2J3lzuZCFNpPz6HpT2m4M8yRXchEieRQYQn4ks+wzhJFHJ20 u7oAU208xsykJVZ8/t7dB9lKdX4VS1T6Tbdn9okHCkha6VAI2210z8zFzoyQyouX5dWw uNukODXaEM8ATxR6lmNhIn6I6wQL2DwGzBKraGCjRMUfjjjbegAAehezmZqzi7Gchr9n 4FKF3tcXVhH4/MPmq944c8H2l+4LSGwqHRDNW31HUVptrPTPEfm3isKyzJaMAknQq/oA H+CEAtCuokD8olLShw9b5MnwnNNAHu3+h23f3B1Kq2rIKn5HPHmwgXafbh6ps2UcL6Kk gQDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b="hvQJikB/"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q12-20020a631f4c000000b0050beb83039esi4914009pgm.515.2023.04.07.22.36.17; Fri, 07 Apr 2023 22:36:31 -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=@mediatek.com header.s=dk header.b="hvQJikB/"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230009AbjDHFWu (ORCPT <rfc822;a1648639935@gmail.com> + 99 others); Sat, 8 Apr 2023 01:22:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229517AbjDHFWs (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 8 Apr 2023 01:22:48 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9837BBDD2; Fri, 7 Apr 2023 22:22:42 -0700 (PDT) X-UUID: 5ecb7e56d5cd11edb6b9f13eb10bd0fe-20230408 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=Wdlz1937eg98NYAB81abic14zLCB/RzHOwbInQ9humY=; b=hvQJikB/1Nc8NvLlEUZJGrU4Wf/bXW/yOpA9LCkozheJr5PaNqhiMq/T/s33dgCivmbmoIyZTGk+s5dWU7lF8nzqJ4tDfHPS8Y+R+rjF6mzywjk1UdjRY2Nw6H6x1xQEV5mF3yqywN9y1A+mDN+xSydamZGgxv0sJbJ4KJTfFFA=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.22,REQID:42bf6f06-109c-45ce-a628-11ce0c3c0bc7,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:100,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:75 X-CID-INFO: VERSION:1.1.22,REQID:42bf6f06-109c-45ce-a628-11ce0c3c0bc7,IP:0,URL :0,TC:0,Content:-25,EDM:0,RT:0,SF:100,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACT ION:quarantine,TS:75 X-CID-META: VersionHash:120426c,CLOUDID:ad781ff8-ddba-41c3-91d9-10eeade8eac7,B ulkID:230408132236CR9EZPQB,BulkQuantity:0,Recheck:0,SF:29|28|17|19|48|38,T C:nil,Content:0,EDM:-3,IP:nil,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 ,OSI:0,OSA:0,AV:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-UUID: 5ecb7e56d5cd11edb6b9f13eb10bd0fe-20230408 Received: from mtkmbs13n1.mediatek.inc [(172.21.101.193)] by mailgw02.mediatek.com (envelope-from <tze-nan.wu@mediatek.com>) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 84322464; Sat, 08 Apr 2023 13:22:35 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.25; Sat, 8 Apr 2023 13:22:34 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.25 via Frontend Transport; Sat, 8 Apr 2023 13:22:34 +0800 From: Tze-nan Wu <Tze-nan.Wu@mediatek.com> To: <rostedt@goodmis.org>, <mhiramat@kernel.org> CC: <bobule.chang@mediatek.com>, <wsd_upstream@mediatek.com>, <Tze-nan.Wu@mediatek.com>, <stable@vger.kernel.org>, "AngeloGioacchino Del Regno" <angelogioacchino.delregno@collabora.com>, <linux-kernel@vger.kernel.org>, <linux-trace-kernel@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>, <linux-mediatek@lists.infradead.org> Subject: [PATCH] ring-buffer: Prevent inconsistent operation on cpu_buffer->resize_disabled Date: Sat, 8 Apr 2023 13:22:26 +0800 Message-ID: <20230408052226.25268-1-Tze-nan.Wu@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,RDNS_NONE,SPF_HELO_PASS, T_SPF_TEMPERROR,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762585153520476691?= X-GMAIL-MSGID: =?utf-8?q?1762585153520476691?= |
Series |
ring-buffer: Prevent inconsistent operation on cpu_buffer->resize_disabled
|
|
Commit Message
Tze-nan Wu
April 8, 2023, 5:22 a.m. UTC
Sometimes, write to buffer_size_kb can be permanently failure if we change
the cpu_online_mask between two for_each_online_buffer_cpu loops in
function ring_buffer_reset_online_cpus.
The number of increasing and decreasing on cpu_buffer->resize_disable
may be inconsistent, leading the resize_disabled in some CPUs becoming
none zero after ring_buffer_reset_online_cpus return.
This issue can be reproduced by "echo 0 > trace" and hotplug cpu at the
same time. After reproducing succeess, we can find out the attempt to
write to buffer_size_kb node failure every time.
This patch prevent the inconsistent increasing and decreasing on
cpu_buffer->resize_disabled by copying the cpu_online_mask at the
beginning of the function.
But I wonder if there's any side-effect of this patch,
since the behavior changed, if we turn on a cpu between the two loops,
reset_disabled_cpu_buffer() of that cpu won't be run as before,
meaning the cpu_buffer on that cpu just awake will not be cleaned up.
Cc: stable@vger.kernel.org
Signed-off-by: Tze-nan Wu <Tze-nan.Wu@mediatek.com>
---
kernel/trace/ring_buffer.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
Comments
Hi Tze-nan, kernel test robot noticed the following build warnings: [auto build test WARNING on linus/master] [also build test WARNING on rostedt-trace/for-next v6.3-rc5 next-20230406] [cannot apply to rostedt-trace/for-next-urgent] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Tze-nan-Wu/ring-buffer-Prevent-inconsistent-operation-on-cpu_buffer-resize_disabled/20230408-132502 patch link: https://lore.kernel.org/r/20230408052226.25268-1-Tze-nan.Wu%40mediatek.com patch subject: [PATCH] ring-buffer: Prevent inconsistent operation on cpu_buffer->resize_disabled config: x86_64-randconfig-a002-20230403 (https://download.01.org/0day-ci/archive/20230408/202304081615.eiaqpbV8-lkp@intel.com/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/d404bc0af0a4bde3aa20704642d69a78bdc154f8 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Tze-nan-Wu/ring-buffer-Prevent-inconsistent-operation-on-cpu_buffer-resize_disabled/20230408-132502 git checkout d404bc0af0a4bde3aa20704642d69a78bdc154f8 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash kernel/trace/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> | Link: https://lore.kernel.org/oe-kbuild-all/202304081615.eiaqpbV8-lkp@intel.com/ All warnings (new ones prefixed by >>): >> kernel/trace/ring_buffer.c:5359:15: warning: variable 'reset_online_mask' is uninitialized when used here [-Wuninitialized] cpumask_copy(reset_online_mask, cpu_online_mask); ^~~~~~~~~~~~~~~~~ kernel/trace/ring_buffer.c:5353:33: note: initialize the variable 'reset_online_mask' to silence this warning cpumask_var_t reset_online_mask; ^ = NULL 1 warning generated. vim +/reset_online_mask +5359 kernel/trace/ring_buffer.c 5344 5345 /** 5346 * ring_buffer_reset_online_cpus - reset a ring buffer per CPU buffer 5347 * @buffer: The ring buffer to reset a per cpu buffer of 5348 * @cpu: The CPU buffer to be reset 5349 */ 5350 void ring_buffer_reset_online_cpus(struct trace_buffer *buffer) 5351 { 5352 struct ring_buffer_per_cpu *cpu_buffer; 5353 cpumask_var_t reset_online_mask; 5354 int cpu; 5355 5356 /* prevent another thread from changing buffer sizes */ 5357 mutex_lock(&buffer->mutex); 5358 > 5359 cpumask_copy(reset_online_mask, cpu_online_mask); 5360 5361 for_each_cpu_and(cpu, buffer->cpumask, reset_online_mask) { 5362 cpu_buffer = buffer->buffers[cpu]; 5363 5364 atomic_inc(&cpu_buffer->resize_disabled); 5365 atomic_inc(&cpu_buffer->record_disabled); 5366 } 5367 5368 /* Make sure all commits have finished */ 5369 synchronize_rcu(); 5370 5371 for_each_cpu_and(cpu, buffer->cpumask, reset_online_mask) { 5372 cpu_buffer = buffer->buffers[cpu]; 5373 5374 reset_disabled_cpu_buffer(cpu_buffer); 5375 5376 atomic_dec(&cpu_buffer->record_disabled); 5377 atomic_dec(&cpu_buffer->resize_disabled); 5378 } 5379 5380 mutex_unlock(&buffer->mutex); 5381 } 5382
Hi Tze-nan, kernel test robot noticed the following build warnings: [auto build test WARNING on linus/master] [cannot apply to rostedt-trace/for-next-urgent] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Tze-nan-Wu/ring-buffer-Prevent-inconsistent-operation-on-cpu_buffer-resize_disabled/20230408-132502 patch link: https://lore.kernel.org/r/20230408052226.25268-1-Tze-nan.Wu%40mediatek.com patch subject: [PATCH] ring-buffer: Prevent inconsistent operation on cpu_buffer->resize_disabled config: s390-allyesconfig (https://download.01.org/0day-ci/archive/20230408/202304082051.Dp50upfS-lkp@intel.com/config) compiler: s390-linux-gcc (GCC) 12.1.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/d404bc0af0a4bde3aa20704642d69a78bdc154f8 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Tze-nan-Wu/ring-buffer-Prevent-inconsistent-operation-on-cpu_buffer-resize_disabled/20230408-132502 git checkout d404bc0af0a4bde3aa20704642d69a78bdc154f8 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=s390 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=s390 SHELL=/bin/bash kernel/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> | Link: https://lore.kernel.org/oe-kbuild-all/202304082051.Dp50upfS-lkp@intel.com/ All warnings (new ones prefixed by >>): kernel/trace/ring_buffer.c: In function 'ring_buffer_reset_online_cpus': >> kernel/trace/ring_buffer.c:5359:9: warning: 'reset_online_mask' is used uninitialized [-Wuninitialized] 5359 | cpumask_copy(reset_online_mask, cpu_online_mask); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kernel/trace/ring_buffer.c:5353:23: note: 'reset_online_mask' was declared here 5353 | cpumask_var_t reset_online_mask; | ^~~~~~~~~~~~~~~~~ vim +/reset_online_mask +5359 kernel/trace/ring_buffer.c 5344 5345 /** 5346 * ring_buffer_reset_online_cpus - reset a ring buffer per CPU buffer 5347 * @buffer: The ring buffer to reset a per cpu buffer of 5348 * @cpu: The CPU buffer to be reset 5349 */ 5350 void ring_buffer_reset_online_cpus(struct trace_buffer *buffer) 5351 { 5352 struct ring_buffer_per_cpu *cpu_buffer; 5353 cpumask_var_t reset_online_mask; 5354 int cpu; 5355 5356 /* prevent another thread from changing buffer sizes */ 5357 mutex_lock(&buffer->mutex); 5358 > 5359 cpumask_copy(reset_online_mask, cpu_online_mask); 5360 5361 for_each_cpu_and(cpu, buffer->cpumask, reset_online_mask) { 5362 cpu_buffer = buffer->buffers[cpu]; 5363 5364 atomic_inc(&cpu_buffer->resize_disabled); 5365 atomic_inc(&cpu_buffer->record_disabled); 5366 } 5367 5368 /* Make sure all commits have finished */ 5369 synchronize_rcu(); 5370 5371 for_each_cpu_and(cpu, buffer->cpumask, reset_online_mask) { 5372 cpu_buffer = buffer->buffers[cpu]; 5373 5374 reset_disabled_cpu_buffer(cpu_buffer); 5375 5376 atomic_dec(&cpu_buffer->record_disabled); 5377 atomic_dec(&cpu_buffer->resize_disabled); 5378 } 5379 5380 mutex_unlock(&buffer->mutex); 5381 } 5382
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 76a2d91eecad..468f46bba71e 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -288,9 +288,6 @@ EXPORT_SYMBOL_GPL(ring_buffer_event_data); #define for_each_buffer_cpu(buffer, cpu) \ for_each_cpu(cpu, buffer->cpumask) -#define for_each_online_buffer_cpu(buffer, cpu) \ - for_each_cpu_and(cpu, buffer->cpumask, cpu_online_mask) - #define TS_SHIFT 27 #define TS_MASK ((1ULL << TS_SHIFT) - 1) #define TS_DELTA_TEST (~TS_MASK) @@ -5353,12 +5350,15 @@ EXPORT_SYMBOL_GPL(ring_buffer_reset_cpu); void ring_buffer_reset_online_cpus(struct trace_buffer *buffer) { struct ring_buffer_per_cpu *cpu_buffer; + cpumask_var_t reset_online_mask; int cpu; /* prevent another thread from changing buffer sizes */ mutex_lock(&buffer->mutex); - for_each_online_buffer_cpu(buffer, cpu) { + cpumask_copy(reset_online_mask, cpu_online_mask); + + for_each_cpu_and(cpu, buffer->cpumask, reset_online_mask) { cpu_buffer = buffer->buffers[cpu]; atomic_inc(&cpu_buffer->resize_disabled); @@ -5368,7 +5368,7 @@ void ring_buffer_reset_online_cpus(struct trace_buffer *buffer) /* Make sure all commits have finished */ synchronize_rcu(); - for_each_online_buffer_cpu(buffer, cpu) { + for_each_cpu_and(cpu, buffer->cpumask, reset_online_mask) { cpu_buffer = buffer->buffers[cpu]; reset_disabled_cpu_buffer(cpu_buffer);