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

Re: [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code


  • To: Bertrand Marquis <bertrand.marquis@xxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Fri, 15 Oct 2021 09:44:15 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.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=9oz72RjvQ9vrbnCPu8D3PXpkuwlk0cM7YjOj52B/hkg=; b=bKDTbhF1Z4X4CRCRxUhFrN2mx8LXDS74jRnyACdHhiDm0zWVcdfzohvCEk9Br3vbprmHKpMfC1PbueBbjvp7ekxzVtjqU2n0LaGsmeWI1rNfjcRRvwuCTSE3qNU51i5M2qP/fVfIQNx6vB5K133BFNZJFFoeXNUMFg21HVjzFwgJs143fyM8KKXNUX6U/56DnZzb+36DVlh6JwIc6gfxtr2FdTNJHCzOAkpdkI+KW00O9OUeaMK39s78Zy3j/1LZ4/G8VBO1UweNqO50VMcLqwRJuZOfrvIGhu0i1Vj4uyi1sfEFwkyK4hYG6yk6UuR12qhhiB/ZcPsF3p/PsBohZQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n72N+TlMaaqXkpQ12Hme72DlgejgFUxKBBTs7rnDGzA+DNz/yKXdU3R96GlSmLuLwDlSXJYPe1xd7W0bJmTKX7nozGs0rJiPprrePQEEPI+oKEi36aW1BGLfgHU4TSnGeMCsBp6ViwleVcL3Pu+AuP5Sh3HarmSX43D0v4gKcR/xRjLh54kyzEyerbLg5cE9pgNKPzonE8aIChlNht6UyBp8rckC9W/QhMnUQjSLcbV3n00+eMndRAnZU9n1D1am412vfPvRPHAzvNw92K2LkOqhkUywNE+Mu+aMO6t8kMKa7llSWAQFjKOCxD9FfqFEadXG4o4PzyQIV1gkro20Aw==
  • Authentication-results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: <xen-devel@xxxxxxxxxxxxxxxxxxxx>, <iwj@xxxxxxxxxxxxxx>, Paul Durrant <paul@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Fri, 15 Oct 2021 07:44:37 +0000
  • Ironport-data: A9a23:yKI2AK2n/EEclmLbWPbD5Ux2kn2cJEfYwER7XKvMYLTBsI5bpzwPm zBMDD+Abv6ONmLwe9x0a4Sxo0wGscWAmNdnGgM+pC1hF35El5HIVI+TRqvS04J+DSFhoGZPt Zh2hgzodZhsJpPkS5PE3oHJ9RGQ74nRLlbHILOCan0ZqTNMEn970Es7wrNh2+aEvPDia++zk YKqyyHgEAfNNw5cagr4PIra9XuDFNyr0N8plgRWicJj5TcypFFMZH4rHomjLmOQf2VhNrXSq 9Avbl2O1jixEx8FUrtJm1tgG6EAaua60QOm0hK6V0U+6/TrS+NbPqsTbZIhhUlrZzqhhulA0 tpskKyLQyhyEanos7oHcgtRDHQrVUFG0OevzXmXtMWSywvNcmf2wuUoB0YzVWEa0r8pWycUr 6VecW1TKEDY7w616OvTpu1EnMMsIdOtJIoCknph0SvYHbAtRpWrr6DiuIMIhmdq3Z4m8fD2S MklRjppbUn6XTZ2HUo3CJgajef0ryyqG9FfgA3M/vdmi4TJ9yRp2aXpGMrYfJqNX8o9tkSSq 3/C/m/5KgoHL9HZwj2AmlqzgsffkCW9X5gdfJWy++R2mlSVyioWAQcPSFqgifCjjwi1XNc3A 1wZ/G8ioLY/8GSvT8LhRFuorXicpBkeV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XPh9KJyC9I/b2qy nxppgmPH/P6Ar4WBkb6La90Y27MA7hHPlOkPUs1NaZLXPbUQ6TTb2KgrGSpgEIdxeOktK1kJ 0QDJSWa+eAfWSS7/yKmDVQeuxIqLLsndHK9IWuvEuFDzsaEJ2Ihz0JezpzeXcGPTWua6BJc6 Z1saF81kSdkDksH4iGL0hAe9KGi8zAlZrgbxJDLxk76DOWhTftzLLhCRCX0joXTjsKmN4ZgC b4uj28wp/mn+Cwyxfa2WOWx5NKmOH5wt8GIMCXkMAaJhjllw7tToV8XL+puiwzvYiUmRkXue iJhy1lE9V46nvXcG3wiRzx2zP42DJr0HPmwU/wuwqpneXJABYBT+ZRj4NQdRXUr2A6ustn7a 5N12WF87JKEBLphk3Glpv1fiAvsnDxjWspkOYVgXAae5AZcqVtoYsW+14QOIscHRj99JssHI BVfYHhDc5tABanhk3izy1SKITGZAV1Iv7GeDlChiWt6UkVoJgjpHFogvD2nR87hdoAotd/lr 352gkBrsA4ciYsV9MJOA42e7r/NoX8e2O/DIusGyWSKEgmAQOGl3el2sR52AmVEKZ4uqfa3q 6xCG9liQ==
  • Ironport-sdr: IomCdoLKltLV3CGcFUfzTT8IlRrO2YEy+DLlB7H1OGQUVaisc02mQO5sTFIYGLjh9MauMIrGE/ YHadXS6nSQ935tQQuCv9vfBRdT3Er/NNbzc1qFbaO9Cvcorg7Ty+l2JCRnEQvqDXSwNHvhnWL/ Pe34haCn9nGk4t5MvulbTPETqPfCm3QGVDzS8754+A8Kxb2gLkFMP+cO2RMfjRUS7yWgi1ItAT gNeLsSSnB9S/nK1mDZlECY1DDcEeY6Z1LAOhQq8XBOuZ+78Iu1fWTDJu023augk2qZGCDHGPEr 5Sr1/tF4zTs9WsyhQ8mS004y
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Thu, Oct 14, 2021 at 03:49:49PM +0100, Bertrand Marquis wrote:
> PCI standard is using ECAM and not MCFG which is coming from ACPI[1].
> Use ECAM/ecam instead of MCFG in common code and in new functions added
> in common vpci code by this patch.
> 
> Rename vpci_access_allowed to vpci_ecam_access_allowed and move it
> from arch/x86/hvm/io.c to drivers/vpci/vpci.c.
> 
> Create vpci_ecam_mmio_{read,write} in drivers/vpci/vpci.c that
> contains the common code to perform these operations, changed
> vpci_mmcfg_{read,write} accordingly to make use of these functions.
> 
> The vpci_ecam_mmio_{read,write} functions are returning 0 on error and 1
> on success. As the x86 code was previously always returning X86EMUL_OKAY
> the return code is ignored. A comment has been added in the code to show
> that this is intentional.
> 
> Those functions will be used in a following patch inside by arm vpci
> implementation.
> 
> Rename MMCFG_SBDF to ECAM_SBDF.
> 
> Not functional change intended with this patch.
> 
> [1] https://wiki.osdev.org/PCI_Express
> 
> Suggested-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
> Signed-off-by: Bertrand Marquis <bertrand.marquis@xxxxxxx>
> ---
> Changes in v6: Patch added
> ---
>  xen/arch/x86/hvm/io.c     | 50 +++++---------------------------
>  xen/drivers/vpci/vpci.c   | 60 +++++++++++++++++++++++++++++++++++++++
>  xen/include/asm-x86/pci.h |  2 +-
>  xen/include/xen/vpci.h    | 10 +++++++
>  4 files changed, 78 insertions(+), 44 deletions(-)
> 
> diff --git a/xen/arch/x86/hvm/io.c b/xen/arch/x86/hvm/io.c
> index 046a8eb4ed..340b8c8b0e 100644
> --- a/xen/arch/x86/hvm/io.c
> +++ b/xen/arch/x86/hvm/io.c
> @@ -260,20 +260,6 @@ unsigned int hvm_pci_decode_addr(unsigned int cf8, 
> unsigned int addr,
>      return CF8_ADDR_LO(cf8) | (addr & 3);
>  }
>  
> -/* Do some sanity checks. */
> -static bool vpci_access_allowed(unsigned int reg, unsigned int len)
> -{
> -    /* Check access size. */
> -    if ( len != 1 && len != 2 && len != 4 && len != 8 )
> -        return false;
> -
> -    /* Check that access is size aligned. */
> -    if ( (reg & (len - 1)) )
> -        return false;
> -
> -    return true;
> -}
> -
>  /* vPCI config space IO ports handlers (0xcf8/0xcfc). */
>  static bool vpci_portio_accept(const struct hvm_io_handler *handler,
>                                 const ioreq_t *p)
> @@ -305,7 +291,7 @@ static int vpci_portio_read(const struct hvm_io_handler 
> *handler,
>  
>      reg = hvm_pci_decode_addr(cf8, addr, &sbdf);
>  
> -    if ( !vpci_access_allowed(reg, size) )
> +    if ( !vpci_ecam_access_allowed(reg, size) )
>          return X86EMUL_OKAY;
>  
>      *data = vpci_read(sbdf, reg, size);
> @@ -335,7 +321,7 @@ static int vpci_portio_write(const struct hvm_io_handler 
> *handler,
>  
>      reg = hvm_pci_decode_addr(cf8, addr, &sbdf);
>  
> -    if ( !vpci_access_allowed(reg, size) )
> +    if ( !vpci_ecam_access_allowed(reg, size) )
>          return X86EMUL_OKAY;
>  
>      vpci_write(sbdf, reg, size, data);
> @@ -394,7 +380,7 @@ static unsigned int vpci_mmcfg_decode_addr(const struct 
> hvm_mmcfg *mmcfg,
>                                             paddr_t addr, pci_sbdf_t *sbdf)
>  {
>      addr -= mmcfg->addr;
> -    sbdf->bdf = MMCFG_BDF(addr);
> +    sbdf->bdf = ECAM_BDF(addr);
>      sbdf->bus += mmcfg->start_bus;
>      sbdf->seg = mmcfg->segment;
>  
> @@ -434,25 +420,8 @@ static int vpci_mmcfg_read(struct vcpu *v, unsigned long 
> addr,
>      reg = vpci_mmcfg_decode_addr(mmcfg, addr, &sbdf);
>      read_unlock(&d->arch.hvm.mmcfg_lock);
>  
> -    if ( !vpci_access_allowed(reg, len) ||
> -         (reg + len) > PCI_CFG_SPACE_EXP_SIZE )
> -        return X86EMUL_OKAY;
> -
> -    /*
> -     * According to the PCIe 3.1A specification:
> -     *  - Configuration Reads and Writes must usually be DWORD or smaller
> -     *    in size.
> -     *  - Because Root Complex implementations are not required to support
> -     *    accesses to a RCRB that cross DW boundaries [...] software
> -     *    should take care not to cause the generation of such accesses
> -     *    when accessing a RCRB unless the Root Complex will support the
> -     *    access.
> -     *  Xen however supports 8byte accesses by splitting them into two
> -     *  4byte accesses.
> -     */
> -    *data = vpci_read(sbdf, reg, min(4u, len));
> -    if ( len == 8 )
> -        *data |= (uint64_t)vpci_read(sbdf, reg + 4, 4) << 32;
> +    /* Ignore return code */
> +    vpci_ecam_mmio_read(sbdf, reg, len, data);

I think it would be better for vpci_ecam_mmio_read to just return the
read value, or ~0 in case of error, at least that interface would be
simpler and suitable for x86.

Also I would drop the mmio part from the function name.

>  
>      return X86EMUL_OKAY;
>  }
> @@ -476,13 +445,8 @@ static int vpci_mmcfg_write(struct vcpu *v, unsigned 
> long addr,
>      reg = vpci_mmcfg_decode_addr(mmcfg, addr, &sbdf);
>      read_unlock(&d->arch.hvm.mmcfg_lock);
>  
> -    if ( !vpci_access_allowed(reg, len) ||
> -         (reg + len) > PCI_CFG_SPACE_EXP_SIZE )
> -        return X86EMUL_OKAY;
> -
> -    vpci_write(sbdf, reg, min(4u, len), data);
> -    if ( len == 8 )
> -        vpci_write(sbdf, reg + 4, 4, data >> 32);
> +    /* Ignore return code */
> +    vpci_ecam_mmio_write(sbdf, reg, len, data);

Kind of likely here, x86 would be fine with this function return type
being void.

If that's not good for Arm, I think the comment can be dropped as it's
clear the return code is ignored. It would better to maybe add:

/* Failed writes are not propagated to the caller */

>  
>      return X86EMUL_OKAY;
>  }
> diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c
> index cbd1bac7fc..c0853176d7 100644
> --- a/xen/drivers/vpci/vpci.c
> +++ b/xen/drivers/vpci/vpci.c
> @@ -478,6 +478,66 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, 
> unsigned int size,
>      spin_unlock(&pdev->vpci->lock);
>  }
>  
> +/* Helper function to check an access size and alignment on vpci space. */
> +bool vpci_ecam_access_allowed(unsigned int reg, unsigned int len)
> +{
> +    /*
> +     * Check access size.
> +     *
> +     * On arm32 or for 32bit guests on arm, 64bit accesses should be 
> forbidden
> +     * but as for those platform ISV register, which gives the access size,
> +     * cannot have a value 3, checking this would just harden the code.

It feels kind of weird to have an Arm specific comment in common code,
but I guess there's no better place for it to live?

Thanks, Roger.



 


Rackspace

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