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

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


  • To: Ayan Kumar Halder <ayankuma@xxxxxxx>, Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 9 Feb 2023 08:48:59 +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=50Q7QsxYqlbt6OCOWWyZxG+DYtjXGvXKmJwVrKliLw8=; b=ec7j//IVTjy/woBwPkBDKSpqTVaD4QCy1FxZ55gxb+ZazfETFZJURjfzyLPz/ZIuY4F1dVlDeYqdSjW6mvByvHMmjmEFFjWkJqW+GyK607f/eERcpPEGNZrffmVtjIZ1Ztqs1HhGWtfE8SPkZy9ZuKG3yI2K++8MIAk+cwpRFmJXid/wY5PI+3dXWH3VOQCrj54K2JNqqSvse/ETTgOckwFh9wP6eE0NgwyK9Vv43CtFPNwFoaq/coXNtV4XlcEZbm4F4OI0n0uLOftnajgIt161etIXM7PL1pNeQGT3RTV9JFwDAU6HQtyQzmLd+XTJAcYHOftoV+v5YATf93d+Ww==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H5YWvBqzxzVzfnaSSADuJAdjh97Ri5IGyAAKoDcA2FvKoE9dPoYft5eLj9aVTAt2HNn+LuWgUXwhXLlyyn7TcMBSGvXWTjRAWx7eO2nFVSOyIxpb52L5HkC/tVzJoYQmMBrhxZlPJQ7ahMRXE1cGaPu2QmPTb9BnFPOzEZLqHbwp4BTQeowY/v1yqjscqni0OrHF0iY5cz0MBXA037iu3AlXXk+oMIGdKDx/AooOdhqxSoGwLhg5A1EVU4WCdk4sbXd4s6DAZUpbk6y8VlqeMZvvLYjjOepRa97ldNpanDXK7dMj5vRh5SSyZQQyapjOp489qdnnYGmOqMnaIKd1+g==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: sstabellini@xxxxxxxxxx, stefano.stabellini@xxxxxxx, julien@xxxxxxx, Volodymyr_Babchuk@xxxxxxxx, bertrand.marquis@xxxxxxx, andrew.cooper3@xxxxxxxxxx, george.dunlap@xxxxxxxxxx, wl@xxxxxxx, rahul.singh@xxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Thu, 09 Feb 2023 07:49:16 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 08.02.2023 18:07, Ayan Kumar Halder wrote:
> Hi Jan,
> 
> On 08/02/2023 13:52, Jan Beulich wrote:
>> On 08.02.2023 13:05, Ayan Kumar Halder wrote:
>>> @@ -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;
>> uint64_t please (also elsewhere as needed), assuming the variable
>> actually needs to survive. And if it needs to, please move it into
>> a more narrow scope (and perhaps shorten its name).
> Ack.
>>
>>> @@ -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);
>> Why would we want to crash during early boot at all? And then even at a
>> point where it'll be hard to figure out what's going on, as we're only
>> in the process of configuring the serial console?
> 
> I do not understand the best way to return an error from pci_uart_config().
> 
> Out of the 4 invocations of pci_uart_config(), the return value is 
> checked in two invocations only like this.
> 
> if ( pci_uart_config(uart, 0, uart - ns16550_com) )
>                  return true;
> 
> pci_uart_config() returns 0 in case of success and -1 in case of error. 
> But the caller seems to be checking the opposite.

The callers look a little odd, I agree, but iirc that's intentional. Since
this is all PCI _and_ x86-only code, which you don't care all that much
about, one option is to leave that code alone for the time being. The other
is to properly propagate such an error through all involved code paths, e.g.
by way of invoking PARSE_ERR_RET() in parse_namevalue_pairs() in the failure
case.

>>> @@ -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);
>> All the same here.
> 
> I can return false from here and let ns16550_parse_port_config() return.
> 
> I think that might be the correct thing to do here.

Perhaps, and likely again by way of using PARSE_ERR_RET().

Jan



 


Rackspace

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