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

Re: [PATCH v2 3/3] x86: detect PIT aliasing on ports other than 0x4[0-3]


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Jason Andryuk <jason.andryuk@xxxxxxx>
  • Date: Tue, 14 May 2024 15:30:49 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com 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 (0)
  • 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=6HiN2/ngL8lzfBK0HAiA341EyVRfzfAdaOj4pY62+5k=; b=WyCW0CCLjcp3qU4ntToNlI3GG1ed/VNEw9H3/LmzYeM1Yie2+XUL8Rt0Wxf82eHgY4rffXSKnxtOL8BeFEc/TW0iVXpfhAPj9OYVinifXeHDVu0c9cmPRVLFMKPjgd491O1Cj94nsZnXYLjJLc/f5GANFIoi5v4kEPSYxFgv0qxhaNITIY71fTGW9oxdpfwLkQjxX+MDQx/+0EnLsdS5LMK61SvDjnp7CVPJRV/tSIZb7UyJIkzy5bmPb1G+pdBk/ebA3II1PCmDLFBW+BANUewMXv21ZpWYV5ehJaigQrx9U1EZa9gX8zbLNbjpJPYaWt8lI/WbRA9e85hXonpjEA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LSkQRB9EoVnuHyr/a7Is8mY3zM0wG6Fo2hbvxlLCJGWbJr8NlK8B8v301zU6PB7pxMARXABC/ZiJJndvw7TAkZ3J4vgoOJ8kTW3dWVQGo4L0jZvGtpSPmF1/5MNDwTi5S06ua0rTYU78ZQKyDj6IKQp31Q9v+u9TbriYHO75mKRoHRvmX6KKt6vK0KGf1M9VIa6m3LVZ7Rh1xQn52WGf4QM63Zmwco5Q5894gmXnPcHkPaaDqqfL1G0Oc8KYHnuVyajtbswMMMLityfN36dfMoMvI1bfkHxsTXynCYw2hqTUjVEs6kHyRqx7owTudA1wCHa/rp8LpZbj6jZM0ThxJQ==
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 14 May 2024 19:31:23 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 2024-05-14 03:43, Jan Beulich wrote:
On 10.05.2024 19:40, Jason Andryuk wrote:
On 2023-12-18 09:48, Jan Beulich wrote:
--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -425,6 +425,72 @@ static struct platform_timesource __init
       .resume = resume_pit,
   };
+unsigned int __initdata pit_alias_mask;
+
+static void __init probe_pit_alias(void)
+{
+    unsigned int mask = 0x1c;
+    uint8_t val = 0;
+
+    if ( !opt_probe_port_aliases )
+        return;
+
+    /*
+     * Use channel 2 in mode 0 for probing.  In this mode even a non-initial
+     * count is loaded independent of counting being / becoming enabled.  Thus
+     * we have a 16-bit value fully under our control, to write and then check
+     * whether we can also read it back unaltered.
+     */
+
+    /* Turn off speaker output and disable channel 2 counting. */
+    outb(inb(0x61) & 0x0c, 0x61);
+
+    outb((2 << 6) | (3 << 4) | (0 << 1), PIT_MODE); /* Mode 0, LSB/MSB. */

Channel 2, Lobyte/Hibyte, 0b000 Mode 0, (Binary)

#define PIT_MODE_CH2 (2 << 6)
#define PIT_MODE0_16BIT ((3 << 4) | (0 << 1))

outb(PIT_MODE_CH2 | PIT_MODE0_16BIT, PIT_MODE);

Hmm. I can certainly see the value of introducing such #define-s, but then
while doing so one ought to also adjust other code using constants as done
here (for consistency).

I had to look up all these bit values, so I think it's nicer with #defines-s. Particularly, using PIT_MODE0_16BIT for the programming and checking shows the relationship. I wasn't looking to make more work for you. This function is self-contained, so just using them here for the time being seems reasonable.

+
+    do {
+        uint8_t val2;
+        unsigned int offs;
+
+        outb(val, PIT_CH2);
+        outb(val ^ 0xff, PIT_CH2);
+
+        /* Wait for the Null Count bit to clear. */
+        do {
+            /* Latch status. */
+            outb((3 << 6) | (1 << 5) | (1 << 3), PIT_MODE);

Read-back, Latch status,  read back timer channel 2

Was this meant as a request to extend the comment? If so, not quite,
as the line doesn't include any read-back. If not, I'm in trouble seeing
what you mean to tell me here (somewhat similar also for the first line
of your earlier comment still visible in context above).

Sorry, these were my notes as I was interpreting the bits. I should have removed them from the email before sending as they aren't actionable comments. Read back was in reference to writing (3 << 6) to the mode - not the action of read backing back the value.

+
+            /* Try to make sure we're actually having a PIT here. */
+            val2 = inb(PIT_CH2);
+            if ( (val2 & ~(3 << 6)) != ((3 << 4) | (0 << 1)) )

if ( (val2 & PIT_RB_MASK) != PIT_MODE0_16BIT )

I think particularly a define for PIT_MODE0_16BIT would be helpful to
show what is expected to be the same.

+                return;
+        } while ( val2 & (1 << 6) );

I think Roger might have mentioned on an earlier version - would it make
sense to have a counter to prevent looping forever?

Well, as before: The issue with bounding such loops is that the bound is
going to be entirely arbitrary (and hence easily too large / too small).

Ah, yes.  Your response had slipped my mind.

Also, FYI, I tested the series.  My test machine didn't show any aliasing.

That likely was an AMD one then? It's only Intel chipsets I've seen aliasing
on so far, but there it's (almost) all of them (with newer data sheets even
stating that behavior). We could, beyond shim, make the option default in
patch 1 be "false" for systems with AMD CPUs (on the assumption that those
wouldn't have Intel chipsets).

Indeed, it was an AMD system, but my sample size is 1.

I didn't realize this was motivated by aliasing being common on Intel chipsets. I think that would be useful to include in the commit messages.

Thanks,
Jason



 


Rackspace

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