From: "Jan Beulich" Subject: Re: [PATCH] x86/HPET: mask interrupt while changing affinity Date: Wed, 20 Mar 2013 13:38:58 +0000 Message-ID: <5149CA0202000078000C72BD@nat28.tlf.novell.com> References: <514704C202000078000C64A0@nat28.tlf.novell.com> <1701498510.20130319165336@eikelenboom.it> <514899B102000078000C6D74@nat28.tlf.novell.com> <135661008.20130319234805@eikelenboom.it> <51497FD902000078000C708A@nat28.tlf.novell.com> <704281841.20130320111312@eikelenboom.it> <5149A53802000078000C71DB@nat28.tlf.novell.com> <12710184253.20130320125556@eikelenboom.it> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part29193CE2.1__=" Return-path: In-Reply-To: <12710184253.20130320125556@eikelenboom.it> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Sander Eikelenboom , Keir Fraser Cc: xen-devel List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part29193CE2.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline >>> On 20.03.13 at 12:55, Sander Eikelenboom wrote: > Close but not entirely ;) Close to not crashing, maybe, but whether this really helps with your problem is still entirely unclear. > See attached serial log Okay, I wasn't even aware of that assertion in _spin_lock_irq(). Keir, do you really think this is necessary? In the prior patch version, handle_hpet_broadcast() had a flow like this spin_lock_irqsave(); ... spin_unlock_irqrestore(); ... if ( next_event !=3D STIME_MAX ) { spin_lock_irq(); ... spin_unlock_irqrestore(); } avoiding the saving of the flags in the second lock acquire. Said assertion makes it impossible to do this. Sander, in any case, attached a fixed version of the patch (I had to guess which of the two spin_lock_irq() calls it was, as the log was incomplete in that the stack trace got dropped, but am pretty positive that it was the one in handle_hpet_broadcast()). Jan --=__Part29193CE2.1__= Content-Type: text/plain; name="x86-HPET-affinity-masked-deliver.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-HPET-affinity-masked-deliver.patch" x86/HPET: deal with event having expired while interrupt was masked=0A=0ACo= mmit 2d8a282 ("x86/HPET: fix FSB interrupt masking") may cause the=0AHPET = event to occur while its interrupt is masked. In that case we need=0Ato = "manually" deliver the event.=0A=0AUnfortunately this requires the locking = to be changed: For one, it was=0Aalways bogus for handle_hpet_broadcast() = to use spin_unlock_irq() - the=0Afunction is being called from an = interrupt handler, and hence shouldn't=0Ablindly re-enable interrupts = (this should be left up to the generic=0Ainterrupt handling code). And = with the event handler wanting to acquire=0Athe lock for two of its code = regions, we must not enter it with the=0Alock already held. Hence move the = locking into=0Ahpet_{attach,detach}_channel(), permitting the lock to be = dropped by=0Aset_channel_irq_affinity() (which is a tail call of those = functions).=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/xen/arch/x86/hpet.c=0A+++ b/xen/arch/x86/hpet.c=0A@@ -171,13 +171,14 @@ = static void handle_hpet_broadcast(struct=0A cpumask_t mask;=0A = s_time_t now, next_event;=0A unsigned int cpu;=0A+ unsigned long = flags;=0A =0A- spin_lock_irq(&ch->lock);=0A+ spin_lock_irqsave(&ch->l= ock, flags);=0A =0A again:=0A ch->next_event =3D STIME_MAX;=0A =0A- = spin_unlock_irq(&ch->lock);=0A+ spin_unlock_irqrestore(&ch->lock, = flags);=0A =0A next_event =3D STIME_MAX;=0A cpumask_clear(&mask);= =0A@@ -205,13 +206,13 @@ again:=0A =0A if ( next_event !=3D STIME_MAX = )=0A {=0A- spin_lock_irq(&ch->lock);=0A+ spin_lock_irqsav= e(&ch->lock, flags);=0A =0A if ( next_event < ch->next_event &&=0A = reprogram_hpet_evt_channel(ch, next_event, now, 0) )=0A = goto again;=0A =0A- spin_unlock_irq(&ch->lock);=0A+ = spin_unlock_irqrestore(&ch->lock, flags);=0A }=0A }=0A =0A@@ -460,7 = +461,7 @@ static struct hpet_event_channel *hpet_g=0A return ch;=0A = }=0A =0A-static void set_channel_irq_affinity(const struct hpet_event_chann= el *ch)=0A+static void set_channel_irq_affinity(struct hpet_event_channel = *ch)=0A {=0A struct irq_desc *desc =3D irq_to_desc(ch->msi.irq);=0A = =0A@@ -470,12 +471,19 @@ static void set_channel_irq_affinity(con=0A = hpet_msi_set_affinity(desc, cpumask_of(ch->cpu));=0A hpet_msi_unmask(de= sc);=0A spin_unlock(&desc->lock);=0A+=0A+ spin_unlock(&ch->lock);=0A= +=0A+ /* We may have missed an interrupt due to the temporary masking. = */=0A+ if ( ch->event_handler && ch->next_event < NOW() )=0A+ = ch->event_handler(ch);=0A }=0A =0A static void hpet_attach_channel(unsigned= int cpu,=0A struct hpet_event_channel = *ch)=0A {=0A- ASSERT(spin_is_locked(&ch->lock));=0A+ ASSERT(!local_ir= q_is_enabled());=0A+ spin_lock(&ch->lock);=0A =0A per_cpu(cpu_bc_cha= nnel, cpu) =3D ch;=0A =0A@@ -484,31 +492,34 @@ static void hpet_attach_chan= nel(unsigned=0A ch->cpu =3D cpu;=0A =0A if ( ch->cpu !=3D cpu = )=0A- return;=0A-=0A- set_channel_irq_affinity(ch);=0A+ = spin_unlock(&ch->lock);=0A+ else=0A+ set_channel_irq_affinity(ch)= ;=0A }=0A =0A static void hpet_detach_channel(unsigned int cpu,=0A = struct hpet_event_channel *ch)=0A {=0A- = ASSERT(spin_is_locked(&ch->lock));=0A+ spin_lock_irq(&ch->lock);=0A+=0A = ASSERT(ch =3D=3D per_cpu(cpu_bc_channel, cpu));=0A =0A per_cpu(cpu_= bc_channel, cpu) =3D NULL;=0A =0A if ( cpu !=3D ch->cpu )=0A- = return;=0A-=0A- if ( cpumask_empty(ch->cpumask) )=0A+ spin_unlock= _irq(&ch->lock);=0A+ else if ( cpumask_empty(ch->cpumask) )=0A {=0A = ch->cpu =3D -1;=0A clear_bit(HPET_EVT_USED_BIT, &ch->flags)= ;=0A- return;=0A+ spin_unlock_irq(&ch->lock);=0A+ }=0A+ = else=0A+ {=0A+ ch->cpu =3D cpumask_first(ch->cpumask);=0A+ = set_channel_irq_affinity(ch);=0A+ local_irq_enable();=0A = }=0A-=0A- ch->cpu =3D cpumask_first(ch->cpumask);=0A- set_channel_irq= _affinity(ch);=0A }=0A =0A #include =0A@@ -686,11 = +697,7 @@ void hpet_broadcast_enter(void)=0A ASSERT(!local_irq_is_enabl= ed());=0A =0A if ( !(ch->flags & HPET_EVT_LEGACY) )=0A- {=0A- = spin_lock(&ch->lock);=0A hpet_attach_channel(cpu, ch);=0A- = spin_unlock(&ch->lock);=0A- }=0A =0A /* Disable LAPIC timer = interrupts. */=0A disable_APIC_timer();=0A@@ -722,11 +729,7 @@ void = hpet_broadcast_exit(void)=0A cpumask_clear_cpu(cpu, ch->cpumask);=0A = =0A if ( !(ch->flags & HPET_EVT_LEGACY) )=0A- {=0A- = spin_lock_irq(&ch->lock);=0A hpet_detach_channel(cpu, ch);=0A- = spin_unlock_irq(&ch->lock);=0A- }=0A }=0A =0A int hpet_broadcast_is_a= vailable(void)=0A --=__Part29193CE2.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part29193CE2.1__=--