diff mbox

[RFC,31/38] cpu: protect l1_map with tb_lock in full-system mode

Message ID 1440375847-17603-32-git-send-email-cota@braap.org
State New
Headers show

Commit Message

Emilio Cota Aug. 24, 2015, 12:24 a.m. UTC
Note that user-only uses mmap_lock for this.

Signed-off-by: Emilio G. Cota <cota@braap.org>
---
 translate-all.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

Comments

Paolo Bonzini Aug. 24, 2015, 1:07 a.m. UTC | #1
On 23/08/2015 17:24, Emilio G. Cota wrote:
> Note that user-only uses mmap_lock for this.
> 
> Signed-off-by: Emilio G. Cota <cota@braap.org>

Why is this needed?  The RCU-like page_find should work just fine.

Paolo

> ---
>  translate-all.c | 31 +++++++++++++++++++++++--------
>  1 file changed, 23 insertions(+), 8 deletions(-)
> 
> diff --git a/translate-all.c b/translate-all.c
> index e7b4a31..8f8c402 100644
> --- a/translate-all.c
> +++ b/translate-all.c
> @@ -1203,8 +1203,9 @@ void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end)
>   * Called with mmap_lock held for user-mode emulation
>   * If called from generated code, iothread mutex must not be held.
>   */
> -void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,
> -                                   int is_cpu_write_access)
> +static void
> +tb_invalidate_phys_page_range_locked(tb_page_addr_t start, tb_page_addr_t end,
> +                                     int is_cpu_write_access)
>  {
>      TranslationBlock *tb, *tb_next, *saved_tb;
>      CPUState *cpu = current_cpu;
> @@ -1236,7 +1237,6 @@ void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,
>      /* we remove all the TBs in the range [start, end[ */
>      /* XXX: see if in some cases it could be faster to invalidate all
>         the code */
> -    tb_lock();
>      tb = p->first_tb;
>      while (tb != NULL) {
>          n = (uintptr_t)tb & 3;
> @@ -1310,14 +1310,19 @@ void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,
>          cpu_resume_from_signal(cpu, NULL);
>      }
>  #endif
> +}
> +
> +void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,
> +                                   int is_cpu_write_access)
> +{
> +    tb_lock();
> +    tb_invalidate_phys_page_range_locked(start, end, is_cpu_write_access);
>      tb_unlock();
>  }
>  
>  #ifdef CONFIG_SOFTMMU
> -/* len must be <= 8 and start must be a multiple of len.
> - * Called via softmmu_template.h, with iothread mutex not held.
> - */
> -void tb_invalidate_phys_page_fast(tb_page_addr_t start, int len)
> +
> +static void tb_invalidate_phys_page_fast_locked(tb_page_addr_t start, int len)
>  {
>      PageDesc *p;
>  
> @@ -1352,9 +1357,19 @@ void tb_invalidate_phys_page_fast(tb_page_addr_t start, int len)
>          }
>      } else {
>      do_invalidate:
> -        tb_invalidate_phys_page_range(start, start + len, 1);
> +        tb_invalidate_phys_page_range_locked(start, start + len, 1);
>      }
>  }
> +
> +/* len must be <= 8 and start must be a multiple of len.
> + * Called via softmmu_template.h, with iothread mutex not held.
> + */
> +void tb_invalidate_phys_page_fast(tb_page_addr_t start, int len)
> +{
> +    tb_lock();
> +    tb_invalidate_phys_page_fast_locked(start, len);
> +    tb_unlock();
> +}
>  #else
>  /* Called with mmap_lock held.  */
>  static void tb_invalidate_phys_page(tb_page_addr_t addr,
>
Emilio Cota Aug. 25, 2015, 9:54 p.m. UTC | #2
On Sun, Aug 23, 2015 at 18:07:04 -0700, Paolo Bonzini wrote:
> On 23/08/2015 17:24, Emilio G. Cota wrote:
> > Note that user-only uses mmap_lock for this.
> > 
> > Signed-off-by: Emilio G. Cota <cota@braap.org>
> 
> Why is this needed?  The RCU-like page_find should work just fine.

Ouch, you're right, forgot about that. Patch 30, which adds the
tb_lock assertions, should change as well to only check for
have_tb_lock in page_find when alloc==1.

Thanks,

		Emilio
diff mbox

Patch

diff --git a/translate-all.c b/translate-all.c
index e7b4a31..8f8c402 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -1203,8 +1203,9 @@  void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end)
  * Called with mmap_lock held for user-mode emulation
  * If called from generated code, iothread mutex must not be held.
  */
-void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,
-                                   int is_cpu_write_access)
+static void
+tb_invalidate_phys_page_range_locked(tb_page_addr_t start, tb_page_addr_t end,
+                                     int is_cpu_write_access)
 {
     TranslationBlock *tb, *tb_next, *saved_tb;
     CPUState *cpu = current_cpu;
@@ -1236,7 +1237,6 @@  void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,
     /* we remove all the TBs in the range [start, end[ */
     /* XXX: see if in some cases it could be faster to invalidate all
        the code */
-    tb_lock();
     tb = p->first_tb;
     while (tb != NULL) {
         n = (uintptr_t)tb & 3;
@@ -1310,14 +1310,19 @@  void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,
         cpu_resume_from_signal(cpu, NULL);
     }
 #endif
+}
+
+void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,
+                                   int is_cpu_write_access)
+{
+    tb_lock();
+    tb_invalidate_phys_page_range_locked(start, end, is_cpu_write_access);
     tb_unlock();
 }
 
 #ifdef CONFIG_SOFTMMU
-/* len must be <= 8 and start must be a multiple of len.
- * Called via softmmu_template.h, with iothread mutex not held.
- */
-void tb_invalidate_phys_page_fast(tb_page_addr_t start, int len)
+
+static void tb_invalidate_phys_page_fast_locked(tb_page_addr_t start, int len)
 {
     PageDesc *p;
 
@@ -1352,9 +1357,19 @@  void tb_invalidate_phys_page_fast(tb_page_addr_t start, int len)
         }
     } else {
     do_invalidate:
-        tb_invalidate_phys_page_range(start, start + len, 1);
+        tb_invalidate_phys_page_range_locked(start, start + len, 1);
     }
 }
+
+/* len must be <= 8 and start must be a multiple of len.
+ * Called via softmmu_template.h, with iothread mutex not held.
+ */
+void tb_invalidate_phys_page_fast(tb_page_addr_t start, int len)
+{
+    tb_lock();
+    tb_invalidate_phys_page_fast_locked(start, len);
+    tb_unlock();
+}
 #else
 /* Called with mmap_lock held.  */
 static void tb_invalidate_phys_page(tb_page_addr_t addr,