From patchwork Wed Sep 4 15:31:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 13791124 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 1EF99CD4F22 for ; Wed, 4 Sep 2024 15:32:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.790491.1200262 (Exim 4.92) (envelope-from ) id 1slrzH-0003kK-J3; Wed, 04 Sep 2024 15:32:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 790491.1200262; Wed, 04 Sep 2024 15:32:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slrzH-0003kD-GL; Wed, 04 Sep 2024 15:32:03 +0000 Received: by outflank-mailman (input) for mailman id 790491; Wed, 04 Sep 2024 15:32:01 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slrzF-0003Vv-SL for xen-devel@lists.xenproject.org; Wed, 04 Sep 2024 15:32:01 +0000 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [2a00:1450:4864:20::62c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d3e75446-6ad2-11ef-a0b3-8be0dac302b0; Wed, 04 Sep 2024 17:32:00 +0200 (CEST) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a869f6ce2b9so733137566b.2 for ; Wed, 04 Sep 2024 08:32:00 -0700 (PDT) Received: from localhost ([213.195.124.163]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8a6236cfb4sm5500966b.100.2024.09.04.08.31.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 08:31:58 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d3e75446-6ad2-11ef-a0b3-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1725463919; x=1726068719; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3uSQihnqXCf2hMyHenOR5h3swtTmtaH+EXsprydBl94=; b=qLcwj5qWBqiyRy6vRlWKzzJLFUIJpICHYXRKOiT75M259/YlyX2aERKvnUuhAIHo+E Tj98jJ9vvbraWZ/AvCcYFCKg6g0QoqPPjSZC+/PNeFjpH6ia9syOig8Q40bGKM1u9Q8S ZpMzH+4G5FKdPN+WGhyv6oBfhcrDsivt/FkeE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725463919; x=1726068719; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3uSQihnqXCf2hMyHenOR5h3swtTmtaH+EXsprydBl94=; b=K12M5pWp8miV3zL9b8VInSv1LzVlmKlmfPJ3gsz7QBf/ygeW06mkya9mra5GIZ7g1w R9nBedODf27uhqxKvriMmwDPvsOSIH3bxqwP7pIsIdH+EssWEeidMMGn3LHEwJp5ZUA9 65Fjh+fA/5p8S4skW+Ex/WbAlU2ovfrhH5uy3jBPckUR62Yg8bmvWfFPm8HSgdOZ4QWH ovjW7bSJOqV7m5PAjHYFidsGM7N3DsfX74QWTqXlbzQqo/kUzJjHVTBhgpEOrXZzSp8E DEpM9ElHQeqHh7rXnS64kQ3PZSbc4cgVwObqYqKFHo6MG2VAKMNO3uA+tgmZeVcEKHQu U6/w== X-Gm-Message-State: AOJu0YwUE9Do4ha1K14U+UhsY+fiLNJpy51tI8YnqljPE/FfjOEdRU5J iwzUgBMLINrciccGPe6eyT2lmqrBYQiTOEaz3b172MhuBX7jQphsmC2pyvgAO8rqpZGsbDU9IJd d X-Google-Smtp-Source: AGHT+IHfzxlFNr7URNfg+tTFdYyvwqEKKJAiB7ZDtpDrq5OI9vbmMwcP4p+qHmEqgXi1l3nRowguDA== X-Received: by 2002:a17:907:3f09:b0:a86:8e3d:86e2 with SMTP id a640c23a62f3a-a8a32df30c3mr384486466b.11.1725463918850; Wed, 04 Sep 2024 08:31:58 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: "Daniel P. Smith" , =?utf-8?q?Marek_Marczy?= =?utf-8?q?kowski-G=C3=B3recki?= , Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v4 1/6] x86/time: introduce helper to fetch Xen wallclock when running as a guest Date: Wed, 4 Sep 2024 17:31:46 +0200 Message-ID: <20240904153151.83995-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240904153151.83995-1-roger.pau@citrix.com> References: <20240904153151.83995-1-roger.pau@citrix.com> MIME-Version: 1.0 Move the current code in get_wallclock_time() to fetch the Xen wallclock information from the shared page when running as a guest into a separate helper. No functional change intended. Signed-off-by: Roger Pau Monné Acked-by: Jan Beulich --- Changes since v3: - Place ifdef blocks inside the function. Changes since v2: - New in this version. --- xen/arch/x86/time.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index a97d78484105..1959cc4a4f2b 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -787,6 +787,30 @@ static struct platform_timesource __initdata_cf_clobber plt_xen_timer = }; #endif +static unsigned long read_xen_wallclock(void) +{ +#ifdef CONFIG_XEN_GUEST + struct shared_info *sh_info = XEN_shared_info; + uint32_t wc_version; + uint64_t wc_sec; + + ASSERT(xen_guest); + + do { + wc_version = sh_info->wc_version & ~1; + smp_rmb(); + + wc_sec = sh_info->wc_sec; + smp_rmb(); + } while ( wc_version != sh_info->wc_version ); + + return wc_sec + read_xen_timer() / 1000000000; +#else + ASSERT_UNREACHABLE(); + return 0; +#endif +} + #ifdef CONFIG_HYPERV_GUEST /************************************************************ * HYPER-V REFERENCE TSC @@ -1497,24 +1521,8 @@ void rtc_guest_write(unsigned int port, unsigned int data) static unsigned long get_wallclock_time(void) { -#ifdef CONFIG_XEN_GUEST if ( xen_guest ) - { - struct shared_info *sh_info = XEN_shared_info; - uint32_t wc_version; - uint64_t wc_sec; - - do { - wc_version = sh_info->wc_version & ~1; - smp_rmb(); - - wc_sec = sh_info->wc_sec; - smp_rmb(); - } while ( wc_version != sh_info->wc_version ); - - return wc_sec + read_xen_timer() / 1000000000; - } -#endif + return read_xen_wallclock(); return get_cmos_time(); } From patchwork Wed Sep 4 15:31:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 13791121 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 4ABA8CD4F20 for ; Wed, 4 Sep 2024 15:32:13 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.790492.1200269 (Exim 4.92) (envelope-from ) id 1slrzH-0003mo-VA; Wed, 04 Sep 2024 15:32:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 790492.1200269; Wed, 04 Sep 2024 15:32:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slrzH-0003mD-Nx; Wed, 04 Sep 2024 15:32:03 +0000 Received: by outflank-mailman (input) for mailman id 790492; Wed, 04 Sep 2024 15:32:02 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slrzG-0003Vv-3E for xen-devel@lists.xenproject.org; Wed, 04 Sep 2024 15:32:02 +0000 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [2a00:1450:4864:20::62a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d45172c2-6ad2-11ef-a0b3-8be0dac302b0; Wed, 04 Sep 2024 17:32:01 +0200 (CEST) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a868b8bb0feso810568766b.0 for ; Wed, 04 Sep 2024 08:32:01 -0700 (PDT) Received: from localhost ([213.195.124.163]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8a620840b6sm6025966b.92.2024.09.04.08.31.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 08:31:59 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d45172c2-6ad2-11ef-a0b3-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1725463920; x=1726068720; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NrfOkjyZvcFrm5dtWXhSEszzPb0Micj/yQlfQ2ecmso=; b=Ym5DYgJXb/QqD576iAPE/mxsugL5njBlen98x64KsXPIAEGG4a0i7EwPeCECaI6iXO RgFKVYLUjmX8mqO/AEW0PkL76VnhGmKS/N9sZ7Zd0k5l2AE7VE6Hk1bsck9Y/QIHhHWE lSSWo5NtEVbrrPkEtWAyS7RuG6F4jvDf4uDNo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725463920; x=1726068720; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NrfOkjyZvcFrm5dtWXhSEszzPb0Micj/yQlfQ2ecmso=; b=W/9f3DIYhsGG3kKZFGoloZQr2kjKju2Ak/5QG9xK//DYwNQt44BFMH6ghlJnu9nQhV DHckEilLJwxEtcQ8BnwYuZXprxuHm5jL8qKO7plUYES90aGcDM1RvlAUDu3suYQBhq6U chxYY/nsNqoWE/xaNjZwIuakGIIu5q0KRYogXECZpTO3eWXVEYXMQqcje9IGHVAlXOOR vQYK2zAZ6MQ/AlKGRggeL/OyiW44nWsDIiLUBTJJSgTObYD6VCw9EJRS5NYCqOcjQn+o S+ygg7ZSw0issn4TRxyCV4tSs58hi5irP0yqSKNK6BMfcw6CAuwCKCiVgU09w1mM57cq jXBA== X-Gm-Message-State: AOJu0YwWVjUgL+IRn2fQEQWEbJDkUeKgr5Hte8T5dbozP8XxFFoMKDTu hCupx/VHN6GG5CopHy7V6GiEYwzllrRAzAboezzQ7lb/ghy7MsenhQRMmcHUQ4atJ9D3A12PEiP Y X-Google-Smtp-Source: AGHT+IEKwd46aI1FXSeKvqMogs4g+CNs1X3mL1gvBfQn1oSpQxufVbzZyDoD6GdK1DDwCHuEp8mK+w== X-Received: by 2002:a17:907:980c:b0:a86:8f57:7de0 with SMTP id a640c23a62f3a-a89a37aa9famr1280983266b.49.1725463919983; Wed, 04 Sep 2024 08:31:59 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: "Daniel P. Smith" , =?utf-8?q?Marek_Marczy?= =?utf-8?q?kowski-G=C3=B3recki?= , Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v4 2/6] x86/time: move CMOS edge detection into read helper Date: Wed, 4 Sep 2024 17:31:47 +0200 Message-ID: <20240904153151.83995-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240904153151.83995-1-roger.pau@citrix.com> References: <20240904153151.83995-1-roger.pau@citrix.com> MIME-Version: 1.0 Move the logic that ensures the CMOS RTC data is read just after it's been updated into the __get_cmos_time() function that does the register reads. This requires returning a boolean from __get_cmos_time() to signal whether the read has been successfully performed after an update. Note that while __get_cmos_time() can be used without waiting for the update edge, so far the only caller does wait for it, hence move the code inside of the function. The goal, albeit not accomplished by this patch, is to be able to split the probing and the reading of the CMOS RTC data into two separate functions. No functional change intended. Signed-off-by: Roger Pau Monné Acked-by: Jan Beulich --- Changes since v3: - Reduce a bit the locked section. Changes since v2: - New in this version. --- xen/arch/x86/time.c | 50 +++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index 1959cc4a4f2b..571e23431ccd 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -1246,8 +1246,26 @@ struct rtc_time { unsigned int year, mon, day, hour, min, sec; }; -static void __get_cmos_time(struct rtc_time *rtc) +static bool __get_cmos_time(struct rtc_time *rtc) { + s_time_t start, t1, t2; + unsigned long flags; + + spin_lock_irqsave(&rtc_lock, flags); + + /* read RTC exactly on falling edge of update flag */ + start = NOW(); + do { /* may take up to 1 second... */ + t1 = NOW() - start; + } while ( !(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) && + t1 <= SECONDS(1) ); + + start = NOW(); + do { /* must try at least 2.228 ms */ + t2 = NOW() - start; + } while ( (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) && + t2 < MILLISECS(3) ); + rtc->sec = CMOS_READ(RTC_SECONDS); rtc->min = CMOS_READ(RTC_MINUTES); rtc->hour = CMOS_READ(RTC_HOURS); @@ -1265,13 +1283,17 @@ static void __get_cmos_time(struct rtc_time *rtc) BCD_TO_BIN(rtc->year); } + spin_unlock_irqrestore(&rtc_lock, flags); + if ( (rtc->year += 1900) < 1970 ) rtc->year += 100; + + return t1 <= SECONDS(1) && t2 < MILLISECS(3); } static unsigned long get_cmos_time(void) { - unsigned long res, flags; + unsigned long res; struct rtc_time rtc; unsigned int seconds = 60; static bool __read_mostly cmos_rtc_probe; @@ -1292,29 +1314,9 @@ static unsigned long get_cmos_time(void) for ( ; ; ) { - s_time_t start, t1, t2; - - spin_lock_irqsave(&rtc_lock, flags); - - /* read RTC exactly on falling edge of update flag */ - start = NOW(); - do { /* may take up to 1 second... */ - t1 = NOW() - start; - } while ( !(CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) && - t1 <= SECONDS(1) ); - - start = NOW(); - do { /* must try at least 2.228 ms */ - t2 = NOW() - start; - } while ( (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) && - t2 < MILLISECS(3) ); - - __get_cmos_time(&rtc); - - spin_unlock_irqrestore(&rtc_lock, flags); + bool success = __get_cmos_time(&rtc); - if ( likely(!cmos_rtc_probe) || - t1 > SECONDS(1) || t2 >= MILLISECS(3) || + if ( likely(!cmos_rtc_probe) || !success || rtc.sec >= 60 || rtc.min >= 60 || rtc.hour >= 24 || !rtc.day || rtc.day > 31 || !rtc.mon || rtc.mon > 12 ) From patchwork Wed Sep 4 15:31:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 13791125 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 0EF98CD4F21 for ; Wed, 4 Sep 2024 15:32:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.790493.1200271 (Exim 4.92) (envelope-from ) id 1slrzI-0003tO-4r; Wed, 04 Sep 2024 15:32:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 790493.1200271; Wed, 04 Sep 2024 15:32:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slrzH-0003qX-Vx; Wed, 04 Sep 2024 15:32:03 +0000 Received: by outflank-mailman (input) for mailman id 790493; Wed, 04 Sep 2024 15:32:03 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slrzH-0003Vv-9W for xen-devel@lists.xenproject.org; Wed, 04 Sep 2024 15:32:03 +0000 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [2a00:1450:4864:20::630]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d53f1ab9-6ad2-11ef-a0b3-8be0dac302b0; Wed, 04 Sep 2024 17:32:02 +0200 (CEST) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a86e5e9ff05so788841066b.1 for ; Wed, 04 Sep 2024 08:32:02 -0700 (PDT) Received: from localhost ([213.195.124.163]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8a623a9939sm5236366b.158.2024.09.04.08.32.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 08:32:00 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d53f1ab9-6ad2-11ef-a0b3-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1725463921; x=1726068721; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DdGzkJBMdRuuSYc3u2Hg7lyIJS3prPV9F25LIY9VB0g=; b=jIUx0+iD7mdZYl5BppKwSa0orj9+kBko8FYH300AOIR56Fn1ZH2LhB2j6L40aZS/J6 t8JtoOznFJdPZ+SC6iaGfsJqFORRbjHEc5R11gxAGqRsrc1KVZEXN8hD6nHkBbroto6c aGE1QjNAIy846OA3HOzgTgwAxw9uMv/Sa/56w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725463921; x=1726068721; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DdGzkJBMdRuuSYc3u2Hg7lyIJS3prPV9F25LIY9VB0g=; b=esvZY81nAF0s4mMLvifvrxLclXLcNRjttOjf6oAQJIkWU4eUDnhkVnIi/D93ATncm1 gSmUHaPMvbws2NcSEFF9lMO+ScqKy8cqDquyYEdD7sK4Ura1d0+erbh1Ra6U1Ih6osO3 WNR4t+hV9yQCgp7tdb/T9hDP9ARA0p18MRlX8s5TgY3UNR9p6vctA1E3OiiOLiyolTps wm4lzgQ9FOJ5ZlSeGDvCRyPmqHcmLKc5lYZjOFcq+wjbfDCWy08gDSljwYcqTUujm/nx 8bzaMw+jOBaO2MBglVed/rMsrFOVJOo9n/U5aYUCtquOjqEj0ZIt57ALrazx/tTn6WcM TV1Q== X-Gm-Message-State: AOJu0Yz6wZXrQVid7tGfvmabRqDdRvANsTG1hOmAiLFa/oOKE2iocBJy Oeo5OmdS+JCDhY/3pKgFP/mHxnGUGPZQvkUxSWrolpbSj4X8B2RtyPi6wSmMpDm6Hb0ba3F83uB B X-Google-Smtp-Source: AGHT+IE6XkMLQoiA77O1qAsVl6/RLfVs+qbzPjMR2qwXAUzpRGwUiFzq5NDzZGUZpra7+nYpqIMQRQ== X-Received: by 2002:a17:907:2da5:b0:a86:9cff:6798 with SMTP id a640c23a62f3a-a8a32ed4b43mr394525566b.30.1725463921126; Wed, 04 Sep 2024 08:32:01 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: "Daniel P. Smith" , =?utf-8?q?Marek_Marczy?= =?utf-8?q?kowski-G=C3=B3recki?= , Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v4 3/6] x86/time: split CMOS read and probe logic into function Date: Wed, 4 Sep 2024 17:31:48 +0200 Message-ID: <20240904153151.83995-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240904153151.83995-1-roger.pau@citrix.com> References: <20240904153151.83995-1-roger.pau@citrix.com> MIME-Version: 1.0 The current logic to probe for the CMOS RTC is open-coded in get_cmos_time(), move it to a separate function that both serves the purpose of testing for the CMOS RTC existence and returning its value. The goal is to be able to split the probing and the reading logic into separate helpers, and putting the current logic in a separate function helps simplifying further changes. A transient *rtc_p variable is introduced as a parameter to the function, that will be removed by further changes. Also note that due to the code movement, now cmos_rtc_probe will only get cleared on a second call to get_cmos_time(), as the newly introduced cmos_probe() function doesn't modify the variable anymore. No functional change intended. Signed-off-by: Roger Pau Monné Acked-by: Jan Beulich --- Changes since v2: - New in this version. --- xen/arch/x86/time.c | 59 +++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index 571e23431ccd..1e3c13fc7360 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -1291,45 +1291,32 @@ static bool __get_cmos_time(struct rtc_time *rtc) return t1 <= SECONDS(1) && t2 < MILLISECS(3); } -static unsigned long get_cmos_time(void) +static bool cmos_probe(struct rtc_time *rtc_p, bool cmos_rtc_probe) { - unsigned long res; - struct rtc_time rtc; unsigned int seconds = 60; - static bool __read_mostly cmos_rtc_probe; - boolean_param("cmos-rtc-probe", cmos_rtc_probe); - - if ( efi_enabled(EFI_RS) ) - { - res = efi_get_time(); - if ( res ) - return res; - } - - if ( likely(!(acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_CMOS_RTC)) ) - cmos_rtc_probe = false; - else if ( system_state < SYS_STATE_smp_boot && !cmos_rtc_probe ) - panic("System with no CMOS RTC advertised must be booted from EFI" - " (or with command line option \"cmos-rtc-probe\")\n"); for ( ; ; ) { - bool success = __get_cmos_time(&rtc); + bool success = __get_cmos_time(rtc_p); + struct rtc_time rtc = *rtc_p; - if ( likely(!cmos_rtc_probe) || !success || + if ( likely(!cmos_rtc_probe) ) + return true; + + if ( !success || rtc.sec >= 60 || rtc.min >= 60 || rtc.hour >= 24 || !rtc.day || rtc.day > 31 || !rtc.mon || rtc.mon > 12 ) - break; + return false; if ( seconds < 60 ) { if ( rtc.sec != seconds ) { - cmos_rtc_probe = false; acpi_gbl_FADT.boot_flags &= ~ACPI_FADT_NO_CMOS_RTC; + return true; } - break; + return false; } process_pending_softirqs(); @@ -1337,7 +1324,31 @@ static unsigned long get_cmos_time(void) seconds = rtc.sec; } - if ( unlikely(cmos_rtc_probe) ) + ASSERT_UNREACHABLE(); + return false; +} + +static unsigned long get_cmos_time(void) +{ + unsigned long res; + struct rtc_time rtc; + static bool __read_mostly cmos_rtc_probe; + boolean_param("cmos-rtc-probe", cmos_rtc_probe); + + if ( efi_enabled(EFI_RS) ) + { + res = efi_get_time(); + if ( res ) + return res; + } + + if ( likely(!(acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_CMOS_RTC)) ) + cmos_rtc_probe = false; + else if ( system_state < SYS_STATE_smp_boot && !cmos_rtc_probe ) + panic("System with no CMOS RTC advertised must be booted from EFI" + " (or with command line option \"cmos-rtc-probe\")\n"); + + if ( !cmos_probe(&rtc, cmos_rtc_probe) ) panic("No CMOS RTC found - system must be booted from EFI\n"); return mktime(rtc.year, rtc.mon, rtc.day, rtc.hour, rtc.min, rtc.sec); From patchwork Wed Sep 4 15:31:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 13791122 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 3269ACD4857 for ; Wed, 4 Sep 2024 15:32:13 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.790494.1200293 (Exim 4.92) (envelope-from ) id 1slrzJ-0004SY-LF; Wed, 04 Sep 2024 15:32:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 790494.1200293; Wed, 04 Sep 2024 15:32:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slrzJ-0004Ry-HQ; Wed, 04 Sep 2024 15:32:05 +0000 Received: by outflank-mailman (input) for mailman id 790494; Wed, 04 Sep 2024 15:32:04 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slrzI-0003Vv-At for xen-devel@lists.xenproject.org; Wed, 04 Sep 2024 15:32:04 +0000 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [2a00:1450:4864:20::632]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d5d92f24-6ad2-11ef-a0b3-8be0dac302b0; Wed, 04 Sep 2024 17:32:03 +0200 (CEST) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a7aa086b077so100105766b.0 for ; Wed, 04 Sep 2024 08:32:03 -0700 (PDT) Received: from localhost ([213.195.124.163]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8a623c3786sm5325366b.185.2024.09.04.08.32.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 08:32:02 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d5d92f24-6ad2-11ef-a0b3-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1725463923; x=1726068723; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ItQoxobOTKqaNEGEL3xN/mYnQHDAMZg8rUbmhpI3k9A=; b=Gte6u867nbUwNBVMP7EDsIW2202qaBVdZ/Tg9CF9/D3EVztXu6zAeLkxIqFFFMUJlV iL2M6TR0UvD5PHbBEB4xxDgC5atwV2ytPMut/kr68XuaUfR9fYG5XnTr4EAQosD4auUo RZzBSmIl5tUQIhg3FEFCkxdFrhVewqJmvKnuI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725463923; x=1726068723; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ItQoxobOTKqaNEGEL3xN/mYnQHDAMZg8rUbmhpI3k9A=; b=skOGQgEIICabmVbZqqbjZsgdtg8lltV5C++SAzDcU3lz1kLK8JIOZA9sqqnJFeftxc 6p5r0a2P3ap6STVtq73BfvIPu3zjV+StQ7UVE+jIxj/9z060zinHer5C4+Wk9NS33F2D RkgU6edfLpwBRWTAHqe/8auce/mY/4b4Hlrm7zrXMFUoECjqNbbyNJxXuyT/T2n09mW0 BX3ghLT9PY06M0p66D9tl9Yp2EPI5cve4+VoodbJHNpx5DJy6ftZNJHRrm8A2ruGixpk V2P03pLOyExjU4qy7z8wRR+op3FHcdG59jgoNFrXqLCEqX0sXstglODrq08RrgydeQ89 rGvA== X-Gm-Message-State: AOJu0YzDkvibMB1rDFF92XH3SrpS0u+Cb0WA+opwoQ7z3mIU/EYsMHGO AsGeaA6QVVlu/vCS7GH/9pZUxQOnB57XgR631d+JNjOtJogBE4kVXxNP1uv1nuMhz1wb9NwnyOX u X-Google-Smtp-Source: AGHT+IFoVlKxWSyraHL31SO7uY0Qy4yIGRs9TMoqYGF7fkINWk4LESaxR2wSm1JlIwuUBN6BOiu4pg== X-Received: by 2002:a17:907:7245:b0:a86:6fb3:fda5 with SMTP id a640c23a62f3a-a8a3f24a7e8mr193811466b.32.1725463922725; Wed, 04 Sep 2024 08:32:02 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: "Daniel P. Smith" , =?utf-8?q?Marek_Marczy?= =?utf-8?q?kowski-G=C3=B3recki?= , Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v4 4/6] x86/time: introduce probing logic for the wallclock Date: Wed, 4 Sep 2024 17:31:49 +0200 Message-ID: <20240904153151.83995-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240904153151.83995-1-roger.pau@citrix.com> References: <20240904153151.83995-1-roger.pau@citrix.com> MIME-Version: 1.0 Adding such probing allows to clearly separate init vs runtime code, and to place the probing logic into the init section for the CMOS case. Note both the Xen shared_info page wallclock, and the EFI wallclock don't really have any probing-specific logic. The shared_info wallclock will always be there if booted as a Xen guest, while the EFI_GET_TIME method probing relies on checking if it returns a value different than 0. The panic message printed when Xen is unable to find a viable wallclock source has been adjusted slightly, I believe the printed guidance still provides the same amount of information to the user. Signed-off-by: Roger Pau Monné --- Changes since v3: - Remove ASSERT from cmos_read(). - Change indentation of panic message arguments in probe_wallclock(). - Add __init attribute. Changes since v2: - New in this version. --- xen/arch/x86/time.c | 118 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 94 insertions(+), 24 deletions(-) diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index 1e3c13fc7360..9ebeee61b987 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -1291,14 +1291,23 @@ static bool __get_cmos_time(struct rtc_time *rtc) return t1 <= SECONDS(1) && t2 < MILLISECS(3); } -static bool cmos_probe(struct rtc_time *rtc_p, bool cmos_rtc_probe) +static bool __initdata cmos_rtc_probe; +boolean_param("cmos-rtc-probe", cmos_rtc_probe); + +static bool __init cmos_probe(void) { unsigned int seconds = 60; + if ( !(acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_CMOS_RTC) ) + return true; + + if ( !cmos_rtc_probe ) + return false; + for ( ; ; ) { - bool success = __get_cmos_time(rtc_p); - struct rtc_time rtc = *rtc_p; + struct rtc_time rtc; + bool success = __get_cmos_time(&rtc); if ( likely(!cmos_rtc_probe) ) return true; @@ -1328,28 +1337,12 @@ static bool cmos_probe(struct rtc_time *rtc_p, bool cmos_rtc_probe) return false; } -static unsigned long get_cmos_time(void) + +static unsigned long cmos_read(void) { - unsigned long res; struct rtc_time rtc; - static bool __read_mostly cmos_rtc_probe; - boolean_param("cmos-rtc-probe", cmos_rtc_probe); - if ( efi_enabled(EFI_RS) ) - { - res = efi_get_time(); - if ( res ) - return res; - } - - if ( likely(!(acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_CMOS_RTC)) ) - cmos_rtc_probe = false; - else if ( system_state < SYS_STATE_smp_boot && !cmos_rtc_probe ) - panic("System with no CMOS RTC advertised must be booted from EFI" - " (or with command line option \"cmos-rtc-probe\")\n"); - - if ( !cmos_probe(&rtc, cmos_rtc_probe) ) - panic("No CMOS RTC found - system must be booted from EFI\n"); + __get_cmos_time(&rtc); return mktime(rtc.year, rtc.mon, rtc.day, rtc.hour, rtc.min, rtc.sec); } @@ -1532,12 +1525,85 @@ void rtc_guest_write(unsigned int port, unsigned int data) } } -static unsigned long get_wallclock_time(void) +static enum { + WALLCLOCK_UNSET, + WALLCLOCK_XEN, + WALLCLOCK_CMOS, + WALLCLOCK_EFI, +} wallclock_source __ro_after_init; + +static const char *__init wallclock_type_to_string(void) { + switch ( wallclock_source ) + { + case WALLCLOCK_XEN: + return "XEN"; + + case WALLCLOCK_CMOS: + return "CMOS RTC"; + + case WALLCLOCK_EFI: + return "EFI"; + + case WALLCLOCK_UNSET: + return "UNSET"; + } + + ASSERT_UNREACHABLE(); + return ""; +} + +static void __init probe_wallclock(void) +{ + ASSERT(wallclock_source == WALLCLOCK_UNSET); + if ( xen_guest ) + { + wallclock_source = WALLCLOCK_XEN; + return; + } + if ( efi_enabled(EFI_RS) && efi_get_time() ) + { + wallclock_source = WALLCLOCK_EFI; + return; + } + if ( cmos_probe() ) + { + wallclock_source = WALLCLOCK_CMOS; + return; + } + + panic("No usable wallclock found, probed:%s%s%s\n%s", + !cmos_rtc_probe && !efi_enabled(EFI_RS) ? " None" : "", + cmos_rtc_probe ? " CMOS" : "", + efi_enabled(EFI_RS) ? " EFI" : "", + !cmos_rtc_probe + ? "Try with command line option \"cmos-rtc-probe\"\n" + : !efi_enabled(EFI_RS) + ? "System must be booted from EFI\n" + : ""); +} + +static unsigned long get_wallclock_time(void) +{ + switch ( wallclock_source ) + { + case WALLCLOCK_XEN: return read_xen_wallclock(); - return get_cmos_time(); + case WALLCLOCK_CMOS: + return cmos_read(); + + case WALLCLOCK_EFI: + return efi_get_time(); + + case WALLCLOCK_UNSET: + /* Unexpected state - handled by the ASSERT_UNREACHABLE() below. */ + break; + } + + ASSERT_UNREACHABLE(); + return 0; } /*************************************************************************** @@ -2462,6 +2528,10 @@ int __init init_xen_time(void) open_softirq(TIME_CALIBRATE_SOFTIRQ, local_time_calibration); + probe_wallclock(); + + printk(XENLOG_INFO "Wallclock source: %s\n", wallclock_type_to_string()); + /* NB. get_wallclock_time() can take over one second to execute. */ do_settime(get_wallclock_time(), 0, NOW()); From patchwork Wed Sep 4 15:31:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 13791127 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 719A8CD4F23 for ; Wed, 4 Sep 2024 15:32:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.790496.1200308 (Exim 4.92) (envelope-from ) id 1slrzM-0004o7-99; Wed, 04 Sep 2024 15:32:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 790496.1200308; Wed, 04 Sep 2024 15:32:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slrzM-0004ms-2V; Wed, 04 Sep 2024 15:32:08 +0000 Received: by outflank-mailman (input) for mailman id 790496; Wed, 04 Sep 2024 15:32:07 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slrzL-0003Va-Ft for xen-devel@lists.xenproject.org; Wed, 04 Sep 2024 15:32:07 +0000 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [2a00:1450:4864:20::636]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d727354a-6ad2-11ef-99a1-01e77a169b0f; Wed, 04 Sep 2024 17:32:05 +0200 (CEST) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a869332c2c2so158324966b.0 for ; Wed, 04 Sep 2024 08:32:05 -0700 (PDT) Received: from localhost ([213.195.124.163]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8a623a45b0sm5548066b.143.2024.09.04.08.32.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 08:32:03 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d727354a-6ad2-11ef-99a1-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1725463924; x=1726068724; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wttwru9ZqE1vNc2cTpVoP3TJEtmOujc6puRAfHnBzQg=; b=SON+06av0Y+pV3xgXeZt1LHeH0uJbFre9BoYGCikFEpIV1zkDXhKOZwRKBoRmTxwz4 dvy1674C4Afs+OrI0fnwaAtIHFNZ529i9XwlXW3Ds2bmLgxSFtvzF5y6FcRNoc8LCpmQ SrqSLQhtKY4776cVKuY2ica4JBrwpQknlWUog= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725463924; x=1726068724; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wttwru9ZqE1vNc2cTpVoP3TJEtmOujc6puRAfHnBzQg=; b=s6LKgZ28lwBx4zKC+5bUi1Nop4j/OIAc2n15AZCPM3w9Z3TYbP3sX2pIoq30C1qYFk Iwi/yc6797bDBAvbSG3CRYNhywS34Nqpxwu5W/3BnKcSmsV19nmrLnZeinb4dSBHjzu+ XsuXp89NzSLCcmybp0zQGCCwjDHlRxYhIcH+4wgPbFA3Dmv+4pTbMc9J+s1VZC9HZmIn UM4MTwzGJIoY0DLypwUQsJgGGsUvs6uxkuhfz43P4Anjj2opkxfhDiUWrr1/xNlYIG/J NMdE/B4uz0f085t6juzxYLAn5e7p3q+Cl/2O79VbL5aG6lVjLE4bisak7zWXIw1RTJ4u 6qnQ== X-Gm-Message-State: AOJu0Yx8jv/cz6usBSLtTyvaO9sQ2fTvn5LxkbDLBP2odK7WbvwmmC02 1IJl+FPVcNIND1CiAB4sx8gwxb4hTh26w1zgs7+FNskxicWz4Y1QV/USGh6oWV/YsM/B9KJkwmN i X-Google-Smtp-Source: AGHT+IFBzXdkAuKaYu8oiD2UdSN5m8OT1z+hLba5AKJcLQo1M7yXW9aHY2tJl8+iVLfn1VeR7WUnCg== X-Received: by 2002:a17:907:7f14:b0:a7a:8284:c8d6 with SMTP id a640c23a62f3a-a8a43140f0emr268958966b.24.1725463924379; Wed, 04 Sep 2024 08:32:04 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: "Daniel P. Smith" , =?utf-8?q?Marek_Marczy?= =?utf-8?q?kowski-G=C3=B3recki?= , Roger Pau Monne , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v4 5/6] x86/time: introduce command line option to select wallclock Date: Wed, 4 Sep 2024 17:31:50 +0200 Message-ID: <20240904153151.83995-6-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240904153151.83995-1-roger.pau@citrix.com> References: <20240904153151.83995-1-roger.pau@citrix.com> MIME-Version: 1.0 Allow setting the used wallclock from the command line. When the option is set to a value different than `auto` the probing is bypassed and the selected implementation is used (as long as it's available). The `xen` and `efi` options require being booted as a Xen guest (with Xen guest supported built-in) or from UEFI firmware. Signed-off-by: Roger Pau Monné --- Changes since v3: - Note xen option is only available if Xen guest support it built. - Fix typo. --- docs/misc/xen-command-line.pandoc | 19 ++++++++++++++++++ xen/arch/x86/time.c | 33 ++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line.pandoc index 0a66e1ee2d7e..1944b9d8eb9d 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -2821,6 +2821,25 @@ vwfi to `native` reduces irq latency significantly. It can also lead to suboptimal scheduling decisions, but only when the system is oversubscribed (i.e., in total there are more vCPUs than pCPUs). +### wallclock (x86) +> `= auto | xen | cmos | efi` + +> Default: `auto` + +Allow forcing the usage of a specific wallclock source. + + * `auto` let the hypervisor select the clocksource based on internal + heuristics. + + * `xen` force usage of the Xen shared_info wallclock when booted as a Xen + guest. This option is only available if the hypervisor was compiled with + `CONFIG_XEN_GUEST` enabled. + + * `cmos` force usage of the CMOS RTC wallclock. + + * `efi` force usage of the EFI_GET_TIME run-time method when booted from EFI + firmware. + ### watchdog (x86) > `= force | ` diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index 9ebeee61b987..52944b8fbfde 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -1553,6 +1553,36 @@ static const char *__init wallclock_type_to_string(void) return ""; } +static int __init cf_check parse_wallclock(const char *arg) +{ + if ( !arg ) + return -EINVAL; + + if ( !strcmp("auto", arg) ) + wallclock_source = WALLCLOCK_UNSET; + else if ( !strcmp("xen", arg) ) + { + if ( !xen_guest ) + return -EINVAL; + + wallclock_source = WALLCLOCK_XEN; + } + else if ( !strcmp("cmos", arg) ) + wallclock_source = WALLCLOCK_CMOS; + else if ( !strcmp("efi", arg) ) + { + if ( !efi_enabled(EFI_RS) ) + return -EINVAL; + + wallclock_source = WALLCLOCK_EFI; + } + else + return -EINVAL; + + return 0; +} +custom_param("wallclock", parse_wallclock); + static void __init probe_wallclock(void) { ASSERT(wallclock_source == WALLCLOCK_UNSET); @@ -2528,7 +2558,8 @@ int __init init_xen_time(void) open_softirq(TIME_CALIBRATE_SOFTIRQ, local_time_calibration); - probe_wallclock(); + if ( wallclock_source == WALLCLOCK_UNSET ) + probe_wallclock(); printk(XENLOG_INFO "Wallclock source: %s\n", wallclock_type_to_string()); From patchwork Wed Sep 4 15:31:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 13791126 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 89CE7CD4F24 for ; Wed, 4 Sep 2024 15:32:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.790495.1200303 (Exim 4.92) (envelope-from ) id 1slrzL-0004lB-UL; Wed, 04 Sep 2024 15:32:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 790495.1200303; Wed, 04 Sep 2024 15:32:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slrzL-0004ky-Qq; Wed, 04 Sep 2024 15:32:07 +0000 Received: by outflank-mailman (input) for mailman id 790495; Wed, 04 Sep 2024 15:32:07 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slrzL-0003Vv-1c for xen-devel@lists.xenproject.org; Wed, 04 Sep 2024 15:32:07 +0000 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [2a00:1450:4864:20::62f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d78658b1-6ad2-11ef-a0b3-8be0dac302b0; Wed, 04 Sep 2024 17:32:06 +0200 (CEST) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a86c476f679so820004466b.1 for ; Wed, 04 Sep 2024 08:32:06 -0700 (PDT) Received: from localhost ([213.195.124.163]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8a62038d4dsm6197966b.51.2024.09.04.08.32.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 08:32:05 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d78658b1-6ad2-11ef-a0b3-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1725463926; x=1726068726; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=J5xIEyShiXsG0uS8t4KpTmc8gXLGG9Loy1+FhdabqNM=; b=tItn/ACFd3uCkoIfLnmc3Rom9thQgySwBEzTgylso8w3UfolM+hsAbZ6eZ39UjJW86 d+fuDvxUYX5Yxup1DJOHDFj8r3Gm6oseKDUdxIeIB2/bTeyXOWz0THlB48oEyUxIvm+h vWclBWZCAaiXeKxN/yeYqyVwFuNLZr7l+MUeE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725463926; x=1726068726; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J5xIEyShiXsG0uS8t4KpTmc8gXLGG9Loy1+FhdabqNM=; b=hjmKpHtWzXml7EPKELqTx6Lfh37nwCzjKkPg/+D61qukKHIJkQKApYFV+GzkP5P7Jd yWfGoU38TvmzfEpxgOLn07vC8+UMKYIEoibB+SOTwBMGXTWaHlMjAodI4JnhSqSulRAm rhqqBTShLvVwAb8OnnQsrZ1w+N0eLccF02PLhOa3VPDBeFnqrSGwKqYpEueD1iEFvQ7b YRTXzQe52V1pYSCDguI/gk4jflmpjIxfeyEC+EHP53tEOPX+6b43boAO/k5n83q6oQiK Za4ngpKolQNtySbZOgrrYAnMjm9y1oUQAbruEyhQAVX9U6kQHvC9odOno3twHbbWASJe iHtQ== X-Gm-Message-State: AOJu0Yw2AUWxruBEfr6lq0JdiXsQggTQ3rFyjv2cPC/rDB76bNFBmMDu gq09xXxKPcrjPL8mcAxZn4XgLBdpGaVXaaqPM+gJltdUrCnt8sRh2GlgHkHlha6RwF1ksPwMpsY P X-Google-Smtp-Source: AGHT+IHfdDFhhMzIZlyWzfqK0BBgBrqi/pDSrlmGyX8+0tnV19l/1qChJPdG3vaxKWvMuB/EQizN6A== X-Received: by 2002:a17:907:9483:b0:a86:80ef:4fe5 with SMTP id a640c23a62f3a-a89b96f7106mr1073576066b.47.1725463925528; Wed, 04 Sep 2024 08:32:05 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: "Daniel P. Smith" , =?utf-8?q?Marek_Marczy?= =?utf-8?q?kowski-G=C3=B3recki?= , Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v4 6/6] x86/time: prefer CMOS over EFI_GET_TIME Date: Wed, 4 Sep 2024 17:31:51 +0200 Message-ID: <20240904153151.83995-7-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240904153151.83995-1-roger.pau@citrix.com> References: <20240904153151.83995-1-roger.pau@citrix.com> MIME-Version: 1.0 The EFI_GET_TIME implementation is well known to be broken for many firmware implementations, for Xen the result on such implementations are: ----[ Xen-4.19-unstable x86_64 debug=y Tainted: C ]---- CPU: 0 RIP: e008:[<0000000062ccfa70>] 0000000062ccfa70 [...] Xen call trace: [<0000000062ccfa70>] R 0000000062ccfa70 [<00000000732e9a3f>] S 00000000732e9a3f [] F arch/x86/time.c#get_cmos_time+0x1b3/0x26e [] F init_xen_time+0x28/0xa4 [] F __start_xen+0x1ee7/0x2578 [] F __high_start+0x94/0xa0 Pagetable walk from 0000000062ccfa70: L4[0x000] = 000000207ef1c063 ffffffffffffffff L3[0x001] = 000000005d6c0063 ffffffffffffffff L2[0x116] = 8000000062c001e3 ffffffffffffffff (PSE) **************************************** Panic on CPU 0: FATAL PAGE FAULT [error_code=0011] Faulting linear address: 0000000062ccfa70 **************************************** Swap the preference to default to CMOS first, and EFI later, in an attempt to use EFI_GET_TIME as a last resort option only. Note that Linux for example doesn't allow calling the get_time method, and instead provides a dummy handler that unconditionally returns EFI_UNSUPPORTED on x86-64. Such change in the preferences requires some re-arranging of the function logic, so that panic messages with workaround suggestions are suitably printed. Signed-off-by: Roger Pau Monné --- Changes since v2: - Updated to match previous changes. --- xen/arch/x86/time.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index 52944b8fbfde..788a12d52fc3 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -1592,14 +1592,14 @@ static void __init probe_wallclock(void) wallclock_source = WALLCLOCK_XEN; return; } - if ( efi_enabled(EFI_RS) && efi_get_time() ) + if ( cmos_probe() ) { - wallclock_source = WALLCLOCK_EFI; + wallclock_source = WALLCLOCK_CMOS; return; } - if ( cmos_probe() ) + if ( efi_enabled(EFI_RS) && efi_get_time() ) { - wallclock_source = WALLCLOCK_CMOS; + wallclock_source = WALLCLOCK_EFI; return; }