From patchwork Fri Dec 15 22:06:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 13495089 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 889B4C46CA2 for ; Fri, 15 Dec 2023 22:07:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=QblKhkuD+55d0K3P5RKz9HiMb/ZMNjM2G6hcjzGcL6Q=; b=HC6fe6tvPX6ChN sHwbgmIH9Rw9B9XAn7snw1CDtgODCOgX4MFEncpW8KxCdkfq8eGQVOduoEMnNOk0Oq+C81hhiTjLC 08MJDEnqssVJXP7kmjOccxrGUbFYb3zLIrAwf+p5nkT7YCVk8bf3qGbC9N2+8JkgQumAbbnbppZ5O /0dzfkmTfWodtWFgS15wS4a6gbYy6NkolB+SP1q87Rp+3+8AYk26c9T1Au0oHEn6nLr4R96/o74fE QOvZ9Ndufc6N+jFe8aIBgTKt0V1PWyM7jXvtz/IxLfozwWrHglSzKQUw2rWMmodx9BlANfq46xvfu zZ+rEAmUx95Bbm9zW6dQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rEGKa-004i1x-0j; Fri, 15 Dec 2023 22:06:52 +0000 Received: from repost01.tmes.trendmicro.eu ([18.185.115.17]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rEGKO-004hxH-2z for linux-arm-kernel@lists.infradead.org; Fri, 15 Dec 2023 22:06:45 +0000 Received: from 104.47.7.168_.trendmicro.com (unknown [172.21.190.17]) by repost01.tmes.trendmicro.eu (Postfix) with SMTP id DD6FA1000006D; Fri, 15 Dec 2023 22:06:37 +0000 (UTC) X-TM-MAIL-RECEIVED-TIME: 1702677996.868000 X-TM-MAIL-UUID: b9911cce-9f2e-442c-be80-281553fba8e2 Received: from DEU01-BE0-obe.outbound.protection.outlook.com (unknown [104.47.7.168]) by repre01.tmes.trendmicro.eu (Trend Micro Email Security) with ESMTPS id D4032100010AC; Fri, 15 Dec 2023 22:06:36 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B8qwOH0LP0a+2dT6T3bmhN3gwhVzgk7+ijr/YNhHPNVJdrOyaiy9RXTzkf4SIOyafkfrZNBgkGckoWWBbqnK292j+TZj8c2tsRVn7JtaOMm1UmJ1Y1/+Yp37myNVr/H/NjfF58st7C9ZOOH8yjwpPH27b8SRTUZvvDzvz83mhrJkw9lMSBze4ueAU4+YiPvRV+558KX7KPOJtoIezgrnLx+uzTPDckCpryLEKxBcF7Z84IkvGxSzmJ8IsSvoECV2xE8NBhCYX7lix+h0AJGEFI9pC7GnrztssE0N6B9NPUMRC/2FXQ4mpwb3uOaMhEOf7jsEvNTDuHcM5m3E03LMAQ== 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=3xfDBu0dFrCJ0xgcFfSZVaKqG7Zde6VKWwu8n6eP+A0=; b=VhuAcRgFJ75vNoJvAKShPJcMGf4OUw5MhzHILcJNxST5RlaHilsg5tX25tI3kz7OdgdA/ey27WbTTajM39Q60gDzM+XKe4ysJEoSzMrzeacGPV5MapGhl2CqOqQcsN1tk9TWo866L9Fh11O1mvlra2Q4bG+lFqzxM3Ye2tWzQthLLnoakD51bzYVhM2HgC9h2uILF4n+KUkBxLtUtCSopTKZv66Rk+/cVWTeS6XdkWx08GYF/cNK24ddG3juH+NulDwACf81gQfaO/rDDvyeZEhz5xUnbHb8DwWJasUShRmG8zYYAHdc5TlcG8+KaezmEVWOFqOceRMDONTeFfrLbw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 217.66.60.4) smtp.rcpttodomain=alien8.de smtp.mailfrom=opensynergy.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=opensynergy.com; dkim=none (message not signed); arc=none (0) X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 217.66.60.4) smtp.mailfrom=opensynergy.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=opensynergy.com; Received-SPF: Pass (protection.outlook.com: domain of opensynergy.com designates 217.66.60.4 as permitted sender) receiver=protection.outlook.com; client-ip=217.66.60.4; helo=SR-MAIL-03.open-synergy.com; pr=C From: Peter Hilber To: linux-kernel@vger.kernel.org Cc: Peter Hilber , "D, Lakshmi Sowjanya" , Thomas Gleixner , jstultz@google.com, giometti@enneenne.com, corbet@lwn.net, andriy.shevchenko@linux.intel.com, "Dong, Eddie" , "Hall, Christopher S" , Marc Zyngier , linux-arm-kernel@lists.infradead.org, Sean Christopherson , Paolo Bonzini , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Wanpeng Li , Vitaly Kuznetsov , Mark Rutland , Daniel Lezcano , Richard Cochran , kvm@vger.kernel.org, netdev@vger.kernel.org, Stephen Boyd Subject: [RFC PATCH v2 5/7] timekeeping: Evaluate system_counterval_t.cs_id instead of .cs Date: Fri, 15 Dec 2023 23:06:10 +0100 Message-Id: <20231215220612.173603-6-peter.hilber@opensynergy.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231215220612.173603-1-peter.hilber@opensynergy.com> References: <20231215220612.173603-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB8EUR05FT060:EE_|FRYP281MB2304:EE_ X-MS-Office365-Filtering-Correlation-Id: a451a6e6-48ba-49e3-4948-08dbfdba1a79 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2yeCm6q8s6Z7qAa8lz2S9IEc2ybGg3JzMs0IP/j8nkV8GkVhLIFhlp5+3WG5vkrEJkIQzKWh8VZD1sf/GomE6s6W92D+QIRPAiDXuLKziaLBEeZo7c0We+s8MkWqgb75gqBqhSomdvEbyweEKZq3mBzRD3CefmB8IGDz97eQ7xVXkqXXamnpXt2czIdpZbKXOIsL7VJeKPznVlNeOKVw0gvlHEz1XQqOwrqSsxa1dK0XrXEjJLyHzIozMFFUzhcGj8Wr8mhPZ0RWi0x0wH0IgbZcdGZsM7ihyNoazO2p6pLp3WloCCF7RLY9wgIDuki2WcIpfk6UZRjs3f0tCpGi4xi6qcZgl2pCa3dpWgleelPeHQdd0IROEZ5XkqeOzscxgajStmPtqy92qKwEiCeMjKVKhAXM4QCmKzGBszhymDVV1P5k8aZF+kAZk7upZRoONxawO/H6ISSPeWqpTS+KT1s6yUD5tq4jk/GgtOFEpijNkujz4NjAY6vUDIa4AclHfGbeXuvEXMGTB4JYDVDl6SRpRG7yvk+pA929bq0Ca6sFV00bRLpK+udFelW3gpg14YJiyF3IcqULioU4GohLBI8UCgMo+0Az5+VlJecNdP3y+qcl5eZvrgiHeFB9VdTvUyKmrFN04YZc85Otp1afjjF5qKbn6bl17dR6TWmNsFVtVGF90iIZjfhRfPlsHlJnL8e/lJvoeJMxLUIMPXL4XHkPHqy3DOzXNZ/VigK0gjN8+4nSPjGT5o0uc1NusY//JoxfO4AVkQin81zmmnIjuVhA4OY7z02h6GUAJrm98G4= X-Forefront-Antispam-Report: CIP:217.66.60.4;CTRY:DE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SR-MAIL-03.open-synergy.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(396003)(346002)(136003)(39840400004)(376002)(230922051799003)(451199024)(82310400011)(64100799003)(186009)(1800799012)(46966006)(36840700001)(47076005)(83380400001)(1076003)(2616005)(336012)(26005)(36860700001)(4326008)(8676002)(8936002)(5660300002)(44832011)(41300700001)(7416002)(2906002)(478600001)(966005)(42186006)(54906003)(70206006)(6916009)(316002)(70586007)(36756003)(81166007)(86362001)(40480700001)(142923001)(36900700001);DIR:OUT;SFP:1102; X-OriginatorOrg: opensynergy.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2023 22:06:35.1864 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a451a6e6-48ba-49e3-4948-08dbfdba1a79 X-MS-Exchange-CrossTenant-Id: 800fae25-9b1b-4edc-993d-c939c4e84a64 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=800fae25-9b1b-4edc-993d-c939c4e84a64;Ip=[217.66.60.4];Helo=[SR-MAIL-03.open-synergy.com] X-MS-Exchange-CrossTenant-AuthSource: DB8EUR05FT060.eop-eur05.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: FRYP281MB2304 X-TM-AS-ERS: 104.47.7.168-0.0.0.0 X-TMASE-Version: StarCloud-1.3-9.1.1015-28060.002 X-TMASE-Result: 10--4.043200-4.000000 X-TMASE-MatchedRID: xPvPRJicGCRt/9ulvM0QMd/Z7q+hZQVe6wJlKkX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: EMS DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=opensynergy.com; s=TM-DKIM-20210503141657; t=1702677997; bh=NojOs1qfg8jfCnvQpu510s9G5wxEpdRCYhUuXgZyMgM=; l=3420; h=From:To:Date; b=VQhIjNaqWzDConf6m33bHny6T8JEUmz/xXKoo28/UItFI3emjHtLfee5RxKqbhpbR 9JNrSoxG6DUxm/pLxYfHUHgWCG7ib6HyY/yvK6slMXN+EdfTcVpPX8oMjv1j+DSMEV JLzD2OewqgJWBP+KswLFp4OQtI8a16PVZd/+d2L8tODvF826LEg6kgu7+VOyggTQ3I DS8zEvP11DlvzYYyM+C+5L7+9B+fqBF3J5o2Tv3a5zi1Lz45daA6bLavB8h6Zsfl/x 5AnO+q0H5V7D8yljYj1kQv7cDKfDU0tAum/EE1PN/rLOZQD92Cev/R2dbPIXdfoO9s ROQDNI6ceCzSg== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231215_140641_263766_BA249509 X-CRM114-Status: GOOD ( 16.83 ) 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 Clocksource pointers can be problematic to obtain for drivers which are not clocksource drivers themselves. In particular, the RFC virtio_rtc driver [1] would require a new helper function to obtain a pointer to the Arm Generic Timer clocksource. The ptp_kvm driver also required a similar workaround. Address this by evaluating the clocksource ID, rather than the clocksource pointer, of struct system_counterval_t. By this, setting the clocksource pointer becomes unneeded, and it will be dropped from struct system_counterval_t in the future. By this, get_device_system_crosststamp() callers (such as virtio_rtc and ptp_kvm) will no longer need to supply clocksource pointers. This change should not alter any behavior, as the struct system_counterval_t clocksource ID is already being set wherever the clocksource pointer is set. get_device_system_crosststamp() will now fail if the clocksource has id CSID_GENERIC, but all currently relevant clocksources have a custom clocksource id. [1] https://lore.kernel.org/lkml/20230818012014.212155-1-peter.hilber@opensynergy.com/ Signed-off-by: Peter Hilber --- Notes: v2: - Refer to clocksource IDs as such in comments (Thomas Gleixner). - Update comments which were still referring to clocksource pointers. include/linux/timekeeping.h | 10 +++++----- kernel/time/timekeeping.c | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index 74dc7c8b036f..75e957171bd5 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -267,13 +267,13 @@ struct system_device_crosststamp { }; /** - * struct system_counterval_t - system counter value with the pointer to the + * struct system_counterval_t - system counter value with the ID of the * corresponding clocksource * @cycles: System counter value - * @cs: Clocksource corresponding to system counter value. Used by - * timekeeping code to verify comparibility of two cycle values - * @cs_id: Clocksource ID corresponding to system counter value. To be - * used instead of cs in the future. + * @cs: Clocksource corresponding to system counter value. Timekeeping + * code now evaluates cs_id instead. + * @cs_id: Clocksource ID corresponding to system counter value. Used by + * timekeeping code to verify comparability of two cycle values. * The default ID, CSID_GENERIC, does not identify a specific * clocksource. */ diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 266d02809dbb..0ff065c5d25b 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1232,11 +1232,12 @@ int get_device_system_crosststamp(int (*get_time_fn) return ret; /* - * Verify that the clocksource associated with the captured - * system counter value is the same as the currently installed - * timekeeper clocksource + * Verify that the clocksource ID associated with the captured + * system counter value is the same as for the currently + * installed timekeeper clocksource */ - if (tk->tkr_mono.clock != system_counterval.cs) + if (system_counterval.cs_id == CSID_GENERIC || + tk->tkr_mono.clock->id != system_counterval.cs_id) return -ENODEV; cycles = system_counterval.cycles;