From patchwork Fri Jul 14 08:43:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruidong Tian X-Patchwork-Id: 13313272 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8C751C001DF for ; Fri, 14 Jul 2023 08:44:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=SpcJZ1XGt4sSYEmyJpUVBAlJ8iDrKxo8ol1e74VA5+c=; b=etAmdxrEwmRrHO ZWND40e/7hz8CZG/UFwwtSEOTPYh/uWamofLADtUbScNRk7nhmilpDXS6Y3dvFC7sFOsPLx0LOhq2 9hYErnaIr9QdnKTLI1xWpnmbCnpktZpUuXj4tam/jmuEA8ew66xEy1mUwbzCQ+yNavsHyQoD5Y4vc iCj2vS1Md/cDXxnT7IgioXlwLINv26Z9BaEBS21XgrU4ibYn1jaDTefCMZvAQWympyGRhQLZPLTP9 0rvcwGCPNNHjFHjFGuv6TQv4eftna2BXQyrsXafzQz7d380x/uTtmjhG9wsz4PFTSEJZBzGK0Njze DD5VwGTik8drz0xGaWRw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qKEPN-005YPr-1d; Fri, 14 Jul 2023 08:44:13 +0000 Received: from out30-131.freemail.mail.aliyun.com ([115.124.30.131]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qKEPI-005YMK-2z for linux-arm-kernel@lists.infradead.org; Fri, 14 Jul 2023 08:44:12 +0000 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=tianruidong@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0VnLFqNR_1689324233; Received: from localhost(mailfrom:tianruidong@linux.alibaba.com fp:SMTPD_---0VnLFqNR_1689324233) by smtp.aliyun-inc.com; Fri, 14 Jul 2023 16:43:56 +0800 From: Ruidong Tian To: tianruidong@linux.alibaba.com, coresight@lists.linaro.org Cc: suzuki.poulose@arm.com, mike.leach@linaro.org, alexander.shishkin@linux.intel.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RESEND PATCH] coresight: tmc: Explicit type conversions to prevent integer overflow Date: Fri, 14 Jul 2023 16:43:49 +0800 Message-Id: <20230714084349.31567-1-tianruidong@linux.alibaba.com> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230714_014409_459395_BED5C43F X-CRM114-Status: UNSURE ( 8.50 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Perf cs_etm session will failed when AUX buffer > 1G. perf record -C 0 -m ,2G -e cs_etm// -- taskset -c 0 ls failed to mmap with 12 (Cannot allocate memory) In coresight tmc driver, "nr_pages << PAGE_SHIFT" will overflow when nr_pages >= 0x80000(correspond to 1G AUX buffer). Explicit convert nr_pages to 64 bit to avoid overflow. Signed-off-by: Ruidong Tian Reviewed-by: James Clark --- drivers/hwtracing/coresight/coresight-tmc-etr.c | 2 +- drivers/hwtracing/coresight/coresight-tmc.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index 766325de0e29..1425ecd1cf78 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1267,7 +1267,7 @@ alloc_etr_buf(struct tmc_drvdata *drvdata, struct perf_event *event, * than the size requested via sysfs. */ if ((nr_pages << PAGE_SHIFT) > drvdata->size) { - etr_buf = tmc_alloc_etr_buf(drvdata, (nr_pages << PAGE_SHIFT), + etr_buf = tmc_alloc_etr_buf(drvdata, ((ssize_t)nr_pages << PAGE_SHIFT), 0, node, NULL); if (!IS_ERR(etr_buf)) goto done; diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h index b97da39652d2..0ee48c5ba764 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.h +++ b/drivers/hwtracing/coresight/coresight-tmc.h @@ -325,7 +325,7 @@ ssize_t tmc_sg_table_get_data(struct tmc_sg_table *sg_table, static inline unsigned long tmc_sg_table_buf_size(struct tmc_sg_table *sg_table) { - return sg_table->data_pages.nr_pages << PAGE_SHIFT; + return (unsigned long)sg_table->data_pages.nr_pages << PAGE_SHIFT; } struct coresight_device *tmc_etr_get_catu_device(struct tmc_drvdata *drvdata);