From patchwork Thu Sep 12 11:15:13 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: 13801899 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 650A0EEB591 for ; Thu, 12 Sep 2024 11:15:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.797311.1207235 (Exim 4.92) (envelope-from ) id 1sohnG-0006R0-CX; Thu, 12 Sep 2024 11:15:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 797311.1207235; Thu, 12 Sep 2024 11:15:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sohnG-0006OP-7m; Thu, 12 Sep 2024 11:15:22 +0000 Received: by outflank-mailman (input) for mailman id 797311; Thu, 12 Sep 2024 11:15:21 +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 1sohnF-0006KP-Ec for xen-devel@lists.xenproject.org; Thu, 12 Sep 2024 11:15:21 +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 4c284b91-70f8-11ef-a0b5-8be0dac302b0; Thu, 12 Sep 2024 13:15:20 +0200 (CEST) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a8a6d1766a7so108692366b.3 for ; Thu, 12 Sep 2024 04:15:20 -0700 (PDT) Received: from localhost ([213.195.124.163]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25c72748sm730888566b.117.2024.09.12.04.15.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 04:15:18 -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: 4c284b91-70f8-11ef-a0b5-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1726139719; x=1726744519; 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=OIQDU1Hamekzud1T/6MRTc7roHQp5I3um5eAiC+UGfA=; b=djeX/zsl34Bf3tkRToihJH7nb/aVtM6lvYJSJeCVE3iZ54l8eOaLXfnOxuIyCqEEqR GSwsv3t82r+yoJn3dnt100w0qnJBab5ezbf30eTQYaXZdle84m9iTVOta0+GrNsE/J6B i+Vr8/diWEflkG2eBu7jcVxFrvjvDdTiYZeQ8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726139719; x=1726744519; 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=OIQDU1Hamekzud1T/6MRTc7roHQp5I3um5eAiC+UGfA=; b=Y33R5JhSxWJVU6lHsmGcIHMRGF3E+FpvoUrBljLVOdTAywL00xq5rYLwHvgF9FVXkQ XzaivYo8UU9JaG0yfyvFtri6y7SroPxlzDVGsLfd+LycEZDVY6HUgONzFIMjkvGDbv4j 1hJv35qybcvZpLsBMvuLuWLQc81/YIijZ9ks/WTeF8GG81XcXiEo1ojcX/GyRuQTZmB4 1gE7C2rEm02fWS8nhz8iNVvRkjwFcRmi+/E6U4BKaqQBmj67UkNX38oIo06Ek5Tjd05e EpIgsR4I8YDTj/K6yVr5tkkwgJTuD/6TtpptitsfVye6MH6ZQlBwEYGWcAFlYPy5bNi2 Q2+Q== X-Gm-Message-State: AOJu0YzkIk4uT0v8s2VPZu/nMFORrlHQlP4Tf/zVEKZRiGv5XgSUdzQF iRsNmnR7hJb2AbOEvD4E514Dty66DIm+5+NTu0ViDssP5AvPlynnyaLNtuajbz5Gchmx1xyCmmc W X-Google-Smtp-Source: AGHT+IFCSNXfXXjU3pr8LA54EmWvXqjfw4W/A7yLw3mhS3CHwK8how4HhuGgJMeBpljrufjDpcKGvg== X-Received: by 2002:a17:907:f1a2:b0:a8d:250a:52b2 with SMTP id a640c23a62f3a-a90293c543emr205928266b.6.1726139718950; Thu, 12 Sep 2024 04:15:18 -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 v6 1/2] x86/time: introduce command line option to select wallclock Date: Thu, 12 Sep 2024 13:15:13 +0200 Message-ID: <20240912111514.26934-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912111514.26934-1-roger.pau@citrix.com> References: <20240912111514.26934-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 respectively. Signed-off-by: Roger Pau Monné --- Changes since v5: - Do EFI run-time services checking after command line parsing. 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 | 39 ++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line.pandoc index 959cf45b55d9..a4f916d0d33e 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -2816,6 +2816,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 9588502f28e8..b97c81ebd3e9 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -1552,6 +1552,35 @@ 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) ) + /* + * Checking if run-time services are available must be done after + * command line parsing. + */ + 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); @@ -2527,7 +2556,15 @@ int __init init_xen_time(void) open_softirq(TIME_CALIBRATE_SOFTIRQ, local_time_calibration); - probe_wallclock(); + /* + * EFI run time services can be disabled from the command line, hence the + * check for them cannot be done as part of the wallclock option parsing. + */ + if ( wallclock_source == WALLCLOCK_EFI && !efi_enabled(EFI_RS) ) + wallclock_source = WALLCLOCK_UNSET; + + if ( wallclock_source == WALLCLOCK_UNSET ) + probe_wallclock(); printk(XENLOG_INFO "Wallclock source: %s\n", wallclock_type_to_string()); From patchwork Thu Sep 12 11:15:14 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: 13801900 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 760ABEEB594 for ; Thu, 12 Sep 2024 11:15:32 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.797312.1207249 (Exim 4.92) (envelope-from ) id 1sohnI-0006q5-Kn; Thu, 12 Sep 2024 11:15:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 797312.1207249; Thu, 12 Sep 2024 11:15:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sohnI-0006ps-HM; Thu, 12 Sep 2024 11:15:24 +0000 Received: by outflank-mailman (input) for mailman id 797312; Thu, 12 Sep 2024 11:15:23 +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 1sohnH-0006KJ-Bb for xen-devel@lists.xenproject.org; Thu, 12 Sep 2024 11:15:23 +0000 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [2a00:1450:4864:20::52b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4cd94f62-70f8-11ef-99a1-01e77a169b0f; Thu, 12 Sep 2024 13:15:21 +0200 (CEST) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5c24c92f699so574823a12.2 for ; Thu, 12 Sep 2024 04:15:21 -0700 (PDT) Received: from localhost ([213.195.124.163]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd41ba7sm6454950a12.4.2024.09.12.04.15.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 04:15:19 -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: 4cd94f62-70f8-11ef-99a1-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1726139721; x=1726744521; 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=3CJQfMZC1/Ng5+JCHjsNi6ZaFAblZq9Kpgx/jpks0FQ=; b=CGCMFN6FikhziBNpPNhWzqsj+PCv8Zm1s7bcIARTUz2Anoq5fOgh13Mw4iW68xp2e5 u4R86823og4Xe47v6uQQuxITNMdlnHln4IAqDwW8M4eh3jhGNXNDmtXmu4RCu+0l81ww uXkOsBxWqMJKB21rNq+5NUbtc4WVfE1jtBEwk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726139721; x=1726744521; 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=3CJQfMZC1/Ng5+JCHjsNi6ZaFAblZq9Kpgx/jpks0FQ=; b=OncrdGYgy52bzfJcKJeTHteRd65Vet4I5q3VbFwAjABg3el7Maa798TRZI6934JMyB R+uTCXH6gBUTCUZAYS0XmurzZTlsNM2kXU0u9sj+SgcOX2yxoTYpNA8Nsnzo5989jLhn k28jl5Ecu7kDPS44Uz/GPwACkCeI8XKJo5ZmUA4pug4pZmOkllP5gKEbrXY5OX+USB+M 9E+d5ox86ihiL7slwF52uBo9a1IRnKQjXVmkp8F8j03MBGP5JxUh3WJoanXSg/SemsnJ Deh8IWirT0szgQc0VWaeC89ARM+XhV88TQ78M+AAqOiXvBXtbgAGD6z/ml3vhAc/Qqef zuyA== X-Gm-Message-State: AOJu0YxtJoDPTaNTBLg8/d+Szhigj3Sk/jGTH0shMd1xf9t9H7hXF0yY GrRUsgsY+UsxV+rXNtSmWTjXqVPVOHfAogGQ+n5OQR46b4BEWMg79GXLbEZr3cQMVDvHFyEUznE H X-Google-Smtp-Source: AGHT+IENssPDwRzVQlmWHjg5agQuBfSbQzCyl5TolCmoZ1sYw03fhTeYumvJ9eVdv7Rxj9iWgKV0Aw== X-Received: by 2002:a05:6402:350f:b0:5c2:5d34:a481 with SMTP id 4fb4d7f45d1cf-5c413e10c2fmr1658248a12.11.1726139720582; Thu, 12 Sep 2024 04:15:20 -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 v6 2/2] x86/time: prefer CMOS over EFI_GET_TIME Date: Thu, 12 Sep 2024 13:15:14 +0200 Message-ID: <20240912111514.26934-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912111514.26934-1-roger.pau@citrix.com> References: <20240912111514.26934-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 b97c81ebd3e9..e4fe03197381 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -1590,14 +1590,14 @@ static void __init probe_wallclock(void) wallclock_source = WALLCLOCK_XEN; return; } - if ( efi_enabled(EFI_RS) && efi_get_time() ) + if ( cmos_rtc_probe() ) { - wallclock_source = WALLCLOCK_EFI; + wallclock_source = WALLCLOCK_CMOS; return; } - if ( cmos_rtc_probe() ) + if ( efi_enabled(EFI_RS) && efi_get_time() ) { - wallclock_source = WALLCLOCK_CMOS; + wallclock_source = WALLCLOCK_EFI; return; }