From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ingo Molnar Subject: Re: kvm vmload/vmsave vs tss.ist Date: Thu, 25 Dec 2008 19:18:10 +0100 Message-ID: <20081225181810.GA1548@elte.hu> References: <49539FD0.7070103@redhat.com> <20081225151757.GA25117@elte.hu> <4953AAE5.4000708@redhat.com> <20081225162107.GB14486@elte.hu> <20081225164232.GA25195@elte.hu> <4953C57F.70502@redhat.com> <20081225175821.GA23390@elte.hu> <4953CD1A.5090906@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: "H. Peter Anvin" , Joerg Roedel , Benjamin Serebrin , linux-kernel , kvm@vger.kernel.org, Alexander Graf , Arjan van de Ven , Alexander van Heukelum To: Avi Kivity Return-path: Received: from mx3.mail.elte.hu ([157.181.1.138]:57365 "EHLO mx3.mail.elte.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753939AbYLYSSa (ORCPT ); Thu, 25 Dec 2008 13:18:30 -0500 Content-Disposition: inline In-Reply-To: <4953CD1A.5090906@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: * Avi Kivity wrote: > Ingo Molnar wrote: >>> I think it's enough to switch %rsp before incrementing irqcount, no? >>> >> >> no - that would introduce a small race: if an exception (say an NMI or >> MCE, or a debug trap) happens in that small window then the exception >> context thinks that it's on the IRQ stack already, and would use the >> task stack. >> >> > > I'm suggesting > > check irqcount > if (wasnt_in_irq) > rsp = irqstack > ++irqcount > > If the NMI happens before the increment, we'll switch the stack > unconditionally, and if the NMI happens after the increment, then we > won't switch the stack, but we're guaranteed to be on the irqstack > anyway. The window size is negative :) > > Similarly, the exit path should be > > oldstack_reg = oldstack; > --irqcount; > rsp = oldstack_register; > > To guarantee that by the time we decrement irqcount, we don't need the > stack anymore. agreed, something like this would work too. My suggestion, to eliminate irqcount altogether and just check RSP against the known-irqstack-range, could result in slightly smaller (and thus faster) code, but it's a marginal difference at best. Ingo