Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1684968rwo; Wed, 2 Aug 2023 19:54:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlFAcXxveM8GFGLqpWNiQd11X5NrI5aRhq56Mbv4HJBE3q28obuNmCQT5F7khNRB4PIkWJxt X-Received: by 2002:a05:6830:1685:b0:6b8:7166:ea5a with SMTP id k5-20020a056830168500b006b87166ea5amr18372219otr.13.1691031249641; Wed, 02 Aug 2023 19:54:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691031249; cv=none; d=google.com; s=arc-20160816; b=Y5Mk4J7kZrL4V+LjgB4Lq5HgfeY9cxTbqQOCoEySmPQVsyWFhBpVJr2LHfISURQ0bz diJgXUH9X/SRIp0og7kF/75Umhn9d03XREXPzOzaaHS5YAPbeM3jUM9GQcS4mrtk0qBl d9Gi6u7thjzZYGNVzSmEHTPZnMs1bEUGbSlVTYVlARQCpVf31LE9PvE0sgvib39LVW57 s2KfeIxNiJRMzUVpTsSfS3bxcXZiwVlhA389fTc3/zN0e1nhAc3GrSHDMKABnqOaXDMl yy+k8dwXte6U5SBa6vA9zM4taYBxs4SYXk21um24THVc8XaOBV/pr56OlnBTmPc41OO3 4yWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=/ihqBqvzNWhK9ZQKkzjrfJNOrWzI5PPLcJ/AmPq+ONY=; fh=vYLmehEgNlGZdj3CbAwXax39O2v1aVJ34zckEg2qnf4=; b=LKtFKOY3yJlvkl6ee8QThXh1UO+D60e0DtOu1SXJPfT8OaiUmyU42w2lvR/VEbCvBv C4nFTnDJXos3mBwq3+tb++MYQTkyIzEA+1tiKY19s0UsfDoSQ/I8RYCLzghz8GYHYZlt hg3AJFeyidOmwLwM+vS1OMr4k9I6M2kF4JvIYnz47DuPFjJdaJ4/ZLYGhwnEgACt+Eci iZ6XIjlMSJVraZur8vZTGT7eVIBogZxb/nNjO8cl4JwLHi6TIfx95D/yY1F4uLnlnHDi Rl4n4+u8w7PgJIm7wG5fCJZbpvIFzuymXVROZ/CJiQ0tMN7Cpcw96kLumjIsf5y/muc4 OwLg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nu17-20020a17090b1b1100b002568a675b65si2308156pjb.141.2023.08.02.19.53.57; Wed, 02 Aug 2023 19:54:09 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233700AbjHCCfq (ORCPT + 99 others); Wed, 2 Aug 2023 22:35:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233051AbjHCCf0 (ORCPT ); Wed, 2 Aug 2023 22:35:26 -0400 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1E603A9D for ; Wed, 2 Aug 2023 19:33:28 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=tianruidong@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0VowzZp3_1691030002; Received: from localhost(mailfrom:tianruidong@linux.alibaba.com fp:SMTPD_---0VowzZp3_1691030002) by smtp.aliyun-inc.com; Thu, 03 Aug 2023 10:33:25 +0800 From: Ruidong Tian To: tianruidong@linux.alibaba.com Cc: alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, mike.leach@linaro.org, suzuki.poulose@arm.com, james.clark@arm.com Subject: [PATCH v2] coresight: tmc: Explicit type conversions to prevent integer overflow Date: Thu, 3 Aug 2023 10:33:21 +0800 Message-Id: <20230803023321.111078-1-tianruidong@linux.alibaba.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20230714084349.31567-1-tianruidong@linux.alibaba.com> References: <20230714084349.31567-1-tianruidong@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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 Perf cs_etm session executed unexpectedly when AUX buffer > 1G. perf record -C 0 -m ,2G -e cs_etm// -- [ perf record: Captured and wrote 2.615 MB perf.data ] Perf only collect about 2M perf data rather than 2G. This is becasuse the operation, "nr_pages << PAGE_SHIFT", in coresight tmc driver, will overflow when nr_pages >= 0x80000(correspond to 1G AUX buffer). The overflow cause buffer allocation to fail, and TMC driver will alloc minimal buffer size(1M). You can just get about 2M perf data(1M AUX buffer + perf data header) at least. 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); -- 2.33.1