From patchwork Thu Oct 26 23:34:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shanker Donthineni X-Patchwork-Id: 13438004 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 B1901C25B48 for ; Thu, 26 Oct 2023 23:35:56 +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=f1DA+oFMJxLi60jmK6EiIAL5ObkjgpCl/6K+bEczKIs=; b=Q4jpWNhmfdWNK0 hqpe7w5yiJ2McvcY/DD4w+z1A+LKVUZzCY0O/j7NQ3LsPqFOrCCWcQUHTlVBiyAbjJ9TTokKa9hXE WLepwrwL+QrzCsuTn6GyqM12fB2r9nXlxOAfnxjcpVY5nGuvb910GWz//MMickcIZAXHr7+2VrLm0 pIukBX0muJVsppheDwMrTHNg7ZrwaW6dN8QXzhOoY9qGLHA7HG7ZeFrPdqd4uPJrogM0VDrLo3okk kTjZaRHktRj60I6YBprzU1G5v+UqLaha23M0evFCDv597DM5YYvm1M7b6+DRwxoFl4DpOBRRpDY+g jT1lXDKRUWXaQiLcA32g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qw9sk-00FJzK-3D; Thu, 26 Oct 2023 23:35:19 +0000 Received: from mail-bn1nam02on20601.outbound.protection.outlook.com ([2a01:111:f400:7eb2::601] helo=NAM02-BN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qw9sh-00FJyt-1w for linux-arm-kernel@lists.infradead.org; Thu, 26 Oct 2023 23:35:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O4LedsM5aHUo0oMo9e6sHpDNtmdIlj5UXtIHUrd2KP+c+wchm9RC8wrb6Qx9eNhu0Wuf5yJaQ5IMYghyTxGGb/mW/MeLW7ZLM/SBmChHnvExU8yl23zlZCPTtByeyENUMTTs5UaNnZaSJ1KFUzm9vYe6W2mGHIpR4EphfjIxZo/Xr54VManShh08NN7i1qGGOW9M3G0bEVtniyImU9DXc8LoFyx4p8eDFpVm6LejyrUcPIqiqqIO/2vNtnvJbCco0E90vqY+S08Bb/hPFSihKrkNxKDdCYcBtd3GAzIITPsWgwwbCavpxR1VEgEXY9/ZmAK4zqtPnDuO6yV1y+hPRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tZufazNGqP4oQxPmJeGMKAVXHNG4vCH6783rnXn6mXM=; b=b9dCh89/qg6xQJMv82KVTKNdu0k/QYou2AEdYzAs1Isza7LtzNMyI234kb6PijhbW/QwGuByfThNej0y+4/al1mAOoXTeuCEPc+FYiYLFuNutYsMVU0HpEub2PjyWHB+OOkKySvIwz0lVHGeYn7YtPS1+p4vFEpF7LWikq+XJNGp/yxUriplw6QkvwA//rZEHwyQwztKeP6SLmf3+ZaoIjBShuqAy2H6/iuNJGS7aLXDpSVVkNecwAycP0XF6TNTeg8XfRiok5FCvfoTivagcC01M9wKz2KmkX5eDq4EXxTXTnpfSxwSoSH2YjAq7Z534g7UCRf6cudGS7rOrsjOBQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tZufazNGqP4oQxPmJeGMKAVXHNG4vCH6783rnXn6mXM=; b=NLUX/veUaEZtUwyMPshx4zn4noo98xI8bnp/ch1LF8i2Wi9bTYcY+7BS708k8UcaapbqywS8ua20urO+31l8BYaC2IsXhBf40Rr40IrfUNfTkY26xWp6sY6WPNdBUebQtn2biIgtaoJhfOsBjQIUbUYY7oKlBbJGIepfmDggmZmNuGQNdve14R7CVckA1L9zyLqG3+LGhdMWvHY7GEKEM0ZzadsbxL42160gdn3lalbtlvrMHaeIrSdihm3Ayu4UUbyZs0WvPvP+//Nlsn5ugX27Y9LKJDMRJBVuWnalOhpeCWXpyN3YLAcSeOTIVtZKNI0KTIMC/0g5319CEtZN9g== Received: from BL1PR13CA0378.namprd13.prod.outlook.com (2603:10b6:208:2c0::23) by IA0PR12MB7532.namprd12.prod.outlook.com (2603:10b6:208:43e::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33; Thu, 26 Oct 2023 23:35:09 +0000 Received: from BL02EPF0001A101.namprd05.prod.outlook.com (2603:10b6:208:2c0:cafe::b2) by BL1PR13CA0378.outlook.office365.com (2603:10b6:208:2c0::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.19 via Frontend Transport; Thu, 26 Oct 2023 23:35:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by BL02EPF0001A101.mail.protection.outlook.com (10.167.241.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.15 via Frontend Transport; Thu, 26 Oct 2023 23:35:09 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 26 Oct 2023 16:34:59 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 26 Oct 2023 16:34:59 -0700 Received: from SDONTHINENI-DESKTOP.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Thu, 26 Oct 2023 16:34:58 -0700 From: Shanker Donthineni To: James Morse CC: Catalin Marinas , Mark Rutland , Will Deacon , Shanker Donthineni , , "Rohit Mathew" , Vikram Sethi Subject: [PATCH v2 1/1] drivers/perf: Fix kernel panic due to the invalid mon_ctx pointer Date: Thu, 26 Oct 2023 18:34:43 -0500 Message-ID: <20231026233443.3493667-1-sdonthineni@nvidia.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-NVConfidentiality: public X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A101:EE_|IA0PR12MB7532:EE_ X-MS-Office365-Filtering-Correlation-Id: 934695cc-3dc3-457c-1442-08dbd67c3154 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tV1YFFekDFLpBdfHl/OGMNjpRlusScrlhbAdpnEV/uxUeNmAmnDmHpCZE2Qfzt3lQ+9pAclwQjl/5U6gNC2/y+KH+5SDZg+QoE4BeGfH1z7mBl8Bfu6JPdK9EdEKGs2CmHQwqlgjLVeoNfCmLmD1LsPhss31y7wt7Ut/9KPshrvOfzFDL4q0dtbZWsgMkbOsqFH/ae4U0pT+HkJl/j71FQD4aRgfoc1jSyXT6rxlciwDXszmAzvPx/IUMJCVMgGbi5RwiizUJb/LvsXBL+uuKtM88IZVQPOx0a70X3f3hkuGa5XC8EfEtEVqRPi+sYBPEGyF24qXnsk7Q0znmOiP2MqEpTX5E6zsou/Pl2XREWJGD6q8mmjrIRYmgLHfnkrsyeQCCu79mMKqm7UA5o1cx+WMx2nQrMveSsP12XYRGfu7GYZeJkgvQy+3qb8Cl8JmdfNNf17kj0b+HFLWEIpoxP8eOs3E6KbLJoF5p0LxGo6pxSJWwd3vLEdeNQpYzkO/WinUqjxcTw+2cUuu4eCYlAIUqsb4hU2/UxPm3psj4mgXKzYwNGiGjpwBrRd4D3gVUtZowpg7bvFtQlgreYoupCrn1vk0ZrtpSCL0zsamosiauhCQetHucF/ogu7zVOSq31gmJDj9OTvLMEpbaN3X4SOXNaG09t7drPnCjLzYjsxD/th3o+TrBWK62TlS4jy+RyuzTUKO/recFbvtG8VMP4C1OK1w7PQpkwFd2DO/WVc= X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(346002)(136003)(396003)(39860400002)(376002)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(82310400011)(46966006)(40470700004)(36840700001)(26005)(2906002)(1076003)(40460700003)(86362001)(5660300002)(36756003)(4326008)(70206006)(8936002)(8676002)(7636003)(2616005)(356005)(7696005)(107886003)(6916009)(54906003)(478600001)(36860700001)(82740400003)(70586007)(316002)(83380400001)(426003)(47076005)(336012)(40480700001)(41300700001)(6666004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2023 23:35:09.2752 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 934695cc-3dc3-457c-1442-08dbd67c3154 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0001A101.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7532 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231026_163515_735146_B50A9E88 X-CRM114-Status: GOOD ( 15.74 ) 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 The return pointer from the resctrl_arch_mon_ctx_alloc_no_wait() function is saved in a 32-bit variable 'hwc->idx' which results in the loss of the upper 32 bits. This, in turn, triggers a kernel panic when attempting to access a corrupted pointer. Use 'event->pmu_private' instead of 'hwc->idx' to resolve the issue. Another reason contributing to the problem due to continuous 'error irq' messages. The resctrl_arch_mon_ctx_alloc_no_wait() function returns a valid PTR when it cannot allocate monitor resources, resulting in an incorrect MON_SEL configuration. To resolve this issue, return an ERR_PTR when monitor allocation fails dmesg: mpam: error irq from msc:0 'Monitor_Range', partid:228, pmg: 0, ris: 0 mpam: error irq from msc:0 'Monitor_Range', partid:228, pmg: 0, ris: 0 mpam: error irq from msc:0 'Monitor_Range', partid:228, pmg: 0, ris: 0 ... mpam: error irq from msc:0 'Monitor_Range', partid:228, pmg: 0, ris: 0 Signed-off-by: Shanker Donthineni --- Changes in v2: -Use 'event->pmu_private' instead of 'hwc->idx' to keep monitor context -Return ERR_PTR if unable to allocate resource in resctrl_arch_mon_ctx_alloc_no_wait() drivers/perf/resctrl_pmu.c | 12 ++++++------ drivers/platform/mpam/mpam_resctrl.c | 23 ++++++++++++++++------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/drivers/perf/resctrl_pmu.c b/drivers/perf/resctrl_pmu.c index 99a2b90b5d83..1531c8c6fc31 100644 --- a/drivers/perf/resctrl_pmu.c +++ b/drivers/perf/resctrl_pmu.c @@ -66,7 +66,6 @@ static struct rdt_resource *resctrl_event_get_resource(u16 event_num) static void resctrl_pmu_event_destroy(struct perf_event *event) { - struct hw_perf_event *hwc = &event->hw; u16 event_num = get_event(event); struct rdt_resource *r; @@ -74,7 +73,7 @@ static void resctrl_pmu_event_destroy(struct perf_event *event) if (!r) return; - resctrl_arch_mon_ctx_free(r, event_num, hwc->idx); + resctrl_arch_mon_ctx_free(r, event_num, event->pmu_private); } static int resctrl_pmu_event_init(struct perf_event *event) @@ -144,9 +143,9 @@ static int resctrl_pmu_event_init(struct perf_event *event) return -EINVAL; } - hwc->idx = resctrl_arch_mon_ctx_alloc_no_wait(r, event_num); - if (hwc->idx == -ENOSPC) - return -ENOSPC; + event->pmu_private = resctrl_arch_mon_ctx_alloc_no_wait(r, event_num); + if (event->pmu_private && IS_ERR(event->pmu_private)) + return PTR_ERR(event->pmu_private); event->destroy = resctrl_pmu_event_destroy; local64_set(&hwc->prev_count, 0); local64_set(&event->count, 0); @@ -183,7 +182,8 @@ static void resctrl_pmu_event_update(struct perf_event *event) prev = local64_read(&hwc->prev_count); err = resctrl_arch_rmid_read(r, d, closid, rmid, - event_num, &now, hwc->idx); + event_num, &now, + event->pmu_private); if (err) return; } while (local64_cmpxchg(&hwc->prev_count, prev, now) != prev); diff --git a/drivers/platform/mpam/mpam_resctrl.c b/drivers/platform/mpam/mpam_resctrl.c index 1a691535d23d..8ec963aca9d4 100644 --- a/drivers/platform/mpam/mpam_resctrl.c +++ b/drivers/platform/mpam/mpam_resctrl.c @@ -318,28 +318,37 @@ struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l) void *resctrl_arch_mon_ctx_alloc_no_wait(struct rdt_resource *r, int evtid) { struct mpam_resctrl_res *res; - u32 *ret = kmalloc(sizeof(*ret), GFP_KERNEL); + u32 *ctx = kmalloc(sizeof(*ctx), GFP_KERNEL); + int err; - if (!ret) + if (!ctx) return ERR_PTR(-ENOMEM); switch (evtid) { case QOS_L3_OCCUP_EVENT_ID: res = container_of(r, struct mpam_resctrl_res, resctrl_res); - *ret = mpam_alloc_csu_mon(res->class); - return ret; + err = mpam_alloc_csu_mon(res->class); + break; case QOS_L3_MBM_LOCAL_EVENT_ID: case QOS_L3_MBM_TOTAL_EVENT_ID: if (mpam_monitors_free_runing) return mon_is_rmid_idx; res = container_of(r, struct mpam_resctrl_res, resctrl_res); - *ret = mpam_alloc_mbwu_mon(res->class); - return ret; + err = mpam_alloc_mbwu_mon(res->class); + break; + default: + err = -EOPNOTSUPP; + } + + if (err < 0) { + kfree(ctx); + return ERR_PTR(err); } - return ERR_PTR(-EOPNOTSUPP); + *ctx = err; + return ctx; } void resctrl_arch_mon_ctx_free(struct rdt_resource *r, int evtid,