|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH 11/13] x86/HVM: introduce hvm_load_vcpu_instance()
On 26.11.2026 14:41, Jan Beulich wrote:
> Use this to remove open-coding of domain_vcpu().
>
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
> ---
> lapic_load_{hidden,regs}() are left alone, as I fear analysis tools would
> otherwise pick on the missing NULL checks.
I'm sorry, I should have Cc-ed Paul as well.
Jan
> --- a/xen/arch/x86/cpu/mcheck/vmce.c
> +++ b/xen/arch/x86/cpu/mcheck/vmce.c
> @@ -364,15 +364,14 @@ static int cf_check vmce_save_vcpu_ctxt(
>
> static int cf_check vmce_load_vcpu_ctxt(struct domain *d,
> hvm_domain_context_t *h)
> {
> - unsigned int vcpuid = hvm_load_instance(h);
> - struct vcpu *v;
> + struct vcpu *v = hvm_load_vcpu_instance(d, h);
> struct hvm_vmce_vcpu ctxt;
> int err;
>
> - if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) == NULL )
> + if ( !v )
> {
> dprintk(XENLOG_G_ERR, "HVM restore: dom%d has no vcpu%u\n",
> - d->domain_id, vcpuid);
> + d->domain_id, hvm_load_instance(h));
> err = -EINVAL;
> }
> else
> --- a/xen/arch/x86/hvm/hvm.c
> +++ b/xen/arch/x86/hvm/hvm.c
> @@ -804,14 +804,13 @@ static int cf_check hvm_save_tsc_adjust(
>
> static int cf_check hvm_load_tsc_adjust(struct domain *d,
> hvm_domain_context_t *h)
> {
> - unsigned int vcpuid = hvm_load_instance(h);
> - struct vcpu *v;
> + struct vcpu *v = hvm_load_vcpu_instance(d, h);
> struct hvm_tsc_adjust ctxt;
>
> - if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) == NULL )
> + if ( !v )
> {
> dprintk(XENLOG_G_ERR, "HVM restore: dom%d has no vcpu%u\n",
> - d->domain_id, vcpuid);
> + d->domain_id, hvm_load_instance(h));
> return -EINVAL;
> }
>
> @@ -1018,18 +1017,16 @@ unsigned long hvm_cr4_guest_valid_bits(c
> static int cf_check hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t
> *h)
> {
> const struct cpu_policy *p = d->arch.cpu_policy;
> - unsigned int vcpuid = hvm_load_instance(h);
> - struct vcpu *v;
> + struct vcpu *v = hvm_load_vcpu_instance(d, h);
> struct hvm_hw_cpu ctxt;
> struct segment_register seg;
> const char *errstr;
> unsigned long valid;
>
> - /* Which vcpu is this? */
> - if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) == NULL )
> + if ( !v )
> {
> dprintk(XENLOG_G_ERR, "HVM restore: dom%u has no vcpu%u\n",
> - d->domain_id, vcpuid);
> + d->domain_id, hvm_load_instance(h));
> return -EINVAL;
> }
>
> @@ -1267,19 +1264,17 @@ CHECK_FIELD_(struct, xsave_hdr, reserved
> static int cf_check hvm_load_cpu_xsave_states(
> struct domain *d, hvm_domain_context_t *h)
> {
> - unsigned int vcpuid, size;
> + unsigned int size;
> int err;
> - struct vcpu *v;
> + struct vcpu *v = hvm_load_vcpu_instance(d, h);
> struct hvm_hw_cpu_xsave *ctxt;
> const struct hvm_save_descriptor *desc;
> unsigned int i, desc_start, desc_length;
>
> - /* Which vcpu is this? */
> - vcpuid = hvm_load_instance(h);
> - if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) == NULL )
> + if ( !v )
> {
> dprintk(XENLOG_G_ERR, "HVM restore: dom%d has no vcpu%u\n",
> - d->domain_id, vcpuid);
> + d->domain_id, hvm_load_instance(h));
> return -EINVAL;
> }
>
> @@ -1298,14 +1293,14 @@ static int cf_check hvm_load_cpu_xsave_s
> {
> printk(XENLOG_G_WARNING
> "HVM%d.%d restore: not enough data left to read xsave
> descriptor\n",
> - d->domain_id, vcpuid);
> + d->domain_id, v->vcpu_id);
> return -ENODATA;
> }
> if ( desc->length + sizeof (*desc) > h->size - h->cur)
> {
> printk(XENLOG_G_WARNING
> "HVM%d.%d restore: not enough data left to read %u xsave
> bytes\n",
> - d->domain_id, vcpuid, desc->length);
> + d->domain_id, v->vcpu_id, desc->length);
> return -ENODATA;
> }
> if ( desc->length < offsetof(struct hvm_hw_cpu_xsave, save_area) +
> @@ -1313,7 +1308,7 @@ static int cf_check hvm_load_cpu_xsave_s
> {
> printk(XENLOG_G_WARNING
> "HVM%d.%d restore mismatch: xsave length %u < %zu\n",
> - d->domain_id, vcpuid, desc->length,
> + d->domain_id, v->vcpu_id, desc->length,
> offsetof(struct hvm_hw_cpu_xsave,
> save_area) + XSTATE_AREA_MIN_SIZE);
> return -EINVAL;
> @@ -1331,7 +1326,7 @@ static int cf_check hvm_load_cpu_xsave_s
> printk(XENLOG_G_WARNING
> "HVM%d.%d restore: inconsistent xsave state (feat=%#"PRIx64
> " accum=%#"PRIx64" xcr0=%#"PRIx64" bv=%#"PRIx64" err=%d)\n",
> - d->domain_id, vcpuid, ctxt->xfeature_mask, ctxt->xcr0_accum,
> + d->domain_id, v->vcpu_id, ctxt->xfeature_mask,
> ctxt->xcr0_accum,
> ctxt->xcr0, ctxt->save_area.xsave_hdr.xstate_bv, err);
> return err;
> }
> @@ -1350,13 +1345,13 @@ static int cf_check hvm_load_cpu_xsave_s
> {
> printk(XENLOG_G_WARNING
> "HVM%d.%u restore mismatch: xsave length %#x > %#x
> (non-zero data at %#x)\n",
> - d->domain_id, vcpuid, desc->length, size, i);
> + d->domain_id, v->vcpu_id, desc->length, size, i);
> return -EOPNOTSUPP;
> }
> }
> printk(XENLOG_G_WARNING
> "HVM%d.%u restore mismatch: xsave length %#x > %#x\n",
> - d->domain_id, vcpuid, desc->length, size);
> + d->domain_id, v->vcpu_id, desc->length, size);
> /* Rewind desc_length to ignore the extraneous zeros. */
> desc_length = size;
> }
> @@ -1365,14 +1360,14 @@ static int cf_check hvm_load_cpu_xsave_s
> {
> printk(XENLOG_G_WARNING
> "HVM%d.%u restore: compressed xsave state not supported\n",
> - d->domain_id, vcpuid);
> + d->domain_id, v->vcpu_id);
> return -EOPNOTSUPP;
> }
> else if ( desc_length != size )
> {
> printk(XENLOG_G_WARNING
> "HVM%d.%u restore mismatch: xsave length %#x != %#x\n",
> - d->domain_id, vcpuid, desc_length, size);
> + d->domain_id, v->vcpu_id, desc_length, size);
> return -EINVAL;
> }
> /* Checking finished */
> @@ -1481,15 +1476,15 @@ static int cf_check hvm_save_cpu_msrs(st
>
> static int cf_check hvm_load_cpu_msrs(struct domain *d, hvm_domain_context_t
> *h)
> {
> - unsigned int i, vcpuid = hvm_load_instance(h);
> - struct vcpu *v;
> + unsigned int i;
> + struct vcpu *v = hvm_load_vcpu_instance(d, h);
> const struct hvm_save_descriptor *desc;
> struct hvm_msr *ctxt;
>
> - if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) == NULL )
> + if ( !v )
> {
> dprintk(XENLOG_G_ERR, "HVM restore: dom%d has no vcpu%u\n",
> - d->domain_id, vcpuid);
> + d->domain_id, hvm_load_instance(h));
> return -EINVAL;
> }
>
> @@ -1499,21 +1494,21 @@ static int cf_check hvm_load_cpu_msrs(st
> {
> printk(XENLOG_G_WARNING
> "HVM%d.%d restore: not enough data left to read MSR
> descriptor\n",
> - d->domain_id, vcpuid);
> + d->domain_id, v->vcpu_id);
> return -ENODATA;
> }
> if ( desc->length + sizeof (*desc) > h->size - h->cur)
> {
> printk(XENLOG_G_WARNING
> "HVM%d.%d restore: not enough data left to read %u MSR
> bytes\n",
> - d->domain_id, vcpuid, desc->length);
> + d->domain_id, v->vcpu_id, desc->length);
> return -ENODATA;
> }
> if ( desc->length < HVM_CPU_MSR_SIZE(1) )
> {
> printk(XENLOG_G_WARNING
> "HVM%d.%d restore mismatch: MSR length %u < %zu\n",
> - d->domain_id, vcpuid, desc->length, HVM_CPU_MSR_SIZE(1));
> + d->domain_id, v->vcpu_id, desc->length, HVM_CPU_MSR_SIZE(1));
> return -EINVAL;
> }
>
> @@ -1525,7 +1520,7 @@ static int cf_check hvm_load_cpu_msrs(st
> {
> printk(XENLOG_G_WARNING
> "HVM%d.%d restore mismatch: MSR length %u != %zu\n",
> - d->domain_id, vcpuid, desc->length,
> + d->domain_id, v->vcpu_id, desc->length,
> HVM_CPU_MSR_SIZE(ctxt->count));
> return -EOPNOTSUPP;
> }
> --- a/xen/arch/x86/hvm/mtrr.c
> +++ b/xen/arch/x86/hvm/mtrr.c
> @@ -735,15 +735,15 @@ static int cf_check hvm_save_mtrr_msr(st
>
> static int cf_check hvm_load_mtrr_msr(struct domain *d, hvm_domain_context_t
> *h)
> {
> - unsigned int vcpuid = hvm_load_instance(h), i;
> - struct vcpu *v = domain_vcpu(d, vcpuid);
> + unsigned int i;
> + struct vcpu *v = hvm_load_vcpu_instance(d, h);
> struct mtrr_state *m;
> struct hvm_hw_mtrr hw_mtrr;
>
> if ( !v )
> {
> dprintk(XENLOG_G_ERR, "HVM restore: dom%d has no vcpu%u\n",
> - d->domain_id, vcpuid);
> + d->domain_id, hvm_load_instance(h));
> return -EINVAL;
> }
>
> --- a/xen/arch/x86/hvm/viridian/viridian.c
> +++ b/xen/arch/x86/hvm/viridian/viridian.c
> @@ -1152,14 +1152,13 @@ static int cf_check viridian_save_vcpu_c
> static int cf_check viridian_load_vcpu_ctxt(
> struct domain *d, hvm_domain_context_t *h)
> {
> - unsigned int vcpuid = hvm_load_instance(h);
> - struct vcpu *v;
> + struct vcpu *v = hvm_load_vcpu_instance(d, h);
> struct hvm_viridian_vcpu_context ctxt;
>
> - if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) == NULL )
> + if ( !v )
> {
> dprintk(XENLOG_G_ERR, "HVM restore: dom%d has no vcpu%u\n",
> - d->domain_id, vcpuid);
> + d->domain_id, hvm_load_instance(h));
> return -EINVAL;
> }
>
> --- a/xen/arch/x86/hvm/vlapic.c
> +++ b/xen/arch/x86/hvm/vlapic.c
> @@ -1577,16 +1577,17 @@ static void lapic_load_fixup(struct vlap
> }
>
>
> -static int lapic_check_common(const struct domain *d, unsigned int vcpuid)
> +static int lapic_check_common(const struct domain *d,
> + const hvm_domain_context_t *h)
> {
> if ( !has_vlapic(d) )
> return -ENODEV;
>
> /* Which vlapic to load? */
> - if ( !domain_vcpu(d, vcpuid) )
> + if ( !hvm_load_vcpu_instance(d, h) )
> {
> dprintk(XENLOG_G_ERR, "HVM restore: dom%d has no vCPU %u\n",
> - d->domain_id, vcpuid);
> + d->domain_id, hvm_load_instance(h));
> return -EINVAL;
> }
>
> @@ -1596,9 +1597,8 @@ static int lapic_check_common(const stru
> static int cf_check lapic_check_hidden(const struct domain *d,
> hvm_domain_context_t *h)
> {
> - unsigned int vcpuid = hvm_load_instance(h);
> struct hvm_hw_lapic s;
> - int rc = lapic_check_common(d, vcpuid);
> + int rc = lapic_check_common(d, h);
>
> if ( rc )
> return rc;
> @@ -1638,10 +1638,9 @@ static int cf_check lapic_load_hidden(st
> static int cf_check lapic_check_regs(const struct domain *d,
> hvm_domain_context_t *h)
> {
> - unsigned int vcpuid = hvm_load_instance(h);
> int rc;
>
> - if ( (rc = lapic_check_common(d, vcpuid)) )
> + if ( (rc = lapic_check_common(d, h)) )
> return rc;
>
> if ( !hvm_get_entry(LAPIC_REGS, h) )
> --- a/xen/arch/x86/include/asm/hvm/save.h
> +++ b/xen/arch/x86/include/asm/hvm/save.h
> @@ -6,8 +6,8 @@
> #ifndef __XEN_HVM_SAVE_H__
> #define __XEN_HVM_SAVE_H__
>
> -#include <xen/types.h>
> #include <xen/init.h>
> +#include <xen/sched.h>
> #include <public/xen.h>
> #include <public/hvm/save.h>
>
> @@ -97,6 +97,13 @@ static inline unsigned int hvm_load_inst
> return d->instance;
> }
>
> +/* Unmarshalling: Wrapper around the above for per-vCPU instances. */
> +static inline struct vcpu *hvm_load_vcpu_instance(
> + const struct domain *d, const struct hvm_domain_context *h)
> +{
> + return domain_vcpu(d, hvm_load_instance(h));
> +}
> +
> /* Handler types for different types of save-file entry.
> * The save handler may save multiple instances of a type into the buffer;
> * the load handler will be called once for each instance found when
>
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |