From patchwork Wed Apr 3 07:02:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 10882941 X-Patchwork-Delegate: lenb@kernel.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 151B41575 for ; Wed, 3 Apr 2019 07:02:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1BDD289D2 for ; Wed, 3 Apr 2019 07:02:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E5968289D4; Wed, 3 Apr 2019 07:02:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B9FD289EC for ; Wed, 3 Apr 2019 07:02:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726048AbfDCHCW (ORCPT ); Wed, 3 Apr 2019 03:02:22 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:39569 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726004AbfDCHCW (ORCPT ); Wed, 3 Apr 2019 03:02:22 -0400 Received: by mail-pl1-f196.google.com with SMTP id b65so7552892plb.6; Wed, 03 Apr 2019 00:02:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=jNVqIdkQAScEraNgcu9ceQ0w+kYTL5wKNdPzTcIDlJY=; b=luXAbXnDU/p+ppmXlPcONno4pW0wV7ew0QOa4GTHSfrsGEEqoCiiHcQFJg1AtnnwaL LMEgHqfMJ75JgaXHUgFa1XCwqg7keppAEGUEO+UthIXK1p6VpbV4jZiW2/JbnKG0s8d8 Cq/l2pz45Upw3b1s+XcDkoGkWVaL3vdGthJZfhIATfF7/UxhHHYRnss9FbQK26DkbOwA P2aCRnTvRpN4XraKBFkkAHTMQHYcab6eu/M4uAIU7f9TZTHL7Dg3lHFxZgi3w+di5lrT zT5fDLjW/ghrt7o9PxKPQnoVHVRcgdVM/JteOP8OKGaQxE4347cJhX3K/DIcOBJqzycP JHFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=jNVqIdkQAScEraNgcu9ceQ0w+kYTL5wKNdPzTcIDlJY=; b=uKMtRpAQVOkvnLw1AKVZjcmmd22VFkzTi9yiDCYBP5TGvWuCqK2/b9FStfZaaE+sVn pa2ZYmghIvOBaj77n8hXYEamPFq7WQez3b4VlAvSDj9lSmAWb5OABIJdGRCIVg/RmBft RkjKJxw6P0hBu46THSgMbcCpJFeAxwILZ+0gNXX1YylQtWbUNapSzlobtcfchhZxTj/U Qkt2TrP4Rp7ThwcAN+eM0jeakveRfmE/9wWuCbNDfqP7st06r4Zww4zWY/KCSUHFQDlp 8k/q1yOQfJRKsxZpHyyvqhSAsSlAEXfYgt2b9yC8XpFGuhZ0wurQezClsCrTvIFjUnrq jycA== X-Gm-Message-State: APjAAAXMUXQK1JaSc2VMxkF32g7QkVbpMER5v+g4oBzcKNncIjDLo1rI sytT1RrqWEaI0wl4tiyEqTJ5Hss= X-Google-Smtp-Source: APXvYqyqo8W/vbheA5rzlhe+jJh45BQlslGVg0jAkAzAU570ZVghufi+XzcamzUkx8ZU+NWa7JTxyA== X-Received: by 2002:a17:902:6b8a:: with SMTP id p10mr75622852plk.109.1554274941649; Wed, 03 Apr 2019 00:02:21 -0700 (PDT) Received: from www9186uo.sakura.ne.jp (www9186uo.sakura.ne.jp. [153.121.56.200]) by smtp.gmail.com with ESMTPSA id v6sm19121830pgv.92.2019.04.03.00.02.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 00:02:20 -0700 (PDT) From: Naoya Horiguchi To: linux-pm@vger.kernel.org Cc: Len Brown , "Rafael J. Wysocki" , Prarit Bhargava , linux-kernel@vger.kernel.org Subject: [PATCH v1] tools/power: turbostat: fix buffer overrun Date: Wed, 3 Apr 2019 16:02:14 +0900 Message-Id: <1554274934-12649-1-git-send-email-n-horiguchi@ah.jp.nec.com> X-Mailer: git-send-email 2.7.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP turbostat could be terminated by general protection fault on some latest hardwares which (for example) support 9 levels of C-states and show 18 "tADDED" lines. That bloats the total output and finally causes buffer overrun. So let's extend the buffer to avoid this. This patch also removes duplicated "pc10:" line to reduce buffer usage. Signed-off-by: Naoya Horiguchi --- tools/power/x86/turbostat/turbostat.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git v5.1-rc3-mmotm-2019-04-02-17-16/tools/power/x86/turbostat/turbostat.c v5.1-rc3-mmotm-2019-04-02-17-16_patched/tools/power/x86/turbostat/turbostat.c index c7727be..17b1f544 100644 --- v5.1-rc3-mmotm-2019-04-02-17-16/tools/power/x86/turbostat/turbostat.c +++ v5.1-rc3-mmotm-2019-04-02-17-16_patched/tools/power/x86/turbostat/turbostat.c @@ -861,7 +861,6 @@ int dump_counters(struct thread_data *t, struct core_data *c, outp += sprintf(outp, "pc8: %016llX\n", p->pc8); outp += sprintf(outp, "pc9: %016llX\n", p->pc9); outp += sprintf(outp, "pc10: %016llX\n", p->pc10); - outp += sprintf(outp, "pc10: %016llX\n", p->pc10); outp += sprintf(outp, "cpu_lpi: %016llX\n", p->cpu_lpi); outp += sprintf(outp, "sys_lpi: %016llX\n", p->sys_lpi); outp += sprintf(outp, "Joules PKG: %0X\n", p->energy_pkg); @@ -5135,7 +5134,7 @@ int initialize_counters(int cpu_id) void allocate_output_buffer() { - output_buffer = calloc(1, (1 + topo.num_cpus) * 1024); + output_buffer = calloc(1, (1 + topo.num_cpus) * 2048); outp = output_buffer; if (outp == NULL) err(-1, "calloc output buffer");