All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Grall <julien@xen.org>
To: xen-devel@lists.xenproject.org
Cc: Luca.Fancellu@arm.com, michal.orzel@amd.com, Henry.Wang@arm.com,
	Julien Grall <jgrall@amazon.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>,
	Bertrand Marquis <bertrand.marquis@arm.com>,
	Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Subject: [PATCH 4/7] xen/arm: page: Consolidate write_pte() and clarify the documentation
Date: Mon, 19 Jun 2023 18:01:12 +0100	[thread overview]
Message-ID: <20230619170115.81398-5-julien@xen.org> (raw)
In-Reply-To: <20230619170115.81398-1-julien@xen.org>

From: Julien Grall <jgrall@amazon.com>

The implementation of write_pte() is pretty much the same on arm32
and arm64. So it would be good to consolidate it as this would help
to clarify the requirements when using the helper.

Take the opportunity to switch from assembly to call macros. Note there
is a difference on arm32 because the option was not specified. But this
meant 'sy' (system wide).

Futhermore, the requirements for the ISB is incomplete. Per the Arm Arm,
(Armv7 DDI406C.d A3.8.3 and Armv8 DDI 0487J.a B2.3.12), DSB will only
affect explicit accesses. So an ISB is necessary after DSB to ensure
the completion. Having an ISB after each update to the page-tables is
probably too much, so let the caller add the instruction when it is
convenient.

Lastly, the barrier in write_pte() may be too restrictive but I haven't
yet find the proper section(s) in the Arm Arm.

Signed-off-by: Julien Grall <jgrall@amazon.com>
----

I am a bit split on whether we should add an ISB in write_pte(). It
would make easier for the developper, but would likely force a pipeline
flush too often.

It might also be possible to drop the ISB (and even DSB) when updating
stage-2 PTE (Linux already does it, see 120798d2e7d1). But I am not sure
this is worth it in Xen.
---
 xen/arch/arm/include/asm/arm32/page.h | 16 ----------------
 xen/arch/arm/include/asm/arm64/page.h | 11 -----------
 xen/arch/arm/include/asm/page.h       | 17 +++++++++++++++++
 3 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/xen/arch/arm/include/asm/arm32/page.h b/xen/arch/arm/include/asm/arm32/page.h
index 715a9e4fef48..6d1ff0636ce3 100644
--- a/xen/arch/arm/include/asm/arm32/page.h
+++ b/xen/arch/arm/include/asm/arm32/page.h
@@ -3,22 +3,6 @@
 
 #ifndef __ASSEMBLY__
 
-/* Write a pagetable entry.
- *
- * If the table entry is changing a text mapping, it is responsibility
- * of the caller to issue an ISB after write_pte.
- */
-static inline void write_pte(lpae_t *p, lpae_t pte)
-{
-    asm volatile (
-        /* Ensure any writes have completed with the old mappings. */
-        "dsb;"
-        /* Safely write the entry (STRD is atomic on CPUs that support LPAE) */
-        "strd %0, %H0, [%1];"
-        "dsb;"
-        : : "r" (pte.bits), "r" (p) : "memory");
-}
-
 /* Inline ASM to invalidate dcache on register R (may be an inline asm operand) */
 #define __invalidate_dcache_one(R) STORE_CP32(R, DCIMVAC)
 
diff --git a/xen/arch/arm/include/asm/arm64/page.h b/xen/arch/arm/include/asm/arm64/page.h
index 0cba2663733b..4f58c0382adc 100644
--- a/xen/arch/arm/include/asm/arm64/page.h
+++ b/xen/arch/arm/include/asm/arm64/page.h
@@ -5,17 +5,6 @@
 
 #include <asm/alternative.h>
 
-/* Write a pagetable entry */
-static inline void write_pte(lpae_t *p, lpae_t pte)
-{
-    asm volatile (
-        /* Ensure any writes have completed with the old mappings. */
-        "dsb sy;"
-        "str %0, [%1];"         /* Write the entry */
-        "dsb sy;"
-        : : "r" (pte.bits), "r" (p) : "memory");
-}
-
 /* Inline ASM to invalidate dcache on register R (may be an inline asm operand) */
 #define __invalidate_dcache_one(R) "dc ivac, %" #R ";"
 
diff --git a/xen/arch/arm/include/asm/page.h b/xen/arch/arm/include/asm/page.h
index e7cd62190c7f..ea96983ab976 100644
--- a/xen/arch/arm/include/asm/page.h
+++ b/xen/arch/arm/include/asm/page.h
@@ -126,6 +126,7 @@
 #include <xen/errno.h>
 #include <xen/types.h>
 #include <xen/lib.h>
+#include <asm/atomic.h>
 #include <asm/system.h>
 
 #if defined(CONFIG_ARM_32)
@@ -237,6 +238,22 @@ static inline int clean_and_invalidate_dcache_va_range
             : : "r" (_p), "m" (*_p));                                   \
 } while (0)
 
+/*
+ * Write a pagetable entry.
+ *
+ * It is the responsibility of the caller to issue an ISB (if a new entry)
+ * or a TLB flush (if modified or removed) after write_pte().
+ */
+static inline void write_pte(lpae_t *p, lpae_t pte)
+{
+    /* Ensure any writes have completed with the old mappings. */
+    dsb(sy);
+    /* Safely write the entry. This should always be an atomic write. */
+    write_atomic(p, pte);
+    dsb(sy);
+}
+
+
 /* Flush the dcache for an entire page. */
 void flush_page_to_ram(unsigned long mfn, bool sync_icache);
 
-- 
2.40.1



  parent reply	other threads:[~2023-06-19 17:01 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-19 17:01 [PATCH 0/7] xen/arm: Add some missing ISBs after updating the PTEs Julien Grall
2023-06-19 17:01 ` [PATCH 1/7] xen/arm32: head: Add missing isb in setup_fixmap() Julien Grall
2023-06-20  3:06   ` Henry Wang
2023-06-20 11:10   ` Luca Fancellu
2023-07-04 14:53   ` Bertrand Marquis
2023-06-19 17:01 ` [PATCH 2/7] xen/arm32: head: Add mising isb in switch_to_runtime_mapping() Julien Grall
2023-06-20  3:06   ` Henry Wang
2023-06-20 11:13   ` Luca Fancellu
2023-07-04 14:52   ` Bertrand Marquis
2023-06-19 17:01 ` [PATCH 3/7] xen/arm64: head: Add missing isb in setup_fixmap() Julien Grall
2023-06-20  3:06   ` Henry Wang
2023-06-20 11:14   ` Luca Fancellu
2023-06-21  9:33   ` Michal Orzel
2023-06-21 10:02     ` Julien Grall
2023-06-21 10:13       ` Michal Orzel
2023-06-24  7:49         ` Julien Grall
2023-07-04 14:48   ` Bertrand Marquis
2023-06-19 17:01 ` Julien Grall [this message]
2023-06-20  3:07   ` [PATCH 4/7] xen/arm: page: Consolidate write_pte() and clarify the documentation Henry Wang
2023-07-04 15:06   ` Bertrand Marquis
2023-07-04 19:04     ` Julien Grall
2023-06-19 17:01 ` [PATCH 5/7] xen/arm: pmap: Add missing ISB in arch_pmap_map() Julien Grall
2023-06-20  3:07   ` Henry Wang
2023-07-04 14:56   ` Bertrand Marquis
2023-06-19 17:01 ` [PATCH 6/7] xen/arm: mm: Add missing ISB in xen_pt_update() Julien Grall
2023-06-20  3:07   ` Henry Wang
2023-07-04 14:54   ` Bertrand Marquis
2023-06-19 17:01 ` [PATCH 7/7] xen/arm32: head: Widen the use of the temporary mapping Julien Grall
2023-06-20  3:07   ` Henry Wang
2023-07-04 15:07   ` Bertrand Marquis
2023-07-04 19:08 ` [PATCH 0/7] xen/arm: Add some missing ISBs after updating the PTEs Julien Grall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230619170115.81398-5-julien@xen.org \
    --to=julien@xen.org \
    --cc=Henry.Wang@arm.com \
    --cc=Luca.Fancellu@arm.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=bertrand.marquis@arm.com \
    --cc=jgrall@amazon.com \
    --cc=michal.orzel@amd.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.