Re: [patch uq/master 7/8] MCE: Relay UCR MCE to guest

2010-10-08 Thread Dean Nelson

On 10/07/2010 10:15 PM, Huang Ying wrote:

Hi, Seto,

On Thu, 2010-10-07 at 11:41 +0800, Hidetoshi Seto wrote:

(2010/10/07 3:10), Dean Nelson wrote:

snip

When I applied a patch to the guest's kernel which forces mce_ser to be
set, as if MCG_SER_P was set (see __mcheck_cpu_cap_init()), I found
that when the memory page was 'owned' by a guest process, the process
would be killed (if the page was dirty), and the guest would stay
running. The HWPoisoned page would be sidelined and not cause any more
issues.


Excellent.
So while guest kernel knows which page is poisoned, guest processes
are controlled not to touch the page.

... Therefore rebooting the vm and renewing kernel will lost the
information where is poisoned.


Yes. That is an issue. Dean suggests that make qemu-kvm to refuse reboot
the guest if there is poisoned page and ask for user to intervention. I
have another idea to replace the poison pages with good pages when
reboot, that is, recover without user intervention.


Hi, Huang, I much prefer the replacing of the poisoned pages with good
pages on reboot, over the refusing to reboot. So definitely go with
your idea.

Thanks,
Dean
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [patch uq/master 7/8] MCE: Relay UCR MCE to guest

2010-10-07 Thread Dean Nelson

On 10/06/2010 10:41 PM, Hidetoshi Seto wrote:

(2010/10/07 3:10), Dean Nelson wrote:

On 10/06/2010 11:05 AM, Marcelo Tosatti wrote:

On Wed, Oct 06, 2010 at 10:58:36AM +0900, Hidetoshi Seto wrote:

I got some more question:

(2010/10/05 3:54), Marcelo Tosatti wrote:

Index: qemu/target-i386/cpu.h
===
--- qemu.orig/target-i386/cpu.h
+++ qemu/target-i386/cpu.h
@@ -250,16 +250,32 @@
   #define PG_ERROR_RSVD_MASK 0x08
   #define PG_ERROR_I_D_MASK  0x10

-#define MCG_CTL_P(1UL8)   /* MCG_CAP register available */
+#define MCG_CTL_P(1ULL8)   /* MCG_CAP register available */
+#define MCG_SER_P(1ULL24) /* MCA recovery/new status bits */

-#define MCE_CAP_DEFMCG_CTL_P
+#define MCE_CAP_DEF(MCG_CTL_P|MCG_SER_P)
   #define MCE_BANKS_DEF10



It seems that current kvm doesn't support SER_P, so injecting SRAO
to guest will mean that guest receives VAL|UC|!PCC and RIPV event
from virtual processor that doesn't have SER_P.


Dean also noted this. I don't think it was deliberate choice to not
expose SER_P. Huang?


In my testing, I found that MCG_SER_P was not being set (and I was
running on a Nehalem-EX system). Injecting a MCE resulted in the
guest entering into panic() from mce_panic(). If crash_kexec()
finds a kexec_crash_image the system ends up rebooting, otherwise,
what happens next requires operator intervention.


Good to know.
What I'm concerning is that if memory scrubbing SRAO event is
injected when !SER_P, linux guest with certain mce tolerant level
might grade it as UC severity and continue running with none of
panicking, killing and poisoning because of !PCC and RIPV.

Could you provide the panic message of the guest in your test?
I think it can tell me why the mce handler decided to go panic.


Sure, I'll add the info below at the end of this email.



When I applied a patch to the guest's kernel which forces mce_ser to be
set, as if MCG_SER_P was set (see __mcheck_cpu_cap_init()), I found
that when the memory page was 'owned' by a guest process, the process
would be killed (if the page was dirty), and the guest would stay
running. The HWPoisoned page would be sidelined and not cause any more
issues.


Excellent.
So while guest kernel knows which page is poisoned, guest processes
are controlled not to touch the page.

... Therefore rebooting the vm and renewing kernel will lost the
information where is poisoned.


Correct.



I think most OSes don't expect that it can receives MCE with !PCC
on traditional x86 processor without SER_P.

Q1: Is it safe to expect that guests can handle such !PCC event?


This might be best answered by Huang, but as I mentioned above, without
MCG_SER_P being set, the result was an orderly system panic on the
guest.


Though I'll wait Huang (I think he is on holiday), I believe that
system panic is just a possible option for AO (Action Optional)
event, no matter how the SER_P is.


I think you may be correct, but Huang will know for sure.



Q2: What is the expected behavior on the guest?


I think I answered this above.


Yeah, thanks.




Q3: What happen if guest reboots itself in response to the MCE?


That depends...

And the following issue also holds for a guest that is rebooted at
some point having successfully sidelined the bad page.

After the guest has panic'd, a system_reset of the guest or a restart
initiated by crash_kexec() (called by panic() on the guest), usually
results in the guest hanging because the bad page still belongs
to qemu-kvm and is now being referenced by the new guest in some way.


Yes. In other words my concern about reboot is that new guest kernel
including kdump kernel might try to read the bad page.  If there is
no AR-SIGBUS etc., we need some tricks to inhibit such accesses.


Agreed.



(It actually may not hang, but successfully reboot and be runnable,
with the bad page lurking in the background. It all seems to depend on
where the bad page ends up, and whether it's ever referenced.)


I know some tough guys using their PC with buggy DIMMs :-)



I believe there was an attempt to deal with this in kvm on the host.
See kvm_handle_bad_page(). This function was suppose to result in the
sending of a BUS_MCEERR_AR flavored SIGBUS by do_sigbus() to qemu-kvm
which in theory would result in the right thing happening. But commit
96054569190bdec375fe824e48ca1f4e3b53dd36 prevents the signal from being
sent. So this mechanism needs to be re-worked, and the issue remains.


Definitely.
I guess Huang has some plan or hint for rework this point.


Yeah, as far as I know Huang is looking into this.



I would think that if the the bad page can't be sidelined, such that
the newly booting guest can't use it, then the new guest shouldn't be
allowed to boot. But perhaps there is some merit in letting it try to
boot and see if one gets 'lucky'.


In case of booting a real machine in real world, hardware and firmware
usually (or often) do self-test before passing control

[PATCH] Fix calculation of number of entries based on number of mce_banks

2010-10-06 Thread Dean Nelson
The number of mce_banks needs to be multiplied by 4 in order to actually
reference all of the entries.

Signed-off-by: Dean Nelson dnel...@redhat.com

---
 qemu-kvm-x86.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
index fd974b3..7fd82fb 100644
--- a/qemu-kvm-x86.c
+++ b/qemu-kvm-x86.c
@@ -975,7 +975,7 @@ void kvm_arch_load_regs(CPUState *env, int level)
 } else if (level == KVM_PUT_FULL_STATE) {
 kvm_msr_entry_set(msrs[n++], MSR_MCG_STATUS, env-mcg_status);
 kvm_msr_entry_set(msrs[n++], MSR_MCG_CTL, env-mcg_ctl);
-for (i = 0; i  (env-mcg_cap  0xff); i++) {
+for (i = 0; i  (env-mcg_cap  0xff) * 4; i++) {
 kvm_msr_entry_set(msrs[n++], MSR_MC0_CTL + i, 
env-mce_banks[i]);
 }
 }
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [patch uq/master 7/8] MCE: Relay UCR MCE to guest

2010-10-06 Thread Dean Nelson

On 10/06/2010 11:05 AM, Marcelo Tosatti wrote:

On Wed, Oct 06, 2010 at 10:58:36AM +0900, Hidetoshi Seto wrote:

I got some more question:

(2010/10/05 3:54), Marcelo Tosatti wrote:

Index: qemu/target-i386/cpu.h
===
--- qemu.orig/target-i386/cpu.h
+++ qemu/target-i386/cpu.h
@@ -250,16 +250,32 @@
  #define PG_ERROR_RSVD_MASK 0x08
  #define PG_ERROR_I_D_MASK  0x10

-#define MCG_CTL_P  (1UL8)   /* MCG_CAP register available */
+#define MCG_CTL_P  (1ULL8)   /* MCG_CAP register available */
+#define MCG_SER_P  (1ULL24) /* MCA recovery/new status bits */

-#define MCE_CAP_DEFMCG_CTL_P
+#define MCE_CAP_DEF(MCG_CTL_P|MCG_SER_P)
  #define MCE_BANKS_DEF 10



It seems that current kvm doesn't support SER_P, so injecting SRAO
to guest will mean that guest receives VAL|UC|!PCC and RIPV event
from virtual processor that doesn't have SER_P.


Dean also noted this. I don't think it was deliberate choice to not
expose SER_P. Huang?


In my testing, I found that MCG_SER_P was not being set (and I was
running on a Nehalem-EX system). Injecting a MCE resulted in the
guest entering into panic() from mce_panic(). If crash_kexec()
finds a kexec_crash_image the system ends up rebooting, otherwise,
what happens next requires operator intervention.

When I applied a patch to the guest's kernel which forces mce_ser to be
set, as if MCG_SER_P was set (see __mcheck_cpu_cap_init()), I found
that when the memory page was 'owned' by a guest process, the process
would be killed (if the page was dirty), and the guest would stay
running. The HWPoisoned page would be sidelined and not cause any more
issues.


I think most OSes don't expect that it can receives MCE with !PCC
on traditional x86 processor without SER_P.

Q1: Is it safe to expect that guests can handle such !PCC event?


This might be best answered by Huang, but as I mentioned above, without
MCG_SER_P being set, the result was an orderly system panic on the
guest.


Q2: What is the expected behavior on the guest?


I think I answered this above.


Q3: What happen if guest reboots itself in response to the MCE?


That depends...

And the following issue also holds for a guest that is rebooted at
some point having successfully sidelined the bad page.

After the guest has panic'd, a system_reset of the guest or a restart
initiated by crash_kexec() (called by panic() on the guest), usually
results in the guest hanging because the bad page still belongs
to qemu-kvm and is now being referenced by the new guest in some way.
(It actually may not hang, but successfully reboot and be runnable,
with the bad page lurking in the background. It all seems to depend on
where the bad page ends up, and whether it's ever referenced.)

I believe there was an attempt to deal with this in kvm on the host.
See kvm_handle_bad_page(). This function was suppose to result in the
sending of a BUS_MCEERR_AR flavored SIGBUS by do_sigbus() to qemu-kvm
which in theory would result in the right thing happening. But commit
96054569190bdec375fe824e48ca1f4e3b53dd36 prevents the signal from being
sent. So this mechanism needs to be re-worked, and the issue remains.

I would think that if the the bad page can't be sidelined, such that
the newly booting guest can't use it, then the new guest shouldn't be
allowed to boot. But perhaps there is some merit in letting it try to
boot and see if one gets 'lucky'.

I understand that Huang is looking into what should be done. He can
give you better information than I in answer to your questions.

Dean
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html