[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] xen/arm: Validate generic timer frequency


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Thu, 28 Sep 2023 14:34:35 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org 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
  • 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=V7Ju6bu8OgEJVGjFjrrzrrtbaw0w5O1j5OSxaTy1o/A=; b=JwCWU/xV/jVD3bRJ9LXMivQu49WtNl85tQCoodbAmqaNCmCRWk/eSIQUXHht8VVvWyyEjOXgRUXBBnN+F+68Phqpa01/xxIUJ8Gz2gQjZTJDgNd56FAoc0fBSo9q0x4TYRx8Lip0xbJP1/ST0pVPKocNteJ6vZ5DpfN8dSiz84p23pOeOZP6pu8B+ItzyM/53XW1ESas/OjxgpsmzJf28IgJjls0UUKIw5oOH7IGq7cyzJe8iLHmJuaFl8QqZpTy8HWWjb019Bxh94JbaB17Gmmadsc1TRZNbijEV9hb+gW63WkEscgZkI546ea29TYYWDRO/s3R/Uln131wayz49w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bQsfDjB7xowwh9BjxxJdbRVMGp+Kna5Y3TE29PfxPAjRdoEQtVk57+SzzSG6UJksiR8CUsPKu/d3FWOqSgPVMCikPQWCvvoJ33sS8erb4BFuM1sGeEMNAAsiEC4yaeRm3Lx8qkyhruYlMXugR00jZ5SOpEJ6CapoLqTAGxbtwKq78wFVjGFXPjcVNuPuPe8rXNWZL1PvyPdNpIFmvdWYS9MjJN05Ocaf7bCW81Q8gSrhBcgs0xSCPrdjXN66cFUV5JrK0zWHNj7RVuBDIjZx+HjCWH+4O65bWLD6Ojrp75UJjNGbWN/uXSJYhoLH000j2YiKrTZiMJVlSPFXFQcnjg==
  • Cc: Michal Orzel <michal.orzel@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Thu, 28 Sep 2023 12:35:11 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Generic timer dt node property "clock-frequency" (refer Linux dt binding
Documentation/devicetree/bindings/timer/arm,arch_timer.yaml) is used to
override the incorrect value set by firmware in CNTFRQ_EL0. If the value
of this property is 0 (i.e. by mistake), Xen would continue to work and
use the value from the sysreg instead. The logic is thus incorrect and
results in inconsistency when creating timer node for domUs:
 - libxl domUs: clock_frequency member of struct xen_arch_domainconfig
   is set to 0 and libxl ignores setting the "clock-frequency" property,
 - dom0less domUs: "clock-frequency" property is taken from dt_host and
   thus set to 0.

Property "clock-frequency" is used to override the value from sysreg,
so if it is also invalid, there is nothing we can do and we shall panic
to let user know about incorrect setting. Going even further, we operate
under assumption that the frequency must be at least 1KHz (i.e. cpu_khz
not 0) in order for Xen to boot. Therefore, introduce a new helper
validate_timer_frequency() to verify this assumption and use it to check
the frequency obtained either from dt property or from sysreg.

Signed-off-by: Michal Orzel <michal.orzel@xxxxxxx>
---
 xen/arch/arm/time.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/xen/arch/arm/time.c b/xen/arch/arm/time.c
index 3535bd8ac7c7..04b07096b165 100644
--- a/xen/arch/arm/time.c
+++ b/xen/arch/arm/time.c
@@ -101,6 +101,17 @@ static void __init preinit_acpi_xen_time(void)
 static void __init preinit_acpi_xen_time(void) { }
 #endif
 
+static void __init validate_timer_frequency(void)
+{
+    /*
+     * ARM ARM does not impose any strict limit on the range of allowable
+     * system counter frequencies. However, we operate under the assumption
+     * that cpu_khz must not be 0.
+     */
+    if ( !cpu_khz )
+        panic("Timer frequency is less than 1 KHz\n");
+}
+
 /* Set up the timer on the boot CPU (early init function) */
 static void __init preinit_dt_xen_time(void)
 {
@@ -122,6 +133,7 @@ static void __init preinit_dt_xen_time(void)
     if ( res )
     {
         cpu_khz = rate / 1000;
+        validate_timer_frequency();
         timer_dt_clock_frequency = rate;
     }
 }
@@ -137,7 +149,10 @@ void __init preinit_xen_time(void)
         preinit_acpi_xen_time();
 
     if ( !cpu_khz )
+    {
         cpu_khz = (READ_SYSREG(CNTFRQ_EL0) & CNTFRQ_MASK) / 1000;
+        validate_timer_frequency();
+    }
 
     res = platform_init_time();
     if ( res )
-- 
2.25.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.