From: Paul Durrant <paul@xen.org>
To: xen-devel@lists.xenproject.org
Cc: "Paul Durrant" <pdurrant@amazon.com>, "Wei Liu" <wl@xen.org>,
"Jan Beulich" <jbeulich@suse.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH v3 05/13] viridian: use hypercall_vpmask in hvcall_ipi()
Date: Tue, 24 Nov 2020 19:07:36 +0000 [thread overview]
Message-ID: <20201124190744.11343-6-paul@xen.org> (raw)
In-Reply-To: <20201124190744.11343-1-paul@xen.org>
From: Paul Durrant <pdurrant@amazon.com>
A subsequent patch will need to IPI a mask of virtual processors potentially
wider than 64 bits. A previous patch introduced per-cpu hypercall_vpmask
to allow hvcall_flush() to deal with such wide masks. This patch modifies
the implementation of hvcall_ipi() to make use of the same mask structures,
introducing a for_each_vp() macro to facilitate traversing a mask.
Signed-off-by: Paul Durrant <pdurrant@amazon.com>
---
Cc: Wei Liu <wl@xen.org>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: "Roger Pau Monné" <roger.pau@citrix.com>
v3:
- Couple of extra 'const' qualifiers
v2:
- Drop the 'vp' loop now that vpmask_set() will do it internally
---
xen/arch/x86/hvm/viridian/viridian.c | 44 +++++++++++++++++++++-------
1 file changed, 33 insertions(+), 11 deletions(-)
diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridian/viridian.c
index d8f47b8528a2..cdfeaec8b96b 100644
--- a/xen/arch/x86/hvm/viridian/viridian.c
+++ b/xen/arch/x86/hvm/viridian/viridian.c
@@ -551,6 +551,26 @@ static bool vpmask_test(const struct hypercall_vpmask *vpmask,
return test_bit(vp, vpmask->mask);
}
+static unsigned int vpmask_first(const struct hypercall_vpmask *vpmask)
+{
+ return find_first_bit(vpmask->mask, HVM_MAX_VCPUS);
+}
+
+static unsigned int vpmask_next(const struct hypercall_vpmask *vpmask,
+ unsigned int vp)
+{
+ /*
+ * If vp + 1 > HVM_MAX_VCPUS then find_next_bit() will return
+ * HVM_MAX_VCPUS, ensuring the for_each_vp ( ... ) loop terminates.
+ */
+ return find_next_bit(vpmask->mask, HVM_MAX_VCPUS, vp + 1);
+}
+
+#define for_each_vp(vpmask, vp) \
+ for ( (vp) = vpmask_first(vpmask); \
+ (vp) < HVM_MAX_VCPUS; \
+ (vp) = vpmask_next(vpmask, vp) )
+
/*
* Windows should not issue the hypercalls requiring this callback in the
* case where vcpu_id would exceed the size of the mask.
@@ -631,13 +651,21 @@ static int hvcall_flush(const union hypercall_input *input,
return 0;
}
+static void send_ipi(struct hypercall_vpmask *vpmask, uint8_t vector)
+{
+ struct domain *currd = current->domain;
+ unsigned int vp;
+
+ for_each_vp ( vpmask, vp )
+ vlapic_set_irq(vcpu_vlapic(currd->vcpu[vp]), vector, 0);
+}
+
static int hvcall_ipi(const union hypercall_input *input,
union hypercall_output *output,
paddr_t input_params_gpa,
paddr_t output_params_gpa)
{
- struct domain *currd = current->domain;
- struct vcpu *v;
+ struct hypercall_vpmask *vpmask = &this_cpu(hypercall_vpmask);
uint32_t vector;
uint64_t vcpu_mask;
@@ -676,16 +704,10 @@ static int hvcall_ipi(const union hypercall_input *input,
if ( vector < 0x10 || vector > 0xff )
return -EINVAL;
- for_each_vcpu ( currd, v )
- {
- if ( v->vcpu_id >= (sizeof(vcpu_mask) * 8) )
- return -EINVAL;
+ vpmask_empty(vpmask);
+ vpmask_set(vpmask, 0, vcpu_mask);
- if ( !(vcpu_mask & (1ul << v->vcpu_id)) )
- continue;
-
- vlapic_set_irq(vcpu_vlapic(v), vector, 0);
- }
+ send_ipi(vpmask, vector);
return 0;
}
--
2.20.1
next prev parent reply other threads:[~2020-11-24 19:08 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-24 19:07 [PATCH v3 00/13] viridian: add support for ExProcessorMasks Paul Durrant
2020-11-24 19:07 ` [PATCH v3 01/13] viridian: don't blindly write to 32-bit registers is 'mode' is invalid Paul Durrant
2020-11-25 7:51 ` Jan Beulich
2020-11-25 7:58 ` Durrant, Paul
2020-11-24 19:07 ` [PATCH v3 02/13] viridian: move flush hypercall implementation into separate function Paul Durrant
2020-11-24 19:07 ` [PATCH v3 03/13] viridian: move IPI " Paul Durrant
2020-11-24 19:07 ` [PATCH v3 04/13] viridian: introduce a per-cpu hypercall_vpmask and accessor functions Paul Durrant
2020-11-24 19:07 ` Paul Durrant [this message]
2020-11-24 19:07 ` [PATCH v3 06/13] viridian: use softirq batching in hvcall_ipi() Paul Durrant
2020-11-24 19:07 ` [PATCH v3 07/13] xen/include: import sizeof_field() macro from Linux stddef.h Paul Durrant
2020-11-24 19:07 ` [PATCH v3 08/13] viridian: add ExProcessorMasks variants of the flush hypercalls Paul Durrant
2020-11-24 19:07 ` [PATCH v3 09/13] viridian: add ExProcessorMasks variant of the IPI hypercall Paul Durrant
2020-11-24 19:07 ` [PATCH v3 10/13] viridian: log initial invocation of each type of hypercall Paul Durrant
2020-11-24 19:07 ` [PATCH v3 11/13] viridian: add a new '_HVMPV_ex_processor_masks' bit into HVM_PARAM_VIRIDIAN Paul Durrant
2020-11-24 19:07 ` [PATCH v3 12/13] xl / libxl: add 'ex_processor_mask' into 'libxl_viridian_enlightenment' Paul Durrant
2020-11-24 19:07 ` [PATCH v3 13/13] x86: replace open-coded occurrences of sizeof_field() Paul Durrant
2020-11-25 7:45 ` Jan Beulich
2020-11-30 2:48 ` Tian, Kevin
2020-12-01 14:09 ` [EXTERNAL] [PATCH v3 00/13] viridian: add support for ExProcessorMasks Paul Durrant
2020-12-04 10:36 ` Wei Liu
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=20201124190744.11343-6-paul@xen.org \
--to=paul@xen.org \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=pdurrant@amazon.com \
--cc=roger.pau@citrix.com \
--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 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).