From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KfG1j-0007kb-Ic for qemu-devel@nongnu.org; Mon, 15 Sep 2008 11:30:11 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KfG1h-0007hu-HG for qemu-devel@nongnu.org; Mon, 15 Sep 2008 11:30:10 -0400 Received: from [199.232.76.173] (port=38421 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KfG1h-0007hn-BH for qemu-devel@nongnu.org; Mon, 15 Sep 2008 11:30:09 -0400 Received: from yx-out-1718.google.com ([74.125.44.152]:11344) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KfG1h-0000VK-8e for qemu-devel@nongnu.org; Mon, 15 Sep 2008 11:30:09 -0400 Received: by yx-out-1718.google.com with SMTP id 3so630093yxi.82 for ; Mon, 15 Sep 2008 08:30:08 -0700 (PDT) Message-ID: <48CE7F4A.3060000@codemonkey.ws> Date: Mon, 15 Sep 2008 10:29:14 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] Re: [PATCH] Make page_find() return 0 for too-large addresses References: <20080912185856.GM3982@blackpad> <48CAC809.5000901@codemonkey.ws> <20080912201406.GA10147@blackpad> <20080912204404.GB10147@blackpad> In-Reply-To: <20080912204404.GB10147@blackpad> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eduardo Habkost Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, gcosta@redhat.com Eduardo Habkost wrote: > On Fri, Sep 12, 2008 at 05:14:06PM -0300, Eduardo Habkost wrote: > >> On Fri, Sep 12, 2008 at 02:50:33PM -0500, Anthony Liguori wrote: >> >>> Eduardo Habkost wrote: >>> >>>> 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 too >>>> large for l1_map[], that supports only 32-bit addresses when compiling >>>> without CONFIG_USER_ONLY. >>>> >>>> > > >> 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 already >> 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(). >> > > New patch, reusing the range check from page_find_alloc() on > page_find(). Untested. > Have you tested this patch yet? I like to avoid being the first one to test something when it's not my code :-) Regards, Anthony Liguori > Signed-off-by: Eduardo Habkost > --- > Index: qemu/exec.c > =================================================================== > --- qemu/exec.c (revisão 5200) > +++ qemu/exec.c (cópia de trabalho) > @@ -279,17 +279,24 @@ static void page_init(void) > #endif > } > > -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 already > excluded high addresses. */ > if (index > ((target_ulong)L2_SIZE * L1_SIZE)) > return NULL; > #endif > - lp = &l1_map[index >> L2_BITS]; > + return &l1_map[index >> L2_BITS]; > +} > + > +static inline PageDesc *page_find_alloc(target_ulong index) > +{ > + PageDesc **lp, *p; > + lp = page_l1_map(index); > + if (!lp) > + return NULL; > + > p = *lp; > if (!p) { > /* allocate if not found */ > @@ -316,9 +323,12 @@ static inline PageDesc *page_find_alloc( > > static inline PageDesc *page_find(target_ulong index) > { > - PageDesc *p; > + PageDesc **lp, *p; > + lp = page_l1_map(index); > + if (!lp) > + return NULL; > > - p = l1_map[index >> L2_BITS]; > + p = *lp; > if (!p) > return 0; > return p + (index & (L2_SIZE - 1)); > > >