Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp3502919rwo; Fri, 4 Aug 2023 06:04:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHGpo7bmbhFiAuZs5ETTOjgRrhOdBsTbDvdunTZdMz/Q5k19awVIS9m/J3Jvj/lMgMlxy+d X-Received: by 2002:aa7:cad0:0:b0:521:728f:d84e with SMTP id l16-20020aa7cad0000000b00521728fd84emr2173676edt.0.1691154249403; Fri, 04 Aug 2023 06:04:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691154249; cv=none; d=google.com; s=arc-20160816; b=f0NqLVp201c9QOiccZdPmBOa7u/yiB6LddVp0m99umxwM+GlHS46X88nViTvoR4WA4 V+hDIJ1lC9qt1ieQWmQRCZD6A8+WJ3rV3VAwP0IW2RZdZSAFTC4NFplNCfSIwIsCeeU1 9Hs26r7uomCDWZfYEz/hI2dz3zKjQnic0SccjxEEE1YEoGra7SkcQAz+PCvNitc0lp4f Kfbs0yVB94zyCx2TncUqSrFBLzwsPnmHeOOF/h/q+vmIGb835f+P4mc9JyJIhsukORsO ATW61KZd3uhNbqqd+VN0aUJ987Hjpa0q76ZGjXrEMvTXMezpK0uaYahj7F8Zk5qB7ouP kRpA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=LEVg9wirPEV+VJVrJQ78tfW3hNFiD9W6Lxb0G6/HWQE=; fh=6BCBHd+wd9sM5I7f3nZwXI5uSly3s62mQle808OwsEg=; b=P9j3hHCFSvER3iTikWSBv091cGuM7Mv8aas0y2qerJ+KOeQ6WLulZSW4iQacIGLIM1 Vg8LSp87vXoQmP5+/CS+0ivHbYt9QsIphDTeAtgoyEE1pFyWBNE1Qwt92ttfcrk5XRir 2JMJtlsO1dJMm4smmV60HJtrbFEOSxfAWG+HJmvoWSiqDCCVTyvizPEub7izhBa6RGAj mPMqo+lOhb9XaGXfeJ0wjTN1vXAslDTET6pu5aXVNIGSib5yT7duVEkkAn5hGqOIiDIN LuTTUQ1xVRfQNcDIPrgtEZmTjfVa4jjxnznVwbP5ybd4VMUwz0CfgkTCf9vdratZRFaH TZhQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d23-20020aa7ce17000000b0051fc91de674si1670690edv.557.2023.08.04.06.03.35; Fri, 04 Aug 2023 06:04:09 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230168AbjHDMqi (ORCPT + 99 others); Fri, 4 Aug 2023 08:46:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230054AbjHDMqa (ORCPT ); Fri, 4 Aug 2023 08:46:30 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2E1A46B2; Fri, 4 Aug 2023 05:46:28 -0700 (PDT) Received: from dggpeml500012.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RHQRP5mPBz1KC70; Fri, 4 Aug 2023 20:45:21 +0800 (CST) Received: from localhost.localdomain (10.67.175.61) by dggpeml500012.china.huawei.com (7.185.36.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 4 Aug 2023 20:46:26 +0800 From: Zheng Yejian To: , , , CC: , , Subject: [PATCH 1/2] tracing: Fix cpu buffers unavailable due to 'record_disabled' messed Date: Fri, 4 Aug 2023 20:45:48 +0800 Message-ID: <20230804124549.2562977-2-zhengyejian1@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230804124549.2562977-1-zhengyejian1@huawei.com> References: <20230804124549.2562977-1-zhengyejian1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.175.61] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500012.china.huawei.com (7.185.36.15) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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 Trace ring buffer can no longer record anything after executing like: # cd /sys/kernel/tracing # cat tracing_cpumask fff # echo 0 > tracing_cpumask # echo 1 > snapshot # echo fff > tracing_cpumask # echo "hello world" > trace_marker -bash: echo: write error: Bad file descriptor The root cause is that: 1. After `echo 0 > tracing_cpumask`, 'record_disabled' of cpu buffers in 'tr->array_buffer.buffer' became 1 (see tracing_set_cpumask()); 2. After `echo 1 > snapshot`, 'tr->array_buffer.buffer' is swapped with 'tr->max_buffer.buffer', then the 'record_disabled' became 0 (see update_max_tr()); 3. After `echo fff > tracing_cpumask`, the 'record_disabled' become -1; Then array_buffer and max_buffer are both unavailable due to value of 'record_disabled' is not 0. To fix it, enable or disable both array_buffer and max_buffer at the same time in tracing_set_cpumask(). Fixes: 71babb2705e2 ("tracing: change CPU ring buffer state from tracing_cpumask") Signed-off-by: Zheng Yejian --- kernel/trace/trace.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index b8870078ef58..691ec4d4cd19 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -5277,11 +5277,13 @@ int tracing_set_cpumask(struct trace_array *tr, !cpumask_test_cpu(cpu, tracing_cpumask_new)) { atomic_inc(&per_cpu_ptr(tr->array_buffer.data, cpu)->disabled); ring_buffer_record_disable_cpu(tr->array_buffer.buffer, cpu); + ring_buffer_record_disable_cpu(tr->max_buffer.buffer, cpu); } if (!cpumask_test_cpu(cpu, tr->tracing_cpumask) && cpumask_test_cpu(cpu, tracing_cpumask_new)) { atomic_dec(&per_cpu_ptr(tr->array_buffer.data, cpu)->disabled); ring_buffer_record_enable_cpu(tr->array_buffer.buffer, cpu); + ring_buffer_record_enable_cpu(tr->max_buffer.buffer, cpu); } } arch_spin_unlock(&tr->max_lock); -- 2.25.1