All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 1/2] arm64: mm: Rename asid2idx() to ctxid2asid()
@ 2021-12-09  1:42 ` Yunfeng Ye
  0 siblings, 0 replies; 6+ messages in thread
From: Yunfeng Ye @ 2021-12-09  1:42 UTC (permalink / raw)
  To: catalin.marinas, will, wangkefeng.wang, yeyunfeng,
	linux-arm-kernel, linux-kernel
  Cc: wuxu.wu, Hewenliang

The commit 0c8ea531b774 ("arm64: mm: Allocate ASIDs in pairs") introduce
the asid2idx and idx2asid macro, but these macros are not really useful
after the commit f88f42f853a8 ("arm64: context: Free up kernel ASIDs if
KPTI is not in use").

The code "(asid & ~ASID_MASK)" can be instead by a macro, which is the
same code with asid2idx(). So rename it to ctxid2asid() for a better
understanding.

Also we add asid2ctxid() macro, the contextid can be generated based on
the asid and generation through this macro.

Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
v2 -> v3:
 - Add "Signed-off-by" and "Reviewed-by"

v1 -> v2:
 - Split the patch and rename asid2idx() to ctxid2asid()

 arch/arm64/mm/context.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/arch/arm64/mm/context.c b/arch/arm64/mm/context.c
index cd72576ae2b7..bbc2708fe928 100644
--- a/arch/arm64/mm/context.c
+++ b/arch/arm64/mm/context.c
@@ -35,8 +35,8 @@ static unsigned long *pinned_asid_map;
 #define ASID_FIRST_VERSION	(1UL << asid_bits)

 #define NUM_USER_ASIDS		ASID_FIRST_VERSION
-#define asid2idx(asid)		((asid) & ~ASID_MASK)
-#define idx2asid(idx)		asid2idx(idx)
+#define ctxid2asid(asid)	((asid) & ~ASID_MASK)
+#define asid2ctxid(asid, genid)	((asid) | (genid))

 /* Get the ASIDBits supported by the current CPU */
 static u32 get_cpu_asid_bits(void)
@@ -120,7 +120,7 @@ static void flush_context(void)
 		 */
 		if (asid == 0)
 			asid = per_cpu(reserved_asids, i);
-		__set_bit(asid2idx(asid), asid_map);
+		__set_bit(ctxid2asid(asid), asid_map);
 		per_cpu(reserved_asids, i) = asid;
 	}

@@ -162,7 +162,7 @@ static u64 new_context(struct mm_struct *mm)
 	u64 generation = atomic64_read(&asid_generation);

 	if (asid != 0) {
-		u64 newasid = generation | (asid & ~ASID_MASK);
+		u64 newasid = asid2ctxid(ctxid2asid(asid), generation);

 		/*
 		 * If our current ASID was active during a rollover, we
@@ -183,7 +183,7 @@ static u64 new_context(struct mm_struct *mm)
 		 * We had a valid ASID in a previous life, so try to re-use
 		 * it if possible.
 		 */
-		if (!__test_and_set_bit(asid2idx(asid), asid_map))
+		if (!__test_and_set_bit(ctxid2asid(asid), asid_map))
 			return newasid;
 	}

@@ -209,7 +209,7 @@ static u64 new_context(struct mm_struct *mm)
 set_asid:
 	__set_bit(asid, asid_map);
 	cur_idx = asid;
-	return idx2asid(asid) | generation;
+	return asid2ctxid(asid, generation);
 }

 void check_and_switch_context(struct mm_struct *mm)
@@ -300,13 +300,13 @@ unsigned long arm64_mm_context_get(struct mm_struct *mm)
 	}

 	nr_pinned_asids++;
-	__set_bit(asid2idx(asid), pinned_asid_map);
+	__set_bit(ctxid2asid(asid), pinned_asid_map);
 	refcount_set(&mm->context.pinned, 1);

 out_unlock:
 	raw_spin_unlock_irqrestore(&cpu_asid_lock, flags);

-	asid &= ~ASID_MASK;
+	asid = ctxid2asid(asid);

 	/* Set the equivalent of USER_ASID_BIT */
 	if (asid && arm64_kernel_unmapped_at_el0())
@@ -327,7 +327,7 @@ void arm64_mm_context_put(struct mm_struct *mm)
 	raw_spin_lock_irqsave(&cpu_asid_lock, flags);

 	if (refcount_dec_and_test(&mm->context.pinned)) {
-		__clear_bit(asid2idx(asid), pinned_asid_map);
+		__clear_bit(ctxid2asid(asid), pinned_asid_map);
 		nr_pinned_asids--;
 	}

-- 
2.27.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 1/2] arm64: mm: Rename asid2idx() to ctxid2asid()
@ 2021-12-09  1:42 ` Yunfeng Ye
  0 siblings, 0 replies; 6+ messages in thread
From: Yunfeng Ye @ 2021-12-09  1:42 UTC (permalink / raw)
  To: catalin.marinas, will, wangkefeng.wang, yeyunfeng,
	linux-arm-kernel, linux-kernel
  Cc: wuxu.wu, Hewenliang

The commit 0c8ea531b774 ("arm64: mm: Allocate ASIDs in pairs") introduce
the asid2idx and idx2asid macro, but these macros are not really useful
after the commit f88f42f853a8 ("arm64: context: Free up kernel ASIDs if
KPTI is not in use").

The code "(asid & ~ASID_MASK)" can be instead by a macro, which is the
same code with asid2idx(). So rename it to ctxid2asid() for a better
understanding.

Also we add asid2ctxid() macro, the contextid can be generated based on
the asid and generation through this macro.

Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
v2 -> v3:
 - Add "Signed-off-by" and "Reviewed-by"

v1 -> v2:
 - Split the patch and rename asid2idx() to ctxid2asid()

 arch/arm64/mm/context.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/arch/arm64/mm/context.c b/arch/arm64/mm/context.c
index cd72576ae2b7..bbc2708fe928 100644
--- a/arch/arm64/mm/context.c
+++ b/arch/arm64/mm/context.c
@@ -35,8 +35,8 @@ static unsigned long *pinned_asid_map;
 #define ASID_FIRST_VERSION	(1UL << asid_bits)

 #define NUM_USER_ASIDS		ASID_FIRST_VERSION
-#define asid2idx(asid)		((asid) & ~ASID_MASK)
-#define idx2asid(idx)		asid2idx(idx)
+#define ctxid2asid(asid)	((asid) & ~ASID_MASK)
+#define asid2ctxid(asid, genid)	((asid) | (genid))

 /* Get the ASIDBits supported by the current CPU */
 static u32 get_cpu_asid_bits(void)
@@ -120,7 +120,7 @@ static void flush_context(void)
 		 */
 		if (asid == 0)
 			asid = per_cpu(reserved_asids, i);
-		__set_bit(asid2idx(asid), asid_map);
+		__set_bit(ctxid2asid(asid), asid_map);
 		per_cpu(reserved_asids, i) = asid;
 	}

@@ -162,7 +162,7 @@ static u64 new_context(struct mm_struct *mm)
 	u64 generation = atomic64_read(&asid_generation);

 	if (asid != 0) {
-		u64 newasid = generation | (asid & ~ASID_MASK);
+		u64 newasid = asid2ctxid(ctxid2asid(asid), generation);

 		/*
 		 * If our current ASID was active during a rollover, we
@@ -183,7 +183,7 @@ static u64 new_context(struct mm_struct *mm)
 		 * We had a valid ASID in a previous life, so try to re-use
 		 * it if possible.
 		 */
-		if (!__test_and_set_bit(asid2idx(asid), asid_map))
+		if (!__test_and_set_bit(ctxid2asid(asid), asid_map))
 			return newasid;
 	}

@@ -209,7 +209,7 @@ static u64 new_context(struct mm_struct *mm)
 set_asid:
 	__set_bit(asid, asid_map);
 	cur_idx = asid;
-	return idx2asid(asid) | generation;
+	return asid2ctxid(asid, generation);
 }

 void check_and_switch_context(struct mm_struct *mm)
@@ -300,13 +300,13 @@ unsigned long arm64_mm_context_get(struct mm_struct *mm)
 	}

 	nr_pinned_asids++;
-	__set_bit(asid2idx(asid), pinned_asid_map);
+	__set_bit(ctxid2asid(asid), pinned_asid_map);
 	refcount_set(&mm->context.pinned, 1);

 out_unlock:
 	raw_spin_unlock_irqrestore(&cpu_asid_lock, flags);

-	asid &= ~ASID_MASK;
+	asid = ctxid2asid(asid);

 	/* Set the equivalent of USER_ASID_BIT */
 	if (asid && arm64_kernel_unmapped_at_el0())
@@ -327,7 +327,7 @@ void arm64_mm_context_put(struct mm_struct *mm)
 	raw_spin_lock_irqsave(&cpu_asid_lock, flags);

 	if (refcount_dec_and_test(&mm->context.pinned)) {
-		__clear_bit(asid2idx(asid), pinned_asid_map);
+		__clear_bit(ctxid2asid(asid), pinned_asid_map);
 		nr_pinned_asids--;
 	}

-- 
2.27.0

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 2/2] arm64: mm: Use asid feature macro for cheanup
  2021-12-09  1:42 ` Yunfeng Ye
@ 2021-12-09  1:46   ` Yunfeng Ye
  -1 siblings, 0 replies; 6+ messages in thread
From: Yunfeng Ye @ 2021-12-09  1:46 UTC (permalink / raw)
  To: catalin.marinas, will, wangkefeng.wang, linux-arm-kernel, linux-kernel
  Cc: wuxu.wu, Hewenliang

The commit 95b54c3e4c92 ("KVM: arm64: Add feature register flag
definitions") introduce the ID_AA64MMFR0_ASID_8 and ID_AA64MMFR0_ASID_16
macros.

We can use these macros for cheanup in get_cpu_asid_bits().

No functional change.

Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
v2 -> v3:
 - Delete the first blank line
 - Add "Signed-off-by" and "Reviewed-by"

v1 -> v2:
 - Split the patch

 arch/arm64/mm/context.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/mm/context.c b/arch/arm64/mm/context.c
index bbc2708fe928..b8b4cf0bcf39 100644
--- a/arch/arm64/mm/context.c
+++ b/arch/arm64/mm/context.c
@@ -50,10 +50,10 @@ static u32 get_cpu_asid_bits(void)
 		pr_warn("CPU%d: Unknown ASID size (%d); assuming 8-bit\n",
 					smp_processor_id(),  fld);
 		fallthrough;
-	case 0:
+	case ID_AA64MMFR0_ASID_8:
 		asid = 8;
 		break;
-	case 2:
+	case ID_AA64MMFR0_ASID_16:
 		asid = 16;
 	}

-- 
2.27.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 2/2] arm64: mm: Use asid feature macro for cheanup
@ 2021-12-09  1:46   ` Yunfeng Ye
  0 siblings, 0 replies; 6+ messages in thread
From: Yunfeng Ye @ 2021-12-09  1:46 UTC (permalink / raw)
  To: catalin.marinas, will, wangkefeng.wang, linux-arm-kernel, linux-kernel
  Cc: wuxu.wu, Hewenliang

The commit 95b54c3e4c92 ("KVM: arm64: Add feature register flag
definitions") introduce the ID_AA64MMFR0_ASID_8 and ID_AA64MMFR0_ASID_16
macros.

We can use these macros for cheanup in get_cpu_asid_bits().

No functional change.

Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
v2 -> v3:
 - Delete the first blank line
 - Add "Signed-off-by" and "Reviewed-by"

v1 -> v2:
 - Split the patch

 arch/arm64/mm/context.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/mm/context.c b/arch/arm64/mm/context.c
index bbc2708fe928..b8b4cf0bcf39 100644
--- a/arch/arm64/mm/context.c
+++ b/arch/arm64/mm/context.c
@@ -50,10 +50,10 @@ static u32 get_cpu_asid_bits(void)
 		pr_warn("CPU%d: Unknown ASID size (%d); assuming 8-bit\n",
 					smp_processor_id(),  fld);
 		fallthrough;
-	case 0:
+	case ID_AA64MMFR0_ASID_8:
 		asid = 8;
 		break;
-	case 2:
+	case ID_AA64MMFR0_ASID_16:
 		asid = 16;
 	}

-- 
2.27.0

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 1/2] arm64: mm: Rename asid2idx() to ctxid2asid()
  2021-12-09  1:42 ` Yunfeng Ye
@ 2021-12-10 18:40   ` Catalin Marinas
  -1 siblings, 0 replies; 6+ messages in thread
From: Catalin Marinas @ 2021-12-10 18:40 UTC (permalink / raw)
  To: linux-arm-kernel, wangkefeng.wang, will, linux-kernel, Yunfeng Ye
  Cc: Hewenliang, wuxu.wu

On Thu, 9 Dec 2021 09:42:25 +0800, Yunfeng Ye wrote:
> The commit 0c8ea531b774 ("arm64: mm: Allocate ASIDs in pairs") introduce
> the asid2idx and idx2asid macro, but these macros are not really useful
> after the commit f88f42f853a8 ("arm64: context: Free up kernel ASIDs if
> KPTI is not in use").
> 
> The code "(asid & ~ASID_MASK)" can be instead by a macro, which is the
> same code with asid2idx(). So rename it to ctxid2asid() for a better
> understanding.
> 
> [...]

Applied to arm64 (for-next/misc), thanks!

[1/2] arm64: mm: Rename asid2idx() to ctxid2asid()
      https://git.kernel.org/arm64/c/a3a5b763410c
[2/2] arm64: mm: Use asid feature macro for cheanup
      https://git.kernel.org/arm64/c/386a74677be1

-- 
Catalin


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 1/2] arm64: mm: Rename asid2idx() to ctxid2asid()
@ 2021-12-10 18:40   ` Catalin Marinas
  0 siblings, 0 replies; 6+ messages in thread
From: Catalin Marinas @ 2021-12-10 18:40 UTC (permalink / raw)
  To: linux-arm-kernel, wangkefeng.wang, will, linux-kernel, Yunfeng Ye
  Cc: Hewenliang, wuxu.wu

On Thu, 9 Dec 2021 09:42:25 +0800, Yunfeng Ye wrote:
> The commit 0c8ea531b774 ("arm64: mm: Allocate ASIDs in pairs") introduce
> the asid2idx and idx2asid macro, but these macros are not really useful
> after the commit f88f42f853a8 ("arm64: context: Free up kernel ASIDs if
> KPTI is not in use").
> 
> The code "(asid & ~ASID_MASK)" can be instead by a macro, which is the
> same code with asid2idx(). So rename it to ctxid2asid() for a better
> understanding.
> 
> [...]

Applied to arm64 (for-next/misc), thanks!

[1/2] arm64: mm: Rename asid2idx() to ctxid2asid()
      https://git.kernel.org/arm64/c/a3a5b763410c
[2/2] arm64: mm: Use asid feature macro for cheanup
      https://git.kernel.org/arm64/c/386a74677be1

-- 
Catalin


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-12-10 18:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-09  1:42 [PATCH v3 1/2] arm64: mm: Rename asid2idx() to ctxid2asid() Yunfeng Ye
2021-12-09  1:42 ` Yunfeng Ye
2021-12-09  1:46 ` [PATCH v3 2/2] arm64: mm: Use asid feature macro for cheanup Yunfeng Ye
2021-12-09  1:46   ` Yunfeng Ye
2021-12-10 18:40 ` [PATCH v3 1/2] arm64: mm: Rename asid2idx() to ctxid2asid() Catalin Marinas
2021-12-10 18:40   ` Catalin Marinas

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.