diff mbox

[v2,07/11] exec: check MRU in qemu_ram_addr_from_host

Message ID 1372438702-20491-8-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini June 28, 2013, 4:58 p.m. UTC
This function is not used outside the iothread mutex, so it
can use ram_list.mru_block.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 exec.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Jan Kiszka July 1, 2013, 6:33 p.m. UTC | #1
On 2013-06-28 18:58, Paolo Bonzini wrote:
> This function is not used outside the iothread mutex, so it
> can use ram_list.mru_block.

Add a comment to qemu_ram_addr_from_host to document this requirement?

> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  exec.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index 8722420..f3d7b18 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1408,18 +1408,26 @@ int qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr)
>          return 0;
>      }
>  
> +    block = ram_list.mru_block;
> +    if (block && block->host && host - block->host < block->length) {
> +        goto found;
> +    }
> +
>      QTAILQ_FOREACH(block, &ram_list.blocks, next) {
>          /* This case append when the block is not mapped. */
>          if (block->host == NULL) {
>              continue;
>          }
>          if (host - block->host < block->length) {
> -            *ram_addr = block->offset + (host - block->host);
> -            return 0;
> +            goto found;
>          }
>      }
>  
>      return -1;
> +
> +found:
> +    *ram_addr = block->offset + (host - block->host);
> +    return 0;
>  }
>  
>  /* Some of the softmmu routines need to translate from a host pointer
> 

Beside the nit:
Reviewed-by: Jan Kiszka <jan.kiszka@siemens.com>

Jan
Paolo Bonzini July 1, 2013, 8:48 p.m. UTC | #2
Il 01/07/2013 20:33, Jan Kiszka ha scritto:
> > This function is not used outside the iothread mutex, so it
> > can use ram_list.mru_block.
> 
> Add a comment to qemu_ram_addr_from_host to document this requirement?

Right now there is hardly any documentation of what does _not_ require
the iothread mutex...  basically everything except qemu_safe_ram_ptr and
qemu_ram_ptr_length requires it.

Paolo
Jan Kiszka July 2, 2013, 7:09 a.m. UTC | #3
On 2013-07-01 22:48, Paolo Bonzini wrote:
> Il 01/07/2013 20:33, Jan Kiszka ha scritto:
>>> This function is not used outside the iothread mutex, so it
>>> can use ram_list.mru_block.
>>
>> Add a comment to qemu_ram_addr_from_host to document this requirement?
> 
> Right now there is hardly any documentation of what does _not_ require
> the iothread mutex...  basically everything except qemu_safe_ram_ptr and
> qemu_ram_ptr_length requires it.

I don't disagree regarding the current state. But that doesn't imply it
has to be preserved.

Jan
Paolo Bonzini July 2, 2013, 7:52 a.m. UTC | #4
Il 02/07/2013 09:09, Jan Kiszka ha scritto:
>> > 
>> > Right now there is hardly any documentation of what does _not_ require
>> > the iothread mutex...  basically everything except qemu_safe_ram_ptr and
>> > qemu_ram_ptr_length requires it.
> I don't disagree regarding the current state. But that doesn't imply it
> has to be preserved.

As soon as there are exec.c APIs that are BQL-safe, I'll document the
state of all of them.

In the meanwhile, I'll add a note that memory_region_find can be called
outside the BQL.

Paolo
diff mbox

Patch

diff --git a/exec.c b/exec.c
index 8722420..f3d7b18 100644
--- a/exec.c
+++ b/exec.c
@@ -1408,18 +1408,26 @@  int qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr)
         return 0;
     }
 
+    block = ram_list.mru_block;
+    if (block && block->host && host - block->host < block->length) {
+        goto found;
+    }
+
     QTAILQ_FOREACH(block, &ram_list.blocks, next) {
         /* This case append when the block is not mapped. */
         if (block->host == NULL) {
             continue;
         }
         if (host - block->host < block->length) {
-            *ram_addr = block->offset + (host - block->host);
-            return 0;
+            goto found;
         }
     }
 
     return -1;
+
+found:
+    *ram_addr = block->offset + (host - block->host);
+    return 0;
 }
 
 /* Some of the softmmu routines need to translate from a host pointer