Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp970046rwl; Wed, 12 Apr 2023 06:42:22 -0700 (PDT) X-Google-Smtp-Source: AKy350b0NwC/17TcTGXputjb/D1Uj9oq6lTy2xIdGcz67TgOgyvdeSWKKKAAn8SQSTOQBOmFh+1Q X-Received: by 2002:aa7:d849:0:b0:504:9394:188c with SMTP id f9-20020aa7d849000000b005049394188cmr2317570eds.9.1681306942246; Wed, 12 Apr 2023 06:42:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681306942; cv=none; d=google.com; s=arc-20160816; b=K5SH5tuN6NiBA/88L6vDNu3qGxSarexxbW3p5LHrPE6/a0bimibHYvNyg/Sem6TKZ3 wdCjHD8fLYAdI/yDqxArVeBpOJxVX61uAIDreoRQmaDh/BoC6drcxUTrH+Z/dnvUHOfU WfUiV4LMOz6k3pLErzb/S9SHmsFqvLb4tPp51dk5YaCLzXr8/GP0iYRsQRvsas+J4A2n rhg0fwt0fIk7YfmjvPaLMmE18GBklYxD/VxPhExgD8SMP3V8t/+V98gebXPBwgnuJ5Pi 8oE41ztNDEVO/L0jeNIIo3xrhqFtHjsn76bIlHMb9xeSw+G/OPr51ckxXKDCeILSjqe9 1vVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=2fhhnJmcAtek4XGjUpAhSRHFd+0C7ZktxPkOdZp7fCI=; b=ZiySFJJ4xHAPw8HzcuBr75uik3heG8qmsGiaWVhEmh+ME4yUWsqfshJZ+6pBBnLxRb 6w7Tc+pf/q3gyuGCYORY7SqeB5V6RLZlSMgRH2/sHNOyBRN8w876cpegfu7+mLSD0N8H oJR/IwKwlD/9UIZXdCf8ID5WLqtiO1hin+90vrUvOcrpxCvcLl0JX9P3EM/p/5iTx3uZ LFg++8of90Od47GP1FmbSVJdpEiab3iCJPICLcguXTXJA9mJceu7cyCtj+BtNZ2E5M5M 8xD0Gs23JqWWmJSshoSBGs/Q+hakhGq4Ptus8zImuowBNO1MnpmlFvzeL36NLXdUIX/O zslA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=S06GYfa0; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u22-20020aa7db96000000b00501d7ce6144si1960887edt.474.2023.04.12.06.41.57; Wed, 12 Apr 2023 06:42:22 -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=@kernel.org header.s=k20201202 header.b=S06GYfa0; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230188AbjDLNjc (ORCPT + 99 others); Wed, 12 Apr 2023 09:39:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230129AbjDLNja (ORCPT ); Wed, 12 Apr 2023 09:39:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CF7649C2; Wed, 12 Apr 2023 06:39:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 165AD6353E; Wed, 12 Apr 2023 13:39:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46C06C4339E; Wed, 12 Apr 2023 13:39:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681306768; bh=GOykW6XA+0igU5TTxTnc1Z+ANk1/amyaw2FES3+7QbY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=S06GYfa0tW/T6dAqB6kE/T7Ra7by1ctHfjP+AKCOzRCWE7jX3z97ZKg/Q5z5v8r2s kf1P8tn30DVeWBZE269ec6ASQNBGVrVw7s/Yk5K7DQVqwAdaRZpyuOHvJPCDJSzigX F4yKv0gyqSeYA04L9VZXXo1iEqxSZZu5KmqqE8GE8SxGRYdedjHGeN1xq1+nC7dAXt YvmBiNDGhFHsS2zS6Pr471UcjrSjx3oy/pJGKkbdaKzKVa2kLjv242x90zmCybbEcx BR2QAipN/RjOwXU32U82VD9PYDfLcjIzM2Kd7NYiS7hVF0fsZ7AoHrYxlDfHVbDTjH xKbeV3CRb36VQ== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id F115840080; Wed, 12 Apr 2023 10:39:25 -0300 (-03) Date: Wed, 12 Apr 2023 10:39:25 -0300 From: Arnaldo Carvalho de Melo To: Hangliang Lai Cc: namhyung@kernel.org, adrian.hunter@intel.com, alexander.shishkin@linux.intel.com, brauner@kernel.org, hewenliang4@huawei.com, irogers@google.com, jolsa@kernel.org, linfeilong@huawei.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, liuwenyu7@huawei.com, mark.rutland@arm.com, mingo@redhat.com, yeyunfeng@huawei.com Subject: Re: [PATCH v4] perf top: expand the range of multithreaded phase Message-ID: References: <20230411013224.2079-1-laihangliang1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230411013224.2079-1-laihangliang1@huawei.com> X-Url: http://acmel.wordpress.com X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 Em Tue, Apr 11, 2023 at 09:32:24AM +0800, Hangliang Lai escreveu: > In __cmd_top, perf_set_multithreaded is used to enable pthread_rwlock, thus > donw_read and down_write can work to handle concurrency problems. Then top > use perf_set_singlethreaded and switch to single threaded phase, assuming > that no thread concurrency will happen later. > However, a UAF problem could occur in perf top in single threaded phase, > The concurrent procedure is like this: > display_thread process_thread > -------------- -------------- > thread__comm_len > -> thread__comm_str > -> __thread__comm_str(thread) > thread__delete > -> comm__free > -> comm_str__put > -> zfree(&cs->str) > -> thread->comm_len = strlen(comm); > Since in single thread phase, perf_singlethreaded is true, down_read and > down_write can not work to avoid concurrency problems. > This patch put perf_set_singlethreaded to the function tail to expand the > multithreaded phase range, make display_thread and process_thread run > safe. > > Signed-off-by: Hangliang Lai > Co-developed-by: Wenyu Liu > Reviewed-by: Yunfeng Ye > Acked-by: Namhyung Kim Thanks, applied. - Arnaldo > --- > v3 -> v4 > - Add Acked-by and Co-developed-by. > > tools/perf/builtin-top.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c > index d4b5b02bab73..ae96ddaf85c4 100644 > --- a/tools/perf/builtin-top.c > +++ b/tools/perf/builtin-top.c > @@ -1273,8 +1273,7 @@ static int __cmd_top(struct perf_top *top) > top->evlist->core.threads, true, false, > top->nr_threads_synthesize); > > - if (top->nr_threads_synthesize > 1) > - perf_set_singlethreaded(); > + perf_set_multithreaded(); > > if (perf_hpp_list.socket) { > ret = perf_env__read_cpu_topology_map(&perf_env); > @@ -1352,6 +1351,7 @@ static int __cmd_top(struct perf_top *top) > out_join_thread: > cond_signal(&top->qe.cond); > pthread_join(thread_process, NULL); > + perf_set_singlethreaded(); > return ret; > } > > -- > 2.33.0 > -- - Arnaldo