From patchwork Tue Nov 28 05:36: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: 13471273 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="3rS+6oCs" Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2073.outbound.protection.outlook.com [40.107.212.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A0C28E; Tue, 28 Nov 2023 06:46:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j7Mgffdz2hC/s6zCct7HDqjYDpCYwKCtNVv9lGYsWU2HYrhz1dl/f98ztRVhztkFbbkoCrxt87oA1ccbEfFLnadhJx3p2JH+AGnCylCrmOl4n5wC4qocOmMBtuFQh66/PGbzrvoXhRJURcEMOCCcoblur2VkEW5FY4yRN9buHJhwOALrJhLBbLSGdrHUzrgYCRhflv6fObzJGSmBbCoz0Ah11svbhGKGZU/xM5z4MN3DNERleAoE5mAbBSYJMc9MPGANq9XdUpedcI2WkDF+I4C7/VYJhHayTk/MbjWdNsx8wL/1IbjV5knL2+hFzVweJUuDK10RnK/HH7OwVunCJw== 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=GWVhftJxAnjeHG18fbGelcmh3UkRFm4gXVb2H6TB3tZ82KsGg/aKL+8y/cDFDSfDj/sjJAN9KxtvjELfEFPtb2NoKLHoHq7Go71oHxoqxXAJlLSF3XXHY1I+GiF2M76um1I5g8lYbeFr0vC7VEsGRyUIVvGLSWruAkDWn67RHgOzGnxaDtraqaQjxC5wI6LC+tkOXVK8NAF+amVRq1sWpL2HR+NDS+Efc2Iz4YQYblX928Xw3OFC1ITlWqKKMp2JrKcT0J+fLZgux9XD2DQUtXWS5fwiB5g4lGJ1u4IgmsTyeMf5z1ZhjHkwpMWb9UVkrRwXyHvG+kMx95bE7cJl/A== 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=3rS+6oCsX2U4QZ/30geX/AKk48QMkBcSKQ4wdIcjo9XTGWReU15fZrhC+qIg0y+/gpWf49YtZQXXDYShbX+dPJGl1eH3XG0C1LV89EGqREUOJSrZlsD1vxVR2APzvaluULNwUXXA/50TKtxzNVxQVkXIZca+kxW/iX4OrbNmdLc= Received: from BY5PR13CA0026.namprd13.prod.outlook.com (2603:10b6:a03:180::39) by SJ2PR12MB8953.namprd12.prod.outlook.com (2603:10b6:a03:544::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.27; Tue, 28 Nov 2023 14:46:41 +0000 Received: from CO1PEPF000042A7.namprd03.prod.outlook.com (2603:10b6:a03:180:cafe::8a) by BY5PR13CA0026.outlook.office365.com (2603:10b6:a03:180::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.21 via Frontend Transport; Tue, 28 Nov 2023 14:46:41 +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 CO1PEPF000042A7.mail.protection.outlook.com (10.167.243.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7046.17 via Frontend Transport; Tue, 28 Nov 2023 14:46:40 +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; Tue, 28 Nov 2023 08:46:35 -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 v4 1/4] rtc: mc146818-lib: Adjust failure return code for mc146818_get_time() Date: Mon, 27 Nov 2023 23:36:50 -0600 Message-ID: <20231128053653.101798-2-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231128053653.101798-1-mario.limonciello@amd.com> References: <20231128053653.101798-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000042A7:EE_|SJ2PR12MB8953:EE_ X-MS-Office365-Filtering-Correlation-Id: 71eb3626-0c07-4b2a-e696-08dbf020d53b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UsyCSoGX8NGGGu7BQDlwvWP+9FHEI8s6/3mjsHLeCFMnSxmshg5Ty7R/CVL66FULH+gPkQc21IabFfmzEtQOGyhw3KwCfRQE+XhMrQR6mKbu/OWzUVnfMt8vUBFEy0EI6r0bxL637/rId12Xwxwr1Pjs9Dnqvz3AY7pcrjwMi17jp2bQdjlsELKCJL1n20WZS3z30SZ3d16IiReob647+KOnQ9lp0h+jbIf5ljxQWZDn9QezLI8r3Nm/FDmZcaARXwGKCoKDKrAQC1qgKbhy/48trCbxqvOT9yJhH+lakVCJa6Sc/zlHiPyGHf2rCVLa962HoH9TDAYcVpU/qUtPrAUdtwvfeV7QsJeCzP7Fg7sOE2jMCS4gBPG4kl9BcER1WLXGZ+xuR1qZSW8ZjTFGOmrkh+OOOdUZrRzw3pOo0SdJp+CN3INHZeCkywuSKhRG2qGAkab5/66Wd77q3bILuzfWNvUpYwxSyMONmPps+NAKGU07Wx//p7Mf7ArmhfSSSW98Ds+kVheA13wTwXU75ZigeZJc6tnu8h/o/tpRVM+bDQ3khgFScN0NSzEPdmiPCe+/XMisb9mq+jVVq+2bwCbemT9Bg8R4ddl8TGVJ/BzXBY2Pc1jPfSGzjQITBc+PxHrG8a6+CURbX7DR2/18LwjxubCkiXP5fMaZJC+Da4eQijqpCr7CPAgbPxow8ueMt28a3DcoH2fE0XpsoNUNKjmJ++e4jkcSdJcfOUm8d9u9AdqR+/Fv/+l0PqBDooAriV7k34MLaJ01LthyWZydOg== 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)(136003)(376002)(39860400002)(346002)(396003)(230922051799003)(64100799003)(451199024)(186009)(1800799012)(82310400011)(40470700004)(46966006)(36840700001)(6666004)(8936002)(8676002)(4326008)(7696005)(54906003)(70586007)(70206006)(316002)(110136005)(40460700003)(478600001)(81166007)(47076005)(356005)(36756003)(41300700001)(1076003)(86362001)(26005)(16526019)(36860700001)(44832011)(2616005)(40480700001)(2906002)(83380400001)(336012)(426003)(66574015)(7416002)(82740400003)(5660300002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Nov 2023 14:46:40.8587 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 71eb3626-0c07-4b2a-e696-08dbf020d53b 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: CO1PEPF000042A7.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8953 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 Tue Nov 28 05:36: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: 13471274 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="p0IaIJVi" Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2066.outbound.protection.outlook.com [40.107.220.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6675C10CC; Tue, 28 Nov 2023 06:46:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=atOo0kGInHztqzvQ58facD6fG6cteSnANyXzTNom+p0PO07H5w1GP7/Sij0rBsGHG2absooKTzAPEj9kAkdYp5nwecQUmPTdm+25KDjNZehX8c8McVNhFnYxxVExSoCiwGKpKEvZfa5s0b6/FtPuvYrDrCBDlH9JeQDhgzmlTHpD0vpdQZGbEBre0lDFXxVFJE1o+njqNV6UeF6FSis8Zhxph0mmMM1ROWzI7zrINxjMDrsIlBimnGgCFjjrQvZGuxM80qAR70C/iZPVGDiEalKgCvksEUAhBfzibwhhgEhK015LBuc6r78+V3+QSNmTnRcGW+RhDfyY6qebY7OUiw== 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=C0EV6i7VZTrBz2sbwuZP2OJ4Q6+o21oxCatcrNBo/ufIeEj7zPVN8xDEuW0bBHQWngln/6pTAvUJIczxuctUvWPZdR/axStq93VYNQ3txW+opxkc713bo2FNia7ly+CkRtSVY8kp16bgspE2U39lU8wZRXgLAQeOszlzGZPf+OXiHP5LmRT9nJALiYFC44ZT+fkACC+IcNlF+VEREM7NfhJ0gkraL7fvUu2TYQGMOFbNs9JIvTxjVcWKp5QCAq+8UnC9OcCtp8lZewwgOCK5b17y4XLA0kDKMeIHogZJ9CAaeGhUJZLPt4TLUDpg4To3EnvwOEgUfgZQiD0Rm5xGLw== 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=p0IaIJVib06pY5t7ytv/n9xYsp+YVobF0DEp+Onh5EG1zBQsPtZd2hVwrQ5u76OHIg+j+ryW/767gI7kQnW9XY49okz+543jNzuZ8WGZCh3PdnY4JQUhJ/l7njMqKQ+qIZR9+mAgLmEE/643BKxsvVmA8phvnbrhTGk+NVKK3CI= Received: from BY5PR13CA0003.namprd13.prod.outlook.com (2603:10b6:a03:180::16) by SA3PR12MB7878.namprd12.prod.outlook.com (2603:10b6:806:31e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.22; Tue, 28 Nov 2023 14:46:42 +0000 Received: from CO1PEPF000042A7.namprd03.prod.outlook.com (2603:10b6:a03:180:cafe::57) by BY5PR13CA0003.outlook.office365.com (2603:10b6:a03:180::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.17 via Frontend Transport; Tue, 28 Nov 2023 14:46:41 +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 CO1PEPF000042A7.mail.protection.outlook.com (10.167.243.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7046.17 via Frontend Transport; Tue, 28 Nov 2023 14:46:41 +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; Tue, 28 Nov 2023 08:46:37 -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 v4 2/4] rtc: Adjust failure return code for cmos_set_alarm() Date: Mon, 27 Nov 2023 23:36:51 -0600 Message-ID: <20231128053653.101798-3-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231128053653.101798-1-mario.limonciello@amd.com> References: <20231128053653.101798-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000042A7:EE_|SA3PR12MB7878:EE_ X-MS-Office365-Filtering-Correlation-Id: 0626876e-76e5-410d-e253-08dbf020d598 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Csee8n+vbtvsnQD57UQ0mDOyLsyQ4iF1hJ5AvrvhmMmUIYpRBGO/Yt0XCpj0w2k+nNhkxV7AbPbdj25zD3dKPZBL5Qj7yawxSJKRJpmUG9BMeJHAkqyNikWmGCb0g3e8G5ZYloQ6MJkX8E4GqobZJe2i3yqr0F3uTENTdt2d+yCWzB7BcFcjuLUflWMzuZTZYVLinCdhE+HJKAoxv1MY93gB4kq+kR38mgswN+1g9XjNYjLjGKN46WusCzJwe3Ff0PydeQoxrbuBCFaiJRdHyfWMC8nHYKOxJv5zXFl9zZocUMrWDZLxmGt3hhg9khk00RcY3UZOlVEkQ+kAOccLMSFPHARGTVeKezxsYZuOCxyEpzlgC5Jst4i052RpSBWMuzoOlBOOEiRwI2ic4XoXkRNyWYcy7HqkdfGMSeTly077aQOLdcTsb93ofvMAOWgFcKeIOUpJUGftyKp29kCyBZgq+pAoDis5lZgUygTasN/heEi0HHnQdlg+dtlNJCB2YuzDEzFyv9sZivtiozpk8Vc7Zauv1SoMZ6rByGLJIldzEtB6TGoxqWgur4d2iKjIF7YCPmQV+nyINOFClsPoCIHw0kK7YyIkfOYbuoJTbzRsLjIIqws2zuQMtv4fwc9QVXES6yyxfT1Is515WOBPG2I2ljBCJ0byz/EYn2jNmSEPE15006ExXUet7LQ/SHKYHvqWgvL1pxA4NshHQP2wAusvHemgeJMfiWO4Eag9XaEfL4xZnBzFTtV56vWzQ3l5qOvcdp0UvBJ5B4jSkNHZzA== 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)(376002)(346002)(136003)(396003)(39860400002)(230922051799003)(451199024)(186009)(64100799003)(82310400011)(1800799012)(46966006)(36840700001)(40470700004)(40460700003)(81166007)(356005)(82740400003)(478600001)(36756003)(4326008)(41300700001)(8936002)(8676002)(86362001)(316002)(54906003)(110136005)(70586007)(70206006)(1076003)(26005)(16526019)(2616005)(47076005)(66574015)(426003)(336012)(83380400001)(7696005)(6666004)(36860700001)(44832011)(40480700001)(2906002)(5660300002)(7416002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Nov 2023 14:46:41.4680 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0626876e-76e5-410d-e253-08dbf020d598 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: CO1PEPF000042A7.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7878 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 Tue Nov 28 05:36:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13471276 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="OdpgXv1H" Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2054.outbound.protection.outlook.com [40.107.92.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21B49D53; Tue, 28 Nov 2023 06:46:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QRmQt++Y2C4diQcPL3o/uV4UfNNwNK3tD3J2Kqnm/iWZx30UhGWcfy10xlUvfzhXw+MvMzqBb0w1vB13S3QXecqxMvDBtngwLp8S/xwtrbhTKj0M0Pa3qhKxX2TrSZaERd9nve7botDlJ39AD2hCttucRfSpAEIPya6jH51YK4jTewkw7w7CcjuWS8mYvgV+e4kmyH4o9zyyY8lGcgVqxRCVmj+bgSD0XjwIPIC6HYvlkTK/iIwLPbS0lgMuCHQRASDYjMWfaYt46FWIcRjq6iKfzFzHQffoFFmt8eLEjTckGfk3Rq37JwENVgQFAOjfo+iOj7fJY3imjbiFY6ioAQ== 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=ps6iDQXFBMjrpu52pMY4QXIybFrEFrNvG7BxcKU0/28=; b=gIaR94fAL4XfAy9vwTKHlzAbQFRfGh3gc1jnK66YFdKCOa8ZTzqtiWmB5NlAkzBmbq+FM0wi+DknfBnqr0AuLoxm55l/NMP8N+6SELuw4bSzhz/5OHEcogkUmXUcURsJoiUfHGQti8OQ+2BFws2v8IAlp/YYu0jr9TvZCI+jTjNY1KfRJFQ7vS4P+533sEk43qaBuIqlJ52VFD0sKR6xe1w7zIu61cqY7i5R/G3CAqQAeGfmfypuaPvd/caHAGkxoJEUTB78Ap5EpbQd0nIed08CjFvQUD+J79WS0Z9cW/cHe+2KTZ4MEcEMkoC/Rwk8Eri3UO3RGJG6VnoO4JypVA== 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=ps6iDQXFBMjrpu52pMY4QXIybFrEFrNvG7BxcKU0/28=; b=OdpgXv1HmZTplZYuzAqnRNft/0sCISIw7ppAeevga9UD2VOKjrOkwBAAnQ0vWPeTDCgSFnZ8Z36Mi7IJO0iNv26Xq0DSpPPOkPqUFRhp4emp3vGdKZg194/suHAgYSY2iET9FmTnXBiMTiQy6Kqr39kxaNDZJQ9xbyYufHuNt6Y= Received: from BY5PR13CA0013.namprd13.prod.outlook.com (2603:10b6:a03:180::26) by DS0PR12MB6605.namprd12.prod.outlook.com (2603:10b6:8:d3::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.27; Tue, 28 Nov 2023 14:46:44 +0000 Received: from CO1PEPF000042A7.namprd03.prod.outlook.com (2603:10b6:a03:180:cafe::a) by BY5PR13CA0013.outlook.office365.com (2603:10b6:a03:180::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.18 via Frontend Transport; Tue, 28 Nov 2023 14:46:44 +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 CO1PEPF000042A7.mail.protection.outlook.com (10.167.243.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7046.17 via Frontend Transport; Tue, 28 Nov 2023 14:46:43 +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; Tue, 28 Nov 2023 08:46:38 -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 v4 3/4] rtc: Add support for configuring the UIP timeout for RTC reads Date: Mon, 27 Nov 2023 23:36:52 -0600 Message-ID: <20231128053653.101798-4-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231128053653.101798-1-mario.limonciello@amd.com> References: <20231128053653.101798-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000042A7:EE_|DS0PR12MB6605:EE_ X-MS-Office365-Filtering-Correlation-Id: 50b24af6-af33-4a40-f804-08dbf020d713 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: i0hJLQ7Ax1ZwOVFbbbSQqCgv+lb/e9gJmjzo9H5UfZOEG1G6t/GzpdJsEjx3ouR6hacOfYkshHaoWFIhCxyzT249/0bTjwbu+OUqsL/2OcTjzoADxx2KhpYS46AwSh9AEhuxKk2URTtbPcHFYscTmI0Py9on01TwoVI9KmO6RkRDn47zRXdXUQ1IIGTNcMB3//yhcD/juyrOe8g+Hco3rj9rE6vYOnHREcCmUzsyxUV+7s2MJ86tt8t/1w3lDuxUQ+l5wyyi/pEZRSbzQ8GEJNhSNIWDf2Z3X92kj8ReWFPVh79szBo1s3N7YmjH9rtAGkVUjgd/6M3FpTr02r1X19HwiktgWyy+vdp6EEK3ts0k2nk3eG/QjbRrY7uQy754yj5X5MYX1Yp16FL1eb/GvV+BxCkJToWW2VizKApOwaZOJpr2XOqoTvjg3Xrj2SiryQ8WBo4Kacnxs+C8tzB2Z/+8TttsoD2oGfnHjQIatnewsiPMvDukhPIhRrsFq8bEyUIZH+5W9ZuGej1dVtWR9ucyqE8Blbp4hK/2CjYLzYlaqy06lOriCCVpFneCQvHoRAx2ubj7bOYEDV+FWNeSs3j7FThxCChLo4/+4+Ca1PDsTL/T68KDHSPMriPCPcy7ZUF4jZJl30kvaCCzLHzTmFd3HCnR76XSsWNzflbGUQXzC9QA9iz41Pr5N57K44mv5xBn3+XcgoN6iefYGmoEXwTQd2NiiZK802s7Sn9dhxky7X0ayVQieLscl3Kk7e8T7Y6soY580Y1D5DjXcQzTxJLkfYlzlu2dSFYhSivb8MFMrt3GKauwuXBovNRAggJBlgzAv5vKuFF7eVtwOSLNfQ== 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)(396003)(39860400002)(136003)(376002)(230273577357003)(230173577357003)(230922051799003)(186009)(451199024)(64100799003)(82310400011)(1800799012)(46966006)(36840700001)(40470700004)(8676002)(6666004)(8936002)(45080400002)(4326008)(7696005)(316002)(70206006)(110136005)(70586007)(54906003)(40460700003)(478600001)(81166007)(47076005)(356005)(36756003)(41300700001)(1076003)(86362001)(26005)(40480700001)(2906002)(36860700001)(44832011)(2616005)(83380400001)(336012)(426003)(16526019)(5660300002)(82740400003)(7416002)(557034005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Nov 2023 14:46:43.9524 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 50b24af6-af33-4a40-f804-08dbf020d713 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: CO1PEPF000042A7.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6605 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 Tested-by: Mateusz Jończyk Reviewed-by: Mateusz Jończyk Acked-by: Mateusz Jończyk --- v3->v4: * Change label * Logic adjustment for for loop * Fix pr_warn variable 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..4c17b3cef11e 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_LOOPS_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; UIP_RECHECK_LOOPS_MS(i) < 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 (UIP_RECHECK_LOOPS_MS(i) >= 100) + pr_warn("Reading current time from RTC took around %li ms\n", + UIP_RECHECK_LOOPS_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 Tue Nov 28 05:36: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: 13471275 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="CCvRNu7h" Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EB60D4B; Tue, 28 Nov 2023 06:46:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HWOEYmXdXHsX9uqxTGDzXdsfUFPsk0joFOfiNEcUNcc86HRXG0ksTSyeT9wuwlRJuy3CuFtqgMCwIjpkBCq6PussD+18Qq8RKjT0b2tg9T7qgySht4V+aH9pdH7Xpvm6PcSB98Rw4KrutqgMHORH6PVdwqNaZP/Aase8OhaFIRkWrnhTJS4ySfJ4K4uIdRGfEE49pxaunyvJF+/sjhCRX6kQi+RqYTXJK2oj7E3pyVQ4jJX4TSNRlAUW/1LtCgAmUWpYsWa5s7ENCv16tR4oWlHkGde8ctHuAV1SqSuX9CxPD0/AqC0gN7/BpUIoV76JKRtDiCnyUX/20fQZxRfKcg== 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=i91a/0SuuQ7ti/AN7riznmuffq98P/Q1GWqlQeZuB6g=; b=Dm2hgTj4mlHQz6szzP8fB60Ru93Qmwo1qoXkUpdIduv3BFJ8slMuf2pEnQW/m6bttH6STZxRk7u+RfTuBKYS0br8uE2P0Kpvy+DwNWp5ahIy6zPLV+1DNyyWPazavey4nuWLMbrjAxx6SOPRgXzOyjbLUj+BWjGzAFRQ0PVS53lRlyWYpgj3p1+AwOusocN8e/Tn866orj949D3Dx4cVT8iLCwr8MJSRZU9/WYXdwhH7Sc8wpo8or0wGfn75StGQK8eb9xcYYvCIjbFZN6xAgpe5ncgsorXFkm+BIdZJR7wrWjZHC6uoJh0iqbOjYeryALkVsT4+uwAvGjnbvII6ew== 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=i91a/0SuuQ7ti/AN7riznmuffq98P/Q1GWqlQeZuB6g=; b=CCvRNu7heBzzKe8NSHHdEWQ/RTrbeDnPpH3I6cTkNyrSFKy3f3qbcWq9YVNC/Q+H+QgAIv48rPoD0qtpRiv+dxG2fhfGPPA+bcRHSMcgPcgmjFClCHeuFQM8+32iHm1xYDbUrOyxH1AHFWSPJWL6nRf8SjzdrN+Hlx1keGJKsrg= Received: from BY5PR13CA0012.namprd13.prod.outlook.com (2603:10b6:a03:180::25) by IA1PR12MB7735.namprd12.prod.outlook.com (2603:10b6:208:421::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.27; Tue, 28 Nov 2023 14:46:45 +0000 Received: from CO1PEPF000042A7.namprd03.prod.outlook.com (2603:10b6:a03:180:cafe::7d) by BY5PR13CA0012.outlook.office365.com (2603:10b6:a03:180::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.17 via Frontend Transport; Tue, 28 Nov 2023 14:46:45 +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 CO1PEPF000042A7.mail.protection.outlook.com (10.167.243.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7046.17 via Frontend Transport; Tue, 28 Nov 2023 14:46:44 +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; Tue, 28 Nov 2023 08:46:40 -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 v4 4/4] rtc: Extend timeout for waiting for UIP to clear to 1s Date: Mon, 27 Nov 2023 23:36:53 -0600 Message-ID: <20231128053653.101798-5-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231128053653.101798-1-mario.limonciello@amd.com> References: <20231128053653.101798-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000042A7:EE_|IA1PR12MB7735:EE_ X-MS-Office365-Filtering-Correlation-Id: 8da0332f-9b1a-4bb8-b6f5-08dbf020d794 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: t6koyZr28VcSNE0558icCWPqkHwWzxqQxiurFH51XmvOiqwS73D/mc4dPYVVb5HzpS8G6XXFJxGpjK7SSaDmjagbuQRJe0s1hykaSsoa4wsX+PD/JKF5pDPwZSB9Jbr/Zm1Ag2jT8Qv+XejF5re9E2J8qNF7KUgl6calwT8b0/WT1vmwpJY+N5MDpeOi7+uk2Xy/JGdExLxJC/O4OvqhynGhJHaZ3QuRpe3HUKNF3lrWYMEL3wjwG/zq2zUBFzEgbMQKrfSfx2hk1opXO3m+rPT+ufZwBHt+/Ywqd9lpl9oAIPbxJXAmA8xLOUuRBYzjEQ6TFS/Qccq3wpiTLisBGsZr4d9eJ5SH8N/ysG6A3Oc1h1GL3Yy21TJQTfVkAMlO32FuSDlSc76WWFi9Vyca1v49tgaryI1Pr5fmGKExPynPEio19h08rMXSV57rKyzzKq6IZnoWcj4elklVZh+7NxBmniExGKr64BaJO9uXRtStD7qoeofbT+5gj+e7dsAQHOezdkIlnMRKbw2JuFe+6E6qQE13YegdmGN6yBGhAY0tSiEz46h7adCi6KoUalOqyePA7+ROL9+UoMrL/A3Nyhnh+epPGlhk9xQBJ7464D4WmTKpDum4IeWwYVPfM9iMl7MobWpc1xwM+9hZDr6jAjFfo73qM27tV6tS5JxKT2lJVcbfcFdbbzLeFplswTWD2wmcd3HeAZDRtM8ODnpi4EfAMcDck+NkPSRTkOmEjSC9LS2PlMbEAtT3F/PD/s5LyRX37BAg8lqLclw5ViISDg== 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)(346002)(136003)(230922051799003)(64100799003)(82310400011)(1800799012)(186009)(451199024)(36840700001)(40470700004)(46966006)(7696005)(1076003)(2616005)(478600001)(6666004)(966005)(47076005)(336012)(426003)(4326008)(16526019)(7416002)(5660300002)(44832011)(2906002)(54906003)(70586007)(70206006)(8936002)(316002)(110136005)(8676002)(83380400001)(41300700001)(40460700003)(36756003)(81166007)(36860700001)(356005)(86362001)(82740400003)(40480700001)(26005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Nov 2023 14:46:44.7961 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8da0332f-9b1a-4bb8-b6f5-08dbf020d794 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: CO1PEPF000042A7.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7735 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 4c17b3cef11e..651bf3c279c7 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);