From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
"Sergey Dyasli" <sergey.dyasli@citrix.com>,
"Wei Liu" <wei.liu2@citrix.com>,
"Jan Beulich" <JBeulich@suse.com>,
"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH 1/2] xen: Introduce an xmemdup() helper
Date: Mon, 9 Jul 2018 11:29:47 +0100 [thread overview]
Message-ID: <1531132188-20564-2-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1531132188-20564-1-git-send-email-andrew.cooper3@citrix.com>
... and use it in place of the opencoded instances.
For consistency, restructure init_domain_cpuid_policy() to be like
init_{domain,vcpu}_msr_policy() by operating on the local pointer where
possible.
No change in behaviour.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Sergey Dyasli <sergey.dyasli@citrix.com>
---
xen/arch/x86/cpuid.c | 13 +++++++------
xen/arch/x86/msr.c | 18 ++++++------------
xen/include/xen/xmalloc.h | 10 ++++++++++
3 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index c33c6d4..e13c657 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -703,16 +703,17 @@ void recalculate_cpuid_policy(struct domain *d)
int init_domain_cpuid_policy(struct domain *d)
{
- d->arch.cpuid = xmalloc(struct cpuid_policy);
+ struct cpuid_policy *p =
+ xmemdup(is_pv_domain(d) ? & pv_max_cpuid_policy
+ : &hvm_max_cpuid_policy);
- if ( !d->arch.cpuid )
+ if ( !p )
return -ENOMEM;
- *d->arch.cpuid = is_pv_domain(d)
- ? pv_max_cpuid_policy : hvm_max_cpuid_policy;
-
if ( d->disable_migrate )
- d->arch.cpuid->extd.itsc = cpu_has_itsc;
+ p->extd.itsc = cpu_has_itsc;
+
+ d->arch.cpuid = p;
recalculate_cpuid_policy(d);
diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index d035c67..27c4915 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -81,16 +81,13 @@ void __init init_guest_msr_policy(void)
int init_domain_msr_policy(struct domain *d)
{
- struct msr_domain_policy *dp;
-
- dp = xmalloc(struct msr_domain_policy);
+ struct msr_domain_policy *dp =
+ xmemdup(is_pv_domain(d) ? & pv_max_msr_domain_policy
+ : &hvm_max_msr_domain_policy);
if ( !dp )
return -ENOMEM;
- *dp = is_pv_domain(d) ? pv_max_msr_domain_policy :
- hvm_max_msr_domain_policy;
-
/* See comment in intel_ctxt_switch_levelling() */
if ( is_control_domain(d) )
dp->plaform_info.cpuid_faulting = false;
@@ -103,16 +100,13 @@ int init_domain_msr_policy(struct domain *d)
int init_vcpu_msr_policy(struct vcpu *v)
{
struct domain *d = v->domain;
- struct msr_vcpu_policy *vp;
-
- vp = xmalloc(struct msr_vcpu_policy);
+ struct msr_vcpu_policy *vp =
+ xmemdup(is_pv_domain(d) ? & pv_max_msr_vcpu_policy
+ : &hvm_max_msr_vcpu_policy);
if ( !vp )
return -ENOMEM;
- *vp = is_pv_domain(d) ? pv_max_msr_vcpu_policy :
- hvm_max_msr_vcpu_policy;
-
v->arch.msr = vp;
return 0;
diff --git a/xen/include/xen/xmalloc.h b/xen/include/xen/xmalloc.h
index cc2673d..34c6588 100644
--- a/xen/include/xen/xmalloc.h
+++ b/xen/include/xen/xmalloc.h
@@ -13,6 +13,16 @@
#define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type), __alignof__(_type)))
#define xzalloc(_type) ((_type *)_xzalloc(sizeof(_type), __alignof__(_type)))
+/* Allocate space for a typed object and copy an existing instance. */
+#define xmemdup(ptr) \
+({ \
+ typeof(*(ptr)) *p_ = (ptr), *n_ = xmalloc(typeof(*p_)); \
+ \
+ if ( n_ ) \
+ memcpy(n_, p_, sizeof(*n_)); \
+ n_; \
+})
+
/* Allocate space for array of typed objects. */
#define xmalloc_array(_type, _num) \
((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num))
--
2.1.4
_______________________________________________
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-09 10:29 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-09 10:29 [PATCH 0/2] x86/msr: Code cleanup and improvements Andrew Cooper
2018-07-09 10:29 ` Andrew Cooper [this message]
2018-07-09 12:02 ` [PATCH 1/2] xen: Introduce an xmemdup() helper Jan Beulich
2018-07-09 12:08 ` Andrew Cooper
2018-07-09 12:40 ` Jan Beulich
2018-07-10 8:32 ` Roger Pau Monné
2018-07-10 8:38 ` Jan Beulich
2018-07-10 8:44 ` Andrew Cooper
2018-07-10 8:53 ` Jan Beulich
2018-07-09 10:29 ` [PATCH 2/2] x86/msr: Rename the msr policy objects Andrew Cooper
2018-07-09 12:04 ` Jan Beulich
2018-07-10 8:33 ` Roger Pau Monné
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=1531132188-20564-2-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=roger.pau@citrix.com \
--cc=sergey.dyasli@citrix.com \
--cc=wei.liu2@citrix.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).