From: "Jan Beulich" Subject: Re: Deadlock in stdvga_mem_accept() with emulation Date: Mon, 13 Jul 2015 10:41:24 +0100 Message-ID: <55A3A3E4020000780009012B@mail.emea.novell.com> References: <55A36D67.3050203@bitdefender.com> <55A37285.3050304@citrix.com> <55A37BD5.2070508@bitdefender.com> <9AAE0902D5BC7E449B7C8E4E778ABCD02F4BF5BC@AMSPEX01CL02.citrite.net> <55A37ED9.7050909@bitdefender.com> <9AAE0902D5BC7E449B7C8E4E778ABCD02F4BF5F8@AMSPEX01CL02.citrite.net> <55A3A0A802000078000900E1@mail.emea.novell.com> <9AAE0902D5BC7E449B7C8E4E778ABCD02F4BF764@AMSPEX01CL02.citrite.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <9AAE0902D5BC7E449B7C8E4E778ABCD02F4BF764@AMSPEX01CL02.citrite.net> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Paul Durrant Cc: Andrew Cooper , "Keir (Xen.org)" , Razvan Cojocaru , "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org >>> On 13.07.15 at 11:30, wrote: >> -----Original Message----- >> From: Jan Beulich [mailto:JBeulich@suse.com] >> Sent: 13 July 2015 10:28 >> To: Paul Durrant >> Cc: Razvan Cojocaru; Andrew Cooper; xen-devel@lists.xen.org; Keir >> (Xen.org) >> Subject: RE: [Xen-devel] Deadlock in stdvga_mem_accept() with emulation >> >> >>> On 13.07.15 at 11:05, wrote: >> > --- a/xen/arch/x86/hvm/stdvga.c >> > +++ b/xen/arch/x86/hvm/stdvga.c >> > @@ -490,11 +490,18 @@ static bool_t stdvga_mem_accept(const struct >> > hvm_io_handle >> > { >> > struct hvm_hw_stdvga *s = ¤t->domain- >> >arch.hvm_domain.stdvga; >> > >> > + /* >> > + * The range check must be done without taking any locks, to avoid >> > + * deadlock when hvm_mmio_internal() is called from >> > + * hvm_copy_to/from_guest_phys() in hvm_process_io_intercept(). >> > + */ >> > + if ( (hvm_mmio_first_byte(p) < VGA_MEM_BASE) || >> > + (hvm_mmio_last_byte(p) >= (VGA_MEM_BASE + VGA_MEM_SIZE)) >> ) >> > + return 0; >> > + >> > spin_lock(&s->lock); >> > >> > - if ( !s->stdvga || >> > - (hvm_mmio_first_byte(p) < VGA_MEM_BASE) || >> > - (hvm_mmio_last_byte(p) >= (VGA_MEM_BASE + VGA_MEM_SIZE)) ) >> > + if ( !s->stdvga ) >> > goto reject; >> > >> > if ( p->dir == IOREQ_WRITE && p->count > 1 ) >> >> But won't the problem continue to exist if the address falls within the >> VGA range? I.e. isn't the problem that the two uses of >> hvm_mmio_internal() are quite different - while >> hvm_hap_nested_page_fault() immediately afterwards calls a >> handle_mmio() variant (which would even seem to call for the lock not >> getting dropped between them), __hvm_copy() uses it as just a check. >> >> I.e. perhaps better to convert the lock to a recursive one? > > I think we are ok because the stdvga model will never actually accept the > I/O since MMIO <-> MMIO rep mov is explicitly disallowed. True, for now at least. Jan