From patchwork Mon Nov 27 19:25:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 749735 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="wjxmWIDx" Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2053.outbound.protection.outlook.com [40.107.93.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE2D5D5F; Mon, 27 Nov 2023 11:26:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NFP+eYN7WgIZedvzWrGsPB3iPhsFhknVd6paBITexzGv0MoKLn5a2hvHuGvjTmCuxXpSLaWVWD8dfvGq+jSDOBJ+i811wmfYMp63wfL0jl2oAFsS7NoNJcJBNy93UkF9XVTxAqOT5d2cpZtIGNcjwiLgrE+7ydQXotnUHCVEGpuq1JQi3mMAWkU1cWy9yHgNM3g4y2Vak583XMGApqmNigjYleOgr1LBkhWjIioGGoMITjQgMYTBYIhcBnDt4kp9zo3y3v55pwN129zp4LUAn0ctZtqytbc7isYkUGSxrSJffFtDkq9CP9pafeT00+jjPK1qREUYEB1q1wOnKFhpoA== 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=g9ZrCFErcBAy7Yk6qivLfS3bEBNFGYcPShN6qVOcVYQ=; b=QAkPK2Ebu60m0BQK9gUWgZH2gHGyZGMeg/odhFSEQMldRToaO22G8QsLWThX8eyHVebeG4pF0xD3r7nRlGJ4QLvF7YCcsn6z6qeveFrnSE8lY9wJHNOn+O7UZqrZbhibsB/2m6FD39Opx/P+b2ZtSVtkjINppBncwTtQoRUjXYv150Rcz5teu4O8q/095+oxj0Hr957IL4SgccLdf1fjWmzGIkrIIcTdAGeAg2ns+94SbiK8y1VU6t9I1lniIRrIXnVG5GZ06Jsg9iZ6NK0wEwjNZqr9xZF4rbchSYKcavCzFaE7jJ2MrAsuwlbhS84T+fe5HgW+rx5nBLOy6Epi4Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=o2.pl smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=g9ZrCFErcBAy7Yk6qivLfS3bEBNFGYcPShN6qVOcVYQ=; b=wjxmWIDxkb6Xgq3PeYsQRGRiULAhJ1bINDqZqEBO/8VYQTkGf5C/Y++fmJzBP5Fq8qzwqNWQICNp44f8FdPlkCN76/HTo5jdrqyBiW+NzZOK6uF+M7UkhVNNzo+qc/tl4lXKjTfKH3yua+l3SvA+EvNFBIeg8tVcIZ/KETl2kIk= Received: from SJ0PR13CA0019.namprd13.prod.outlook.com (2603:10b6:a03:2c0::24) by MN2PR12MB4080.namprd12.prod.outlook.com (2603:10b6:208:1d9::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.28; Mon, 27 Nov 2023 19:26:11 +0000 Received: from DS1PEPF00017096.namprd05.prod.outlook.com (2603:10b6:a03:2c0:cafe::ac) by SJ0PR13CA0019.outlook.office365.com (2603:10b6:a03:2c0::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.19 via Frontend Transport; Mon, 27 Nov 2023 19:26:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF00017096.mail.protection.outlook.com (10.167.18.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7046.17 via Frontend Transport; Mon, 27 Nov 2023 19:26:10 +0000 Received: from AUS-P9-MLIMONCI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Mon, 27 Nov 2023 13:26:09 -0600 From: Mario Limonciello To: =?utf-8?q?Mateusz_Jo=C5=84czyk?= , Alessandro Zummo , Alexandre Belloni CC: "open list:REAL TIME CLOCK (RTC) SUBSYSTEM" , open list , , , , , , , , Dave Hansen , Borislav Petkov , "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , Mario Limonciello Subject: [PATCH v3 1/4] rtc: mc146818-lib: Adjust failure return code for mc146818_get_time() Date: Mon, 27 Nov 2023 13:25:50 -0600 Message-ID: <20231127192553.9734-2-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231127192553.9734-1-mario.limonciello@amd.com> References: <20231127192553.9734-1-mario.limonciello@amd.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017096:EE_|MN2PR12MB4080:EE_ X-MS-Office365-Filtering-Correlation-Id: 2ddda40e-5f3f-45c0-534b-08dbef7eb674 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HMriGn6mpjwtEZt8ZNFHCnDnrRgeAHqrrrJgaNNNGThTXkngszx9JWOrKRMu2xQ/zG+JDACnS5F13/iIPFijtRclzcj12jm851tCsV9AHO7yvVEqrd7HWCOc63x6dKjd5vCqQuu4O5t5NTANtGaKAfRUzVjQJX7Z68AgQsMSAcjFbGIwEED9lJA6Rdfy/Z3r+1WWOBh1fPYaAPj3meF336ElGCLlUZDFa9AqtVfhUsgF4vkYosCKi2PBDu2IcA/g9w9wgS+nb0uiUpVCGq59dIH17QbeCAvh+U0zrydiCU3/TiQc3S9APlwB0GfhtfjyEvM6nVGdw6uC98pfjKtY8jR/JpUfeORDMspi4SwBUbPgQfQkGmTkY7U5v72jU5lMIiKU3fJjzRJOvjQjsgeQbg7jqMmRFAeT2v+A06gY/ezrq2ZrBksghyXkBKkHvdLBRZ+XyXur4XVXTSZ12ukjYUvoIQ++IoTIJ0VtHoWgBfnGis1OHa/SMEtd3C0lqZxOCnnJdm6P48ewgdGosI9FyZcinbnG8z+hdHshHz376YYBZxn98yA1CkK/dZ9o96jUf2l4gmtb544z+heLEzcF5L+LTtP7LT+IA/PHCLN5A03JHuH+wVYFg8FowEYu3vC8FDblHPZZGGcMMv+gqakwC4JFazSwNnEaf27vP7XdBHZI0PTC7d8xsjx4gkVqjejx9u9TsGz7vv6v2Nc6byKm/LpbOiFq4m6TPQY/URyD2rl0wHInwuBjugYZr1OJDrShJvqp8blG6xzLn/3D+7nx+w== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(39860400002)(376002)(136003)(346002)(396003)(230922051799003)(451199024)(64100799003)(186009)(1800799012)(82310400011)(36840700001)(40470700004)(46966006)(40460700003)(356005)(82740400003)(36756003)(478600001)(41300700001)(81166007)(7696005)(8936002)(8676002)(4326008)(336012)(426003)(70206006)(316002)(54906003)(110136005)(70586007)(1076003)(26005)(86362001)(16526019)(47076005)(2616005)(66574015)(83380400001)(6666004)(36860700001)(44832011)(2906002)(5660300002)(40480700001)(7416002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2023 19:26:10.8270 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2ddda40e-5f3f-45c0-534b-08dbef7eb674 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF00017096.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4080 mc146818_get_time() calls mc146818_avoid_UIP() to avoid fetching the time while RTC update is in progress (UIP). When this fails, the return code is -EIO, but actually there was no IO failure. The reason for the return from mc146818_avoid_UIP() is that the UIP wasn't cleared in the time period. Adjust the return code to -ETIMEDOUT to match the behavior. Tested-by: Mateusz Jończyk Reviewed-by: Mateusz Jończyk Acked-by: Mateusz Jończyk Cc: stable@vger.kernel.org Fixes: 2a61b0ac5493 ("rtc: mc146818-lib: refactor mc146818_get_time") Signed-off-by: Mario Limonciello --- v2->v3: * Add tags v1->v2: * Add stable and fixes tag --- drivers/rtc/rtc-mc146818-lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-mc146818-lib.c b/drivers/rtc/rtc-mc146818-lib.c index f1c09f1db044..43a28e82674e 100644 --- a/drivers/rtc/rtc-mc146818-lib.c +++ b/drivers/rtc/rtc-mc146818-lib.c @@ -138,7 +138,7 @@ int mc146818_get_time(struct rtc_time *time) if (!mc146818_avoid_UIP(mc146818_get_time_callback, &p)) { memset(time, 0, sizeof(*time)); - return -EIO; + return -ETIMEDOUT; } if (!(p.ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD) From patchwork Mon Nov 27 19:25:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 747762 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="ZkVXa4hE" Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2062.outbound.protection.outlook.com [40.107.100.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C899D60; Mon, 27 Nov 2023 11:26:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BuMtHx7YaKB2FYe42pltZPlas+uhrWd4h1PYa5eES5wtIhPEAnZIe7Q424t5MbjlcMnQDhugXnwZI1IO1Y77OEeSr/NBr5sofO6HlfyrOyY4m1dzQCdNDfIS7T5BMzZjQmTujcTIeNzkrDZdYxAGZ8aiJJ7+p5jOQ69PStFKWK5cROpcFB1b2396UITcPSzSM5UQ7HbDBW8xx7iWnbN/0C838M3/LbqpY4GV8I8HxLQrOEC9kr2jFRFhyb8+maGNDW9u4MTH6HD4RjnXY+raWtvRju0qTgjvQjh73NrWIqs3fAHBbi/9yt7Tr6kT45e3P5ZCnq9hYXinwCCWG4uVGw== 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=koPpbArlYcE4vPhoQ+Ikg770yizTTTEAbSY0aTCnKVY=; b=C7QP+zpc4rfkjUxa+pgC7m4tg8zFphX1Zxkb/GY/xnb9j9+yxeMAskvq+gIEjIKTpvffk/fFtOY89AL3Byxr/AwXS/Y42MNvEJbQM/4qsG7CCzNBI47VD9knRV+JkUQZhHxwVPimDwCGZJbCpU58My2AeJrwmhcQo1XI/b73dnr+9SwTLxELNU6XKmhRTVEPcrp/SgZ/oemflMkDB3Q1XPKh98wWJ9bz7Z69mvIqHjWfabFb4D56DulMmtgUGZKkephL211rDGuSpm3P5ufZ1fdg65tVrb80Ylu0BYaOMvq7O1CCY5K97J4/dOaWM0nWwPQmQWnwaRhs2K/yUgxvHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=o2.pl smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=koPpbArlYcE4vPhoQ+Ikg770yizTTTEAbSY0aTCnKVY=; b=ZkVXa4hEjw4Q/dN5ROMjOt3CPLnrFZ/vLngCrS7sFiBFez5Dl1oUCLaYfJMxl5Wnku1dAxCjuLmgLD9xJJc+9FNN80GEtUJipzmfLkVksioZJCXcjUG14nHWp3QhXKonX0XktFY24L1sF3VBmQKXkgdKpyUp73vmCkp3OtWohC0= Received: from SJ0PR13CA0018.namprd13.prod.outlook.com (2603:10b6:a03:2c0::23) by PH7PR12MB6737.namprd12.prod.outlook.com (2603:10b6:510:1a8::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.27; Mon, 27 Nov 2023 19:26:12 +0000 Received: from DS1PEPF00017096.namprd05.prod.outlook.com (2603:10b6:a03:2c0:cafe::f2) by SJ0PR13CA0018.outlook.office365.com (2603:10b6:a03:2c0::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.21 via Frontend Transport; Mon, 27 Nov 2023 19:26:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF00017096.mail.protection.outlook.com (10.167.18.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7046.17 via Frontend Transport; Mon, 27 Nov 2023 19:26:11 +0000 Received: from AUS-P9-MLIMONCI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Mon, 27 Nov 2023 13:26:10 -0600 From: Mario Limonciello To: =?utf-8?q?Mateusz_Jo=C5=84czyk?= , Alessandro Zummo , Alexandre Belloni CC: "open list:REAL TIME CLOCK (RTC) SUBSYSTEM" , open list , , , , , , , , Dave Hansen , Borislav Petkov , "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , Mario Limonciello Subject: [PATCH v3 2/4] rtc: Adjust failure return code for cmos_set_alarm() Date: Mon, 27 Nov 2023 13:25:51 -0600 Message-ID: <20231127192553.9734-3-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231127192553.9734-1-mario.limonciello@amd.com> References: <20231127192553.9734-1-mario.limonciello@amd.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017096:EE_|PH7PR12MB6737:EE_ X-MS-Office365-Filtering-Correlation-Id: fa6019ca-a280-4f75-2493-08dbef7eb708 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MK1ecO+vuBzGC2WNPgSXbXOk4FdzcrkoLskO8GkkrYKDBC6xF1LrRWY9s/bALVjkzOHnfBPAgvQmDUWDldDCgZZqZSd3ZuFBfEmjCvn/bUQq5AMslqDsj89LbDFYTEJf1mZ4r422RSpUeL/rlxgr1RVY6aJolyhcIjJh/DGa4U/08tueM4QlVax0qVDjU5WhM18uJHeQL9OCDjwnFLaXS/uTjdxlx4NLtIUQJX+rEX6nUkwW2X2IbmV+aL6Y2jDPFsVFZMSwNZEkcbqwESz+WnNl0zueaPR+fWnpsvltjEHC3XpVBYzcOHBfr5hr0OwYrw/bbjhO3+CCyV8nml3/Lx1M/O4bk+9zZ7P12x0leZrJ46jg+z6p85JFSgq8tOdnuMyYwQgpNBqb/9PoB0Fuwkg9UbvShdY5dEo/xELHALBOnO/syCSkobKF8wopOLLUus8gXE6tRDjOzfbXcLFWCn2Z2zugE/oRojNY1dkyMsUxmcjRxA/sngWmxd6bhdVaSSgBKN+g6sBMlYNhOS9jWyUvsg24QPjHT+DRSEs+oMt74dwoQSY3Ixo7XGmBV6yAJbp6aLvnX8ACciYdqYkcxOMNxZfeqtzchHD85XhUTPePP3ZjAZP3UBrKThWpAQ2hdtEf/ATwGnOFK5BwCQCgXiJ9KSY7KfsfkAGZKIbhr05pyrhhqz/dHKMW9iRBjJ0y7h8lHSNYHPFVBQV58/boqXaYsCh7XqRDOMupylAFv59VTBR7w3lONZpVaT6CaOBerI/wYJ9Xlz8WX6u/WzWsHg== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(39860400002)(396003)(376002)(136003)(346002)(230922051799003)(186009)(451199024)(64100799003)(1800799012)(82310400011)(40470700004)(36840700001)(46966006)(6666004)(4326008)(8936002)(8676002)(7696005)(54906003)(110136005)(316002)(40460700003)(478600001)(81166007)(356005)(47076005)(36756003)(40480700001)(41300700001)(1076003)(86362001)(26005)(44832011)(70586007)(36860700001)(336012)(2906002)(2616005)(426003)(83380400001)(66574015)(16526019)(82740400003)(5660300002)(7416002)(70206006)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2023 19:26:11.7801 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fa6019ca-a280-4f75-2493-08dbef7eb708 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF00017096.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6737 When mc146818_avoid_UIP() fails to return a valid value, this is because UIP didn't clear in the timeout period. Adjust the return code in this case to -ETIMEDOUT. Tested-by: Mateusz Jończyk Reviewed-by: Mateusz Jończyk Acked-by: Mateusz Jończyk Cc: stable@vger.kernel.org Fixes: cdedc45c579f ("rtc: cmos: avoid UIP when reading alarm time") Fixes: cd17420ebea5 ("rtc: cmos: avoid UIP when writing alarm time") Signed-off-by: Mario Limonciello --- v1->v2: * cover cmos_read_alarm() too * Add stable tags --- drivers/rtc/rtc-cmos.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index 228fb2d11c70..391f91d3d144 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -292,7 +292,7 @@ static int cmos_read_alarm(struct device *dev, struct rtc_wkalrm *t) /* This not only a rtc_op, but also called directly */ if (!is_valid_irq(cmos->irq)) - return -EIO; + return -ETIMEDOUT; /* Basic alarms only support hour, minute, and seconds fields. * Some also support day and month, for alarms up to a year in @@ -557,7 +557,7 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t) * Use mc146818_avoid_UIP() to avoid this. */ if (!mc146818_avoid_UIP(cmos_set_alarm_callback, &p)) - return -EIO; + return -ETIMEDOUT; cmos->alarm_expires = rtc_tm_to_time64(&t->time); From patchwork Mon Nov 27 19:25:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 747761 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="OY+6KiZs" Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2061.outbound.protection.outlook.com [40.107.92.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A85F10CA; Mon, 27 Nov 2023 11:26:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZLObBf94vAphWyC1/K98T5vu01XzyrjjjqvQftVrXBKJKD9Aa1hBtuKhcnbMAh5Ygs/ILtvln+BJzKkX+u1Saa7Ab4v61pgs2NGGxDGkXq/JRJ1Jq4NsD6w04aLnlbwXFoMdPehKVgQGm6AHPmyk9XAsw83bH5QxVeFB3vXIKm3+1EVLyZAy8Etx1HNeMsHfxpvOZvxQRwNAP6XCuTmgSalp/esNcSc7lvJQuvl5qiNlBUhOVuH5lGSXdtxP/T2IYC9IvqDpCmDeA2DONP+DBJtwPcHiRI7B/IfXPzEF6kGrG0UcPJ2S3wIkcvvdRdl6mfc/uaIWFgu6XPzgJPZkyg== 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=hcJy6dfauzuJvNcfUZVwibDvAH0IEWGy/wr2Sftqbl4=; b=ClSIUWnn7OZWjTpV2amPjDIieQEM0ji1sENbhKwYg1CeNA1iCxW6YaqoNoUaTW9QqsxI+0wLxcc4pR++ftmrS91d36qHvwd03M0VMYUD0jQb2h1GmAuqekPbfp3mv47nm9ITpNwlz/IP8E6y2CZMU4W2GXrb4z5M1ujF9pCDqntP0LEgfYG7zcaahq1KHDt7c5JzghD2FhRqB0xmOyVpsz09vnqKDU4Hc8pVanhOnuNUywUa2QCd+q9g9TdQZFIXrBJAWz9bHU2uZ3AD2linxYxw3FSIGvnmjZKOh70LbQ5/zQPgg39npPyVgU62NuX2wVm+cuIjSoHvE1NdGGB4eQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=o2.pl smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hcJy6dfauzuJvNcfUZVwibDvAH0IEWGy/wr2Sftqbl4=; b=OY+6KiZsBG9/ioRfS3omJ0IQDuQe7hXmsrmLIb2kw4NvSGqUYIeP74BaJBHjMjlGSxm+goTm8Z+DbcKToNmCZ2NrOTkXzVO9iwqy3z/2iW+xF8JIeIgByNsKGcSvPDRFJ2y2rMPMRk/JYz0dO8sfvc/BKLC10B0z5ckTGjcyUd0= Received: from SJ0PR13CA0018.namprd13.prod.outlook.com (2603:10b6:a03:2c0::23) by BL0PR12MB4868.namprd12.prod.outlook.com (2603:10b6:208:1c4::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.28; Mon, 27 Nov 2023 19:26:14 +0000 Received: from DS1PEPF00017096.namprd05.prod.outlook.com (2603:10b6:a03:2c0:cafe::5c) by SJ0PR13CA0018.outlook.office365.com (2603:10b6:a03:2c0::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.21 via Frontend Transport; Mon, 27 Nov 2023 19:26:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF00017096.mail.protection.outlook.com (10.167.18.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7046.17 via Frontend Transport; Mon, 27 Nov 2023 19:26:13 +0000 Received: from AUS-P9-MLIMONCI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Mon, 27 Nov 2023 13:26:11 -0600 From: Mario Limonciello To: =?utf-8?q?Mateusz_Jo=C5=84czyk?= , Alessandro Zummo , Alexandre Belloni CC: "open list:REAL TIME CLOCK (RTC) SUBSYSTEM" , open list , , , , , , , , Dave Hansen , Borislav Petkov , "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , Mario Limonciello Subject: [PATCH v3 3/4] rtc: Add support for configuring the UIP timeout for RTC reads Date: Mon, 27 Nov 2023 13:25:52 -0600 Message-ID: <20231127192553.9734-4-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231127192553.9734-1-mario.limonciello@amd.com> References: <20231127192553.9734-1-mario.limonciello@amd.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017096:EE_|BL0PR12MB4868:EE_ X-MS-Office365-Filtering-Correlation-Id: bf1be558-534f-4985-410d-08dbef7eb7e8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 62q6jmqWJEvSy8GHvW6y9WIJHgMJyRvdLua6z25c81hFKF9weUmwNLb/lyvce1LWts1iqJoRII8L9+SFosrcClP7Yw7DU4PUvwCR4/L8dDQ+XHTGKX/3Z0Wrywd8A7eoQJgq/Yjx4FGIHXvuxgUW2uJ3KWGoJXb4RpOpDHjas0wUemVAKKZ5UUPVKbKTtZGXMXWCgsRSsxDujqEatozF3bhk59C0JP5LtizFTlI77zyn+RY10hIcCOT06lVGSYMFkCJMomZNzFfSe2oLMklc1QAJUALrBBavLvd01/oDsHRV5ZEeGKLVwljx8BeJgXZqqgj3Ex0yiFZwLRKN9cZAyaBrCbWa5YPQz+JbzMmnyizfDHa/2Hth4YQAEK+w6AO5ijpWgM2BND/2/pzi309gOo1jk9vnlLLLoMobPHfO7psWVi2w07OKJ09/uzlQngPZpHTQZN3IYXQnLZY+zFZTjgH017quSZ44aOV2WCl7DC4zz28q75HFx/rtaWvCuNogXbG686Om2wYW7iurgpZYDwyhfLSJFJks8Q/PB3U/QnBo8YogLeJMGk4Sw2pszMiuraVAm48XuO8mEPcX+6RPJ+ziVIhJfhm93ynU7Hn4Qs+Qi8NncsVaHi3yBNq4rougi5t1OuAMUEHwyd/fO4fkwLnBxGALfJ37yZfPKV6uCh9RClkYAxPOCuWXnBRCoNJPnBeg54zqZM6ikVYGAdzshTBoLoYHlu4yJEPU3A/k4Y90MGFQfY1h9Im0F4kHtdbBZAVn4SesOEN3G0ZXILTKsJJXhjMq6kyZe9mVO9AHg++Iqa847CHbblsYTuTqHUnZvlEetMLa881IwcxQaSa8qA== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(39860400002)(376002)(136003)(346002)(396003)(230922051799003)(230173577357003)(230273577357003)(451199024)(64100799003)(186009)(1800799012)(82310400011)(36840700001)(40470700004)(46966006)(40460700003)(356005)(82740400003)(36756003)(478600001)(45080400002)(41300700001)(81166007)(7696005)(8936002)(8676002)(4326008)(336012)(426003)(70206006)(316002)(54906003)(110136005)(70586007)(1076003)(26005)(86362001)(16526019)(47076005)(2616005)(83380400001)(6666004)(36860700001)(44832011)(2906002)(5660300002)(40480700001)(7416002)(557034005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2023 19:26:13.2488 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bf1be558-534f-4985-410d-08dbef7eb7e8 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF00017096.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB4868 The UIP timeout is hardcoded to 10ms for all RTC reads, but in some contexts this might not be enough time. Add a timeout parameter to mc146818_get_time() and mc146818_get_time_callback(). If UIP timeout is configured by caller to be >=100 ms and a call takes this long, log a warning. Make all callers use 10ms to ensure no functional changes. Cc: stable@vger.kernel.org # 6.1.y Fixes: ec5895c0f2d8 ("rtc: mc146818-lib: extract mc146818_avoid_UIP") Signed-off-by: Mario Limonciello --- v2->v3: * Logic adjustments * Clarify warning message v1->v2: * Add a warning if 100ms or more * Add stable and fixes tags --- arch/alpha/kernel/rtc.c | 2 +- arch/x86/kernel/hpet.c | 2 +- arch/x86/kernel/rtc.c | 2 +- drivers/base/power/trace.c | 2 +- drivers/rtc/rtc-cmos.c | 6 +++--- drivers/rtc/rtc-mc146818-lib.c | 37 ++++++++++++++++++++++++++-------- include/linux/mc146818rtc.h | 3 ++- 7 files changed, 38 insertions(+), 16 deletions(-) diff --git a/arch/alpha/kernel/rtc.c b/arch/alpha/kernel/rtc.c index fb3025396ac9..cfdf90bc8b3f 100644 --- a/arch/alpha/kernel/rtc.c +++ b/arch/alpha/kernel/rtc.c @@ -80,7 +80,7 @@ init_rtc_epoch(void) static int alpha_rtc_read_time(struct device *dev, struct rtc_time *tm) { - int ret = mc146818_get_time(tm); + int ret = mc146818_get_time(tm, 10); if (ret < 0) { dev_err_ratelimited(dev, "unable to read current time\n"); diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c index 41eecf180b7f..17adad4cbe78 100644 --- a/arch/x86/kernel/hpet.c +++ b/arch/x86/kernel/hpet.c @@ -1438,7 +1438,7 @@ irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id) memset(&curr_time, 0, sizeof(struct rtc_time)); if (hpet_rtc_flags & (RTC_UIE | RTC_AIE)) { - if (unlikely(mc146818_get_time(&curr_time) < 0)) { + if (unlikely(mc146818_get_time(&curr_time, 10) < 0)) { pr_err_ratelimited("unable to read current time from RTC\n"); return IRQ_HANDLED; } diff --git a/arch/x86/kernel/rtc.c b/arch/x86/kernel/rtc.c index 1309b9b05338..961ebc7f1872 100644 --- a/arch/x86/kernel/rtc.c +++ b/arch/x86/kernel/rtc.c @@ -67,7 +67,7 @@ void mach_get_cmos_time(struct timespec64 *now) return; } - if (mc146818_get_time(&tm)) { + if (mc146818_get_time(&tm, 10)) { pr_err("Unable to read current time from RTC\n"); now->tv_sec = now->tv_nsec = 0; return; diff --git a/drivers/base/power/trace.c b/drivers/base/power/trace.c index 72b7a92337b1..c2e925357474 100644 --- a/drivers/base/power/trace.c +++ b/drivers/base/power/trace.c @@ -120,7 +120,7 @@ static unsigned int read_magic_time(void) struct rtc_time time; unsigned int val; - if (mc146818_get_time(&time) < 0) { + if (mc146818_get_time(&time, 10) < 0) { pr_err("Unable to read current time from RTC\n"); return 0; } diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index 391f91d3d144..d278b085821e 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -231,7 +231,7 @@ static int cmos_read_time(struct device *dev, struct rtc_time *t) if (!pm_trace_rtc_valid()) return -EIO; - ret = mc146818_get_time(t); + ret = mc146818_get_time(t, 10); if (ret < 0) { dev_err_ratelimited(dev, "unable to read current time\n"); return ret; @@ -307,7 +307,7 @@ static int cmos_read_alarm(struct device *dev, struct rtc_wkalrm *t) * * Use the mc146818_avoid_UIP() function to avoid this. */ - if (!mc146818_avoid_UIP(cmos_read_alarm_callback, &p)) + if (!mc146818_avoid_UIP(cmos_read_alarm_callback, 10, &p)) return -EIO; if (!(p.rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { @@ -556,7 +556,7 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t) * * Use mc146818_avoid_UIP() to avoid this. */ - if (!mc146818_avoid_UIP(cmos_set_alarm_callback, &p)) + if (!mc146818_avoid_UIP(cmos_set_alarm_callback, 10, &p)) return -ETIMEDOUT; cmos->alarm_expires = rtc_tm_to_time64(&t->time); diff --git a/drivers/rtc/rtc-mc146818-lib.c b/drivers/rtc/rtc-mc146818-lib.c index 43a28e82674e..ab077dde397b 100644 --- a/drivers/rtc/rtc-mc146818-lib.c +++ b/drivers/rtc/rtc-mc146818-lib.c @@ -8,26 +8,31 @@ #include #endif +#define UIP_RECHECK_DELAY 100 /* usec */ +#define UIP_RECHECK_DELAY_MS (USEC_PER_MSEC / UIP_RECHECK_DELAY) +#define UIP_RECHECK_TIMEOUT_MS(x) (x / UIP_RECHECK_DELAY_MS) + /* * Execute a function while the UIP (Update-in-progress) bit of the RTC is - * unset. + * unset. The timeout is configurable by the caller in ms. * * Warning: callback may be executed more then once. */ bool mc146818_avoid_UIP(void (*callback)(unsigned char seconds, void *param), + int timeout, void *param) { int i; unsigned long flags; unsigned char seconds; - for (i = 0; i < 100; i++) { + for (i = 0; i < UIP_RECHECK_TIMEOUT_MS(timeout); i++) { spin_lock_irqsave(&rtc_lock, flags); /* * Check whether there is an update in progress during which the * readout is unspecified. The maximum update time is ~2ms. Poll - * every 100 usec for completion. + * for completion. * * Store the second value before checking UIP so a long lasting * NMI which happens to hit after the UIP check cannot make @@ -37,7 +42,7 @@ bool mc146818_avoid_UIP(void (*callback)(unsigned char seconds, void *param), if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) { spin_unlock_irqrestore(&rtc_lock, flags); - udelay(100); + udelay(UIP_RECHECK_DELAY); continue; } @@ -56,7 +61,7 @@ bool mc146818_avoid_UIP(void (*callback)(unsigned char seconds, void *param), */ if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) { spin_unlock_irqrestore(&rtc_lock, flags); - udelay(100); + udelay(UIP_RECHECK_DELAY); continue; } @@ -72,6 +77,10 @@ bool mc146818_avoid_UIP(void (*callback)(unsigned char seconds, void *param), } spin_unlock_irqrestore(&rtc_lock, flags); + if (i >= UIP_RECHECK_TIMEOUT_MS(100)) + pr_warn("Reading current time from RTC took around %d ms\n", + UIP_RECHECK_TIMEOUT_MS(i)); + return true; } return false; @@ -84,7 +93,7 @@ EXPORT_SYMBOL_GPL(mc146818_avoid_UIP); */ bool mc146818_does_rtc_work(void) { - return mc146818_avoid_UIP(NULL, NULL); + return mc146818_avoid_UIP(NULL, 10, NULL); } EXPORT_SYMBOL_GPL(mc146818_does_rtc_work); @@ -130,13 +139,25 @@ static void mc146818_get_time_callback(unsigned char seconds, void *param_in) p->ctrl = CMOS_READ(RTC_CONTROL); } -int mc146818_get_time(struct rtc_time *time) +/** + * mc146818_get_time - Get the current time from the RTC + * @time: pointer to struct rtc_time to store the current time + * @timeout: timeout value in ms + * + * This function reads the current time from the RTC and stores it in the + * provided struct rtc_time. The timeout parameter specifies the maximum + * time to wait for the RTC to become ready. + * + * Return: 0 on success, -ETIMEDOUT if the RTC did not become ready within + * the specified timeout, or another error code if an error occurred. + */ +int mc146818_get_time(struct rtc_time *time, int timeout) { struct mc146818_get_time_callback_param p = { .time = time }; - if (!mc146818_avoid_UIP(mc146818_get_time_callback, &p)) { + if (!mc146818_avoid_UIP(mc146818_get_time_callback, timeout, &p)) { memset(time, 0, sizeof(*time)); return -ETIMEDOUT; } diff --git a/include/linux/mc146818rtc.h b/include/linux/mc146818rtc.h index b0da04fe087b..34dfcc77f505 100644 --- a/include/linux/mc146818rtc.h +++ b/include/linux/mc146818rtc.h @@ -126,10 +126,11 @@ struct cmos_rtc_board_info { #endif /* ARCH_RTC_LOCATION */ bool mc146818_does_rtc_work(void); -int mc146818_get_time(struct rtc_time *time); +int mc146818_get_time(struct rtc_time *time, int timeout); int mc146818_set_time(struct rtc_time *time); bool mc146818_avoid_UIP(void (*callback)(unsigned char seconds, void *param), + int timeout, void *param); #endif /* _MC146818RTC_H */ From patchwork Mon Nov 27 19:25:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 749734 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="qXV29ecQ" Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2067.outbound.protection.outlook.com [40.107.244.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F392A10D7; Mon, 27 Nov 2023 11:26:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dgnzr/WD28guiC5CSf6pfW1uOKLn8pU0sK6E6eOAlusy8y79O33iuBuZ0wgD8bxdVDzoMsahweEZwPJpOhhdx3RfkfNj9UZlzeOQxiGG6JEN16jemqRlwmqHKVJL3JWZ3nEalTMAdlFAle/SvBDnTuKXaOL23KXE8nT0MRuaSM65J32CxouG4VgRQuirJmnbajM8d+ra9x/nNw7ng1PX7v2kdmOzjeITSOo9O1tp/XxxakFzSmuEhFW/YgmvnPYpIPjHrdj5AliF8gEs8vgezmyg8uVdu/BtW1+Pgfsmprh7axUyU9UTbhXtMJTn1IEWRXbXV8gaOiDEn7xzITwphw== 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=umLioW63EAOyf1vpISoUT/wL0Lfpe3FtD1EImu1KLys=; b=An4W6rJUfvgFwIRVefaJKxN5FRkKZ7HeQ0Szm5btIfUbf8FlpFbHWboPJB3eYZA+zI3psGuYCist+uyNHSAf2nIkmZuf7KgxkE+WTRlbX/wrITO5OeJcOfsD6ARGi9ub8x2EIjhXif4gg9TQI2D86b1uJtz74RxDc9Eowiq2jXGmXZG1EqHqLmuBLJFWUxZ2mfPBTUJW5WHzBMPOc/LPIp9twW8HXFcq4/x7Uc+SSEQT5l4Yzt4z6KnMCxOUwtk+Wn9Rr47mwtn1VMIL+o3YxXpEZI+lyJTARpV3xcXGmnaD+Y7vfa1ZIWU9b9KUP/qozeRID8LS9vAXSVtTepQO7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=o2.pl smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=umLioW63EAOyf1vpISoUT/wL0Lfpe3FtD1EImu1KLys=; b=qXV29ecQ1cv3rulNTvc/40mf4Inyo5JOaoe5G1aWsnIq1jHFCrKTDQZjkb5SwF5nQRCQzsAM0oKXYrvUJ4w5QDizd7IEgm6VEtxGWhWYcv20btbuU0J5ca+DjPgFHkjIAtdpSN0P5pCmRO3VYOJN+32Mfy0MuXztiZup4WBaJEY= Received: from SJ0PR13CA0027.namprd13.prod.outlook.com (2603:10b6:a03:2c0::32) by DM4PR12MB6373.namprd12.prod.outlook.com (2603:10b6:8:a4::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.29; Mon, 27 Nov 2023 19:26:14 +0000 Received: from DS1PEPF00017096.namprd05.prod.outlook.com (2603:10b6:a03:2c0:cafe::e9) by SJ0PR13CA0027.outlook.office365.com (2603:10b6:a03:2c0::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.19 via Frontend Transport; Mon, 27 Nov 2023 19:26:14 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF00017096.mail.protection.outlook.com (10.167.18.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7046.17 via Frontend Transport; Mon, 27 Nov 2023 19:26:14 +0000 Received: from AUS-P9-MLIMONCI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Mon, 27 Nov 2023 13:26:12 -0600 From: Mario Limonciello To: =?utf-8?q?Mateusz_Jo=C5=84czyk?= , Alessandro Zummo , Alexandre Belloni CC: "open list:REAL TIME CLOCK (RTC) SUBSYSTEM" , open list , , , , , , , , Dave Hansen , Borislav Petkov , "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , Mario Limonciello Subject: [PATCH v3 4/4] rtc: Extend timeout for waiting for UIP to clear to 1s Date: Mon, 27 Nov 2023 13:25:53 -0600 Message-ID: <20231127192553.9734-5-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231127192553.9734-1-mario.limonciello@amd.com> References: <20231127192553.9734-1-mario.limonciello@amd.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017096:EE_|DM4PR12MB6373:EE_ X-MS-Office365-Filtering-Correlation-Id: c746ae24-a050-42c2-23c0-08dbef7eb8ae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 03QZLve4gPcKn+D+6Wif9kA4R7I0iGDHiuYgBjAkFDlnBvwG8s3bVcW4a4kDoRV/q7dcXoMN5Cf1VjhLZ3/dc/zzWnmPvfFztyVnh8JnTqjzaHG2cd1WMJ3xp794xC/hstfQD+4jld+5uXFtcXsuguF9bEUxLfjFvzEFAwOB6yjsXBz8Ef5WpHD1kdgNbSyaaDNILnZRKuUeeYPLm2mRneqtxjT0esq8QD4SbDY0xfSM1/GjauD9qDg7VU/h0oRoOG2OK5MB1NUqYms/WuOVmrUPfrlXoGd3ZAEM/CnKEXxndWdirvdxx0KXk9/2GgVQrOw4aq6zhUJ0PAMyNzDL35Uq5mRF0uRZBNok9lji97oKjq9Q11zeqPeO8az9SFrSzylLf/yUc0KjuLvne9NGtQzgHBFPZ/NOnV2EmNbgwF/fHJg0yDR3NhJ8mt86Q36w8T4cRia7cUMmyfNzYA2mzdKuloNbLENGYRq41OJ1adSl9p5iy5Z0GstVC9z4uKTVM2U0wOy5TIF2LEsyknTaXZnAn/k5oUJ9tEF49wyCtk8kIVuOzlIiCyDA4kZwECrXiWWQxuIsOJCLYvsjp5hrbhkKNC4HL3nGf45v3GsIvocOMd0aaX5UeW+S1cYw8FfB2sFmzKGTNtuo+T8pSxk9/nH1c81SnWPL28U2/QcLzAzkM5wEyO1hpERywQj7n6xkuwNDHnpWtQct9jH2V5JQEr4jtge4swZe8DsxNzt099f56TEtgi/1QKSXJuXdhfcpXPkj/xV3X411/LDpnXVRbQ== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(346002)(376002)(39860400002)(396003)(136003)(230922051799003)(1800799012)(82310400011)(186009)(64100799003)(451199024)(46966006)(36840700001)(40470700004)(41300700001)(36756003)(1076003)(86362001)(81166007)(47076005)(356005)(83380400001)(5660300002)(82740400003)(7416002)(336012)(426003)(16526019)(26005)(44832011)(2906002)(2616005)(40480700001)(36860700001)(7696005)(6666004)(8676002)(4326008)(8936002)(40460700003)(966005)(478600001)(110136005)(70206006)(70586007)(54906003)(316002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2023 19:26:14.5457 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c746ae24-a050-42c2-23c0-08dbef7eb8ae X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF00017096.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6373 Specs don't say anything about UIP being cleared within 10ms. They only say that UIP won't occur for another 244uS. If a long NMI occurs while UIP is still updating it might not be possible to get valid data in 10ms. This has been observed in the wild that around s2idle some calls can take up to 480ms before UIP is clear. Adjust callers from outside an interrupt context to wait for up to a 1s instead of 10ms. Cc: stable@vger.kernel.org # 6.1.y Fixes: ec5895c0f2d8 ("rtc: mc146818-lib: extract mc146818_avoid_UIP") Reported-by: Carsten Hatger Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217626 Tested-by: Mateusz Jończyk Reviewed-by: Mateusz Jończyk Acked-by: Mateusz Jończyk Signed-off-by: Mario Limonciello --- v2->v3: * Add tags * Add Carsten's name v1->v2: * Add tags --- arch/x86/kernel/rtc.c | 2 +- drivers/base/power/trace.c | 2 +- drivers/rtc/rtc-cmos.c | 2 +- drivers/rtc/rtc-mc146818-lib.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/rtc.c b/arch/x86/kernel/rtc.c index 961ebc7f1872..2e7066980f3e 100644 --- a/arch/x86/kernel/rtc.c +++ b/arch/x86/kernel/rtc.c @@ -67,7 +67,7 @@ void mach_get_cmos_time(struct timespec64 *now) return; } - if (mc146818_get_time(&tm, 10)) { + if (mc146818_get_time(&tm, 1000)) { pr_err("Unable to read current time from RTC\n"); now->tv_sec = now->tv_nsec = 0; return; diff --git a/drivers/base/power/trace.c b/drivers/base/power/trace.c index c2e925357474..cd6e559648b2 100644 --- a/drivers/base/power/trace.c +++ b/drivers/base/power/trace.c @@ -120,7 +120,7 @@ static unsigned int read_magic_time(void) struct rtc_time time; unsigned int val; - if (mc146818_get_time(&time, 10) < 0) { + if (mc146818_get_time(&time, 1000) < 0) { pr_err("Unable to read current time from RTC\n"); return 0; } diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index d278b085821e..6bc1e0279cd9 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -231,7 +231,7 @@ static int cmos_read_time(struct device *dev, struct rtc_time *t) if (!pm_trace_rtc_valid()) return -EIO; - ret = mc146818_get_time(t, 10); + ret = mc146818_get_time(t, 1000); if (ret < 0) { dev_err_ratelimited(dev, "unable to read current time\n"); return ret; diff --git a/drivers/rtc/rtc-mc146818-lib.c b/drivers/rtc/rtc-mc146818-lib.c index ab077dde397b..fa7a09b2123e 100644 --- a/drivers/rtc/rtc-mc146818-lib.c +++ b/drivers/rtc/rtc-mc146818-lib.c @@ -93,7 +93,7 @@ EXPORT_SYMBOL_GPL(mc146818_avoid_UIP); */ bool mc146818_does_rtc_work(void) { - return mc146818_avoid_UIP(NULL, 10, NULL); + return mc146818_avoid_UIP(NULL, 1000, NULL); } EXPORT_SYMBOL_GPL(mc146818_does_rtc_work);