From patchwork Thu Jul 25 19:33:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13742102 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 8B5FBC3DA49 for ; Thu, 25 Jul 2024 19:35:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=Se9rtGe0gsx2t28vr9Hga6+vIF8IF05glvFWcgoTFuw=; b=Y6L0K3qgitwSghOZqVkjVdNDJs FZsGhkWzTatCK+ym+bnL7Dym+B1hMn09ObDhyworFKBM89mf1kXXK/JuOrzdJcaaoVTQrr8H4InMt Rge2IROcPKIFD3GzyCV42t5a8y7jh7a0NtfBSRgMOZS6lbSJEvCppfEWiiykNr7C/mkYEp2mFT1W0 k2bSaudNZnbOJxI8ZXo+WHS5amynk7db4CVsXAFf5UVylbdv7/kmA7J4A1H8loYZb7tBb10IwJbx3 OLWMkBgNar4M4dPihczSivYXPz8lK4q7OwgEZbXte0BKfVThKf6vMl1Co10/OYUSLIjL2NT7ivwam jAmx3iMw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sX4Ee-00000001uZ8-3qB4; Thu, 25 Jul 2024 19:34:44 +0000 Received: from mail-northeuropeazlp170110001.outbound.protection.outlook.com ([2a01:111:f403:c200::1] helo=DB3PR0202CU003.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sX4EF-00000001uRQ-0w4z for linux-arm-kernel@lists.infradead.org; Thu, 25 Jul 2024 19:34:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SrWRSJWoNp6wXDwfV9e3VvT6j23u/U1Nxu5iCDjGlreLUbJjl4MEOW13VVA/rCB1nu/W1VplpAaiXfXtelQcZ4UNJg7UGrGkK9SwzUlT/LbYEraZhElRhUr1nMCEb62hywtMB4i58vFk/CIKFylyHxf1dMTbAehgO9Nov7yQFTclIP6IvrOuZs4WbWto4h9BmkgLZoNwkIhhRKmQIDNkzYncRV9+zCDPmqLYamwLpPQ0ouwaLtSUOJFsuQ3fTIf0z4buio7eB8/fNG/RfJP7heKonpXEyN84ir87akwye10enUmGAz9qu3M587XbSCrBmfBCXR2YjYJACLMg2YG0sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=Se9rtGe0gsx2t28vr9Hga6+vIF8IF05glvFWcgoTFuw=; b=t45UWM/hbnGQ2YmQ/1BclzmgyxvB1F8HwuiyoaxJr9/hyUIzOocni5de4ZeoK38lB7bbIHLaonqMOo7jwT136F6+rkgYFmLyY7DgEwJtB879VJEkXj0hSPQfz1FAc/fy0pgcoyJB0g28Kaw7cf4MJqqE2l5w+aVe0rQ412WWT6Otyl4eZr3sJU4yu7FcoAROW1Mw7PsEvexlrack+oFCz6bPXZMltKv6NmVP/9bntYNlIngNpUOOgcwWBdHzxht08aoTRLRZLQkfXD537bzZN/5IZSUfcp6ITEP6nO6NdVvTdczbagnWRkBRx0T0EoxhLEVmmfpapdqOMKJSqVUNfQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Se9rtGe0gsx2t28vr9Hga6+vIF8IF05glvFWcgoTFuw=; b=EJZ8RF1O9f2/FOY5D5guaoTHW3UqaA5k8dhcTA8LKd6jOvRSmIDGRl8Gu5T56ziScRzLvLi24gf6ARccv5/d3x+dMjaV29WzEJ946v44H7JB4cuhbEZyHMmSSuo36qYuzw3SGVaSp4YlA1nCcotWbODrxgQq7UtZNeeBYteKP6/fGVJpP5JlG1VyeE+/oyccxtSNTmWVLtQalInaGKApzCorHv/MvPzUmKmIX85ZkG8M5NQTTcnxYKmbR+6PZGqlEGPURRn3jbmmNQZpk7an11CCsYWiSQJT++7v8YVKJgl1HOW6EbZA971jRhS2ZM2a7L02hnVDpg9Lf2ayMGBfWA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by DU2PR04MB8791.eurprd04.prod.outlook.com (2603:10a6:10:2e2::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.28; Thu, 25 Jul 2024 19:34:15 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.7784.017; Thu, 25 Jul 2024 19:34:15 +0000 From: Frank Li To: Daniel Lezcano , Thomas Gleixner , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Dong Aisheng , linux-kernel@vger.kernel.org (open list:CLOCKSOURCE, CLOCKEVENT DRIVERS), imx@lists.linux.dev (open list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE), linux-arm-kernel@lists.infradead.org (moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE) Cc: imx@lists.linux.dev Subject: [PATCH 1/2] clocksource: imx-tpm: fix return -ETIME when delta exceeds INT_MAX Date: Thu, 25 Jul 2024 15:33:54 -0400 Message-Id: <20240725193355.1436005-1-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: BYAPR02CA0062.namprd02.prod.outlook.com (2603:10b6:a03:54::39) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|DU2PR04MB8791:EE_ X-MS-Office365-Filtering-Correlation-Id: 61d9fc54-e00a-4336-08ef-08dcace0c46c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|376014|366016|921020|38350700014; X-Microsoft-Antispam-Message-Info: 4G2Q9Sp+C1qrVElvvdMZC0hEfSqS1zb9UTXDlNcdFZk5Ge+ALF1T6bkomNA8ZNrHpa11ZNfbo5QI9w7MFQSnlmea9Hn3pyrvofrBTC+gE6FbdIBBGa207NVQZfCZ0Z5Ur5YKpnD4daN3be4Fw4v5Ao44vt6voIjsFWLtIb4L6lKWKyr1LzSiUpKcnybPeQv9oaMCfHXZkej0aIFWYRKIbsU/0BqNXj/MRagOwCWIuwW4GkhQaseVfC/TjkKovJZcr5C0wVUt160S2JyENdeMRql9rqQXx7+5kH04T3iq5N7W7kgZbFrCoU38je7r7fW2uh6iHJo23zi/s/c0BGhecMdZ//2Adqo936q5AD3bT3+4aiO54jMGy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efront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(52116014)(376014)(366016)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ASg/prKSCNXmZmYSKDtQF3KB7S4uLP9wG3WWGlXYi2cf6LsKg0+i8g0VxayWRMsyBsfT2vdotHFuA17G6n0eZhrCD9IufzsLH9SUwjFEvyZPPgjMZ5SgeM9D0TzUMI/ay26qIrz/PSYUrXZ77ojW/+w/gZOLwZZ03x+Pc3V69VwtZ27QEJ4iH9suk0Cd4IDd6bVEOxl/aZVd320BBZVxdHdBhAC1UtqhBdby96VOdGS6a8nFAKs0hzDmKVKutUq8fqS+xXDS4mlzrwIIv9rqVlUbMU0cU/swM8Rv1LBX8tCVYfwJpBYukCgqr6th511GTvYTkM9cvi4JxYdqicowK8WjvN4rix3mjIK9h5l0rynmXUq82BskuicOb3VGlaIzEte9MLr5TpScBNKiIv+9Xu8+MK+f/Ox1tz6nWwscDTYMCxtEDHGLL3EYtDHCVTRuulX2z38D56hVu0xMx8wgVVOmeO0HeaE9gWc40gvCNl3zfFazMEH2s8qsY/GfIDOKvTiIv8zN0wwf1X0YWQXXngD/soWECD9PX2m/xhGvlEhiPnzj4/Xu6G7YFefp+/awtATCtXUKLiiCdDt7P1IZuzOwMZ77/qhF+W1JrXHDYYkD/o+woQEt46g/QAxEHIApiU0hmXF5DpoyWzaE3RokTiUN5UMN+fD+AehcbsWVRFhEz5r0vdaK/jdePp6Ayy2dqOx5OTTsoaJh0rq+tNcICUdJ0v3m4Zlh2s12B0J+bAZHWx2i8tpxtVylriqJ6HJPDm8mtH0EiNAwijgFKr9f4oayyl6I3G+y2kKgv3FwEomXNX9GRyL4vedZnHOauqs7t6E2hcXoxS1g49/yYAufjQ4YByJic67vjETaaZHSzQ4nEPaCrk0WnlpBr3EstvGTOAc9GmMmATi6Ndzjx5i0A1Kf/on2/YywV4ypSUWDIyjB6vi3cyoxnV/JFiHtsqJXlgfICC/2E6au4NMUhVHHOZsu6x3G8jY0PWzLWOFCRgvE6jRZ00OtD/AYjrCwdjty8Y/O1V01xx1iqVqX9NGnDFiFldJhfe/cDtUoY7Ej7RlZF8dIzWXGhH6VQvfwhh6bFf7nhctqNSWY2siaLIb9lM9/69gxstbs7Szm3J7IJOUD897GaxpNuXOKBKKI6N92q8rI4HoKAPOl1JwTR4AjAeOrcZMDhDLcLJsIAC5qfcvs00lPYqOPo6bdfSrCJ8EmAxC8KsW3wFpgBpnjCVVUIfCH9hPrXROwweFsghjt4vg1YqMmLjJIfDWbiRBFDssPf72le+ShwakNZXrrLd5Gu0r65Irp9SGxhe4ewCNGGzUyB8quve31vlSVicIrJ63iiokuvV7M8ZuPgfjaTqLtdgGOpLuUM7SVadHetou0LaREVcSGIv7yu4rH/536dVhOonZNICEBXRZd1eYcRG7DfVlY8qhRw4BX7KgoKWoSv+FCNDl2dFmt3l7mipFVhymRJiGyFGAsS/KIRWGciZNO0e+MOxH6TXtu/RVWqJpSvKMR5iHBb3ild3IYIUboa8/1aQMoTUnOBCZzzBkwnG2QMS6LQ5CWhKSBmqusOcEBQRwIH4nR8P8yLc9zrSw3I//w X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 61d9fc54-e00a-4336-08ef-08dcace0c46c X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2024 19:34:14.9666 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: eRT0HLDDcNE75z2z2ZK8D6JNVQ17SQ04WekjT5KO/kDuyyf13D3d6rT4Zsp6F/RpC1nkmGotqz/lXNmvh7xFAA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8791 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240725_123419_336306_48391ED3 X-CRM114-Status: GOOD ( 13.71 ) 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 From: Jacky Bai In tpm_set_next_event(delta), return -ETIME by wrong cast to int when delta is larger than INT_MAX. For example: tpm_set_next_event(delta = 0xffff_fffe) { ... next = tpm_read_counter(); // assume next is 0x10 next += delta; // next will 0xffff_fffe + 0x10 = 0x1_0000_000e now = tpm_read_counter(); // now is 0x10 ... return (int)(next - now) <= 0 ? -ETIME : 0; ^^^^^^^^^^ 0x1_0000_000e - 0x10 = 0xffff_fffe, which is -2 when cast to int. So return -ETIME. } To fix this, introduce a 'prev' variable and check if 'now - prev' is larger than delta. Cc: Fixes: 059ab7b82eec ("clocksource/drivers/imx-tpm: Add imx tpm timer support") Signed-off-by: Jacky Bai Reviewed-by: Peng Fan Reviewed-by: Ye Li Reviewed-by: Jason Liu Signed-off-by: Frank Li --- drivers/clocksource/timer-imx-tpm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/clocksource/timer-imx-tpm.c b/drivers/clocksource/timer-imx-tpm.c index bd64a8a8427f3..cd23caf1e5999 100644 --- a/drivers/clocksource/timer-imx-tpm.c +++ b/drivers/clocksource/timer-imx-tpm.c @@ -83,10 +83,10 @@ static u64 notrace tpm_read_sched_clock(void) static int tpm_set_next_event(unsigned long delta, struct clock_event_device *evt) { - unsigned long next, now; + unsigned long next, prev, now; - next = tpm_read_counter(); - next += delta; + prev = tpm_read_counter(); + next = prev + delta; writel(next, timer_base + TPM_C0V); now = tpm_read_counter(); @@ -96,7 +96,7 @@ static int tpm_set_next_event(unsigned long delta, * of writing CNT registers which may cause the min_delta event got * missed, so we need add a ETIME check here in case it happened. */ - return (int)(next - now) <= 0 ? -ETIME : 0; + return (now - prev) >= delta ? -ETIME : 0; } static int tpm_set_state_oneshot(struct clock_event_device *evt) From patchwork Thu Jul 25 19:33:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13742103 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 EA73CC3DA5D for ; Thu, 25 Jul 2024 19:35:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To: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:List-Owner; bh=QekM0muMH05kCvJf8WblyLADqXuVT928CCeuFdA9sLQ=; b=TCthpadv2tRHV9MFn2WrZwHtlS ccV0rFJNQLtdTsM0K4EiMFhgn3u9r4QKJ/iPp6jJG+6dZFXLOZHKW3Aa53JbPafA5I7AH1qkggew/ 7Y8tsEm4bu0Q2x9m95mjHc+L0NBiA0sLtZec9uV+iC3Omxf9pi3GYhrnc3HlHk+MMWZCm5+jYfaVX MVHVn8Ntaw+n1yfOmCktNf5QG/oecdn5KwiRx0iCYnjC72cMZg0YCzi0aSbahaJf7Zx9jJ8PMZAwO XIz0HDU/oX9dymgDI+dMQKQomu7rOkqMq4d5fKc/GyeN9ivT6gWLcel2JgyAuAmtGew4hJ8MlLqbq IXvfm5UA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sX4F0-00000001udp-1mFM; Thu, 25 Jul 2024 19:35:06 +0000 Received: from mail-northeuropeazlp170110001.outbound.protection.outlook.com ([2a01:111:f403:c200::1] helo=DB3PR0202CU003.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sX4EH-00000001uRQ-3xvH for linux-arm-kernel@lists.infradead.org; Thu, 25 Jul 2024 19:34:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=X++lXOunx0+JwbNTWv4z2lHMxxC0EiIRi3RD16AP5Mm3BNeOTZEIPgQJnZyJOKtWkwCS82JdfU1feZ5foZNoJ8HMEyoFi3PubLPJyPAnVIR+Hivyu4kUZuAuN3MHIErT9keWTvk2lhfP8BkW1Y7lE/WH9h+T13Zxg8HDpkNXqIz39GwkblCaw930FwilLQeugGmpR83y0omaor3qffmq0IsHN3Cq8lPuUPyityoCvHe2SniVJSlrHVE4BHiBFAK4r1hWWwFM2Hlkfq99JrywAgR2It96X6w3A2ktFdJfN7x3tHht2+EclMX8DqjrsriracF837nwq7Jjp7TOvqgTEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=QekM0muMH05kCvJf8WblyLADqXuVT928CCeuFdA9sLQ=; b=InBOwHTS2yL08D+tGBvsgvVhsJ9SbeUEj5WbednLh9ueUgUtQYv9ITHbDWH09bFlOm/GTOceY/UEE4ebH6ll8vf4X365CuyrGTgzej76Nr6vnHu3sOKlCWgdg7Np8pwEHU49K3HnbEnpbmwvRUFBelZXU6lkWxzt+WjohYPMqY9AVMgEdimxRsjZIzCT2FO2pMsRSap4M75b2c2zNJhQp8vTRESDqKWsa9P1BPjOqeTOIEG5jN6yOhNPNUlMY0aJq8wzts4u74PkiQh3h0IYkxbrL75iPZP5agThY3boW4NmicIgOa5TMTvwleVDFgkBpHIFLAxxVk+B+Roii8Or+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QekM0muMH05kCvJf8WblyLADqXuVT928CCeuFdA9sLQ=; b=YUiGqi9kZ3OTlaKxsRNxstbyeord1vBTwdzwCF4dCAXyWtxMJrwFhRr/0uEaKak1Q/3KrgA8ikJMfKk/VqWjknTxoaN1hJum/wPJKxhIJ7hMZEvedjGthz/ZcsAlL4lzhkFe0HkWHltEohI0HXriJk9xfQaxezsiOn54Kq+c4S4xuKxWcMsah3ECGhxezKASHn/pxBzkkXIRvAL0PCCTsDcxQ3QEVB0Aepk9RPFtFHlKeefHanlqh0Or5xMOpfbdEa+4N4mgZwjZkWENgMaFkLvq5Ek5pg3zZUfZZD7qVLTp973Icvo8PlJEZaaWKci4PNttcttKdLxuwmRPF+x00g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by DU2PR04MB8791.eurprd04.prod.outlook.com (2603:10a6:10:2e2::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.28; Thu, 25 Jul 2024 19:34:18 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.7784.017; Thu, 25 Jul 2024 19:34:18 +0000 From: Frank Li To: Daniel Lezcano , Thomas Gleixner , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Dong Aisheng , linux-kernel@vger.kernel.org (open list:CLOCKSOURCE, CLOCKEVENT DRIVERS), imx@lists.linux.dev (open list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE), linux-arm-kernel@lists.infradead.org (moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE) Cc: imx@lists.linux.dev Subject: [PATCH 2/2] clocksource: imx-tpm: fix next event not taking effect sometime Date: Thu, 25 Jul 2024 15:33:55 -0400 Message-Id: <20240725193355.1436005-2-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240725193355.1436005-1-Frank.Li@nxp.com> References: <20240725193355.1436005-1-Frank.Li@nxp.com> X-ClientProxiedBy: BYAPR02CA0062.namprd02.prod.outlook.com (2603:10b6:a03:54::39) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|DU2PR04MB8791:EE_ X-MS-Office365-Filtering-Correlation-Id: 84afb012-8043-4962-4822-08dcace0c647 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|376014|366016|921020|38350700014; X-Microsoft-Antispam-Message-Info: LEca3I948bmu0rln+7GYQKdMzly8aZZt1KFYLsf6cvn50iS07rstr2SsAi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6Vf2rFt5llEwrSeqC05GyybPhJ4uXcLDTs+Uu8TeqYSgrtw9nzUKMv/fI0v45k3BpnsB67jEpocuBcAkv7pHsOnL5FSWJ4mMVLJcnAP3gaf7HvoiWAquBjUQNraULehv+CrgOCSGY7lZwHJIcYbeqIXRHQ+bnAEyq++282ZbV8+1eggNqOdskTlPZR9kOEJQXCItOe8oOlyuHKcnKCdj6hio3ukX4a0HlePxyZ5yEr6fdVNAt5K4rA7zsA27d0V3WRCJDkS/CKZlsQqh0OdiC2uFXAQIFxIFAYu8JSvv5u8+SSgT2lJc6qlG9eTNaGU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(52116014)(376014)(366016)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GubiVGbbOSZu+31szOseyVpSAYeEWuIO7BGIt6n3CpedbUcNGqigE38cPJ38MSWkbCugnULHloUdHqFUkc9eoTb83zBvRCYAqJvrlNupK3+G+04/fz3MyHZGge0p7cnQ7d0YlajhwCy+gFY8w6qZh4McInQTggK/ekH92aimheCXgO3Q4XATn5dh7NuErR3Lwzj/s+/k4ePQWHDbg200wrNXag4FEu4d8YSqpiq8T+m7IYDaHaDoqD8en7vl11ldDpx7vI6fNR8RI3cgX0/KAnZrcC2tnYty5xU79S0pQiH460EGzRZyRLSF4jDMbuZ52ad9B7bSA3V7ZpG/6zhXESyGdhWg1hslVfnQCc8Ejq3O4J2P/wLhXYGt6Tl1wijquOWgac3heFcSVz66+/4XtUMbhi1wLbPso+51vJmXBCaAtrBYRbvMlkItujr/cKmqwBON1DRVcMOAHH9RuyRRY1C8f+3C4c4ZVnXNAOBwdHlIeea4v2DJ0D29dlHbacjhG8PGUKZNFW28v18t+n9zwkPg5Gz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network-Message-Id: 84afb012-8043-4962-4822-08dcace0c647 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2024 19:34:18.0473 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PBFz4uLvPccRwA6JRAqvRxe7FDzWf3Pc43NzrcfsuSQzMQ8kWjs5UgjBNinAlsQudX851z+/pY0y3D5dlV/KpA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8791 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240725_123422_014541_A4E5A5FF X-CRM114-Status: GOOD ( 15.72 ) 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 From: Jacky Bai The value written into the TPM CnV can only be updated into the hardware when the counter increases. Additional writes to the CnV write buffer are ignored until the register has been updated. Therefore, we need to check if the CnV has been updated before continuing. This may require waiting for 1 counter cycle in the worst case. Cc: Fixes: 059ab7b82eec ("clocksource/drivers/imx-tpm: Add imx tpm timer support") Signed-off-by: Jacky Bai Reviewed-by: Peng Fan Reviewed-by: Ye Li Reviewed-by: Jason Liu Signed-off-by: Frank Li --- drivers/clocksource/timer-imx-tpm.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/clocksource/timer-imx-tpm.c b/drivers/clocksource/timer-imx-tpm.c index cd23caf1e5999..92c025b70eb62 100644 --- a/drivers/clocksource/timer-imx-tpm.c +++ b/drivers/clocksource/timer-imx-tpm.c @@ -90,6 +90,14 @@ static int tpm_set_next_event(unsigned long delta, writel(next, timer_base + TPM_C0V); now = tpm_read_counter(); + /* + * Need to wait CNT increase at least 1 cycle to make sure + * the C0V has been updated into HW. + */ + if ((next & 0xffffffff) != readl(timer_base + TPM_C0V)) + while (now == tpm_read_counter()) + ; + /* * NOTE: We observed in a very small probability, the bus fabric * contention between GPU and A7 may results a few cycles delay