diff mbox

Re: [PATCH 1/2] Fix segfault in mmio subpage handling code.

Message ID 20100729104145.GA24773@redhat.com
State New
Headers show

Commit Message

Gleb Natapov July 29, 2010, 10:41 a.m. UTC
Use this one instead.

On Wed, Jul 28, 2010 at 06:13:22PM +0300, Gleb Natapov wrote:
> It is possible that subpage mmio is registered over existing memory
> page. When this happens "memory" will have real memory address and not
> index into io_mem array so next access to the page will generate
> segfault. It is uncommon to have some part of a page to be accessed as
> memory and some as mmio, but qemu shouldn't crash even when guest does
> stupid things. So lets just pretend that the rest of the page is
> unassigned if guest configure part of the memory page as mmio.
> 
> Signed-off-by: Gleb Natapov <gleb@redhat.com>

--
			Gleb.

Comments

Marcelo Tosatti July 29, 2010, 9:16 p.m. UTC | #1
On Thu, Jul 29, 2010 at 01:41:45PM +0300, Gleb Natapov wrote:
> Use this one instead.
> 
> On Wed, Jul 28, 2010 at 06:13:22PM +0300, Gleb Natapov wrote:
> > It is possible that subpage mmio is registered over existing memory
> > page. When this happens "memory" will have real memory address and not
> > index into io_mem array so next access to the page will generate
> > segfault. It is uncommon to have some part of a page to be accessed as
> > memory and some as mmio, but qemu shouldn't crash even when guest does
> > stupid things. So lets just pretend that the rest of the page is
> > unassigned if guest configure part of the memory page as mmio.
> > 
> > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> 
> diff --git a/exec.c b/exec.c
> index 5e9a5b7..53483bc 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -3362,6 +3362,8 @@ static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end,
>      printf("%s: %p start %08x end %08x idx %08x eidx %08x mem %ld\n", __func__,
>             mmio, start, end, idx, eidx, memory);
>  #endif
> +    if ((memory & ~TARGET_PAGE_MASK) == IO_MEM_RAM)
> +        memory = IO_MEM_UNASSIGNED;
>      memory = (memory >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1);
>      for (; idx <= eidx; idx++) {
>          mmio->sub_io_index[idx] = memory;

Looks good to me.
Blue Swirl Aug. 28, 2010, 8:49 a.m. UTC | #2
Thanks, applied.

On Thu, Jul 29, 2010 at 9:16 PM, Marcelo Tosatti <mtosatti@redhat.com> wrote:
> On Thu, Jul 29, 2010 at 01:41:45PM +0300, Gleb Natapov wrote:
>> Use this one instead.
>>
>> On Wed, Jul 28, 2010 at 06:13:22PM +0300, Gleb Natapov wrote:
>> > It is possible that subpage mmio is registered over existing memory
>> > page. When this happens "memory" will have real memory address and not
>> > index into io_mem array so next access to the page will generate
>> > segfault. It is uncommon to have some part of a page to be accessed as
>> > memory and some as mmio, but qemu shouldn't crash even when guest does
>> > stupid things. So lets just pretend that the rest of the page is
>> > unassigned if guest configure part of the memory page as mmio.
>> >
>> > Signed-off-by: Gleb Natapov <gleb@redhat.com>
>>
>> diff --git a/exec.c b/exec.c
>> index 5e9a5b7..53483bc 100644
>> --- a/exec.c
>> +++ b/exec.c
>> @@ -3362,6 +3362,8 @@ static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end,
>>      printf("%s: %p start %08x end %08x idx %08x eidx %08x mem %ld\n", __func__,
>>             mmio, start, end, idx, eidx, memory);
>>  #endif
>> +    if ((memory & ~TARGET_PAGE_MASK) == IO_MEM_RAM)
>> +        memory = IO_MEM_UNASSIGNED;
>>      memory = (memory >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1);
>>      for (; idx <= eidx; idx++) {
>>          mmio->sub_io_index[idx] = memory;
>
> Looks good to me.
>
>
>
diff mbox

Patch

diff --git a/exec.c b/exec.c
index 5e9a5b7..53483bc 100644
--- a/exec.c
+++ b/exec.c
@@ -3362,6 +3362,8 @@  static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end,
     printf("%s: %p start %08x end %08x idx %08x eidx %08x mem %ld\n", __func__,
            mmio, start, end, idx, eidx, memory);
 #endif
+    if ((memory & ~TARGET_PAGE_MASK) == IO_MEM_RAM)
+        memory = IO_MEM_UNASSIGNED;
     memory = (memory >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1);
     for (; idx <= eidx; idx++) {
         mmio->sub_io_index[idx] = memory;