Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5213865ybl; Tue, 27 Aug 2019 00:54:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVQQZfLHmTTE9FLB6Dgjkj8xJ1K/F6qamaJbqZQXrEyfF7F8TQWAzinqN1Orto33dx7dQk X-Received: by 2002:a17:902:e68f:: with SMTP id cn15mr23385923plb.212.1566892471912; Tue, 27 Aug 2019 00:54:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566892471; cv=none; d=google.com; s=arc-20160816; b=J3kpKSTxJn54r5Qt8xFqDqNFiG/DqOUsSVQjTIqBWhD1K5JaRic9ApoT4QrTYdSw9q T0iHRIC7vFVux4xMh8BQyKAFGV1JWr+CQwaLy86xFYZf1og6/aDARcDJL8X5jhd91TJT HRR59+P+DhKTe0o2qJA8aOAfDvq0KDNKj35odDP6SCmR9NXSvWp33U2oBMLMgmIi4HkK hu0CuLTePsWxSpDLXPNgHfBimN0U0R94G+AhIchBk8aWumF9+ms/nmORodfALqp3RmoY kEgBCDGc6gSPGoG1frOv+FnLQTqYn6Jt+I1X45Wadbt1TjCmklhmXRZZKBsERJm9ea/V fxCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cnlvU41SpExuGYnnTdn2kHznnkGOHUjSuNMR/tCwFjM=; b=ljP3v0aWfvUdF3ZcAYRICtZsR/HO070mZsN+oifjEWgCRbVbsYrtZvajUdZOXun7lQ F9r7S1Ag02Z3gVxlwmSols7P6c0lYt56fc5sL1fhizbgwjQDeys/GMqlDktRg94ulJq5 LEZVX2T1xfKDWc70yLlGMqmUnNJgcK4o6GMtbvwHijFNkENcJQfPyloD0ac6VRUwryMY k6hI7URv8xMZiJeu04ZokgKlOk66mdmmWghFpRsN5FviDKOtdTJanCbgXhoA2vFiuTqJ /rUYdzSZGCWtWa1H3F7B2/RgOKJF97s72yIjsPB2GHOiPXqmULptBcesGix/8Z3zPIr/ K+jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AvEoGq4+; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c137si11400721pga.80.2019.08.27.00.54.16; Tue, 27 Aug 2019 00:54:31 -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; dkim=pass header.i=@kernel.org header.s=default header.b=AvEoGq4+; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729640AbfH0Hw4 (ORCPT + 99 others); Tue, 27 Aug 2019 03:52:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:44344 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729611AbfH0Hww (ORCPT ); Tue, 27 Aug 2019 03:52:52 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5DC4021881; Tue, 27 Aug 2019 07:52:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566892371; bh=9/5dpNPUo2nUy+0Uk5+4xtKNFRNAwE8t6rqidz1AH48=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AvEoGq4+TXN7wVW9eyauk54c2g7tvTDpvQUXuOOSc/ZzfHRUVwV0sP3nP9xlTZ61M KJzIs0TwZvIAHugpa1Otwo03aCIudHgHP8R1VYxItvxa+YvRZGEgoeO0VDMEI7Tr2O p5lp8FcNEVCYZj2blHFel3K4Ye4x82S/qX6B5Gbo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, He Zhe , Arnaldo Carvalho de Melo , Alexander Shishkin , Alexey Budankov , Jiri Olsa , Kan Liang , Namhyung Kim , Peter Zijlstra , Stephane Eranian , Sasha Levin Subject: [PATCH 4.14 32/62] perf ftrace: Fix failure to set cpumask when only one cpu is present Date: Tue, 27 Aug 2019 09:50:37 +0200 Message-Id: <20190827072702.573643896@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190827072659.803647352@linuxfoundation.org> References: <20190827072659.803647352@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit cf30ae726c011e0372fd4c2d588466c8b50a8907 ] The buffer containing the string used to set cpumask is overwritten at the end of the 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 the cpumask string size. Signed-off-by: He Zhe Tested-by: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: Alexey Budankov Cc: Jiri Olsa Cc: Kan Liang Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Fixes: dc23103278c5 ("perf ftrace: Add support for -a and -C option") Link: http://lkml.kernel.org/r/1564734592-15624-1-git-send-email-zhe.he@windriver.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- 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 25a42acabee18..13a33fb71a6da 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -162,7 +162,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 */ cpumask = malloc(mask_size); -- 2.20.1