Re: [Xen-devel] [PATCH v9 7/7] tools/xen-mceinj: add support of injecting LMCE

2017-07-18 Thread Wei Liu
On Tue, Jul 18, 2017 at 11:33:04AM +0100, Wei Liu wrote:
> On Wed, Jul 12, 2017 at 10:04:40AM +0800, Haozhong Zhang wrote:
> >  
> > +static int inject_lmce(xc_interface *xc_handle, unsigned int cpu)
> > +{
> > +uint8_t *cpumap = NULL;
> > +size_t cpumap_size, line, shift;
> > +unsigned int nr_cpus;
> > +int ret;
> > +
> > +nr_cpus = mca_cpuinfo(xc_handle);
> > +if ( !nr_cpus )
> > +err(xc_handle, "Failed to get mca_cpuinfo");
> > +if ( cpu >= nr_cpus )
> > +err(xc_handle, "-c %u is larger than %u", cpu, nr_cpus - 1);
> > +
> > +cpumap_size = (nr_cpus + 7) / 8;
> > +cpumap = malloc(cpumap_size);
> > +if ( !cpumap )
> > +err(xc_handle, "Failed to allocate cpumap\n");
> > +memset(cpumap, 0, cpumap_size);
> > +line = cpu / 8;
> > +shift = cpu % 8;
> > +memset(cpumap + line, 1 << shift, 1);
> > +
> > +ret = xc_mca_op_inject_v2(xc_handle, XEN_MC_INJECT_TYPE_LMCE,
> > +  cpumap, cpumap_size * 8);
> 
> This doesn't compile because XEN_MC_INJECT_TYPE_LMCE is not defined.
> 
> Please rework this patch and make sure it compiles before submitting.

Oh, actually that's my fault. I forgot to pull in your hypervisor
patches.

Sorry for the noise.

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v9 7/7] tools/xen-mceinj: add support of injecting LMCE

2017-07-18 Thread Wei Liu
On Wed, Jul 12, 2017 at 10:04:40AM +0800, Haozhong Zhang wrote:
>  
> +static int inject_lmce(xc_interface *xc_handle, unsigned int cpu)
> +{
> +uint8_t *cpumap = NULL;
> +size_t cpumap_size, line, shift;
> +unsigned int nr_cpus;
> +int ret;
> +
> +nr_cpus = mca_cpuinfo(xc_handle);
> +if ( !nr_cpus )
> +err(xc_handle, "Failed to get mca_cpuinfo");
> +if ( cpu >= nr_cpus )
> +err(xc_handle, "-c %u is larger than %u", cpu, nr_cpus - 1);
> +
> +cpumap_size = (nr_cpus + 7) / 8;
> +cpumap = malloc(cpumap_size);
> +if ( !cpumap )
> +err(xc_handle, "Failed to allocate cpumap\n");
> +memset(cpumap, 0, cpumap_size);
> +line = cpu / 8;
> +shift = cpu % 8;
> +memset(cpumap + line, 1 << shift, 1);
> +
> +ret = xc_mca_op_inject_v2(xc_handle, XEN_MC_INJECT_TYPE_LMCE,
> +  cpumap, cpumap_size * 8);

This doesn't compile because XEN_MC_INJECT_TYPE_LMCE is not defined.

Please rework this patch and make sure it compiles before submitting.

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v9 7/7] tools/xen-mceinj: add support of injecting LMCE

2017-07-17 Thread Wei Liu
On Mon, Jul 17, 2017 at 11:05:24AM +0100, Wei Liu wrote:
> On Thu, Jul 13, 2017 at 10:10:05AM +0800, Haozhong Zhang wrote:
> > On 07/12/17 09:26 -0400, Konrad Rzeszutek Wilk wrote:
> > > On Wed, Jul 12, 2017 at 10:04:40AM +0800, Haozhong Zhang wrote:
> > > > If option '-l' or '--lmce' is specified and the host supports LMCE,
> > > > xen-mceinj will inject LMCE to CPU specified by '-c' (or CPU0 if '-c'
> > > > is not present).
> > > > 
> > > > Signed-off-by: Haozhong Zhang 
> > > > Acked-by: Wei Liu 
> > > > ---
> > > > Cc: Ian Jackson 
> > > > Cc: Wei Liu 
> > > > ---
> > > >  tools/tests/mce-test/tools/xen-mceinj.c | 50 
> > > > +++--
> > > >  1 file changed, 48 insertions(+), 2 deletions(-)
> > > > 
> > > > diff --git a/tools/tests/mce-test/tools/xen-mceinj.c 
> > > > b/tools/tests/mce-test/tools/xen-mceinj.c
> > > > index bae5a46eb5..380e42190c 100644
> > > > --- a/tools/tests/mce-test/tools/xen-mceinj.c
> > > > +++ b/tools/tests/mce-test/tools/xen-mceinj.c
> > [..]
> > > >  
> > > > +static int inject_lmce(xc_interface *xc_handle, unsigned int cpu)
> > > > +{
> > > > +uint8_t *cpumap = NULL;
> > > > +size_t cpumap_size, line, shift;
> > > > +unsigned int nr_cpus;
> > > > +int ret;
> > > > +
> > > > +nr_cpus = mca_cpuinfo(xc_handle);
> > > > +if ( !nr_cpus )
> > > > +err(xc_handle, "Failed to get mca_cpuinfo");
> > > > +if ( cpu >= nr_cpus )
> > > > +err(xc_handle, "-c %u is larger than %u", cpu, nr_cpus - 1);
> > > > +
> > > > +cpumap_size = (nr_cpus + 7) / 8;
> > > 
> > > bitmap_size
> > >
> > 
> > IIUC, these bitmap_* functions/macros are libxc internals and should
> > not be used here.
> > 
> 
> Correct. Those aren't available to external users. If we want to export
> those we would need to add libxc_ prefix.

FAOD I think bitmap_* aren't appropriate to use here for the reason
stated above. That also makes the suggestion on previous patch moot. If
I hear no objection by tomorrow I will just commit these two remaining
patches.

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v9 7/7] tools/xen-mceinj: add support of injecting LMCE

2017-07-17 Thread Wei Liu
On Thu, Jul 13, 2017 at 10:10:05AM +0800, Haozhong Zhang wrote:
> On 07/12/17 09:26 -0400, Konrad Rzeszutek Wilk wrote:
> > On Wed, Jul 12, 2017 at 10:04:40AM +0800, Haozhong Zhang wrote:
> > > If option '-l' or '--lmce' is specified and the host supports LMCE,
> > > xen-mceinj will inject LMCE to CPU specified by '-c' (or CPU0 if '-c'
> > > is not present).
> > > 
> > > Signed-off-by: Haozhong Zhang 
> > > Acked-by: Wei Liu 
> > > ---
> > > Cc: Ian Jackson 
> > > Cc: Wei Liu 
> > > ---
> > >  tools/tests/mce-test/tools/xen-mceinj.c | 50 
> > > +++--
> > >  1 file changed, 48 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/tools/tests/mce-test/tools/xen-mceinj.c 
> > > b/tools/tests/mce-test/tools/xen-mceinj.c
> > > index bae5a46eb5..380e42190c 100644
> > > --- a/tools/tests/mce-test/tools/xen-mceinj.c
> > > +++ b/tools/tests/mce-test/tools/xen-mceinj.c
> [..]
> > >  
> > > +static int inject_lmce(xc_interface *xc_handle, unsigned int cpu)
> > > +{
> > > +uint8_t *cpumap = NULL;
> > > +size_t cpumap_size, line, shift;
> > > +unsigned int nr_cpus;
> > > +int ret;
> > > +
> > > +nr_cpus = mca_cpuinfo(xc_handle);
> > > +if ( !nr_cpus )
> > > +err(xc_handle, "Failed to get mca_cpuinfo");
> > > +if ( cpu >= nr_cpus )
> > > +err(xc_handle, "-c %u is larger than %u", cpu, nr_cpus - 1);
> > > +
> > > +cpumap_size = (nr_cpus + 7) / 8;
> > 
> > bitmap_size
> >
> 
> IIUC, these bitmap_* functions/macros are libxc internals and should
> not be used here.
> 

Correct. Those aren't available to external users. If we want to export
those we would need to add libxc_ prefix.

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v9 7/7] tools/xen-mceinj: add support of injecting LMCE

2017-07-12 Thread Haozhong Zhang
On 07/12/17 09:26 -0400, Konrad Rzeszutek Wilk wrote:
> On Wed, Jul 12, 2017 at 10:04:40AM +0800, Haozhong Zhang wrote:
> > If option '-l' or '--lmce' is specified and the host supports LMCE,
> > xen-mceinj will inject LMCE to CPU specified by '-c' (or CPU0 if '-c'
> > is not present).
> > 
> > Signed-off-by: Haozhong Zhang 
> > Acked-by: Wei Liu 
> > ---
> > Cc: Ian Jackson 
> > Cc: Wei Liu 
> > ---
> >  tools/tests/mce-test/tools/xen-mceinj.c | 50 
> > +++--
> >  1 file changed, 48 insertions(+), 2 deletions(-)
> > 
> > diff --git a/tools/tests/mce-test/tools/xen-mceinj.c 
> > b/tools/tests/mce-test/tools/xen-mceinj.c
> > index bae5a46eb5..380e42190c 100644
> > --- a/tools/tests/mce-test/tools/xen-mceinj.c
> > +++ b/tools/tests/mce-test/tools/xen-mceinj.c
[..]
> >  
> > +static int inject_lmce(xc_interface *xc_handle, unsigned int cpu)
> > +{
> > +uint8_t *cpumap = NULL;
> > +size_t cpumap_size, line, shift;
> > +unsigned int nr_cpus;
> > +int ret;
> > +
> > +nr_cpus = mca_cpuinfo(xc_handle);
> > +if ( !nr_cpus )
> > +err(xc_handle, "Failed to get mca_cpuinfo");
> > +if ( cpu >= nr_cpus )
> > +err(xc_handle, "-c %u is larger than %u", cpu, nr_cpus - 1);
> > +
> > +cpumap_size = (nr_cpus + 7) / 8;
> 
> bitmap_size
>

IIUC, these bitmap_* functions/macros are libxc internals and should
not be used here.

Haozhong

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v9 7/7] tools/xen-mceinj: add support of injecting LMCE

2017-07-12 Thread Konrad Rzeszutek Wilk
On Wed, Jul 12, 2017 at 10:04:40AM +0800, Haozhong Zhang wrote:
> If option '-l' or '--lmce' is specified and the host supports LMCE,
> xen-mceinj will inject LMCE to CPU specified by '-c' (or CPU0 if '-c'
> is not present).
> 
> Signed-off-by: Haozhong Zhang 
> Acked-by: Wei Liu 
> ---
> Cc: Ian Jackson 
> Cc: Wei Liu 
> ---
>  tools/tests/mce-test/tools/xen-mceinj.c | 50 
> +++--
>  1 file changed, 48 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/tests/mce-test/tools/xen-mceinj.c 
> b/tools/tests/mce-test/tools/xen-mceinj.c
> index bae5a46eb5..380e42190c 100644
> --- a/tools/tests/mce-test/tools/xen-mceinj.c
> +++ b/tools/tests/mce-test/tools/xen-mceinj.c
> @@ -56,6 +56,8 @@
>  #define MSR_IA32_MC0_MISC0x0403
>  #define MSR_IA32_MC0_CTL20x0280
>  
> +#define MCG_STATUS_LMCE  0x8
> +
>  struct mce_info {
>  const char *description;
>  uint8_t mcg_stat;
> @@ -113,6 +115,7 @@ static struct mce_info mce_table[] = {
>  #define LOGFILE stdout
>  
>  int dump;
> +int lmce;
>  struct xen_mc_msrinject msr_inj;
>  
>  static void Lprintf(const char *fmt, ...)
> @@ -212,6 +215,35 @@ static int inject_mce(xc_interface *xc_handle, int 
> cpu_nr)
>  return xc_mca_op(xc_handle, );
>  }
>  
> +static int inject_lmce(xc_interface *xc_handle, unsigned int cpu)
> +{
> +uint8_t *cpumap = NULL;
> +size_t cpumap_size, line, shift;
> +unsigned int nr_cpus;
> +int ret;
> +
> +nr_cpus = mca_cpuinfo(xc_handle);
> +if ( !nr_cpus )
> +err(xc_handle, "Failed to get mca_cpuinfo");
> +if ( cpu >= nr_cpus )
> +err(xc_handle, "-c %u is larger than %u", cpu, nr_cpus - 1);
> +
> +cpumap_size = (nr_cpus + 7) / 8;

bitmap_size

> +cpumap = malloc(cpumap_size);

bitmap_alloc ?
> +if ( !cpumap )
> +err(xc_handle, "Failed to allocate cpumap\n");
> +memset(cpumap, 0, cpumap_size);

bitmap_clear?

> +line = cpu / 8;

BITMAP_ENTRY?
> +shift = cpu % 8;

BITMAP_SHIFT?
> +memset(cpumap + line, 1 << shift, 1);
> +
> +ret = xc_mca_op_inject_v2(xc_handle, XEN_MC_INJECT_TYPE_LMCE,
> +  cpumap, cpumap_size * 8);
> +
> +free(cpumap);
> +return ret;
> +}
> +
>  static uint64_t bank_addr(int bank, int type)
>  {
>  uint64_t addr;
> @@ -330,8 +362,15 @@ static int inject(xc_interface *xc_handle, struct 
> mce_info *mce,
>uint32_t cpu_nr, uint32_t domain, uint64_t gaddr)
>  {
>  int ret = 0;
> +uint8_t mcg_status = mce->mcg_stat;
>  
> -ret = inject_mcg_status(xc_handle, cpu_nr, mce->mcg_stat, domain);
> +if ( lmce )
> +{
> +if ( mce->cmci )
> +err(xc_handle, "No support to inject CMCI as LMCE");
> +mcg_status |= MCG_STATUS_LMCE;
> +}
> +ret = inject_mcg_status(xc_handle, cpu_nr, mcg_status, domain);
>  if ( ret )
>  err(xc_handle, "Failed to inject MCG_STATUS MSR");
>  
> @@ -354,6 +393,8 @@ static int inject(xc_interface *xc_handle, struct 
> mce_info *mce,
>  err(xc_handle, "Failed to inject MSR");
>  if ( mce->cmci )
>  ret = inject_cmci(xc_handle, cpu_nr);
> +else if ( lmce )
> +ret = inject_lmce(xc_handle, cpu_nr);
>  else
>  ret = inject_mce(xc_handle, cpu_nr);
>  if ( ret )
> @@ -393,6 +434,7 @@ static struct option opts[] = {
>  {"dump", 0, 0, 'D'},
>  {"help", 0, 0, 'h'},
>  {"page", 0, 0, 'p'},
> +{"lmce", 0, 0, 'l'},
>  {"", 0, 0, '\0'}
>  };
>  
> @@ -409,6 +451,7 @@ static void help(void)
> "  -d, --domain=DOMID   target domain, the default is Xen 
> itself\n"
> "  -h, --help   print this page\n"
> "  -p, --page=ADDR  physical address to report\n"
> +   "  -l, --lmce   inject as LMCE (Intel only)\n"
> "  -t, --type=ERROR error type\n");
>  
>  for ( i = 0; i < MCE_TABLE_SIZE; i++ )
> @@ -438,7 +481,7 @@ int main(int argc, char *argv[])
>  }
>  
>  while ( 1 ) {
> -c = getopt_long(argc, argv, "c:Dd:t:hp:", opts, _index);
> +c = getopt_long(argc, argv, "c:Dd:t:hp:l", opts, _index);
>  if ( c == -1 )
>  break;
>  switch ( c ) {
> @@ -463,6 +506,9 @@ int main(int argc, char *argv[])
>  case 't':
>  type = strtol(optarg, NULL, 0);
>  break;
> +case 'l':
> +lmce = 1;
> +break;
>  case 'h':
>  default:
>  help();
> -- 
> 2.11.0
> 
> 
> ___
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> https://lists.xen.org/xen-devel

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v9 7/7] tools/xen-mceinj: add support of injecting LMCE

2017-07-11 Thread Haozhong Zhang
If option '-l' or '--lmce' is specified and the host supports LMCE,
xen-mceinj will inject LMCE to CPU specified by '-c' (or CPU0 if '-c'
is not present).

Signed-off-by: Haozhong Zhang 
Acked-by: Wei Liu 
---
Cc: Ian Jackson 
Cc: Wei Liu 
---
 tools/tests/mce-test/tools/xen-mceinj.c | 50 +++--
 1 file changed, 48 insertions(+), 2 deletions(-)

diff --git a/tools/tests/mce-test/tools/xen-mceinj.c 
b/tools/tests/mce-test/tools/xen-mceinj.c
index bae5a46eb5..380e42190c 100644
--- a/tools/tests/mce-test/tools/xen-mceinj.c
+++ b/tools/tests/mce-test/tools/xen-mceinj.c
@@ -56,6 +56,8 @@
 #define MSR_IA32_MC0_MISC0x0403
 #define MSR_IA32_MC0_CTL20x0280
 
+#define MCG_STATUS_LMCE  0x8
+
 struct mce_info {
 const char *description;
 uint8_t mcg_stat;
@@ -113,6 +115,7 @@ static struct mce_info mce_table[] = {
 #define LOGFILE stdout
 
 int dump;
+int lmce;
 struct xen_mc_msrinject msr_inj;
 
 static void Lprintf(const char *fmt, ...)
@@ -212,6 +215,35 @@ static int inject_mce(xc_interface *xc_handle, int cpu_nr)
 return xc_mca_op(xc_handle, );
 }
 
+static int inject_lmce(xc_interface *xc_handle, unsigned int cpu)
+{
+uint8_t *cpumap = NULL;
+size_t cpumap_size, line, shift;
+unsigned int nr_cpus;
+int ret;
+
+nr_cpus = mca_cpuinfo(xc_handle);
+if ( !nr_cpus )
+err(xc_handle, "Failed to get mca_cpuinfo");
+if ( cpu >= nr_cpus )
+err(xc_handle, "-c %u is larger than %u", cpu, nr_cpus - 1);
+
+cpumap_size = (nr_cpus + 7) / 8;
+cpumap = malloc(cpumap_size);
+if ( !cpumap )
+err(xc_handle, "Failed to allocate cpumap\n");
+memset(cpumap, 0, cpumap_size);
+line = cpu / 8;
+shift = cpu % 8;
+memset(cpumap + line, 1 << shift, 1);
+
+ret = xc_mca_op_inject_v2(xc_handle, XEN_MC_INJECT_TYPE_LMCE,
+  cpumap, cpumap_size * 8);
+
+free(cpumap);
+return ret;
+}
+
 static uint64_t bank_addr(int bank, int type)
 {
 uint64_t addr;
@@ -330,8 +362,15 @@ static int inject(xc_interface *xc_handle, struct mce_info 
*mce,
   uint32_t cpu_nr, uint32_t domain, uint64_t gaddr)
 {
 int ret = 0;
+uint8_t mcg_status = mce->mcg_stat;
 
-ret = inject_mcg_status(xc_handle, cpu_nr, mce->mcg_stat, domain);
+if ( lmce )
+{
+if ( mce->cmci )
+err(xc_handle, "No support to inject CMCI as LMCE");
+mcg_status |= MCG_STATUS_LMCE;
+}
+ret = inject_mcg_status(xc_handle, cpu_nr, mcg_status, domain);
 if ( ret )
 err(xc_handle, "Failed to inject MCG_STATUS MSR");
 
@@ -354,6 +393,8 @@ static int inject(xc_interface *xc_handle, struct mce_info 
*mce,
 err(xc_handle, "Failed to inject MSR");
 if ( mce->cmci )
 ret = inject_cmci(xc_handle, cpu_nr);
+else if ( lmce )
+ret = inject_lmce(xc_handle, cpu_nr);
 else
 ret = inject_mce(xc_handle, cpu_nr);
 if ( ret )
@@ -393,6 +434,7 @@ static struct option opts[] = {
 {"dump", 0, 0, 'D'},
 {"help", 0, 0, 'h'},
 {"page", 0, 0, 'p'},
+{"lmce", 0, 0, 'l'},
 {"", 0, 0, '\0'}
 };
 
@@ -409,6 +451,7 @@ static void help(void)
"  -d, --domain=DOMID   target domain, the default is Xen itself\n"
"  -h, --help   print this page\n"
"  -p, --page=ADDR  physical address to report\n"
+   "  -l, --lmce   inject as LMCE (Intel only)\n"
"  -t, --type=ERROR error type\n");
 
 for ( i = 0; i < MCE_TABLE_SIZE; i++ )
@@ -438,7 +481,7 @@ int main(int argc, char *argv[])
 }
 
 while ( 1 ) {
-c = getopt_long(argc, argv, "c:Dd:t:hp:", opts, _index);
+c = getopt_long(argc, argv, "c:Dd:t:hp:l", opts, _index);
 if ( c == -1 )
 break;
 switch ( c ) {
@@ -463,6 +506,9 @@ int main(int argc, char *argv[])
 case 't':
 type = strtol(optarg, NULL, 0);
 break;
+case 'l':
+lmce = 1;
+break;
 case 'h':
 default:
 help();
-- 
2.11.0


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel