From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anthony Liguori Subject: Re: [Qemu-devel] Re: [PATCH] Make page_find() return 0 for too-large addresses Date: Mon, 15 Sep 2008 10:29:14 -0500 Message-ID: <48CE7F4A.3060000@codemonkey.ws> References: <20080912185856.GM3982@blackpad> <48CAC809.5000901@codemonkey.ws> <20080912201406.GA10147@blackpad> <20080912204404.GB10147@blackpad> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, gcosta@redhat.com To: Eduardo Habkost Return-path: Received: from yx-out-2324.google.com ([74.125.44.29]:59905 "EHLO yx-out-2324.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754156AbYIOPaJ (ORCPT ); Mon, 15 Sep 2008 11:30:09 -0400 Received: by yx-out-2324.google.com with SMTP id 8so650290yxm.1 for ; Mon, 15 Sep 2008 08:30:08 -0700 (PDT) In-Reply-To: <20080912204404.GB10147@blackpad> Sender: kvm-owner@vger.kernel.org List-ID: Eduardo Habkost wrote: > On Fri, Sep 12, 2008 at 05:14:06PM -0300, Eduardo Habkost wrote: > =20 >> On Fri, Sep 12, 2008 at 02:50:33PM -0500, Anthony Liguori wrote: >> =20 >>> Eduardo Habkost wrote: >>> =20 >>>> On some cases, such as under KVM, tb_invalidate_phys_page_range() >>>> may be called for large addresses, when qemu is configured to more= than >>>> 4GB of RAM. >>>> >>>> On these cases, qemu was crashing because it was using an index to= o >>>> large for l1_map[], that supports only 32-bit addresses when compi= ling >>>> without CONFIG_USER_ONLY. >>>> =20 >>>> =20 > > =20 >> BTW, I've just noticed page_find_alloc() has this: >> >> #if TARGET_LONG_BITS > 32 >> /* Host memory outside guest VM. For 32-bit targets we have alr= eady >> excluded high addresses. */ >> if (index > ((target_ulong)L2_SIZE * L1_SIZE)) >> return NULL; >> #endif >> >> So, we can just use a similar check on page_find(). >> =20 > > New patch, reusing the range check from page_find_alloc() on > page_find(). Untested. > =20 Have you tested this patch yet? I like to avoid being the first one to= =20 test something when it's not my code :-) Regards, Anthony Liguori > Signed-off-by: Eduardo Habkost > --- > Index: qemu/exec.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- qemu/exec.c (revis=E3o 5200) > +++ qemu/exec.c (c=F3pia de trabalho) > @@ -279,17 +279,24 @@ static void page_init(void) > #endif > } > =20 > -static inline PageDesc *page_find_alloc(target_ulong index) > +static inline PageDesc **page_l1_map(target_ulong index) > { > - PageDesc **lp, *p; > - > #if TARGET_LONG_BITS > 32 > /* Host memory outside guest VM. For 32-bit targets we have alr= eady > excluded high addresses. */ > if (index > ((target_ulong)L2_SIZE * L1_SIZE)) > return NULL; > #endif > - lp =3D &l1_map[index >> L2_BITS]; > + return &l1_map[index >> L2_BITS]; > +} > + > +static inline PageDesc *page_find_alloc(target_ulong index) > +{ > + PageDesc **lp, *p; > + lp =3D page_l1_map(index); > + if (!lp) > + return NULL; > + > p =3D *lp; > if (!p) { > /* allocate if not found */ > @@ -316,9 +323,12 @@ static inline PageDesc *page_find_alloc( > =20 > static inline PageDesc *page_find(target_ulong index) > { > - PageDesc *p; > + PageDesc **lp, *p; > + lp =3D page_l1_map(index); > + if (!lp) > + return NULL; > =20 > - p =3D l1_map[index >> L2_BITS]; > + p =3D *lp; > if (!p) > return 0; > return p + (index & (L2_SIZE - 1)); > > > =20