From: Jan Beulich <jbeulich@suse.com>
To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: Kevin Tian <kevin.tian@intel.com>
Subject: [PATCH 5/6] VT-d: introduce helper to convert DID to domid_t
Date: Fri, 12 Nov 2021 10:49:31 +0100 [thread overview]
Message-ID: <ff49be66-1d4f-9e1b-95ac-b445eef29d41@suse.com> (raw)
In-Reply-To: <a97adc3d-2808-1c87-8fd6-d6b24b83bd2b@suse.com>
This is in preparation of adding another "translation" method. Take the
combination of the extra validation both previously open-coded have been
doing: Bounds check and bitmap check. But don't propagate the previous
pointless check of whether ->domid_map[] was actually allocated, as
failure there would lead to overall failure of IOMMU initialization
anyway.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/drivers/passthrough/vtd/extern.h
+++ b/xen/drivers/passthrough/vtd/extern.h
@@ -45,6 +45,8 @@ void disable_intremap(struct vtd_iommu *
int iommu_alloc(struct acpi_drhd_unit *drhd);
void iommu_free(struct acpi_drhd_unit *drhd);
+domid_t did_to_domain_id(const struct vtd_iommu *iommu, unsigned int did);
+
int iommu_flush_iec_global(struct vtd_iommu *iommu);
int iommu_flush_iec_index(struct vtd_iommu *iommu, u8 im, u16 iidx);
void clear_fault_bits(struct vtd_iommu *iommu);
--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -123,15 +123,16 @@ static int context_get_domain_id(const s
if ( iommu && context )
{
- unsigned int nr_dom = cap_ndoms(iommu->cap);
unsigned int dom_index = context_domain_id(*context);
- if ( dom_index < nr_dom && iommu->domid_map )
- domid = iommu->domid_map[dom_index];
- else
+ domid = did_to_domain_id(iommu, dom_index);
+ if ( domid == DOMID_INVALID )
+ {
dprintk(XENLOG_DEBUG VTDPREFIX,
- "dom_index %u exceeds nr_dom %u or iommu has no domid_map\n",
- dom_index, nr_dom);
+ "no domid for did %u (nr_dom %u)\n",
+ dom_index, cap_ndoms(iommu->cap));
+ domid = -1;
+ }
}
return domid;
@@ -193,6 +194,14 @@ static void check_cleanup_domid_map(stru
}
}
+domid_t did_to_domain_id(const struct vtd_iommu *iommu, unsigned int did)
+{
+ if ( did >= cap_ndoms(iommu->cap) || !test_bit(did, iommu->domid_bitmap) )
+ return DOMID_INVALID;
+
+ return iommu->domid_map[did];
+}
+
static void sync_cache(const void *addr, unsigned int size)
{
static unsigned long clflush_size = 0;
--- a/xen/drivers/passthrough/vtd/qinval.c
+++ b/xen/drivers/passthrough/vtd/qinval.c
@@ -229,10 +229,7 @@ static int __must_check dev_invalidate_s
rc = queue_invalidate_wait(iommu, 0, 1, 1, 1);
if ( rc == -ETIMEDOUT )
{
- struct domain *d = NULL;
-
- if ( test_bit(did, iommu->domid_bitmap) )
- d = rcu_lock_domain_by_id(iommu->domid_map[did]);
+ struct domain *d = rcu_lock_domain_by_id(did_to_domain_id(iommu, did));
/*
* In case the domain has been freed or the IOMMU domid bitmap is
next prev parent reply other threads:[~2021-11-12 9:49 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-12 9:46 [PATCH 0/6] VT-d: domain ID mapping improvements Jan Beulich
2021-11-12 9:47 ` [PATCH 1/6] VT-d: properly reserve DID 0 for caching mode IOMMUs Jan Beulich
2021-11-12 11:23 ` Roger Pau Monné
2021-11-12 12:07 ` Jan Beulich
2021-11-12 12:19 ` Roger Pau Monné
2021-11-15 5:13 ` Tian, Kevin
2021-11-12 12:21 ` Roger Pau Monné
2021-11-15 5:13 ` Tian, Kevin
2021-11-12 9:48 ` [PATCH 2/6] VT-d: split domid map cleanup check into a function Jan Beulich
2021-11-12 12:31 ` Roger Pau Monné
2021-11-15 5:16 ` Tian, Kevin
2021-11-12 9:48 ` [PATCH 3/6] VT-d: don't leak domid mapping on error path Jan Beulich
2021-11-12 13:42 ` Roger Pau Monné
2021-11-12 13:45 ` Jan Beulich
2021-11-12 14:35 ` Roger Pau Monné
2021-11-15 9:32 ` Jan Beulich
2021-11-15 5:21 ` Tian, Kevin
2021-11-12 9:49 ` [PATCH 4/6] VT-d: tidy domid map handling Jan Beulich
2021-11-15 5:51 ` Tian, Kevin
2021-11-12 9:49 ` Jan Beulich [this message]
2021-11-15 5:54 ` [PATCH 5/6] VT-d: introduce helper to convert DID to domid_t Tian, Kevin
2021-11-12 9:50 ` [PATCH 6/6] VT-d: avoid allocating domid_{bit,}map[] when possible Jan Beulich
2021-11-15 6:18 ` Tian, Kevin
2021-11-15 9:37 ` 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=ff49be66-1d4f-9e1b-95ac-b445eef29d41@suse.com \
--to=jbeulich@suse.com \
--cc=kevin.tian@intel.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.