From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: [PATCH RFC 07/31] xen/x86: Export host featureset via SYSCTL Date: Wed, 16 Dec 2015 21:24:09 +0000 Message-ID: <1450301073-28191-8-git-send-email-andrew.cooper3@citrix.com> References: <1450301073-28191-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1450301073-28191-1-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen-devel Cc: Andrew Cooper , Tim Deegan , Ian Campbell , Jan Beulich List-Id: xen-devel@lists.xenproject.org Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Tim Deegan CC: Ian Campbell --- xen/arch/x86/sysctl.c | 51 +++++++++++++++++++++++++++++++++++++++++++++ xen/include/public/sysctl.h | 20 ++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c index 38b5dcb..1f483b8 100644 --- a/xen/arch/x86/sysctl.c +++ b/xen/arch/x86/sysctl.c @@ -29,6 +29,7 @@ #include #include #include +#include #define get_xen_guest_handle(val, hnd) do { val = (hnd).p; } while (0) @@ -190,6 +191,56 @@ long arch_do_sysctl( } break; + case XEN_SYSCTL_get_featureset: + { + uint32_t *featureset; + unsigned int nr; + + /* Request for maximum number of features? */ + if ( guest_handle_is_null(sysctl->u.featureset.features) ) + { + sysctl->u.featureset.nr_features = XEN_NR_FEATURESET_ENTRIES; + if ( __copy_to_guest(u_sysctl, sysctl, 1) ) + ret = -EFAULT; + break; + } + + /* Clip the number of entries. */ + nr = min_t(unsigned int, sysctl->u.featureset.nr_features, + XEN_NR_FEATURESET_ENTRIES); + + switch ( sysctl->u.featureset.index ) + { + case XEN_SYSCTL_featureset_host: + featureset = host_featureset; + break; + + default: + featureset = NULL; + break; + } + + /* Bad featureset index? */ + if ( !ret && !featureset ) + ret = -EINVAL; + + /* Copy the requested featureset into place. */ + if ( !ret && copy_to_guest(sysctl->u.featureset.features, + featureset, nr) ) + ret = -EFAULT; + + /* Inform the caller of how many features we wrote. */ + sysctl->u.featureset.nr_features = nr; + if ( !ret && __copy_to_guest(u_sysctl, sysctl, 1) ) + ret = -EFAULT; + + /* Inform the caller if there was more data to provide. */ + if ( !ret && nr < XEN_NR_FEATURESET_ENTRIES ) + ret = -ENOBUFS; + + break; + } + default: ret = -ENOSYS; break; diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 0cacacc..dfde433 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -764,6 +764,24 @@ struct xen_sysctl_tmem_op { typedef struct xen_sysctl_tmem_op xen_sysctl_tmem_op_t; DEFINE_XEN_GUEST_HANDLE(xen_sysctl_tmem_op_t); +/* + * XEN_SYSCTL_get_featureset (x86 specific) + * + * Return information about the maximum sets of features which can be offered + * to different types of guests. This is all strictly information as found in + * `cpuid` feature leaves with no synthetic alterations. + */ +struct xen_sysctl_featureset { +#define XEN_SYSCTL_featureset_host 0 + uint32_t index; /* IN: Which featureset to query? */ + uint32_t nr_features; /* IN/OUT: Number of entries in/written to + * 'features', or the maximum number of features if + * the guest handle is NULL. */ + XEN_GUEST_HANDLE_64(uint32) features; /* OUT: */ +}; +typedef struct xen_sysctl_featureset xen_sysctl_featureset_t; +DEFINE_XEN_GUEST_HANDLE(xen_sysctl_featureset_t); + struct xen_sysctl { uint32_t cmd; #define XEN_SYSCTL_readconsole 1 @@ -789,6 +807,7 @@ struct xen_sysctl { #define XEN_SYSCTL_pcitopoinfo 22 #define XEN_SYSCTL_psr_cat_op 23 #define XEN_SYSCTL_tmem_op 24 +#define XEN_SYSCTL_get_featureset 25 uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */ union { struct xen_sysctl_readconsole readconsole; @@ -814,6 +833,7 @@ struct xen_sysctl { struct xen_sysctl_psr_cmt_op psr_cmt_op; struct xen_sysctl_psr_cat_op psr_cat_op; struct xen_sysctl_tmem_op tmem_op; + struct xen_sysctl_featureset featureset; uint8_t pad[128]; } u; }; -- 2.1.4