diff mbox series

[07/24] accel/tcg: Introduce page_check_range_empty

Message ID 20230630132159.376995-8-richard.henderson@linaro.org
State Superseded
Headers show
Series linux-user: mmap range fixes | expand

Commit Message

Richard Henderson June 30, 2023, 1:21 p.m. UTC
Examine the interval tree to validate that a region
has no existing mappings.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/exec/cpu-all.h | 11 +++++++++++
 accel/tcg/user-exec.c  |  7 +++++++
 2 files changed, 18 insertions(+)

Comments

Alex Bennée July 3, 2023, 9:45 a.m. UTC | #1
Richard Henderson <richard.henderson@linaro.org> writes:

> Examine the interval tree to validate that a region
> has no existing mappings.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  include/exec/cpu-all.h | 11 +++++++++++
>  accel/tcg/user-exec.c  |  7 +++++++
>  2 files changed, 18 insertions(+)
>
> diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
> index 8018ce783e..5b2c230d52 100644
> --- a/include/exec/cpu-all.h
> +++ b/include/exec/cpu-all.h
> @@ -224,6 +224,17 @@ void page_set_flags(target_ulong start, target_ulong last, int flags);
>  void page_reset_target_data(target_ulong start, target_ulong last);
>  int page_check_range(target_ulong start, target_ulong len, int flags);
>  
> +/**
> + * page_check_range_empty:
> + * @start: first byte of range
> + * @last: last byte of range

* Context: holding mmap lock

Otherwise:

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Richard Henderson July 3, 2023, 10:33 a.m. UTC | #2
On 7/3/23 11:45, Alex Bennée wrote:
> 
> Richard Henderson <richard.henderson@linaro.org> writes:
> 
>> Examine the interval tree to validate that a region
>> has no existing mappings.
>>
>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>> ---
>>   include/exec/cpu-all.h | 11 +++++++++++
>>   accel/tcg/user-exec.c  |  7 +++++++
>>   2 files changed, 18 insertions(+)
>>
>> diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
>> index 8018ce783e..5b2c230d52 100644
>> --- a/include/exec/cpu-all.h
>> +++ b/include/exec/cpu-all.h
>> @@ -224,6 +224,17 @@ void page_set_flags(target_ulong start, target_ulong last, int flags);
>>   void page_reset_target_data(target_ulong start, target_ulong last);
>>   int page_check_range(target_ulong start, target_ulong len, int flags);
>>   
>> +/**
>> + * page_check_range_empty:
>> + * @start: first byte of range
>> + * @last: last byte of range
> 
> * Context: holding mmap lock

Is this parsable magic? Two lines below I do say "memory lock must be held"...


r~

> 
> Otherwise:
> 
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> 
>
Alex Bennée July 3, 2023, 11:36 a.m. UTC | #3
Richard Henderson <richard.henderson@linaro.org> writes:

> On 7/3/23 11:45, Alex Bennée wrote:
>> Richard Henderson <richard.henderson@linaro.org> writes:
>> 
>>> Examine the interval tree to validate that a region
>>> has no existing mappings.
>>>
>>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>>> ---
>>>   include/exec/cpu-all.h | 11 +++++++++++
>>>   accel/tcg/user-exec.c  |  7 +++++++
>>>   2 files changed, 18 insertions(+)
>>>
>>> diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
>>> index 8018ce783e..5b2c230d52 100644
>>> --- a/include/exec/cpu-all.h
>>> +++ b/include/exec/cpu-all.h
>>> @@ -224,6 +224,17 @@ void page_set_flags(target_ulong start, target_ulong last, int flags);
>>>   void page_reset_target_data(target_ulong start, target_ulong last);
>>>   int page_check_range(target_ulong start, target_ulong len, int flags);
>>>   +/**
>>> + * page_check_range_empty:
>>> + * @start: first byte of range
>>> + * @last: last byte of range
>> * Context: holding mmap lock
>
> Is this parsable magic? Two lines below I do say "memory lock must be
> held"...

Yeah - the kerneldoc describes it as:

 * Context: Describes whether the function can sleep, what locks it takes,
 *          releases, or expects to be held. It can extend over multiple
 *          lines.

We use it in a couple of places in the existing code although mostly
referring to the BQL.

>
>
> r~
>
>> Otherwise:
>> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
>>
diff mbox series

Patch

diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index 8018ce783e..5b2c230d52 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -224,6 +224,17 @@  void page_set_flags(target_ulong start, target_ulong last, int flags);
 void page_reset_target_data(target_ulong start, target_ulong last);
 int page_check_range(target_ulong start, target_ulong len, int flags);
 
+/**
+ * page_check_range_empty:
+ * @start: first byte of range
+ * @last: last byte of range
+ *
+ * Return true if the entire range [@start, @last] is unmapped.
+ * The memory lock must be held, as the caller will want to ensure
+ * the result stays true until a new mapping can be installed.
+ */
+bool page_check_range_empty(target_ulong start, target_ulong last);
+
 /**
  * page_get_target_data(address)
  * @address: guest virtual address
diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c
index 8fbcbf9771..25c605dc1b 100644
--- a/accel/tcg/user-exec.c
+++ b/accel/tcg/user-exec.c
@@ -598,6 +598,13 @@  int page_check_range(target_ulong start, target_ulong len, int flags)
     return ret;
 }
 
+bool page_check_range_empty(target_ulong start, target_ulong last)
+{
+    assert(last >= start);
+    assert_memory_lock();
+    return pageflags_find(start, last) == NULL;
+}
+
 void page_protect(tb_page_addr_t address)
 {
     PageFlagsNode *p;