From: "Jan Beulich" Subject: Re: [PATCH] x86/HPET: mask interrupt while changing affinity Date: Wed, 20 Mar 2013 11:02:00 +0000 Message-ID: <5149A53802000078000C71DB@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> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartDFEFCA38.1__=" Return-path: In-Reply-To: <704281841.20130320111312@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 Cc: Keir Fraser , 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. --=__PartDFEFCA38.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline >>> On 20.03.13 at 11:13, Sander Eikelenboom wrote: > Wednesday, March 20, 2013, 9:22:33 AM, you wrote: >=20 >>>>> On 19.03.13 at 23:48, Sander Eikelenboom = wrote: >>> Yes they still work, and somehow using the debug keys seems to make = it=20 >>> continu for a bit (slowly and ending up in infinite loop printing = firewall=20 >>> messages) >=20 >> That information is perhaps more important than the contents of >> the log. On my way home yesterday I had already realized that >> the temporary masking of the interrupt may cause wakeup events >> to be missed. Unfortunately the fix for this is quite a bit larger >> than the three of four lines I had hoped would need to be added. >> Could you give the attached patch a try? (Without seeing the >> problem, I obviously can't say anything other about it than I >> know it compiles.) >=20 >=20 > One of your assertions failed, serial log attached ... That was due to me blindly doing the same thing to hpet_detach_channel() that I did for hpet_attach_channel(). Fixed now. Jan --=__PartDFEFCA38.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 wrong 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. And = with the event handler wanting to=0Aacquire the lock for two of its code = regions, we must not enter it with=0Athe lock 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@@ -211,7 +212,7 @@ again:=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_ch= annel *hpet_g=0A return ch;=0A }=0A =0A-static void set_channel_irq_aff= inity(const struct hpet_event_channel *ch)=0A+static void set_channel_irq_a= ffinity(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(desc);=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_irq_is_enabled());=0A+ spin_lock(&ch->= lock);=0A =0A per_cpu(cpu_bc_channel, cpu) =3D ch;=0A =0A@@ -484,31 = +492,34 @@ static void hpet_attach_channel(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_enabled());=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_available(void)=0A --=__PartDFEFCA38.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 --=__PartDFEFCA38.1__=--