Skip to contentSkip to conversation

qom/cpu: Remove cpu->exit_request from reset state

PATCH Applied [email protected] 3 participants 11 messages Feb 13, 2014 – Mar 12, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qom/cpu: Remove cpu->exit_request from reset state

From: "Edgar E. Iglesias" <[email protected]>

cpu->exit_request is part of the execution environment and should not be cleared when a CPU resets.

Otherwise, we might deadlock QEMU if a CPU resets while there is I/O going on.

---
 qom/cpu.c | 1 -
 1 file changed, 1 deletion(-)
qom/cpu.c +0 -1
index 9d62479..40d82dd 100644
@@ -195,7 +195,6 @@ static void cpu_common_reset(CPUState *cpu)
         log_cpu_state(cpu, cc->reset_dump_flags);
     }
 
-    cpu->exit_request = 0;
     cpu->interrupt_request = 0;
     cpu->current_tb = NULL;
     cpu->halted = 0;
Signature · 1 line
1.8.1.2
#1 lore raw
Quoted 18 lines · On 13 February 2014 05:07, <[email protected]> wrote:

From: "Edgar E. Iglesias" <[email protected]>

cpu->exit_request is part of the execution environment and should not be cleared when a CPU resets.

Otherwise, we might deadlock QEMU if a CPU resets while there is I/O going on.

---
 qom/cpu.c | 1 -
 1 file changed, 1 deletion(-)
qom/cpu.c +0 -0
index 9d62479..40d82dd 100644

qom/cpu.c static void cpu_common_reset(CPUState *cpu) · line 200

Quoted 7 lines
qom/cpu.c +0 -1
@@ -195,7 +195,6 @@ static void cpu_common_reset(CPUState *cpu)
         log_cpu_state(cpu, cc->reset_dump_flags);
     }
 
-    cpu->exit_request = 0;
     cpu->interrupt_request = 0;
     cpu->current_tb = NULL;
     cpu->halted = 0;

This looks kind of odd to me. What's the situation you see where this matters -- is the CPU resetting itself, or is some other device in another thread triggering the CPU reset? TCG or KVM?

thanks
-- PMM

#2 lore raw
Quoted 22 lines · Peter Maydell
Quoted 21 lines · On 13 February 2014 05:07, <[email protected]> wrote:

From: "Edgar E. Iglesias" <[email protected]>

cpu->exit_request is part of the execution environment and should not be cleared when a CPU resets.

Otherwise, we might deadlock QEMU if a CPU resets while there is I/O going on.

---
 qom/cpu.c | 1 -
 1 file changed, 1 deletion(-)
qom/cpu.c +0 -0
index 9d62479..40d82dd 100644
@@ -195,7 +195,6 @@ static void cpu_common_reset(CPUState *cpu)
         log_cpu_state(cpu, cc->reset_dump_flags);
     }
 
Quoted 8 lines

qom/cpu.c static void cpu_common_reset(CPUState *cpu) · line 200

Quoted 4 lines
qom/cpu.c +0 -1
-    cpu->exit_request = 0;
     cpu->interrupt_request = 0;
     cpu->current_tb = NULL;
     cpu->halted = 0;

This looks kind of odd to me. What's the situation you see where this matters -- is the CPU resetting itself, or is some other device in another thread triggering the CPU reset? TCG or KVM?

Seeing this in TCG. The CPU gets signaled by the IO thread while the CPU is resetting itself. If the CPU looses the race, it clears its exit_request leaving the IO thread waiting for the global lock potentially forever.

The CPU actually exits generated code but goes right back in because there is no exit_request pending.

Cheers,
Edgar

Reviewed-by
#3 lore raw
Quoted 32 lines · Edgar E. Iglesias
Quoted 22 lines · Peter Maydell
Quoted 21 lines · On 13 February 2014 05:07, <[email protected]> wrote:

From: "Edgar E. Iglesias" <[email protected]>

cpu->exit_request is part of the execution environment and should not be cleared when a CPU resets.

Otherwise, we might deadlock QEMU if a CPU resets while there is I/O going on.

---
 qom/cpu.c | 1 -
 1 file changed, 1 deletion(-)
qom/cpu.c +0 -0
index 9d62479..40d82dd 100644
@@ -195,7 +195,6 @@ static void cpu_common_reset(CPUState *cpu)
         log_cpu_state(cpu, cc->reset_dump_flags);
     }
 
Quoted 8 lines

qom/cpu.c static void cpu_common_reset(CPUState *cpu) · line 200

Quoted 4 lines
qom/cpu.c +0 -1
-    cpu->exit_request = 0;
     cpu->interrupt_request = 0;
     cpu->current_tb = NULL;
     cpu->halted = 0;

This looks kind of odd to me. What's the situation you see where this matters -- is the CPU resetting itself, or is some other device in another thread triggering the CPU reset? TCG or KVM?

Quoted 7 lines

Seeing this in TCG. The CPU gets signaled by the IO thread while the CPU is resetting itself. If the CPU looses the race, it clears its exit_request leaving the IO thread waiting for the global lock potentially forever.

The CPU actually exits generated code but goes right back in because there is no exit_request pending.

Yes, having looked at the code I agree with you, so:

However, doesn't this also apply to interrupt_request ? If we have a pending asserted interrupt on the CPU (ie the IRQ line into the chip is being held high) this should result in an interrupt as soon as the CPU reenables interrupts after reset, I would have thought. Clearing cpu->interrupt_request here will make us drop it on the floor.

thanks
-- PMM

#4 lore raw

Am 20.02.2014 16:58, schrieb Peter Maydell:

Quoted 38 lines · Edgar E. Iglesias
Quoted 37 lines · Peter Maydell
Quoted 22 lines · On 13 February 2014 05:07, <[email protected]> wrote:
Quoted 21 lines

From: "Edgar E. Iglesias" <[email protected]>

cpu->exit_request is part of the execution environment and should not be cleared when a CPU resets.

Otherwise, we might deadlock QEMU if a CPU resets while there is I/O going on.

---
 qom/cpu.c | 1 -
 1 file changed, 1 deletion(-)
qom/cpu.c +0 -0
index 9d62479..40d82dd 100644
@@ -195,7 +195,6 @@ static void cpu_common_reset(CPUState *cpu)
         log_cpu_state(cpu, cc->reset_dump_flags);
     }
 
Quoted 8 lines

qom/cpu.c static void cpu_common_reset(CPUState *cpu) · line 200

Quoted 4 lines
qom/cpu.c +0 -1
-    cpu->exit_request = 0;
     cpu->interrupt_request = 0;
     cpu->current_tb = NULL;
     cpu->halted = 0;

This looks kind of odd to me. What's the situation you see where this matters -- is the CPU resetting itself, or is some other device in another thread triggering the CPU reset? TCG or KVM?

Seeing this in TCG. The CPU gets signaled by the IO thread while the CPU is resetting itself. If the CPU looses the race, it clears its exit_request leaving the IO thread waiting for the global lock potentially forever.

Quoted 8 lines
Quoted 2 lines

The CPU actually exits generated code but goes right back in because there is no exit_request pending.

Yes, having looked at the code I agree with you, so:

However, doesn't this also apply to interrupt_request ?

I was wondering the same thing but didn't find time to investigate yet.

Is it possible that we rather need to register some reset hook or bottom half to process the exit_request *before* this reset code runs?

Regards,
Andreas

Quoted 10 lines

If we have a pending asserted interrupt on the CPU (ie the IRQ line into the chip is being held high) this should result in an interrupt as soon as the CPU reenables interrupts after reset, I would have thought. Clearing cpu->interrupt_request here will make us drop it on the floor.

thanks
-- PMM

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#5 lore raw
Quoted 12 lines · Andreas Färber

Am 20.02.2014 16:58, schrieb Peter Maydell:

Quoted 11 lines · Edgar E. Iglesias
Quoted 7 lines

Seeing this in TCG. The CPU gets signaled by the IO thread while the CPU is resetting itself. If the CPU looses the race, it clears its exit_request leaving the IO thread waiting for the global lock potentially forever.

The CPU actually exits generated code but goes right back in because there is no exit_request pending.

Yes, having looked at the code I agree with you, so:

Quoted 8 lines
Quoted 3 lines

However, doesn't this also apply to interrupt_request ?

I was wondering the same thing but didn't find time to investigate yet.

Is it possible that we rather need to register some reset hook or bottom half to process the exit_request *before* this reset code runs?

The only way to process the exit_request is to abandon execution of whatever instruction caused us to try to do the CPU reset. That's in the general case impossible because we probably got here via an emulated power control device which has already updated its internal state and isn't capable of rolling back.

Simply making sure we honour the exit_request as soon as we've completed the cpu_reset is much simpler, I think.

thanks
-- PMM

#6 lore raw
In reply to Peter Maydell
Quoted 45 lines · Peter Maydell
Quoted 32 lines · Edgar E. Iglesias
Quoted 22 lines · Peter Maydell
Quoted 21 lines · On 13 February 2014 05:07, <[email protected]> wrote:

From: "Edgar E. Iglesias" <[email protected]>

cpu->exit_request is part of the execution environment and should not be cleared when a CPU resets.

Otherwise, we might deadlock QEMU if a CPU resets while there is I/O going on.

---
 qom/cpu.c | 1 -
 1 file changed, 1 deletion(-)
qom/cpu.c +0 -0
index 9d62479..40d82dd 100644
@@ -195,7 +195,6 @@ static void cpu_common_reset(CPUState *cpu)
         log_cpu_state(cpu, cc->reset_dump_flags);
     }
 
Quoted 8 lines

qom/cpu.c static void cpu_common_reset(CPUState *cpu) · line 200

Quoted 4 lines
qom/cpu.c +0 -1
-    cpu->exit_request = 0;
     cpu->interrupt_request = 0;
     cpu->current_tb = NULL;
     cpu->halted = 0;

This looks kind of odd to me. What's the situation you see where this matters -- is the CPU resetting itself, or is some other device in another thread triggering the CPU reset? TCG or KVM?

Quoted 7 lines

Seeing this in TCG. The CPU gets signaled by the IO thread while the CPU is resetting itself. If the CPU looses the race, it clears its exit_request leaving the IO thread waiting for the global lock potentially forever.

The CPU actually exits generated code but goes right back in because there is no exit_request pending.

Yes, having looked at the code I agree with you, so:

Quoted 7 lines

However, doesn't this also apply to interrupt_request ? If we have a pending asserted interrupt on the CPU (ie the IRQ line into the chip is being held high) this should result in an interrupt as soon as the CPU reenables interrupts after reset, I would have thought. Clearing cpu->interrupt_request here will make us drop it on the floor.

Hi,

I'm not sure about interrupt_request, seems to be a bit of a mix. For example, I' not sure it's safe to keep all the CPU_INTERRUPT_TGT_INT_X bits alive across a reset? Agree with you about the interrupt hard line though.

Cheers,
Edgar

#7 lore raw
Quoted 9 lines · Edgar E. Iglesias
Quoted 7 lines · Peter Maydell

However, doesn't this also apply to interrupt_request ? If we have a pending asserted interrupt on the CPU (ie the IRQ line into the chip is being held high) this should result in an interrupt as soon as the CPU reenables interrupts after reset, I would have thought. Clearing cpu->interrupt_request here will make us drop it on the floor.

Quoted 4 lines

I'm not sure about interrupt_request, seems to be a bit of a mix. For example, I' not sure it's safe to keep all the CPU_INTERRUPT_TGT_INT_X bits alive across a reset? Agree with you about the interrupt hard line though.

Mm, could probably use an audit of the uses of interrupt_request. I suspect that one doesn't matter so much in practice because a guest dealing with a reset CPU is going to either (a) ensure that any sources of interrupts are cleared before it unmasks them or (b) have arranged that nobody sends it interrupts during the reset in the first place. It would be nice to go through and check we can avoid the reset of interrupt_request, but we don't need to delay this patch for that.

thanks
-- PMM

#8 lore raw
In reply to Peter Maydell

Am 20.02.2014 16:58, schrieb Peter Maydell:

Quoted 38 lines · Edgar E. Iglesias
Quoted 37 lines · Peter Maydell
Quoted 22 lines · On 13 February 2014 05:07, <[email protected]> wrote:
Quoted 21 lines

From: "Edgar E. Iglesias" <[email protected]>

cpu->exit_request is part of the execution environment and should not be cleared when a CPU resets.

Otherwise, we might deadlock QEMU if a CPU resets while there is I/O going on.

---
 qom/cpu.c | 1 -
 1 file changed, 1 deletion(-)
qom/cpu.c +0 -0
index 9d62479..40d82dd 100644
@@ -195,7 +195,6 @@ static void cpu_common_reset(CPUState *cpu)
         log_cpu_state(cpu, cc->reset_dump_flags);
     }
 
Quoted 8 lines

qom/cpu.c static void cpu_common_reset(CPUState *cpu) · line 200

Quoted 4 lines
qom/cpu.c +0 -1
-    cpu->exit_request = 0;
     cpu->interrupt_request = 0;
     cpu->current_tb = NULL;
     cpu->halted = 0;

This looks kind of odd to me. What's the situation you see where this matters -- is the CPU resetting itself, or is some other device in another thread triggering the CPU reset? TCG or KVM?

Seeing this in TCG. The CPU gets signaled by the IO thread while the CPU is resetting itself. If the CPU looses the race, it clears its exit_request leaving the IO thread waiting for the global lock potentially forever.

Quoted 6 lines
Quoted 2 lines

The CPU actually exits generated code but goes right back in because there is no exit_request pending.

Yes, having looked at the code I agree with you, so:

Thanks, applied to qom-cpu (with clarified commit message):
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#9 lore raw
Quoted 42 lines · Andreas Färber

Am 20.02.2014 16:58, schrieb Peter Maydell:

Quoted 41 lines · Edgar E. Iglesias
Quoted 39 lines · Peter Maydell
Quoted 22 lines · On 13 February 2014 05:07, <[email protected]> wrote:
Quoted 21 lines

From: "Edgar E. Iglesias" <[email protected]>

cpu->exit_request is part of the execution environment and should not be cleared when a CPU resets.

Otherwise, we might deadlock QEMU if a CPU resets while there is I/O going on.

---
 qom/cpu.c | 1 -
 1 file changed, 1 deletion(-)
qom/cpu.c +0 -0
index 9d62479..40d82dd 100644
@@ -195,7 +195,6 @@ static void cpu_common_reset(CPUState *cpu)
         log_cpu_state(cpu, cc->reset_dump_flags);
     }
 
Quoted 8 lines

qom/cpu.c static void cpu_common_reset(CPUState *cpu) · line 200

Quoted 4 lines
qom/cpu.c +0 -1
-    cpu->exit_request = 0;
     cpu->interrupt_request = 0;
     cpu->current_tb = NULL;
     cpu->halted = 0;

This looks kind of odd to me. What's the situation you see where this matters -- is the CPU resetting itself, or is some other device in another thread triggering the CPU reset? TCG or KVM?

Seeing this in TCG. The CPU gets signaled by the IO thread while the CPU is resetting itself. If the CPU looses the race, it clears its exit_request leaving the IO thread waiting for the global lock potentially forever.

The CPU actually exits generated code but goes right back in because there is no exit_request pending.

Quoted 6 lines
Quoted 3 lines

Yes, having looked at the code I agree with you, so:

Thanks, applied to qom-cpu (with clarified commit message):
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

I'd forgotten about this, but it's a bugfix for a hang, right? Seems to me like we ought to put it into 2.0 -- were you planning to submit it via qom-cpu for 2.0?

thanks
-- PMM

#10 lore raw
Quoted 43 lines · Peter Maydell
Quoted 42 lines · Andreas Färber

Am 20.02.2014 16:58, schrieb Peter Maydell:

Quoted 41 lines · Edgar E. Iglesias
Quoted 39 lines · Peter Maydell
Quoted 22 lines · On 13 February 2014 05:07, <[email protected]> wrote:
Quoted 21 lines

From: "Edgar E. Iglesias" <[email protected]>

cpu->exit_request is part of the execution environment and should not be cleared when a CPU resets.

Otherwise, we might deadlock QEMU if a CPU resets while there is I/O going on.

---
 qom/cpu.c | 1 -
 1 file changed, 1 deletion(-)
qom/cpu.c +0 -0
index 9d62479..40d82dd 100644
@@ -195,7 +195,6 @@ static void cpu_common_reset(CPUState *cpu)
         log_cpu_state(cpu, cc->reset_dump_flags);
     }
 
Quoted 8 lines

qom/cpu.c static void cpu_common_reset(CPUState *cpu) · line 200

Quoted 4 lines
qom/cpu.c +0 -1
-    cpu->exit_request = 0;
     cpu->interrupt_request = 0;
     cpu->current_tb = NULL;
     cpu->halted = 0;

This looks kind of odd to me. What's the situation you see where this matters -- is the CPU resetting itself, or is some other device in another thread triggering the CPU reset? TCG or KVM?

Seeing this in TCG. The CPU gets signaled by the IO thread while the CPU is resetting itself. If the CPU looses the race, it clears its exit_request leaving the IO thread waiting for the global lock potentially forever.

The CPU actually exits generated code but goes right back in because there is no exit_request pending.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Yes, having looked at the code I agree with you, so:

Thanks, applied to qom-cpu (with clarified commit message):
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

I'd forgotten about this, but it's a bugfix for a hang, right?

Hi, yes it's a bugfix for a hang.

Quoted 1 line

Seems to me like we ought to put it into 2.0 -- were you

Makes sense to me

Thanks,
Edgar

Quoted 4 lines

planning to submit it via qom-cpu for 2.0?

thanks
-- PMM