* [Qemu-devel] [PATCH 07/11] kvm, x86: unify sigbus handling, prep
@ 2010-10-14 8:49 Jin Dongming
2010-10-15 0:36 ` [Qemu-devel] " Marcelo Tosatti
0 siblings, 1 reply; 4+ messages in thread
From: Jin Dongming @ 2010-10-14 8:49 UTC (permalink / raw)
To: KVM list
Cc: Hidetoshi Seto, Dean Nelson, Marcelo Tosatti,
qemu-devel@nongnu.org, Avi Kivity, Huang Ying
There are 2 similar functions to handle SIGBUS:
sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
void *ctx)
kvm_on_sigbus(CPUState *env, siginfo_t *siginfo)
The former is used when main thread receives SIGBUS via signalfd,
while latter is used when vcpu thread receives SIGBUS.
These 2 take different siginfo, but in both case required parameters
are common, the code and the addr in the info.
Restruct functions to take the code and the addr explicitly.
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Tested-by: Jin Dongming <jin.dongming@np.css.fujitsu.com>
---
qemu-kvm.c | 41 ++++++++++++++++++++---------------------
1 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/qemu-kvm.c b/qemu-kvm.c
index 89ae524..b58181a 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -1219,32 +1219,28 @@ static void kvm_mce_inj_srao_broadcast(target_phys_addr_t paddr)
}
#endif
-static void sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
- void *ctx)
+static void kvm_handle_sigbus(int code, void *vaddr)
{
#if defined(KVM_CAP_MCE) && defined(TARGET_I386)
- if ((first_cpu->mcg_cap & MCG_SER_P) && siginfo->ssi_addr
- && siginfo->ssi_code == BUS_MCEERR_AO) {
- void *vaddr;
+ if ((first_cpu->mcg_cap & MCG_SER_P) && vaddr && code == BUS_MCEERR_AO) {
ram_addr_t ram_addr;
target_phys_addr_t paddr;
/* Hope we are lucky for AO MCE */
- vaddr = (void *)(intptr_t)siginfo->ssi_addr;
if (do_qemu_ram_addr_from_host(vaddr, &ram_addr) ||
!kvm_physical_memory_addr_from_ram(kvm_state, ram_addr, &paddr)) {
fprintf(stderr, "Hardware memory error for memory used by "
"QEMU itself instead of guest system!: %llx\n",
- (unsigned long long)siginfo->ssi_addr);
+ (unsigned long long)vaddr);
return;
}
kvm_mce_inj_srao_broadcast(paddr);
} else
#endif
{
- if (siginfo->ssi_code == BUS_MCEERR_AO) {
+ if (code == BUS_MCEERR_AO) {
return;
- } else if (siginfo->ssi_code == BUS_MCEERR_AR) {
+ } else if (code == BUS_MCEERR_AR) {
hardware_memory_error();
} else {
sigbus_reraise();
@@ -1252,6 +1248,11 @@ static void sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
}
}
+static void sigbus_handler(int n, struct qemu_signalfd_siginfo *ssi, void *ctx)
+{
+ kvm_handle_sigbus(ssi->ssi_code, (void *)(intptr_t)ssi->ssi_addr);
+}
+
static void on_vcpu(CPUState *env, void (*func)(void *data), void *data)
{
struct qemu_work_item wi;
@@ -1377,36 +1378,34 @@ static void flush_queued_work(CPUState *env)
pthread_cond_broadcast(&qemu_work_cond);
}
-static void kvm_on_sigbus(CPUState *env, siginfo_t *siginfo)
+static void kvm_on_sigbus(CPUState *env, int code, void *vaddr)
{
#if defined(KVM_CAP_MCE) && defined(TARGET_I386)
- void *vaddr;
ram_addr_t ram_addr;
target_phys_addr_t paddr;
- if ((env->mcg_cap & MCG_SER_P) && siginfo->si_addr
- && (siginfo->si_code == BUS_MCEERR_AR
- || siginfo->si_code == BUS_MCEERR_AO)) {
+ if ((env->mcg_cap & MCG_SER_P) && vaddr
+ && (code == BUS_MCEERR_AR || code == BUS_MCEERR_AO)) {
/*
* If there is an MCE excpetion being processed, ignore this SRAO MCE
*/
- if (siginfo->si_code == BUS_MCEERR_AO && kvm_mce_in_progress(env)) {
+ if (code == BUS_MCEERR_AO && kvm_mce_in_progress(env)) }
return;
}
- vaddr = (void *)siginfo->si_addr;
+
if (do_qemu_ram_addr_from_host(vaddr, &ram_addr) ||
!kvm_physical_memory_addr_from_ram(kvm_state, ram_addr, &paddr)) {
fprintf(stderr, "Hardware memory error for memory used by "
"QEMU itself instead of guest system!\n");
/* Hope we are lucky for AO MCE */
- if (siginfo->si_code == BUS_MCEERR_AO) {
+ if (code == BUS_MCEERR_AO) {
return;
} else {
hardware_memory_error();
}
}
- if (siginfo->si_code == BUS_MCEERR_AR) {
+ if (code == BUS_MCEERR_AR) {
/* Fake an Intel architectural Data Load SRAR UCR */
kvm_mce_inj_srar_dataload(env, paddr);
} else {
@@ -1416,9 +1415,9 @@ static void kvm_on_sigbus(CPUState *env, siginfo_t *siginfo)
} else
#endif
{
- if (siginfo->si_code == BUS_MCEERR_AO) {
+ if (code == BUS_MCEERR_AO) {
return;
- } else if (siginfo->si_code == BUS_MCEERR_AR) {
+ } else if (code == BUS_MCEERR_AR) {
hardware_memory_error();
} else {
sigbus_reraise();
@@ -1455,7 +1454,7 @@ static void kvm_main_loop_wait(CPUState *env, int timeout)
switch (r) {
case SIGBUS:
- kvm_on_sigbus(env, &siginfo);
+ kvm_on_sigbus(env, siginfo.si_code, (void *)siginfo.si_addr);
break;
default:
break;
--
1.7.1.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [Qemu-devel] Re: [PATCH 07/11] kvm, x86: unify sigbus handling, prep
2010-10-14 8:49 [Qemu-devel] [PATCH 07/11] kvm, x86: unify sigbus handling, prep Jin Dongming
@ 2010-10-15 0:36 ` Marcelo Tosatti
2010-10-15 1:29 ` Hidetoshi Seto
0 siblings, 1 reply; 4+ messages in thread
From: Marcelo Tosatti @ 2010-10-15 0:36 UTC (permalink / raw)
To: Jin Dongming
Cc: Hidetoshi Seto, KVM list, Dean Nelson, qemu-devel@nongnu.org,
Avi Kivity, Huang Ying
On Thu, Oct 14, 2010 at 05:49:43PM +0900, Jin Dongming wrote:
> There are 2 similar functions to handle SIGBUS:
> sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
> void *ctx)
> kvm_on_sigbus(CPUState *env, siginfo_t *siginfo)
>
> The former is used when main thread receives SIGBUS via signalfd,
> while latter is used when vcpu thread receives SIGBUS.
> These 2 take different siginfo, but in both case required parameters
> are common, the code and the addr in the info.
>
> Restruct functions to take the code and the addr explicitly.
>
> Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
> Tested-by: Jin Dongming <jin.dongming@np.css.fujitsu.com>
> ---
> qemu-kvm.c | 41 ++++++++++++++++++++---------------------
> 1 files changed, 20 insertions(+), 21 deletions(-)
Don't see the benefit, separate functions are cleaner.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] Re: [PATCH 07/11] kvm, x86: unify sigbus handling, prep
2010-10-15 0:36 ` [Qemu-devel] " Marcelo Tosatti
@ 2010-10-15 1:29 ` Hidetoshi Seto
2010-10-15 1:46 ` Marcelo Tosatti
0 siblings, 1 reply; 4+ messages in thread
From: Hidetoshi Seto @ 2010-10-15 1:29 UTC (permalink / raw)
To: Marcelo Tosatti
Cc: KVM list, Dean Nelson, qemu-devel@nongnu.org, Avi Kivity,
Huang Ying, Jin Dongming
(2010/10/15 9:36), Marcelo Tosatti wrote:
> On Thu, Oct 14, 2010 at 05:49:43PM +0900, Jin Dongming wrote:
>> There are 2 similar functions to handle SIGBUS:
>> sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
>> void *ctx)
>> kvm_on_sigbus(CPUState *env, siginfo_t *siginfo)
>>
>> The former is used when main thread receives SIGBUS via signalfd,
>> while latter is used when vcpu thread receives SIGBUS.
>> These 2 take different siginfo, but in both case required parameters
>> are common, the code and the addr in the info.
>>
>> Restruct functions to take the code and the addr explicitly.
>>
>> Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
>> Tested-by: Jin Dongming <jin.dongming@np.css.fujitsu.com>
>> ---
>> qemu-kvm.c | 41 ++++++++++++++++++++---------------------
>> 1 files changed, 20 insertions(+), 21 deletions(-)
>
> Don't see the benefit, separate functions are cleaner.
I think this is good for maintainability.
If you want to fix a bug in this area, you might have to change
2 separate functions in completely same way.
See 6c85786 and a05684e for examples.
Thanks,
H.Seto
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] Re: [PATCH 07/11] kvm, x86: unify sigbus handling, prep
2010-10-15 1:29 ` Hidetoshi Seto
@ 2010-10-15 1:46 ` Marcelo Tosatti
0 siblings, 0 replies; 4+ messages in thread
From: Marcelo Tosatti @ 2010-10-15 1:46 UTC (permalink / raw)
To: Hidetoshi Seto
Cc: KVM list, Dean Nelson, qemu-devel@nongnu.org, Avi Kivity,
Huang Ying, Jin Dongming
On Fri, Oct 15, 2010 at 10:29:25AM +0900, Hidetoshi Seto wrote:
> (2010/10/15 9:36), Marcelo Tosatti wrote:
> > On Thu, Oct 14, 2010 at 05:49:43PM +0900, Jin Dongming wrote:
> >> There are 2 similar functions to handle SIGBUS:
> >> sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
> >> void *ctx)
> >> kvm_on_sigbus(CPUState *env, siginfo_t *siginfo)
> >>
> >> The former is used when main thread receives SIGBUS via signalfd,
> >> while latter is used when vcpu thread receives SIGBUS.
> >> These 2 take different siginfo, but in both case required parameters
> >> are common, the code and the addr in the info.
> >>
> >> Restruct functions to take the code and the addr explicitly.
> >>
> >> Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
> >> Tested-by: Jin Dongming <jin.dongming@np.css.fujitsu.com>
> >> ---
> >> qemu-kvm.c | 41 ++++++++++++++++++++---------------------
> >> 1 files changed, 20 insertions(+), 21 deletions(-)
> >
> > Don't see the benefit, separate functions are cleaner.
>
> I think this is good for maintainability.
> If you want to fix a bug in this area, you might have to change
> 2 separate functions in completely same way.
> See 6c85786 and a05684e for examples.
>
> Thanks,
> H.Seto
OK, makes sense. Do you mind to rebase your patchset after MCE support is merged in qemu
upstream?
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-10-15 11:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-14 8:49 [Qemu-devel] [PATCH 07/11] kvm, x86: unify sigbus handling, prep Jin Dongming
2010-10-15 0:36 ` [Qemu-devel] " Marcelo Tosatti
2010-10-15 1:29 ` Hidetoshi Seto
2010-10-15 1:46 ` Marcelo Tosatti
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).