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

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


  • To: Jan Beulich <jbeulich@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jason Andryuk <jason.andryuk@xxxxxxx>
  • Date: Wed, 22 May 2024 09:57:25 -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=JHQ7yRqcmXj9s0rkz0OK7BakOpjTzOKqOpjDy3dS5/0=; b=fVxwc1mODReGAeEx9ZFdXBSJduiQS4Iy6vKXRdaHXKbE/wJg57tzW3bKsSOyQO0BAK3gRUqG/pgy2gX14nXmZPk6t80SYnaQHUSYa0qpfXB7rVEJ2Yu5xycPHvwZLj2YdTqfVzDZBQAcESUJdmVEkpZIPH0f/OwURBUhx+UstH1RwXdPB/5PBulpt38fN1zfehPoAWuGFK1PYmZcyvRBQmGSaZsjYhjRnjOR2Wz3FuN0NhhBf9KO0psZ+fMv6QoPvWIoKSSUS84OPaZDvkFzw1RQtBoz3xF2eNuyRO5efSaVTxWMlEo/MVGgZHmeOhLNL2RQocyFpyTO4XsCpHG08Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CqTs30b683Llb2qdtzxD8zJ0hon4k8WMc7NCXyklAMPj4fzfGPu4gVF6v9DXOKdjHMjyL2XOjeIyX+S0+ZZGFQxJgVeo1AesTMIrImQU80AQex9WB695TbwJ2YJzbV0IV6xPaa+1fsaIMEO6Fll6sWH+NIN/KYwf/NTL4f5SWCqGrjZe5D8iYips/KcLb/jfUAoSnhkq9GHZf6MBkYGNHVaJzMEHzG0WvpoJn+QKeNlYhBFccmoY42JRPlvNLA5cLCggs5K3evbUfoj8/wMp0nIXTRmm9Re7NiKUL1eQPbVrNft+4rpwBsF3coMVPcAvXwiDdbuOlQf59PJCIQYxVg==
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Wed, 22 May 2024 13:57:32 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 2024-05-22 08:59, Jan Beulich wrote:
... in order to also deny Dom0 access through the alias ports (commonly
observed on Intel chipsets). Without this it is only giving the
impression of denying access to PIT. Unlike for CMOS/RTC, do detection
pretty early, to avoid disturbing normal operation later on (even if
typically we won't use much of the PIT).

Like for CMOS/RTC a fundamental assumption of the probing is that reads
from the probed alias port won't have side effects (beyond such that PIT
reads have anyway) in case it does not alias the PIT's.

As to the port 0x61 accesses: Unlike other accesses we do, this masks
off the top four bits (in addition to the bottom two ones), following
Intel chipset documentation saying that these (read-only) bits should
only be written with zero.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -427,6 +427,74 @@ 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(PIT_LTCH_CH(2) | PIT_RW_LSB_MSB | PIT_MODE_EOC | PIT_BINARY,
+         PIT_MODE);
+
+    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(PIT_RDB | PIT_RDB_NO_COUNT | PIT_RDB_CH2, PIT_MODE);
+
+            /* Try to make sure we're actually having a PIT here. */
+            val2 = inb(PIT_CH2);
+            if ( (val2 & ~(PIT_STATUS_OUT_PIN | PIT_STATUS_NULL_COUNT)) !=
+                 (PIT_RW_LSB_MSB | PIT_MODE_EOC | PIT_BINARY) )
+                return;
+        } while ( val2 & (1 << 6) );

You can use PIT_STATUS_NULL_COUNT here.

With that:
Reviewed-by: Jason Andryuk <jason.andryuk@xxxxxxx>

Thanks,
Jason



 


Rackspace

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