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

[PATCH] x86/time: minor adjustments to init_pit()


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 17 Jan 2022 11:36:06 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; 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=PuPpMRe4iBZJ2b9btJlh43iuryshFfSWWcyP6KkV9CQ=; b=S3Qjxc2R+7Aq9Eyl7SF5PVxvCPHDkiQaoYslKnxSaFWHKltdNUQQn1JQ2/2DIWD/QUFcPbfuREILQsPJyywBzMgOdCz3hIaSgfBAVAQXWVeeHfb2397BTCN7p9iJSqmEKD+F9308DiXFa5ywENB8VottSxTaOtUSk99hRSTYgeoK7BanzjfhCGIQN+hdbwmYbHKS2ydYhojNDWfMO6/92VS+C7Xj0mzcCAlDjHYDeWKT+QamX4mbDHhyIIRpUrFIudrulGUxQO9XMfqx5KLJsbDCQvt8uCaIpFDE53THoKqWUJ3q5fOjdJ+M+Uh4KRGfnmoAxU5k18BULpQyqs/tMg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ICNRnE9A4BXNZ0GwKxmRYLZm6Odxj/jIxH0XVBn9v73GSqQlveSp4QEX8sV3yppevzrufTRm10LABViSx9V/xTWRb3/ucfVhuh4ahC7qLCHNbWUotguNd9A4jJCMouukRdsLng0IkQ9oe6ODgDpBkq09beOGvAU5shTfOQv0gY1PNka6cMsI0aLbj91XhuutA5r4N+T8+9mkfv5ClI+aWCzwnUHbhCMKsyHUCfoHKC0k2RdgPWKVqEKG9Wn/NyV3yRpluRPGT0ZxcUxcCUciBgsjttq2Fv7MKvd8bwbTOpWMa8/Ba9OcRaaCFpBzbNuwchqhf82SWKrf41//klzSew==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Mon, 17 Jan 2022 10:36:18 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

For one, "using_pit" shouldn't be set ahead of the function's last
(for now: only) error path. Otherwise "clocksource=pit" on the command
line can lead to misbehavior when actually taking that error path.

And then make an implicit assumption explicit: CALIBRATE_FRAC cannot,
for example, simply be changed to 10. The way init_pit() works, the
upper bound on the calibration period is about 54ms.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
Really I've noticed this while considering what would happen if someone
specified  "clocksource=pit" on the shim's command line. Unlike "hpet"
and "acpi", "pit" presently wouldn't be (explicitly) ignored. While,
aiui, right now the only error path would be taken (due to port 0x61
reads being supposed to get back 0xff), I don't think we can build on
that longer term: Seeing what we use port 0x61 for in traps.c, I think
sooner or later we will need to have some form of emulation for it. Such
emulation is then not unlikely to continuously report 0 in the bit in
question. That would leed to an infinite loop here.

--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -333,8 +333,6 @@ static s64 __init init_pit(struct platfo
     u64 start, end;
     unsigned long count;
 
-    using_pit = true;
-
     /* Set the Gate high, disable speaker. */
     outb((portb & ~0x02) | 0x01, 0x61);
 
@@ -344,6 +342,7 @@ static s64 __init init_pit(struct platfo
      * (LSB and MSB) to begin countdown.
      */
 #define CALIBRATE_LATCH CALIBRATE_VALUE(CLOCK_TICK_RATE)
+    BUILD_BUG_ON(CALIBRATE_LATCH >> 16);
     outb(0xb0, PIT_MODE);                  /* binary, mode 0, LSB/MSB, Ch 2 */
     outb(CALIBRATE_LATCH & 0xff, PIT_CH2); /* LSB of count */
     outb(CALIBRATE_LATCH >> 8, PIT_CH2);   /* MSB of count */
@@ -361,6 +360,8 @@ static s64 __init init_pit(struct platfo
     if ( count == 0 )
         return 0;
 
+    using_pit = true;
+
     return (end - start) * CALIBRATE_FRAC;
 }
 




 


Rackspace

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