From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Dongxiao Xu <dongxiao.xu@intel.com>, xen-devel@lists.xen.org
Cc: keir@xen.org, Ian.Campbell@citrix.com,
George.Dunlap@eu.citrix.com, stefano.stabellini@eu.citrix.com,
Ian.Jackson@eu.citrix.com, JBeulich@suse.com,
dgdegra@tycho.nsa.gov
Subject: Re: [PATCH v11 1/9] x86: add generic MSR access hypercall
Date: Fri, 20 Jun 2014 15:57:08 +0100 [thread overview]
Message-ID: <53A44BC4.6070905@citrix.com> (raw)
In-Reply-To: <b232012005c6c374eaf8e79c2c7d1deb1bd1c4e2.1403248468.git.dongxiao.xu@intel.com>
On 20/06/14 15:31, Dongxiao Xu wrote:
> Add a generic MSR access hypercall for tool stack or other components to
> read or write certain system MSRs.
>
> Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com>
> ---
> xen/arch/x86/sysctl.c | 54 +++++++++++++++++++++++++++++++++++++++++++++
> xen/include/public/sysctl.h | 25 +++++++++++++++++++++
> 2 files changed, 79 insertions(+)
>
> diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c
> index 15d4b91..49f95e4 100644
> --- a/xen/arch/x86/sysctl.c
> +++ b/xen/arch/x86/sysctl.c
> @@ -66,10 +66,27 @@ void arch_do_physinfo(xen_sysctl_physinfo_t *pi)
> pi->capabilities |= XEN_SYSCTL_PHYSCAP_hvm_directio;
> }
>
> +static void msr_access_helper(void *data)
> +{
> + struct msr_access_info *info = data;
> + xen_sysctl_msr_data_t *msr_data;
> + unsigned int i;
> +
> + for ( i = 0; i < info->nr_ops; i++ )
> + {
> + msr_data = &info->msr_data[i];
> + if ( msr_data->cmd == XEN_SYSCTL_MSR_read )
> + rdmsrl(msr_data->msr, msr_data->val);
> + else if ( msr_data->cmd == XEN_SYSCTL_MSR_write )
> + wrmsrl(msr_data->msr, msr_data->val);
These must be the _safe() variants, otherwise it is trivial for a
privileged domain to cause Xen to die with #GP faults.
> + }
> +}
> +
> long arch_do_sysctl(
> struct xen_sysctl *sysctl, XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
> {
> long ret = 0;
> + bool_t copyback = 0;
>
> switch ( sysctl->cmd )
> {
> @@ -101,11 +118,48 @@ long arch_do_sysctl(
> }
> break;
>
> + case XEN_SYSCTL_msr_op:
> + {
> + unsigned int cpu = sysctl->u.msr_op.cpu;
> + struct msr_access_info info;
> +
> + info.nr_ops = sysctl->u.msr_op.nr_ops;
> + info.msr_data = xzalloc_array(xen_sysctl_msr_data_t, info.nr_ops);
This memory allocation can be avoided. Do a copy_from_user() on the
msr_op structure and pass the guest handle and nr into msr_access_helper().
It can then do copy_to/from_user on the individual entries.
> + if ( !info.msr_data )
> + return -ENOMEM;
> +
> + if ( copy_from_guest(info.msr_data, sysctl->u.msr_op.msr_data,
> + info.nr_ops) )
> + {
> + xfree(info.msr_data);
> + return -EFAULT;
> + }
> +
> + if ( cpu == smp_processor_id() )
> + msr_access_helper(&info);
> + else
> + on_selected_cpus(cpumask_of(cpu), msr_access_helper, &info, 1);
> +
> + if ( copy_to_guest(sysctl->u.msr_op.msr_data, info.msr_data,
> + info.nr_ops ) )
> + {
> + xfree(info.msr_data);
> + return -EFAULT;
> + }
> +
> + xfree(info.msr_data);
> + copyback = 1;
> + }
> + break;
> +
> default:
> ret = -ENOSYS;
> break;
> }
>
> + if ( copyback && __copy_to_guest(u_sysctl, sysctl, 1) )
> + ret = -EFAULT;
> +
> return ret;
> }
>
> diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h
> index 3588698..fd042bb 100644
> --- a/xen/include/public/sysctl.h
> +++ b/xen/include/public/sysctl.h
> @@ -636,6 +636,29 @@ struct xen_sysctl_coverage_op {
> typedef struct xen_sysctl_coverage_op xen_sysctl_coverage_op_t;
> DEFINE_XEN_GUEST_HANDLE(xen_sysctl_coverage_op_t);
>
> +#define XEN_SYSCTL_MSR_read 0
> +#define XEN_SYSCTL_MSR_write 1
> +
> +struct xen_sysctl_msr_data {
> + uint32_t cmd; /* XEN_SYSCTL_MSR_* */
> + uint32_t msr;
> + uint64_t val;
> +};
> +typedef struct xen_sysctl_msr_data xen_sysctl_msr_data_t;
> +DEFINE_XEN_GUEST_HANDLE(xen_sysctl_msr_data_t);
> +struct xen_sysctl_msr_op {
> + uint32_t nr_ops;
> + uint32_t cpu;
> + XEN_GUEST_HANDLE_64(xen_sysctl_msr_data_t) msr_data;
> +};
> +typedef struct xen_sysctl_msr_op xen_sysctl_msr_op_t;
> +DEFINE_XEN_GUEST_HANDLE(xen_sysctl_msr_op_t);
> +
> +struct msr_access_info {
> + uint32_t nr_ops;
> + xen_sysctl_msr_data_t *msr_data;
> +};
This is private to Xen. It should not be here in a public header.
~Andrew
> +
>
> struct xen_sysctl {
> uint32_t cmd;
> @@ -658,6 +681,7 @@ struct xen_sysctl {
> #define XEN_SYSCTL_cpupool_op 18
> #define XEN_SYSCTL_scheduler_op 19
> #define XEN_SYSCTL_coverage_op 20
> +#define XEN_SYSCTL_msr_op 21
> uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */
> union {
> struct xen_sysctl_readconsole readconsole;
> @@ -679,6 +703,7 @@ struct xen_sysctl {
> struct xen_sysctl_cpupool_op cpupool_op;
> struct xen_sysctl_scheduler_op scheduler_op;
> struct xen_sysctl_coverage_op coverage_op;
> + struct xen_sysctl_msr_op msr_op;
> uint8_t pad[128];
> } u;
> };
next prev parent reply other threads:[~2014-06-20 14:57 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-20 14:31 [PATCH v11 0/9] enable Cache QoS Monitoring (CQM) feature Dongxiao Xu
2014-06-20 14:31 ` [PATCH v11 1/9] x86: add generic MSR access hypercall Dongxiao Xu
2014-06-20 14:57 ` Andrew Cooper [this message]
2014-06-23 6:34 ` Xu, Dongxiao
2014-06-20 15:00 ` Jan Beulich
2014-06-23 6:27 ` Xu, Dongxiao
2014-06-23 6:45 ` Jan Beulich
2014-06-23 7:29 ` Xu, Dongxiao
2014-06-23 7:42 ` Jan Beulich
2014-06-23 13:32 ` Konrad Rzeszutek Wilk
2014-06-20 14:31 ` [PATCH v11 2/9] xsm: add MSR operation related xsm policy Dongxiao Xu
2014-06-24 19:20 ` Daniel De Graaf
2014-06-20 14:31 ` [PATCH v11 3/9] tools: provide interface for generic MSR access Dongxiao Xu
2014-06-20 17:34 ` Konrad Rzeszutek Wilk
2014-06-23 7:13 ` Jan Beulich
2014-06-23 13:29 ` Konrad Rzeszutek Wilk
2014-06-27 13:05 ` Ian Campbell
2014-06-20 14:31 ` [PATCH v11 4/9] x86: detect and initialize Platform QoS Monitoring feature Dongxiao Xu
2014-06-20 15:04 ` Jan Beulich
2014-06-23 6:38 ` Xu, Dongxiao
2014-06-23 6:50 ` Jan Beulich
2014-06-23 7:30 ` Xu, Dongxiao
2014-06-20 17:35 ` Konrad Rzeszutek Wilk
2014-06-20 14:31 ` [PATCH v11 5/9] x86: dynamically attach/detach QoS monitoring service for a guest Dongxiao Xu
2014-06-20 15:08 ` Jan Beulich
2014-06-23 6:43 ` Xu, Dongxiao
2014-06-20 14:31 ` [PATCH v11 6/9] x86: collect global QoS monitoring information Dongxiao Xu
2014-06-20 15:16 ` Jan Beulich
2014-06-23 6:55 ` Xu, Dongxiao
2014-06-23 7:06 ` Jan Beulich
2014-06-20 14:31 ` [PATCH v11 7/9] x86: enable QoS monitoring for each domain RMID Dongxiao Xu
2014-06-20 15:20 ` Jan Beulich
2014-06-23 6:55 ` Xu, Dongxiao
2014-06-20 14:31 ` [PATCH v11 8/9] xsm: add platform QoS related xsm policies Dongxiao Xu
2014-06-24 19:24 ` Daniel De Graaf
2014-06-20 14:31 ` [PATCH v11 9/9] tools: CMDs and APIs for Platform QoS Monitoring Dongxiao Xu
2014-06-23 15:22 ` Ian Jackson
2014-06-27 7:15 ` Xu, Dongxiao
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=53A44BC4.6070905@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=George.Dunlap@eu.citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=JBeulich@suse.com \
--cc=dgdegra@tycho.nsa.gov \
--cc=dongxiao.xu@intel.com \
--cc=keir@xen.org \
--cc=stefano.stabellini@eu.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 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.