Skip to contentSkip to conversation

exec: set map length to zero when returning NULL

PATCH Applied P J P 3 participants 3 messages May 26, 2020 – Jun 4, 2020

lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH v4 1/1 exec: set map length to zero when returning NULL

From: Prasad J Pandit <[email protected]>

When mapping physical memory into host's virtual address space, 'address_space_map' may return NULL if BounceBuffer is in_use. Set and return '*plen = 0' to avoid later NULL pointer dereference.

---
 exec.c                | 1 +
 include/exec/memory.h | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

Update v4: update address_space_map API doc text
-> https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg07281.html

exec.c +1 -0
index 5162f0d12f..4eea84bf66 100644
@@ -3538,6 +3538,7 @@ void *address_space_map(AddressSpace *as,
 
     if (!memory_access_is_direct(mr, is_write)) {
         if (atomic_xchg(&bounce.in_use, true)) {
+            *plen = 0;
             return NULL;
         }
         /* Avoid unbounded allocations */
include/exec/memory.h +2 -1
index e000bd2f97..8fa2d3cab2 100644
@@ -2303,7 +2303,8 @@ bool address_space_access_valid(AddressSpace *as, hwaddr addr, hwaddr len,
 /* address_space_map: map a physical memory region into a host virtual address
  *
  * May map a subset of the requested range, given by and returned in @plen.
- * May return %NULL if resources needed to perform the mapping are exhausted.
+ * May return %NULL and set *@plen to zero(0), if resources needed to perform
+ * the mapping are exhausted.
  * Use only for reads OR writes - not for read-modify-write operations.
  * Use cpu_register_map_client() to know when retrying the map operation is
  * likely to succeed.
Signature · 1 line
2.26.2
Reviewed-by on v4 1/1
#1 lore raw
Quoted 24 lines · P J P

From: Prasad J Pandit <[email protected]>

When mapping physical memory into host's virtual address space, 'address_space_map' may return NULL if BounceBuffer is in_use. Set and return '*plen = 0' to avoid later NULL pointer dereference.

---
 exec.c                | 1 +
 include/exec/memory.h | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

Update v4: update address_space_map API doc text
-> https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg07281.html

exec.c +0 -0
index 5162f0d12f..4eea84bf66 100644

exec.c void *address_space_map(AddressSpace *as, · line 3541

Quoted 4 lines
exec.c +1 -0
@@ -3538,6 +3538,7 @@ void *address_space_map(AddressSpace *as,
 
     if (!memory_access_is_direct(mr, is_write)) {
         if (atomic_xchg(&bounce.in_use, true)) {
+            *plen = 0;
Quoted 18 lines
exec.c +0 -0
             return NULL;
         }
         /* Avoid unbounded allocations */
include/exec/memory.h +2 -1
index e000bd2f97..8fa2d3cab2 100644
@@ -2303,7 +2303,8 @@ bool address_space_access_valid(AddressSpace *as, hwaddr addr, hwaddr len,
 /* address_space_map: map a physical memory region into a host virtual address
  *
  * May map a subset of the requested range, given by and returned in @plen.
- * May return %NULL if resources needed to perform the mapping are exhausted.
+ * May return %NULL and set *@plen to zero(0), if resources needed to perform
+ * the mapping are exhausted.
  * Use only for reads OR writes - not for read-modify-write operations.
  * Use cpu_register_map_client() to know when retrying the map operation is
  * likely to succeed.
#2 lore raw
In reply to P J P
Quoted 37 lines · P J P

From: Prasad J Pandit <[email protected]>

When mapping physical memory into host's virtual address space, 'address_space_map' may return NULL if BounceBuffer is in_use. Set and return '*plen = 0' to avoid later NULL pointer dereference.

---
 exec.c                | 1 +
 include/exec/memory.h | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

Update v4: update address_space_map API doc text
-> https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg07281.html

exec.c +1 -0
index 5162f0d12f..4eea84bf66 100644
@@ -3538,6 +3538,7 @@ void *address_space_map(AddressSpace *as,
 
     if (!memory_access_is_direct(mr, is_write)) {
         if (atomic_xchg(&bounce.in_use, true)) {
+            *plen = 0;
             return NULL;
         }
         /* Avoid unbounded allocations */
include/exec/memory.h +0 -0
index e000bd2f97..8fa2d3cab2 100644

include/exec/memory.h bool address_space_access_valid(AddressSpace *as, hwaddr addr, hwaddr len, · line 2310

Quoted 9 lines
include/exec/memory.h +2 -1
@@ -2303,7 +2303,8 @@ bool address_space_access_valid(AddressSpace *as, hwaddr addr, hwaddr len,
 /* address_space_map: map a physical memory region into a host virtual address
  *
  * May map a subset of the requested range, given by and returned in @plen.
- * May return %NULL if resources needed to perform the mapping are exhausted.
+ * May return %NULL and set *@plen to zero(0), if resources needed to perform
+ * the mapping are exhausted.
  * Use only for reads OR writes - not for read-modify-write operations.
  * Use cpu_register_map_client() to know when retrying the map operation is
  * likely to succeed.

Queued, thanks.

Paolo