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

[XEN v3 3/9] xen/drivers: ns16550: Use paddr_t for io_base/io_size


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
  • Date: Wed, 8 Feb 2023 12:05:23 +0000
  • 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=bWDdC45h3TzmFMpzP68+i+YB/5cnNKV4V21ZBbTbtAQ=; b=QQvgoS5851Ps3UJFxrNHDbY+Y4fteovcy4xvGkgVL6de+to4wzQC6d2xzqhuBBF1cEQcx2uVAuZZegAfEZVp4x/uhV3b9VG01464mqJNwgrB8hEVU79CIk65FqX6myOigPw9W3xEpUHaN11sZcs6SjGXhnkXLhW5SRa8uluovTLaqbrgfIPYVAUJ5DKaHeaGLJUYSGFQfgt3C8Nfhs+joRJGa5RENxgtteWHoIE0MtUAsOsZhPzqEHKb7+2iJkwXP1ZfunHUmDc8zsZKK0/JnmuqMNjp6dH6No0cvnJaLlAfCPgvH0P6nmv/9GBMgTZXaWcRA/2pPpKVqZ/2nSfLHA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DoSiBqEi2+4Yk4MIqB0BxRKbboquC7mtftIDBFP+id3WgqxmHoSqqZyEO5sDz4ERohiJO4i2pyvIeg2VRpe8F+b2bUjmohGIYw44VCigl3WwJwy+Iytejl54EpHba2q3zQa/ISA4zu12CR7+lT2hGgyrdPDTZV/3vJrAnUBym1vqTpVQSdtFtdeR4X/6UFPZCOvJaMPU2eCnDIuGXzSGTvV1CgdC2Z3PtI5j0GRID8IcCdM3evDOiFrSUd6cyWBFIQXg+nC+ishSs4OaCJPkU3vqGN7eH+7ybLhtcMyA+SHx1Dps4TI5AFjcREPfGKjtrTUjZA3wMgV2lCuqR+phjQ==
  • Cc: <sstabellini@xxxxxxxxxx>, <stefano.stabellini@xxxxxxx>, <julien@xxxxxxx>, <Volodymyr_Babchuk@xxxxxxxx>, <bertrand.marquis@xxxxxxx>, <andrew.cooper3@xxxxxxxxxx>, <george.dunlap@xxxxxxxxxx>, <jbeulich@xxxxxxxx>, <wl@xxxxxxx>, <rahul.singh@xxxxxxx>, Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
  • Delivery-date: Wed, 08 Feb 2023 12:06:12 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

io_base and io_size represent physical addresses. So they should use
paddr_t (instead of u64).

However in future, paddr_t may be defined as u32. So when typecasting
values from u64 to paddr_t, one should always check for any possible
truncation. If any truncation is discovered, Xen needs to raise a BUG
for this (as the address is provided either by reading the PCIE registers
or parsing parameters from string, so the error is unrecoverable).

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
---
Changes from -
v1 - NA

v2 - 1. Extracted the patch from "[XEN v2 05/11] xen/arm: Use paddr_t instead 
of u64 for address/size"
into a separate patch of its own.


 xen/drivers/char/ns16550.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c
index 092f6b9c4b..2aee5642f9 100644
--- a/xen/drivers/char/ns16550.c
+++ b/xen/drivers/char/ns16550.c
@@ -42,8 +42,8 @@
 
 static struct ns16550 {
     int baud, clock_hz, data_bits, parity, stop_bits, fifo_size, irq;
-    u64 io_base;   /* I/O port or memory-mapped I/O address. */
-    u64 io_size;
+    paddr_t io_base;   /* I/O port or memory-mapped I/O address. */
+    paddr_t io_size;
     int reg_shift; /* Bits to shift register offset by */
     int reg_width; /* Size of access to use, the registers
                     * themselves are still bytes */
@@ -1166,8 +1166,9 @@ static const struct ns16550_config __initconst 
uart_config[] =
 static int __init
 pci_uart_config(struct ns16550 *uart, bool_t skip_amt, unsigned int idx)
 {
-    u64 orig_base = uart->io_base;
+    paddr_t orig_base = uart->io_base;
     unsigned int b, d, f, nextf, i;
+    u64 pci_uart_io_base;
 
     /* NB. Start at bus 1 to avoid AMT: a plug-in card cannot be on bus 0. */
     for ( b = skip_amt ? 1 : 0; b < 0x100; b++ )
@@ -1259,8 +1260,13 @@ pci_uart_config(struct ns16550 *uart, bool_t skip_amt, 
unsigned int idx)
                     else
                         size = len & PCI_BASE_ADDRESS_MEM_MASK;
 
-                    uart->io_base = ((u64)bar_64 << 32) |
-                                    (bar & PCI_BASE_ADDRESS_MEM_MASK);
+                    pci_uart_io_base = ((u64)bar_64 << 32) |
+                                        (bar & PCI_BASE_ADDRESS_MEM_MASK);
+
+                    /* Truncation detected while converting to paddr_t */
+                    BUG_ON((pci_uart_io_base >> (PADDR_SHIFT - 1)) > 1);
+
+                    uart->io_base = pci_uart_io_base;
                 }
                 /* IO based */
                 else if ( !param->mmio && (bar & PCI_BASE_ADDRESS_SPACE_IO) )
@@ -1468,6 +1474,7 @@ static bool __init parse_positional(struct ns16550 *uart, 
char **str)
     int baud;
     const char *conf;
     char *name_val_pos;
+    u64 uart_io_base;
 
     conf = *str;
     name_val_pos = strchr(conf, '=');
@@ -1532,7 +1539,12 @@ static bool __init parse_positional(struct ns16550 
*uart, char **str)
         else
 #endif
         {
-            uart->io_base = simple_strtoull(conf, &conf, 0);
+            uart_io_base = simple_strtoull(conf, &conf, 0);
+
+            /* Truncation detected while converting to paddr_t */
+            BUG_ON((uart_io_base >> (PADDR_SHIFT - 1)) > 1);
+
+            uart->io_base = uart_io_base;
         }
     }
 
-- 
2.17.1




 


Rackspace

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