All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bertrand Marquis <Bertrand.Marquis@arm.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "Rahul Singh" <Rahul.Singh@arm.com>,
	"Andre Przywara" <Andre.Przywara@arm.com>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Julien Grall" <julien@xen.org>,
	"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"George Dunlap" <george.dunlap@citrix.com>,
	"Ian Jackson" <iwj@xenproject.org>, "Wei Liu" <wl@xen.org>,
	"Paul Durrant" <paul@xen.org>,
	"Roger Pau Monné" <roger.pau@citrix.com>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM.
Date: Mon, 11 Oct 2021 12:41:30 +0000	[thread overview]
Message-ID: <CEF7FFB0-779A-4F46-8667-6BCD9BA5CB6C@arm.com> (raw)
In-Reply-To: <6752f2d3-171b-37f5-c809-82995a8f3f36@suse.com>

Hi Jan,

As Rahul is on leave, I will answer you and make the changes needed.

> On 7 Oct 2021, at 14:43, Jan Beulich <jbeulich@suse.com> wrote:
> 
> On 06.10.2021 19:40, Rahul Singh wrote:
>> --- /dev/null
>> +++ b/xen/arch/arm/vpci.c
>> @@ -0,0 +1,102 @@
>> +/*
>> + * xen/arch/arm/vpci.c
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> + * GNU General Public License for more details.
>> + */
>> +#include <xen/sched.h>
>> +
>> +#include <asm/mmio.h>
>> +
>> +#define REGISTER_OFFSET(addr)  ( (addr) & 0x00000fff)
> 
> Nit: Stray blank (like you had in an earlier version for MMCFG_BDF()).
> Also isn't this effectively part of the public interface (along with
> MMCFG_BDF()), alongside GUEST_VPCI_ECAM_{BASE,SIZE}?

I will move that in the next version to xen/pci.h and rename it MMCFG_REG_OFFSET.
Would that be ok ?

> 
>> +/* Do some sanity checks. */
>> +static bool vpci_mmio_access_allowed(unsigned int reg, unsigned int len)
>> +{
>> +    /* Check access size. */
>> +    if ( len > 8 )
>> +        return false;
> 
> struct hsr_dabt's size field doesn't allow len to be above 8. I could
> see that you may want to sanity check things, but that's not helpful
> if done incompletely. Elsewhere you assume the value to be non-zero,
> and ...
> 
>> +    /* Check that access is size aligned. */
>> +    if ( (reg & (len - 1)) )
> 
> ... right here you assume the value to be a power of 2. While I'm not
> a maintainer, I'd still like to suggest consistency: Do all pertinent
> checks or none of them (relying on the caller).

I will remove the check for len > 8 as dabt.size cannot have a value
greater than 3.

But I will have to introduce a check for len > 4 on 32 bit systems (see after).

> 
> Independent of this - is bare metal Arm enforcing this same
> alignment restriction (unconditionally)? Iirc on x86 we felt we'd
> better synthesize misaligned accesses.

Unaligned IO access could be synthesise also on arm to but I would
rather not make such a change now without testing it (and there is
also a question of it making sense).

So if it is ok with you I will keep that check and discuss it with Rahul
when he is back. I will add a comment in the code to make that clear.

> 
>> +static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info,
>> +                          register_t *r, void *p)
>> +{
>> +    unsigned int reg;
>> +    pci_sbdf_t sbdf;
>> +    unsigned long data = ~0UL;
> 
> What use is this initializer? The error path further down doesn't
> forward the value into *r, and subsequently the value gets fully
> overwritten.

Right I will remove it.

> 
>> +    unsigned int size = 1U << info->dabt.size;
>> +
>> +    sbdf.sbdf = MMCFG_BDF(info->gpa);
> 
> This implies segment to be zero. While probably fine for now, I
> wonder if this wouldn't warrant a comment.

I will add the following comment just before:
/* We ignore segment part and always handle segment 0 */

> 
>> +    reg = REGISTER_OFFSET(info->gpa);
>> +
>> +    if ( !vpci_mmio_access_allowed(reg, size) )
>> +        return 0;
>> +
>> +    data = vpci_read(sbdf, reg, min(4u, size));
>> +    if ( size == 8 )
>> +        data |= (uint64_t)vpci_read(sbdf, reg + 4, 4) << 32;
> 
> Throughout this series I haven't been able to spot where the HAS_VPCI
> Kconfig symbol would get selected. Hence I cannot tell whether all of
> this is Arm64-specific. Otherwise I wonder whether size 8 actually
> can occur on Arm32.

Dabt.size could be 3 even on ARM32 but we should not allow 64bit
access on mmio regions on arm32.

So I will surround this code with ifdef CONFIG_ARM_64 and add a test
for len > 4 to prevent this case on 32bit.

To be completely right we should disable this also for 32bit guests but
this change would be a bit more invasive.

> 
>> +static int vpci_mmio_write(struct vcpu *v, mmio_info_t *info,
>> +                           register_t r, void *p)
>> +{
>> +    unsigned int reg;
>> +    pci_sbdf_t sbdf;
>> +    unsigned long data = r;
> 
> A little like in the read function - what use is this local variable?
> Can't you use r directly?

We can and I will remove the data variable.

> 
>> --- a/xen/drivers/passthrough/pci.c
>> +++ b/xen/drivers/passthrough/pci.c
>> @@ -766,6 +766,24 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,
>>     else
>>         iommu_enable_device(pdev);
> 
> Please note the context above; ...
> 
>> +#ifdef CONFIG_ARM
>> +    /*
>> +     * On ARM PCI devices discovery will be done by Dom0. Add vpci handler when
>> +     * Dom0 inform XEN to add the PCI devices in XEN.
>> +     */
>> +    ret = vpci_add_handlers(pdev);
>> +    if ( ret )
>> +    {
>> +        printk(XENLOG_ERR "setup of vPCI failed: %d\n", ret);
>> +        pci_cleanup_msi(pdev);
>> +        ret = iommu_remove_device(pdev);
>> +        if ( pdev->domain )
>> +            list_del(&pdev->domain_list);
>> +        free_pdev(pseg, pdev);
> 
> ... you unconditionally undo the if() part of the earlier conditional;
> is there any guarantee that the other path can't ever be taken, now
> and forever? If it can't be taken now (which I think is the case as
> long as Dom0 wouldn't report the same device twice), then at least some
> precaution wants taking. Maybe moving your addition into that if()
> could be an option.
> 
> Furthermore I continue to wonder whether this ordering is indeed
> preferable over doing software setup before hardware arrangements. This
> would address the above issue as well as long as vpci_add_handlers() is
> idempotent. And it would likely simplify error cleanup.

I agree with you so I will move this code block before iommu part.

But digging deeper into this, I would have 2 questions:

- msi_cleanup was done there after a request from Stefano, but is not
done in case or iommu error, is there an issue to solve here ?
Same could also go for the free_pdev ?

- cleanup code was exactly the same as pci_remove_device code.
Should the question about the path also be checked there ?

Regards
Bertrand


> 
> Jan
> 
> 



  reply	other threads:[~2021-10-11 12:42 UTC|newest]

Thread overview: 190+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-06 17:40 [PATCH v5 00/11] PCI devices passthrough on Arm Rahul Singh
2021-10-06 17:40 ` [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM Rahul Singh
2021-10-11 11:47   ` Roger Pau Monné
2021-10-11 12:11     ` Bertrand Marquis
2021-10-11 13:20       ` Roger Pau Monné
2021-10-11 13:40         ` Bertrand Marquis
2021-10-11 13:57           ` Roger Pau Monné
2021-10-11 14:16             ` Bertrand Marquis
2021-10-11 16:32               ` Roger Pau Monné
2021-10-11 17:11                 ` Bertrand Marquis
2021-10-12  8:29                   ` Jan Beulich
2021-10-12  8:41                     ` Bertrand Marquis
2021-10-12  9:32                       ` Jan Beulich
2021-10-12  9:38                         ` Oleksandr Andrushchenko
2021-10-12 10:01                           ` Jan Beulich
2021-10-12 10:06                             ` Oleksandr Andrushchenko
2021-10-12 10:20                               ` Jan Beulich
2021-10-12 10:41                                 ` Bertrand Marquis
2021-10-12 10:44                                   ` Jan Beulich
2021-10-12 14:53                                   ` Ian Jackson
2021-10-12 16:15                                     ` Bertrand Marquis
2021-10-12 16:29                                       ` Ian Jackson
2021-10-12 20:42                                         ` Stefano Stabellini
2021-10-13  8:07                                           ` Roger Pau Monné
2021-10-13 11:52                                             ` Ian Jackson
2021-10-13  8:02                                       ` Roger Pau Monné
2021-10-13 12:02                                         ` Ian Jackson
2021-10-12  9:40                         ` Bertrand Marquis
2021-10-12 10:03                           ` Jan Beulich
2021-10-11 14:16           ` Oleksandr Andrushchenko
2021-10-06 17:40 ` [PATCH v5 02/11] xen/arm: Add PHYSDEVOP_pci_device_(*add/remove) support for ARM Rahul Singh
2021-10-07  0:05   ` Stefano Stabellini
2021-10-07 12:58     ` Jan Beulich
2021-10-21  9:28   ` xen/arm: Missing appropriate locking for the IOMMU (WAS Re: [PATCH v5 02/11] xen/arm: Add PHYSDEVOP_pci_device_(*add/remove) support for ARM) Julien Grall
2021-10-21 13:15     ` Bertrand Marquis
2021-10-21 13:47       ` Julien Grall
2021-10-21 13:52         ` Bertrand Marquis
2021-10-06 17:40 ` [PATCH v5 03/11] xen/arm: Add cmdline boot option "pci-passthrough = <boolean>" Rahul Singh
2021-10-07  8:27   ` Jan Beulich
2021-10-07  8:32     ` Rahul Singh
2021-10-07 12:59   ` Jan Beulich
2021-10-06 17:40 ` [PATCH v5 04/11] xen/arm: PCI host bridge discovery within XEN on ARM Rahul Singh
2021-10-06 17:40 ` [PATCH v5 05/11] xen/arm: Add support for Xilinx ZynqMP PCI host controller Rahul Singh
2021-10-06 17:40 ` [PATCH v5 06/11] xen/arm: Implement pci access functions Rahul Singh
2021-10-06 17:40 ` [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag Rahul Singh
2021-10-07 13:08   ` Jan Beulich
2021-10-08 18:06   ` Andrew Cooper
2021-10-08 21:12     ` Julien Grall
2021-10-08 21:46       ` Stefano Stabellini
2021-10-11  9:24         ` Julien Grall
2021-10-11 11:29         ` Michal Orzel
2021-10-11 11:35           ` Jan Beulich
2021-10-11 13:17             ` Roger Pau Monné
2021-10-11  9:48     ` Ian Jackson
2021-10-11  9:27   ` Roger Pau Monné
2021-10-11 12:06     ` Michal Orzel
2021-10-12 10:38     ` Michal Orzel
2021-10-13  8:30       ` Roger Pau Monné
2021-10-13  9:36         ` Bertrand Marquis
2021-10-13 10:56           ` Roger Pau Monné
2021-10-13 12:11             ` Bertrand Marquis
2021-10-13 12:57               ` Jan Beulich
2021-10-13 20:41                 ` Stefano Stabellini
2021-10-14  6:23                   ` Jan Beulich
2021-10-14  7:53                     ` Bertrand Marquis
2021-10-13 14:28               ` Roger Pau Monné
2021-10-13 20:53             ` Stefano Stabellini
2021-10-13 23:21               ` Stefano Stabellini
2021-10-12 21:48     ` Stefano Stabellini
2021-10-13  6:18       ` Jan Beulich
2021-10-13  7:11         ` Michal Orzel
2021-10-06 17:40 ` [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM Rahul Singh
2021-10-07 13:43   ` Jan Beulich
2021-10-11 12:41     ` Bertrand Marquis [this message]
2021-10-11 13:09       ` Jan Beulich
2021-10-11 13:34         ` Bertrand Marquis
2021-10-11 14:10           ` Jan Beulich
2021-10-11 14:52             ` Bertrand Marquis
2021-10-11 18:18             ` Stefano Stabellini
2021-10-12  8:04               ` Jan Beulich
2021-10-12 21:37                 ` Stefano Stabellini
2021-10-13  6:10                   ` Jan Beulich
2021-10-13 10:02                     ` Bertrand Marquis
2021-10-13 12:21                       ` Jan Beulich
2021-10-12 15:04       ` Julien Grall
2021-10-12 16:12         ` Bertrand Marquis
2021-10-12 16:20           ` Julien Grall
2021-10-12 17:50             ` Bertrand Marquis
2021-10-11 10:51   ` Roger Pau Monné
2021-10-11 16:12     ` Bertrand Marquis
2021-10-11 16:20       ` Oleksandr Andrushchenko
2021-10-11 16:43         ` Roger Pau Monné
2021-10-11 17:15           ` Bertrand Marquis
2021-10-11 18:30             ` Oleksandr Andrushchenko
2021-10-11 19:27               ` Stefano Stabellini
2021-10-12  5:34                 ` Oleksandr Andrushchenko
2021-10-12  7:44                 ` Bertrand Marquis
2021-10-12 14:32   ` Julien Grall
2021-10-12 14:34     ` Bertrand Marquis
2021-10-13  8:45   ` Roger Pau Monné
2021-10-13  9:48     ` Bertrand Marquis
2021-10-13 10:33       ` Roger Pau Monné
2021-10-13 13:00     ` Jan Beulich
2021-10-13 14:51       ` Oleksandr Andrushchenko
2021-10-13 15:15         ` Jan Beulich
2021-10-13 19:27           ` Stefano Stabellini
2021-10-14  6:33             ` Jan Beulich
2021-10-14  7:53               ` Bertrand Marquis
2021-10-14  9:03               ` Bertrand Marquis
2021-10-14  9:24                 ` Jan Beulich
2021-10-06 17:40 ` [PATCH v5 09/11] xen/arm: Transitional change to build HAS_VPCI on ARM Rahul Singh
2021-10-11 11:43   ` Roger Pau Monné
2021-10-11 12:15     ` Bertrand Marquis
2021-10-12  1:32       ` Stefano Stabellini
2021-10-06 17:40 ` [PATCH v5 10/11] arm/libxl: Emulated PCI device tree node in libxl Rahul Singh
2021-10-06 18:01   ` Julien Grall
2021-10-07  0:26     ` Stefano Stabellini
2021-10-07 15:31       ` Rahul Singh
2021-10-07 10:53     ` Ian Jackson
2021-10-07 15:29       ` Rahul Singh
2021-10-07 16:11         ` Ian Jackson
2021-10-11 13:46           ` Roger Pau Monné
2021-10-14 17:16           ` Bertrand Marquis
2021-10-14 14:49             ` [PATCH v6 0/3] PCI devices passthrough on Arm Bertrand Marquis
2021-10-14 14:49               ` [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code Bertrand Marquis
2021-10-14 16:06                 ` Jan Beulich
2021-10-14 17:09                   ` Bertrand Marquis
2021-10-15  6:29                     ` Jan Beulich
2021-10-15  7:37                       ` Bertrand Marquis
2021-10-15  8:13                         ` Jan Beulich
2021-10-15  8:20                           ` Bertrand Marquis
2021-10-15  8:24                             ` Jan Beulich
2021-10-15  9:49                           ` Roger Pau Monné
2021-10-14 23:47                 ` Stefano Stabellini
2021-10-15  7:44                 ` Roger Pau Monné
2021-10-15  7:53                   ` Bertrand Marquis
2021-10-15  9:53                     ` Roger Pau Monné
2021-10-15 10:12                       ` Bertrand Marquis
2021-10-15 10:14                       ` Jan Beulich
2021-10-14 14:49               ` [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM Bertrand Marquis
2021-10-14 23:49                 ` Stefano Stabellini
2021-10-15  6:40                   ` Jan Beulich
2021-10-15  9:59                     ` Ian Jackson
2021-10-15 10:10                   ` Bertrand Marquis
2021-10-15  8:00                 ` Jan Beulich
2021-10-15 10:09                   ` Bertrand Marquis
2021-10-15 10:14                     ` Ian Jackson
2021-10-15 10:18                       ` Jan Beulich
2021-10-15 11:35                         ` Roger Pau Monné
2021-10-15 12:13                           ` Bertrand Marquis
2021-10-15 12:18                             ` Jan Beulich
2021-10-15 12:28                               ` Bertrand Marquis
2021-10-15 13:00                                 ` Jan Beulich
2021-10-15 13:10                                   ` Bertrand Marquis
2021-10-15 10:38                     ` Jan Beulich
2021-10-15  8:32                 ` Roger Pau Monné
2021-10-15  8:42                   ` Michal Orzel
2021-10-15  9:52                   ` Bertrand Marquis
2021-10-15 10:13                     ` Luca Fancellu
2021-10-15 10:17                       ` Bertrand Marquis
2021-10-15 10:19                     ` Roger Pau Monné
2021-10-15 10:31                       ` Bertrand Marquis
2021-10-15 10:24                     ` Jan Beulich
2021-10-15 10:33                       ` Bertrand Marquis
2021-10-15 10:41                         ` Jan Beulich
2021-10-15 10:48                           ` Bertrand Marquis
2021-10-15 10:51                             ` Jan Beulich
2021-10-15 11:08                               ` Bertrand Marquis
2021-10-15 13:47                             ` Roger Pau Monné
2021-10-15 14:00                               ` Luca Fancellu
2021-10-15 14:32                                 ` Roger Pau Monné
2021-10-14 14:49               ` [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl Bertrand Marquis
2021-10-14 17:54                 ` [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl [and 1 more messages] Ian Jackson
2021-10-14 23:50                   ` Stefano Stabellini
2021-10-15  7:28                   ` Julien Grall
2021-10-15  7:41                     ` Michal Orzel
2021-10-15  9:01                       ` Julien Grall
2021-10-15 10:02                     ` Ian Jackson
2021-10-15 10:58                       ` Michal Orzel
2021-10-15 11:04                         ` Michal Orzel
2021-10-15 11:46                         ` Ian Jackson
2021-10-15 11:53                           ` Michal Orzel
2021-10-15 12:10                             ` Julien Grall
2021-10-15 12:14                               ` Ian Jackson
2021-10-15 12:13                             ` Ian Jackson
2021-10-12 15:03   ` [PATCH v5 10/11] arm/libxl: Emulated PCI device tree node in libxl Ian Jackson
2021-10-06 17:40 ` [PATCH v5 11/11] xen/arm: Add linux,pci-domain property for hwdom if not available Rahul Singh
2021-10-13 20:54   ` Stefano Stabellini
2021-10-07 19:54 ` [PATCH v5 00/11] PCI devices passthrough on Arm Stefano Stabellini
2021-10-07 21:29   ` Rahul Singh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CEF7FFB0-779A-4F46-8667-6BCD9BA5CB6C@arm.com \
    --to=bertrand.marquis@arm.com \
    --cc=Andre.Przywara@arm.com \
    --cc=Rahul.Singh@arm.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=iwj@xenproject.org \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=paul@xen.org \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.