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

Re: [PATCH v2] vpci/msix: handle accesses adjacent to the MSI-X table


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 21 Mar 2023 16:39:41 +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=6aPeiQ9ffIgYgvyxSUaYaydPyVm0vnc9BWpICLVdN78=; b=WFIwAVxvE8x5FmLveJv3XSD/QIVqtr+VOJzAbuf+cK+6Q+9GOWWWqvyL/WUdnB2+kTQ0xKN0K9yNSsh26RQ3zRyVV2QFn7HJcFqV6RP2wjh3gwwTtjIRoMEnSgwIUMlrXYTOddKv8WWM2RoyTXD2aXBeOokyEB82Kk/oZct2yu5yGVsnmZ4bF/UHvYR1QVwxmNmAoN9qtq4a7WvhvPkV0RKWfoJJ+PucnDVqHcEnBbAyeZzgt7jv2w2v7DpEgu1e1jHOnIIQkhZq/NdgxN8R6Qx6hD8lza9HIDwtoG8DQ0C1oTZBU7DwggpDmCLnKdW5o4EMD7Drf5XlRWnV4224Mw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DymPyIb21amqI4ak2d9TE446Au1vh9RdRUUkSFedHEVzIhL1CR21rBmU6mbCVAdYfmvCVzmMtnpeJnRsEAaISAuXK6PToxUPeedihH1X1CgS7rV7wQ5mv0P9oDC6UMv9+OxW8XNRBOpSSyEPuyiR2O88A4didaxaUMwdOY+eQ+UHWxY8QehllyfH9F75uiQ7N2Vc8Nj1ze0Rlrsl/juT/7yQCdD1njwRLcYscBd7m9I7OhCB0A3fommS/XbIg47Ss0eCggBJnxc5spumup1u3MQpxTsaDG+i9Rr8yb3AWl1/ur6b93WtwoBpI0mpjFPZBk56oh5PNuG9qb/N8HYw3w==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 21 Mar 2023 15:39:50 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 21.03.2023 16:31, Roger Pau Monné wrote:
> On Mon, Mar 20, 2023 at 01:08:48PM +0100, Jan Beulich wrote:
>> On 16.03.2023 13:07, Roger Pau Monne wrote:
>>>      {
>>> -        struct vpci *vpci = msix->pdev->vpci;
>>> -        unsigned int idx = addr - vmsix_table_addr(vpci, VPCI_MSIX_PBA);
>>> -        const void __iomem *pba = get_pba(vpci);
>>> +        unsigned int i;
>>> +
>>> +        gprintk(XENLOG_DEBUG, "%pp: unaligned read to MSI-X related 
>>> page\n",
>>> +                &msix->pdev->sbdf);
>>>  
>>>          /*
>>> -         * Access to PBA.
>>> +         * Split unaligned accesses into byte sized ones. Shouldn't happen 
>>> in
>>> +         * the first place, but devices shouldn't have registers in the 
>>> same 4K
>>> +         * page as the MSIX tables either.
>>>           *
>>> -         * TODO: note that this relies on having the PBA identity mapped 
>>> to the
>>> -         * guest address space. If this changes the address will need to be
>>> -         * translated.
>>> +         * It's unclear whether this could cause issues if a guest expects 
>>> a
>>> +         * registers to be accessed atomically, it better use an aligned 
>>> access
>>> +         * if it has such expectations.
>>>           */
>>> -        if ( !pba )
>>> -        {
>>> -            gprintk(XENLOG_WARNING,
>>> -                    "%pp: unable to map MSI-X PBA, report all pending\n",
>>> -                    &msix->pdev->sbdf);
>>> -            return X86EMUL_OKAY;
>>> -        }
>>>  
>>> -        switch ( len )
>>> +        for ( i = 0; i < len; i++ )
>>>          {
>>> -        case 4:
>>> -            *data = readl(pba + idx);
>>> -            break;
>>> +            unsigned long partial = ~0ul;
>>
>> Pointless initializer (~0ul is written first thing above, i.e. also in
>> the recursive invocation). Then again that setting is also redundant
>> with msix_read()'s. So I guess the initializer wants to stay but the
>> setting at the top of the function can be dropped.
> 
> I'm always extra cautious with variables on the stack that contain
> data to be returned to the guest.  All your points are valid and
> correct, but I like to explicitly initialize them so that further
> changes in the functions don't end up leaking them.  If you don't mind
> that much I would rather leave it as-is.

Well, such extra code always raises the question "Why is this here?"
But no, I won't insist if you prefer to keep the redundancy.

Jan



 


Rackspace

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