All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: StefanoStabellini <sstabellini@kernel.org>,
	Wei Liu <wei.liu2@citrix.com>,
	GeorgeDunlap <George.Dunlap@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>, Tim Deegan <tim@xen.org>,
	xen-devel@lists.xenproject.org, boris.ostrovsky@oracle.com
Subject: Re: [PATCH v7 for-next 09/12] vpci/bars: add handlers to map the BARs
Date: Fri, 19 Jan 2018 15:47:33 +0000	[thread overview]
Message-ID: <20180119154733.qipgoiyhltzclkls@MacBook-Pro-de-Roger.local> (raw)
In-Reply-To: <5A33C35F0200007800197A98@prv-mh.provo.novell.com>

Thanks for the review, and sorry for the very late reply.

On Fri, Dec 15, 2017 at 04:43:11AM -0700, Jan Beulich wrote:
> >>> On 18.10.17 at 13:40, <roger.pau@citrix.com> wrote:
> > +static void modify_decoding(const struct pci_dev *pdev, bool map, bool rom)
> > +{
> > +    struct vpci_header *header = &pdev->vpci->header;
> > +    uint8_t slot = PCI_SLOT(pdev->devfn), func = PCI_FUNC(pdev->devfn);
> > +    unsigned int i;
> > +
> > +    for ( i = 0; i < ARRAY_SIZE(header->bars); i++ )
> > +    {
> > +        if ( rom && header->bars[i].type == VPCI_BAR_ROM )
> > +        {
> > +            unsigned int rom_pos = (i == 6) ? PCI_ROM_ADDRESS
> > +                                            : PCI_ROM_ADDRESS1;
> > +            uint32_t val = pci_conf_read32(pdev->seg, pdev->bus, slot, func,
> > +                                           rom_pos);
> > +
> > +            header->bars[i].enabled = header->bars[i].rom_enabled = map;
> > +
> > +            val &= ~PCI_ROM_ADDRESS_ENABLE;
> > +            val |= map ? PCI_ROM_ADDRESS_ENABLE : 0;
> > +            pci_conf_write32(pdev->seg, pdev->bus, slot, func, rom_pos, val);
> > +            break;
> > +        }
> > +        if ( !rom && (header->bars[i].type != VPCI_BAR_ROM ||
> > +                      header->bars[i].rom_enabled) )
> > +            header->bars[i].enabled = map;
> > +    }
> 
> Looking at all of this, it would clearly be more logical for
> rom_enabled to be a per-header instead of a per-BAR flag.

Hm, I'm not sure just moving the rom_enable would be such a win, we
would still need to iterate over the array of BARs in order to find
the position of the ROM BAR and thus which register has to be used
(PCI_ROM_ADDRESS or PCI_ROM_ADDRESS1).

I could solve that but it would mean adding a bool plus an unsigned
int field to store the position of the ROM BAR. Since this is not
going to change the behavior I would rather leave this for future
improvements, likely when SR-IOV is implemented and we have a better
picture of what needs to be stored in the 'header' struct.

> > +    if ( !rom )
> > +    {
> > +        uint16_t cmd = pci_conf_read16(pdev->seg, pdev->bus, slot,
> > +                                       func, PCI_COMMAND);
> > +
> > +        cmd &= ~PCI_COMMAND_MEMORY;
> > +        cmd |= map ? PCI_COMMAND_MEMORY : 0;
> > +        pci_conf_write16(pdev->seg, pdev->bus, slot, func, PCI_COMMAND,
> > +                         cmd);
> > +    }
> 
> For both writes, wouldn't it be worthwhile to avoid them when the
> flag is already in the intended state?

If the flag is in the intended state modify_decoding would not be
called at all, because cmd_write and rom_write already filter those
cases.

> > +            if ( v->vpci.map )
> > +            {
> > +                spin_lock(&v->vpci.pdev->vpci->lock);
> > +                modify_decoding(v->vpci.pdev, v->vpci.map, v->vpci.rom);
> > +                spin_unlock(&v->vpci.pdev->vpci->lock);
> > +            }
> > +            /* fallthrough. */
> > +        case -ENOMEM:
> > +            /*
> > +             * Other errors are ignored, hopping that at least some regions
> 
> hoping
> 
> I also don't really understand your intentions here: If other errors
> are being ignored, wouldn't that lead to the rangeset being leaked?
> Or is "other" here meant to include -ENOMEM, in which case you
> really mean "default:" above?

Yes, s/case 0/default/ above, or else this is simply not true, and
leaks the partially consumed rangeset.

> >  struct vpci {
> >      /* List of vPCI handlers for a device. */
> >      struct list_head handlers;
> >      spinlock_t lock;
> > +
> > +#ifdef __XEN__
> > +    /* Hide the rest of the vpci struct from the user-space test harness. */
> > +    struct vpci_header {
> > +        /* Information about the PCI BARs of this device. */
> > +        struct vpci_bar {
> > +            uint64_t addr;
> > +            uint64_t size;
> > +            enum {
> > +                VPCI_BAR_EMPTY,
> > +                VPCI_BAR_IO,
> > +                VPCI_BAR_MEM32,
> > +                VPCI_BAR_MEM64_LO,
> > +                VPCI_BAR_MEM64_HI,
> > +                VPCI_BAR_ROM,
> > +            } type;
> > +            bool prefetchable : 1;
> > +            /* Store whether the BAR is mapped into guest p2m. */
> > +            bool enabled      : 1;
> > +            /*
> > +             * Store whether the ROM enable bit is set (doesn't imply ROM BAR
> > +             * is mapped into guest p2m). Only used for type VPCI_BAR_ROM.
> > +             */
> > +            bool rom_enabled  : 1;
> > +        } bars[7]; /* At most 6 BARS + 1 expansion ROM BAR. */
> > +        /* FIXME: currently there's no support for SR-IOV. */
> > +    } header;
> > +#endif
> >  };
> >  
> > +#ifdef __XEN__
> > +struct vpci_vcpu {
> > +    struct rangeset *mem;
> > +    const struct pci_dev *pdev;
> > +    bool map : 1;
> > +    bool rom : 1;
> > +};
> > +#endif
> 
> This structure could do with a comment briefly noting it purpose.
> Also - if the #ifdef really needed here?

I prefer to add the ifdef rather than adding a struct rangeset forward
declaration to tests/vpci/emul.h.

I've added the following comment:

/* Per-vcpu structure to store state while {un}mapping of PCI BARs. */

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2018-01-19 15:47 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-18 11:40 [PATCH v7 for-next 00/12] vpci: PCI config space emulation Roger Pau Monne
2017-10-18 11:40 ` [PATCH v7 for-next 01/12] x86/pio: allow internal PIO handlers to return RETRY Roger Pau Monne
2017-10-20  9:28   ` Paul Durrant
2017-10-18 11:40 ` [PATCH v7 for-next 02/12] pci: introduce a type to store a SBDF Roger Pau Monne
2017-10-26 15:57   ` Jan Beulich
2017-10-31 10:50   ` Wei Liu
2017-10-18 11:40 ` [PATCH v7 for-next 03/12] vpci: introduce basic handlers to trap accesses to the PCI config space Roger Pau Monne
2017-10-20  9:34   ` Paul Durrant
2017-12-12 16:17   ` Jan Beulich
2017-10-18 11:40 ` [PATCH v7 for-next 04/12] x86/mmcfg: add handlers for the PVH Dom0 MMCFG areas Roger Pau Monne
2017-10-20  9:47   ` Paul Durrant
2017-12-12 16:25   ` Jan Beulich
2017-10-18 11:40 ` [PATCH v7 for-next 05/12] x86/physdev: enable PHYSDEVOP_pci_mmcfg_reserved for PVH Dom0 Roger Pau Monne
2017-12-15 10:45   ` Jan Beulich
2017-10-18 11:40 ` [PATCH v7 for-next 06/12] pci: split code to size BARs from pci_add_device Roger Pau Monne
2017-12-15 10:54   ` Jan Beulich
2017-10-18 11:40 ` [PATCH v7 for-next 07/12] pci: add support to size ROM BARs to pci_size_mem_bar Roger Pau Monne
2017-10-18 11:40 ` [PATCH v7 for-next 08/12] xen: introduce rangeset_consume_ranges Roger Pau Monne
2017-10-31 10:50   ` Wei Liu
2017-10-18 11:40 ` [PATCH v7 for-next 09/12] vpci/bars: add handlers to map the BARs Roger Pau Monne
2017-12-15 11:43   ` Jan Beulich
2018-01-19 15:47     ` Roger Pau Monné [this message]
2018-01-19 16:16       ` Jan Beulich
2018-01-19 16:57         ` Roger Pau Monné
2017-10-18 11:40 ` [PATCH v7 for-next 10/12] vpci/msi: add MSI handlers Roger Pau Monne
2017-10-20  9:58   ` Paul Durrant
2017-12-15 12:07   ` Jan Beulich
2018-01-22 12:48     ` Roger Pau Monné
2018-01-22 12:58       ` Jan Beulich
2018-01-22 14:55         ` Roger Pau Monné
2017-10-18 11:40 ` [PATCH v7 for-next 11/12] vpci: add a priority parameter to the vPCI register initializer Roger Pau Monne
2017-10-18 11:40 ` [PATCH v7 for-next 12/12] vpci/msix: add MSI-X handlers Roger Pau Monne
2017-12-20 16:13   ` Jan Beulich
2018-01-23 10:38     ` Roger Pau Monné

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=20180119154733.qipgoiyhltzclkls@MacBook-Pro-de-Roger.local \
    --to=roger.pau@citrix.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --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.