public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] s390: mm: convert pgste locking functions to C
@ 2023-12-05 17:32 Claudio Imbrenda
  2023-12-05 18:49 ` Heiko Carstens
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Claudio Imbrenda @ 2023-12-05 17:32 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-s390, linux390-list, kvm390-list, hca, borntraeger, frankja,
	nrb, nsg, svens, gor, gerald.schaefer, agordeev

Convert pgste_get_lock() and pgste_set_unlock() to C.

There is no real reasons to keep them in assembler. Having them in C
makes them more readable and maintainable, and better instructions are
used automatically when available.

Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
 arch/s390/mm/pgtable.c | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c
index 3bd2ab2a9a34..6c4523aa4fdf 100644
--- a/arch/s390/mm/pgtable.c
+++ b/arch/s390/mm/pgtable.c
@@ -125,32 +125,23 @@ static inline pte_t ptep_flush_lazy(struct mm_struct *mm,
 
 static inline pgste_t pgste_get_lock(pte_t *ptep)
 {
-	unsigned long new = 0;
+	unsigned long value = 0;
 #ifdef CONFIG_PGSTE
-	unsigned long old;
-
-	asm(
-		"	lg	%0,%2\n"
-		"0:	lgr	%1,%0\n"
-		"	nihh	%0,0xff7f\n"	/* clear PCL bit in old */
-		"	oihh	%1,0x0080\n"	/* set PCL bit in new */
-		"	csg	%0,%1,%2\n"
-		"	jl	0b\n"
-		: "=&d" (old), "=&d" (new), "=Q" (ptep[PTRS_PER_PTE])
-		: "Q" (ptep[PTRS_PER_PTE]) : "cc", "memory");
+	unsigned long *ptr = (unsigned long *)(ptep + PTRS_PER_PTE);
+
+	do {
+		value = __atomic64_or_barrier(PGSTE_PCL_BIT, ptr);
+	} while (value & PGSTE_PCL_BIT);
+	value |= PGSTE_PCL_BIT;
 #endif
-	return __pgste(new);
+	return __pgste(value);
 }
 
 static inline void pgste_set_unlock(pte_t *ptep, pgste_t pgste)
 {
 #ifdef CONFIG_PGSTE
-	asm(
-		"	nihh	%1,0xff7f\n"	/* clear PCL bit */
-		"	stg	%1,%0\n"
-		: "=Q" (ptep[PTRS_PER_PTE])
-		: "d" (pgste_val(pgste)), "Q" (ptep[PTRS_PER_PTE])
-		: "cc", "memory");
+	barrier();
+	WRITE_ONCE(*(unsigned long *)(ptep + PTRS_PER_PTE), pgste_val(pgste) & ~PGSTE_PCL_BIT);
 #endif
 }
 
-- 
2.43.0


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

* Re: [PATCH v1 1/1] s390: mm: convert pgste locking functions to C
  2023-12-05 17:32 [PATCH v1 1/1] s390: mm: convert pgste locking functions to C Claudio Imbrenda
@ 2023-12-05 18:49 ` Heiko Carstens
  2023-12-06  8:58 ` Alexander Gordeev
  2023-12-06  9:01 ` Alexander Gordeev
  2 siblings, 0 replies; 6+ messages in thread
From: Heiko Carstens @ 2023-12-05 18:49 UTC (permalink / raw)
  To: Claudio Imbrenda
  Cc: linux-kernel, linux-s390, linux390-list, kvm390-list, borntraeger,
	frankja, nrb, nsg, svens, gor, gerald.schaefer, agordeev

On Tue, Dec 05, 2023 at 06:32:52PM +0100, Claudio Imbrenda wrote:
> Convert pgste_get_lock() and pgste_set_unlock() to C.
> 
> There is no real reasons to keep them in assembler. Having them in C
> makes them more readable and maintainable, and better instructions are
> used automatically when available.
> 
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> ---
>  arch/s390/mm/pgtable.c | 29 ++++++++++-------------------
>  1 file changed, 10 insertions(+), 19 deletions(-)

Reviewed-by: Heiko Carstens <hca@linux.ibm.com>

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

* Re: [PATCH v1 1/1] s390: mm: convert pgste locking functions to C
  2023-12-05 17:32 [PATCH v1 1/1] s390: mm: convert pgste locking functions to C Claudio Imbrenda
  2023-12-05 18:49 ` Heiko Carstens
@ 2023-12-06  8:58 ` Alexander Gordeev
  2023-12-06  9:01 ` Alexander Gordeev
  2 siblings, 0 replies; 6+ messages in thread
From: Alexander Gordeev @ 2023-12-06  8:58 UTC (permalink / raw)
  To: Claudio Imbrenda
  Cc: linux-kernel, linux-s390, linux390-list, kvm390-list, hca,
	borntraeger, frankja, nrb, nsg, svens, gor, gerald.schaefer

On Tue, Dec 05, 2023 at 06:32:52PM +0100, Claudio Imbrenda wrote:

Hi Claudio,

> Convert pgste_get_lock() and pgste_set_unlock() to C.
> 
> There is no real reasons to keep them in assembler. Having them in C
> makes them more readable and maintainable, and better instructions are
> used automatically when available.
> 
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> ---
>  arch/s390/mm/pgtable.c | 29 ++++++++++-------------------
>  1 file changed, 10 insertions(+), 19 deletions(-)

Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>

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

* Re: [PATCH v1 1/1] s390: mm: convert pgste locking functions to C
  2023-12-05 17:32 [PATCH v1 1/1] s390: mm: convert pgste locking functions to C Claudio Imbrenda
  2023-12-05 18:49 ` Heiko Carstens
  2023-12-06  8:58 ` Alexander Gordeev
@ 2023-12-06  9:01 ` Alexander Gordeev
  2023-12-06  9:15   ` Heiko Carstens
  2 siblings, 1 reply; 6+ messages in thread
From: Alexander Gordeev @ 2023-12-06  9:01 UTC (permalink / raw)
  To: Claudio Imbrenda
  Cc: linux-kernel, linux-s390, linux390-list, kvm390-list, hca,
	borntraeger, frankja, nrb, nsg, svens, gor, gerald.schaefer

On Tue, Dec 05, 2023 at 06:32:52PM +0100, Claudio Imbrenda wrote:

(Internal lists only)

...
> +	do {
> +		value = __atomic64_or_barrier(PGSTE_PCL_BIT, ptr);

Would it make sense to cpu_relax() here, e.g with a follow-up patch?

> +	} while (value & PGSTE_PCL_BIT);
> +	value |= PGSTE_PCL_BIT;
>  #endif
> -	return __pgste(new);
> +	return __pgste(value);
>  }

Thanks!

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

* Re: [PATCH v1 1/1] s390: mm: convert pgste locking functions to C
  2023-12-06  9:01 ` Alexander Gordeev
@ 2023-12-06  9:15   ` Heiko Carstens
  2023-12-06 13:14     ` Alexander Gordeev
  0 siblings, 1 reply; 6+ messages in thread
From: Heiko Carstens @ 2023-12-06  9:15 UTC (permalink / raw)
  To: Alexander Gordeev, Claudio Imbrenda, linux-kernel, linux-s390,
	borntraeger, frankja, nrb, nsg, svens, gor, gerald.schaefer

On Wed, Dec 06, 2023 at 10:01:18AM +0100, Alexander Gordeev wrote:
> On Tue, Dec 05, 2023 at 06:32:52PM +0100, Claudio Imbrenda wrote:
> ...
> > +	do {
> > +		value = __atomic64_or_barrier(PGSTE_PCL_BIT, ptr);
> 
> Would it make sense to cpu_relax() here, e.g with a follow-up patch?

No, because cpu_relax() is a no-op on our architecture (besides that it
translates to barrier(); but __atomic64_or_barrier() obviously comes also
with barrier() semantics).

We used to do diag 0x44 with cpu_relax() but that caused many performance
problems, therefore we removed diag 0x44 completely from the kernel quite
some time ago.

See also commit 1b68ac8678a8 ("s390: remove last diag 0x44 caller").

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

* Re: [PATCH v1 1/1] s390: mm: convert pgste locking functions to C
  2023-12-06  9:15   ` Heiko Carstens
@ 2023-12-06 13:14     ` Alexander Gordeev
  0 siblings, 0 replies; 6+ messages in thread
From: Alexander Gordeev @ 2023-12-06 13:14 UTC (permalink / raw)
  To: Heiko Carstens
  Cc: Claudio Imbrenda, linux-kernel, linux-s390, borntraeger, frankja,
	nrb, nsg, svens, gor, gerald.schaefer

On Wed, Dec 06, 2023 at 10:15:41AM +0100, Heiko Carstens wrote:
> On Wed, Dec 06, 2023 at 10:01:18AM +0100, Alexander Gordeev wrote:
> > On Tue, Dec 05, 2023 at 06:32:52PM +0100, Claudio Imbrenda wrote:
> > ...
> > > +	do {
> > > +		value = __atomic64_or_barrier(PGSTE_PCL_BIT, ptr);
> > 
> > Would it make sense to cpu_relax() here, e.g with a follow-up patch?
> 
> No, because cpu_relax() is a no-op on our architecture (besides that it
> translates to barrier(); but __atomic64_or_barrier() obviously comes also
> with barrier() semantics).
> 
> We used to do diag 0x44 with cpu_relax() but that caused many performance
> problems, therefore we removed diag 0x44 completely from the kernel quite
> some time ago.
> 
> See also commit 1b68ac8678a8 ("s390: remove last diag 0x44 caller").

Thanks for the clarification!

Applied.

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

end of thread, other threads:[~2023-12-06 13:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-05 17:32 [PATCH v1 1/1] s390: mm: convert pgste locking functions to C Claudio Imbrenda
2023-12-05 18:49 ` Heiko Carstens
2023-12-06  8:58 ` Alexander Gordeev
2023-12-06  9:01 ` Alexander Gordeev
2023-12-06  9:15   ` Heiko Carstens
2023-12-06 13:14     ` Alexander Gordeev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox