Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1468316ybi; Fri, 2 Aug 2019 16:37:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwk+Z2EpL4vIpX8J1PzGrvZnYpuqQiK0md9/FFZkec7vtlY/H8AJVfyJnKaFordog9y3hX X-Received: by 2002:a17:90a:c596:: with SMTP id l22mr6783642pjt.46.1564789031764; Fri, 02 Aug 2019 16:37:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564789031; cv=none; d=google.com; s=arc-20160816; b=Yz80Q45T6nNMnSo57NUW+j6g/mIXsw+xP0tO8C5HldWiwFZfm5TgsDQYSQNvmcJQW2 f/ZJ06oVeoJse4MmecBwKnqrEPJf1czwsIMEC29IRT+kQ7d+VUiiUzxaFaJOYCGCzXz/ w5w/oG2+IuhKEtCWiuRozhlV6pYeXZXjdKghrbMrJqAUGQAhS6JwCFF6mR3H2qXJPdSK ikpFK3huPjSUj1FPUjIuSFL0xgZQqL5YGUl0dZbBvCJGRtwBkSiC+9I6FZTsd/JjCyB8 9uZh2j/Zc3zkas+wi1sQO1FsYCMo7ezIjg3pid01sR3LrEFJYWi4Hbh51QhAvNZjNvSn 4chQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=AiB+hZUlw/soTcgkgaYvH8iRaaV8FBM01E3ZHgQKEHs=; b=Y/F6qJj8i+q8bNFJh2PfroYfWIFdmqg6+3+NU/zTgxXfzRjIuE/UHnVaZCvbq0pY43 dWoEAM3tfVwonsjSRZSlpF10geSvYKXPQOOvx4ULNiNH67L/qrWnG/5WbdIx4Zxm6dKO mMPDXXLewFyWE2TyqlEPhKFStUGWkrWFMBVstphJu5JZssDvZaj6GTZuKvrRj60ChN3Y X5T+Iw9nrK3wqhkhQtTFxDpR4hsV4bjhN50QJcsxB+hgzwyHY80oa0nMAlV/9tNlX9GU cVZc038V8Znt1ZvP84gdpEQUmj6/QzgzxpNw3WTBjBuGaIhG0djBuDgjC6oJAxZhjFvl /bcw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j1si40708346pgb.482.2019.08.02.16.36.55; Fri, 02 Aug 2019 16:37:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392939AbfHBNGK (ORCPT + 99 others); Fri, 2 Aug 2019 09:06:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58858 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388240AbfHBNGK (ORCPT ); Fri, 2 Aug 2019 09:06:10 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0A2603082E20; Fri, 2 Aug 2019 13:06:10 +0000 (UTC) Received: from krava (ovpn-204-20.brq.redhat.com [10.40.204.20]) by smtp.corp.redhat.com (Postfix) with SMTP id D4E1160BF4; Fri, 2 Aug 2019 13:06:07 +0000 (UTC) Date: Fri, 2 Aug 2019 15:06:07 +0200 From: Jiri Olsa To: zhe.he@windriver.com Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, alexander.shishkin@linux.intel.com, namhyung@kernel.org, kan.liang@linux.intel.com, eranian@google.com, alexey.budankov@linux.intel.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] perf: Fix failure to set cpumask when only one cpu Message-ID: <20190802130607.GA27223@krava> References: <1564734592-15624-1-git-send-email-zhe.he@windriver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1564734592-15624-1-git-send-email-zhe.he@windriver.com> User-Agent: Mutt/1.12.0 (2019-05-25) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 02 Aug 2019 13:06:10 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 02, 2019 at 04:29:51PM +0800, zhe.he@windriver.com wrote: > From: He Zhe > > The buffer containing string used to set cpumask is overwritten by end of > string later in cpu_map__snprint_mask due to not enough memory space, when > there is only one cpu. And thus causes the following failure. > > $ perf ftrace ls > failed to reset ftrace > > This patch fixes the calculation of cpumask string size. > > Signed-off-by: He Zhe > --- > tools/perf/builtin-ftrace.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c > index 66d5a66..0193128 100644 > --- a/tools/perf/builtin-ftrace.c > +++ b/tools/perf/builtin-ftrace.c > @@ -173,7 +173,7 @@ static int set_tracing_cpumask(struct cpu_map *cpumap) > int last_cpu; > > last_cpu = cpu_map__cpu(cpumap, cpumap->nr - 1); > - mask_size = (last_cpu + 3) / 4 + 1; > + mask_size = last_cpu / 4 + 2; /* one more byte for EOS */ > mask_size += last_cpu / 32; /* ',' is needed for every 32th cpus */ ugh.. why do we care about last_cpu value in here at all? feels like using static buffer would be more reasonable jirka > > cpumask = malloc(mask_size); > -- > 2.7.4 >