From patchwork Fri Aug 4 12:45:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Yejian X-Patchwork-Id: 131161 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp245927vqb; Fri, 4 Aug 2023 06:04:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHbeq5bphm/iAxw62fK+lWWHQf4UWv1K3umoCzaXwO6HBTCoDxQ3MCZUGVT8Gu8cchk6o70 X-Received: by 2002:a05:6a20:3d84:b0:137:c971:6a0c with SMTP id s4-20020a056a203d8400b00137c9716a0cmr1899898pzi.31.1691154240934; Fri, 04 Aug 2023 06:04:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691154240; cv=none; d=google.com; s=arc-20160816; b=cybJvRynCvbGqFJBa3vLRiOal62R55EyFao8s+1qcd/kcAWOe35WMEt5KDn7xO8X28 r6fnWttu+LsEVAQCAXhCpHN6XStplkwkBXZ3AGRYdye3aL4JWcBIleG1Q/zgsMfvmVgC Dks4/Y0jj2iY9uK44B9ev+hPlvSOlN58joc/BPQIEkRf50SfrvHbb/XgeJefBgE3N0lO 8jLo5PZa5bloyDLmsjzANfUjOqCUd2DpggWWaxn7/wLNOUZYPhWo7fgqsCkSYImJ0X3y PPYeev8tKPs0+RjzkGsb8wOafa/Z3SSlt2bf2mcEtPHhx0sH2n6pCip+Iv2cp7lvAsDJ jyMA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cn11-20020a056a00340b00b00661cd40bd67si1617086pfb.314.2023.08.04.06.03.16; Fri, 04 Aug 2023 06:04:00 -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 S230170AbjHDMqj (ORCPT + 99 others); Fri, 4 Aug 2023 08:46:39 -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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773303749145505185 X-GMAIL-MSGID: 1773303749145505185 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);