From: Haozhong Zhang <haozhong.zhang@intel.com>
To: xen-devel@lists.xen.org
Cc: Haozhong Zhang <haozhong.zhang@intel.com>,
Jan Beulich <jbeulich@suse.com>,
Andrew Cooper <andrew.cooper3@citrix.com>
Subject: [PATCH v7 1/7] x86/domctl: generalize the restore of vMCE parameters
Date: Fri, 7 Jul 2017 11:53:08 +0800 [thread overview]
Message-ID: <20170707035314.15659-2-haozhong.zhang@intel.com> (raw)
In-Reply-To: <20170707035314.15659-1-haozhong.zhang@intel.com>
vMCE parameters in struct xen_domctl_ext_vcpucontext were extended in
the past, and is likely to be extended in the future. When migrating a
PV domain from old Xen, XEN_DOMCTL_set_ext_vcpucontext should handle
the differences.
Instead of adding ad-hoc handling code at each extension, we introduce
an array to record sizes of the current and all past versions of vMCE
parameters, and search for the largest one that does not expire the
size of passed-in parameters to determine vMCE parameters that will be
restored. If vMCE parameters are extended in the future, we only need
to adapt the array to reflect the extension.
Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
---
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
---
xen/arch/x86/domctl.c | 51 ++++++++++++++++++++++++++++++++++-----------------
1 file changed, 34 insertions(+), 17 deletions(-)
diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c
index 7fa58b49af..5cd2af76bb 100644
--- a/xen/arch/x86/domctl.c
+++ b/xen/arch/x86/domctl.c
@@ -302,6 +302,39 @@ static int update_domain_cpuid_info(struct domain *d,
return 0;
}
+static int vcpu_set_vmce(struct vcpu *v,
+ const struct xen_domctl_ext_vcpucontext *evc)
+{
+ /*
+ * Sizes of vMCE parameters used by the current and past versions
+ * of Xen in descending order. If vMCE parameters are extended,
+ * remember to add the old size in this array.
+ */
+ static const unsigned int valid_vmce_size[] = {
+ sizeof(evc->vmce),
+ sizeof(evc->mcg_cap),
+ 0,
+ };
+ struct hvm_vmce_vcpu vmce = { };
+ unsigned int vmce_size = evc->size - offsetof(typeof(*evc), mcg_cap);
+ int i = 0;
+
+ BUILD_BUG_ON(offsetof(struct xen_domctl_ext_vcpucontext, mcg_cap) !=
+ offsetof(struct xen_domctl_ext_vcpucontext, vmce.caps));
+ BUILD_BUG_ON(sizeof(evc->mcg_cap) != sizeof(evc->vmce.caps));
+
+ while ( i < ARRAY_SIZE(valid_vmce_size) - 1 &&
+ vmce_size < valid_vmce_size[i] )
+ ++i;
+ vmce_size = valid_vmce_size[i];
+
+ if ( !vmce_size )
+ return 0;
+
+ memcpy(&vmce, &evc->vmce, vmce_size);
+ return vmce_restore_vcpu(v, &vmce);
+}
+
void arch_get_domain_info(const struct domain *d,
struct xen_domctl_getdomaininfo *info)
{
@@ -912,23 +945,7 @@ long arch_do_domctl(
else
domain_pause(d);
- BUILD_BUG_ON(offsetof(struct xen_domctl_ext_vcpucontext,
- mcg_cap) !=
- offsetof(struct xen_domctl_ext_vcpucontext,
- vmce.caps));
- BUILD_BUG_ON(sizeof(evc->mcg_cap) != sizeof(evc->vmce.caps));
- if ( evc->size >= offsetof(typeof(*evc), vmce) +
- sizeof(evc->vmce) )
- ret = vmce_restore_vcpu(v, &evc->vmce);
- else if ( evc->size >= offsetof(typeof(*evc), mcg_cap) +
- sizeof(evc->mcg_cap) )
- {
- struct hvm_vmce_vcpu vmce = { .caps = evc->mcg_cap };
-
- ret = vmce_restore_vcpu(v, &vmce);
- }
- else
- ret = 0;
+ ret = vcpu_set_vmce(v, evc);
domain_unpause(d);
}
--
2.11.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-07-07 3:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-07 3:53 [PATCH v7 0/7] Add LMCE support Haozhong Zhang
2017-07-07 3:53 ` Haozhong Zhang [this message]
2017-07-07 15:24 ` [PATCH v7 1/7] x86/domctl: generalize the restore of vMCE parameters Jan Beulich
2017-07-07 3:53 ` [PATCH v7 2/7] x86/vmce: emulate MSR_IA32_MCG_EXT_CTL Haozhong Zhang
2017-07-07 3:53 ` [PATCH v7 3/7] x86/vmce: enable injecting LMCE to guest on Intel host Haozhong Zhang
2017-07-07 3:53 ` [PATCH v7 4/7] x86/vmce, tools/libxl: expose LMCE capability in guest MSR_IA32_MCG_CAP Haozhong Zhang
2017-07-07 3:53 ` [PATCH v7 5/7] xen/mce: add support of vLMCE injection to XEN_MC_inject_v2 Haozhong Zhang
2017-07-07 3:53 ` [PATCH v7 6/7] tools/libxc: add support of injecting MC# to specified CPUs Haozhong Zhang
2017-07-07 3:53 ` [PATCH v7 7/7] tools/xen-mceinj: add support of injecting LMCE Haozhong Zhang
2017-07-07 11:22 ` [PATCH v7 0/7] Add LMCE support 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=20170707035314.15659-2-haozhong.zhang@intel.com \
--to=haozhong.zhang@intel.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=xen-devel@lists.xen.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).