From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Stefano Stabellini <sstabellini@kernel.org>,
Wei Liu <wei.liu2@citrix.com>,
George Dunlap <George.Dunlap@eu.citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>, Tim Deegan <tim@xen.org>,
Julien Grall <julien.grall@arm.com>,
Jan Beulich <jbeulich@suse.com>,
Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH v2 02/11] vpci/msix: add lock to protect the list of MSIX regions
Date: Tue, 17 Jul 2018 11:48:21 +0200 [thread overview]
Message-ID: <20180717094830.54806-3-roger.pau@citrix.com> (raw)
In-Reply-To: <20180717094830.54806-1-roger.pau@citrix.com>
This is required in order to allow run-time removal of MSI-X regions.
No functional change.
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
---
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: George Dunlap <George.Dunlap@eu.citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Julien Grall <julien.grall@arm.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Tim Deegan <tim@xen.org>
Cc: Wei Liu <wei.liu2@citrix.com>
---
xen/arch/x86/hvm/hvm.c | 1 +
xen/drivers/vpci/msix.c | 17 +++++++++++------
xen/include/asm-x86/hvm/domain.h | 1 +
3 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index c7eb943ed3..955330019d 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -587,6 +587,7 @@ int hvm_domain_initialise(struct domain *d)
spin_lock_init(&d->arch.hvm_domain.uc_lock);
spin_lock_init(&d->arch.hvm_domain.write_map.lock);
rwlock_init(&d->arch.hvm_domain.mmcfg_lock);
+ rwlock_init(&d->arch.hvm_domain.msix_lock);
INIT_LIST_HEAD(&d->arch.hvm_domain.write_map.list);
INIT_LIST_HEAD(&d->arch.hvm_domain.g2m_ioport_list);
INIT_LIST_HEAD(&d->arch.hvm_domain.mmcfg_regions);
diff --git a/xen/drivers/vpci/msix.c b/xen/drivers/vpci/msix.c
index e28096329d..41138e4c73 100644
--- a/xen/drivers/vpci/msix.c
+++ b/xen/drivers/vpci/msix.c
@@ -148,10 +148,11 @@ static void control_write(const struct pci_dev *pdev, unsigned int reg,
pci_conf_write16(pdev->seg, pdev->bus, slot, func, reg, val);
}
-static struct vpci_msix *msix_find(const struct domain *d, unsigned long addr)
+static struct vpci_msix *msix_find(struct domain *d, unsigned long addr)
{
struct vpci_msix *msix;
+ read_lock(&d->arch.hvm_domain.msix_lock);
list_for_each_entry ( msix, &d->arch.hvm_domain.msix_tables, next )
{
const struct vpci_bar *bars = msix->pdev->vpci->header.bars;
@@ -160,8 +161,12 @@ static struct vpci_msix *msix_find(const struct domain *d, unsigned long addr)
for ( i = 0; i < ARRAY_SIZE(msix->tables); i++ )
if ( bars[msix->tables[i] & PCI_MSIX_BIRMASK].enabled &&
VMSIX_ADDR_IN_RANGE(addr, msix->pdev->vpci, i) )
+ {
+ read_unlock(&d->arch.hvm_domain.msix_lock);
return msix;
+ }
}
+ read_unlock(&d->arch.hvm_domain.msix_lock);
return NULL;
}
@@ -196,8 +201,7 @@ static struct vpci_msix_entry *get_entry(struct vpci_msix *msix,
static int msix_read(struct vcpu *v, unsigned long addr, unsigned int len,
unsigned long *data)
{
- const struct domain *d = v->domain;
- struct vpci_msix *msix = msix_find(d, addr);
+ struct vpci_msix *msix = msix_find(v->domain, addr);
const struct vpci_msix_entry *entry;
unsigned int offset;
@@ -273,8 +277,7 @@ static int msix_read(struct vcpu *v, unsigned long addr, unsigned int len,
static int msix_write(struct vcpu *v, unsigned long addr, unsigned int len,
unsigned long data)
{
- const struct domain *d = v->domain;
- struct vpci_msix *msix = msix_find(d, addr);
+ struct vpci_msix *msix = msix_find(v->domain, addr);
struct vpci_msix_entry *entry;
unsigned int offset;
@@ -287,7 +290,7 @@ static int msix_write(struct vcpu *v, unsigned long addr, unsigned int len,
if ( VMSIX_ADDR_IN_RANGE(addr, msix->pdev->vpci, VPCI_MSIX_PBA) )
{
/* Ignore writes to PBA for DomUs, it's behavior is undefined. */
- if ( is_hardware_domain(d) )
+ if ( is_hardware_domain(v->domain) )
{
switch ( len )
{
@@ -438,10 +441,12 @@ static int init_msix(struct pci_dev *pdev)
if ( rc )
return rc;
+ write_lock(&d->arch.hvm_domain.msix_lock);
if ( list_empty(&d->arch.hvm_domain.msix_tables) )
register_mmio_handler(d, &vpci_msix_table_ops);
list_add(&pdev->vpci->msix->next, &d->arch.hvm_domain.msix_tables);
+ write_unlock(&d->arch.hvm_domain.msix_lock);
return 0;
}
diff --git a/xen/include/asm-x86/hvm/domain.h b/xen/include/asm-x86/hvm/domain.h
index 588595059d..181f6a2704 100644
--- a/xen/include/asm-x86/hvm/domain.h
+++ b/xen/include/asm-x86/hvm/domain.h
@@ -187,6 +187,7 @@ struct hvm_domain {
/* List of MSI-X tables. */
struct list_head msix_tables;
+ rwlock_t msix_lock;
/* List of permanently write-mapped pages. */
struct {
--
2.17.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-07-17 9:49 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-17 9:48 [PATCH v2 00/11] vpci: add support for SR-IOV capability Roger Pau Monne
2018-07-17 9:48 ` [PATCH v2 01/11] vpci: move lock Roger Pau Monne
2018-09-06 9:57 ` Wei Liu
2018-09-26 10:37 ` Jan Beulich
2018-07-17 9:48 ` Roger Pau Monne [this message]
2018-09-26 10:42 ` [PATCH v2 02/11] vpci/msix: add lock to protect the list of MSIX regions Jan Beulich
2018-07-17 9:48 ` [PATCH v2 03/11] vpci: add tear down functions Roger Pau Monne
2018-09-06 9:57 ` Wei Liu
2018-09-26 10:50 ` Jan Beulich
2018-07-17 9:48 ` [PATCH v2 04/11] vpci/msix: add teardown cleanup Roger Pau Monne
2018-09-06 10:14 ` Wei Liu
2018-09-26 15:32 ` Jan Beulich
2018-07-17 9:48 ` [PATCH v2 05/11] vpci/msi: " Roger Pau Monne
2018-09-06 10:14 ` Wei Liu
2018-09-26 15:34 ` Jan Beulich
2018-07-17 9:48 ` [PATCH v2 06/11] vpci/header: " Roger Pau Monne
2018-09-28 15:29 ` Jan Beulich
2018-07-17 9:48 ` [PATCH v2 07/11] rangeset: introduce rangeset_merge Roger Pau Monne
2018-07-17 9:48 ` [PATCH v2 08/11] vpci/header: allow multiple map operations Roger Pau Monne
2018-09-28 15:38 ` Jan Beulich
2018-07-17 9:48 ` [PATCH v2 09/11] pci: add vpci hooks for device addition/removal Roger Pau Monne
2018-09-28 15:48 ` Jan Beulich
2018-07-17 9:48 ` [PATCH v2 10/11] vpci: add a wait operation to the vpci vcpu pending actions Roger Pau Monne
2018-07-17 9:48 ` [PATCH v2 11/11] vpci/sriov: add support for SR-IOV capability Roger Pau Monne
2018-09-06 10:37 ` Wei Liu
2018-09-07 9:16 ` Roger Pau Monné
2018-10-04 14:50 ` Jan Beulich
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=20180717094830.54806-3-roger.pau@citrix.com \
--to=roger.pau@citrix.com \
--cc=George.Dunlap@eu.citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=julien.grall@arm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).