Skip to contentSkip to conversation

powerpc: Remove eieio in _memcpy_fromio

PATCH In review Julian Vetter 3 participants 6 messages Jan 28, 2025 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc: Remove eieio in _memcpy_fromio

Remove the eieio() calls in _memcpy_fromio, to bring its implementation closer to the one from lib/iomem_copy.c. These eieio() calls don't seem to be necessary, because the _memcpy_toio completely omits them. Also the legacy code from ppc was not doing them.

---
 arch/powerpc/kernel/io.c | 3 ---
 1 file changed, 3 deletions(-)
arch/powerpc/kernel/io.c +0 -3
index 6af535905984..81e5d54260a1 100644
@@ -155,21 +155,18 @@ void _memcpy_fromio(void *dest, const volatile void __iomem *src,
 	__asm__ __volatile__ ("sync" : : : "memory");
 	while(n && (!IO_CHECK_ALIGN(vsrc, 4) || !IO_CHECK_ALIGN(dest, 4))) {
 		*((u8 *)dest) = *((volatile u8 *)vsrc);
-		eieio();
 		vsrc++;
 		dest++;
 		n--;
 	}
 	while(n >= 4) {
 		*((u32 *)dest) = *((volatile u32 *)vsrc);
-		eieio();
 		vsrc += 4;
 		dest += 4;
 		n -= 4;
 	}
 	while(n) {
 		*((u8 *)dest) = *((volatile u8 *)vsrc);
-		eieio();
 		vsrc++;
 		dest++;
 		n--;
Signature · 1 line
2.34.1
#1 lore raw

Le 28/01/2025 à 14:57, Julian Vetter a écrit :

Quoted 4 lines

Remove the eieio() calls in _memcpy_fromio, to bring its implementation closer to the one from lib/iomem_copy.c. These eieio() calls don't seem to be necessary, because the _memcpy_toio completely omits them. Also the legacy code from ppc was not doing them.

What do you mean exactly by "legacy code" ?

As far as I can see they were already there before commit 68a64357d15a ("[POWERPC] Merge 32 and 64 bits asm-powerpc/io.h"):

-static inline void eeh_memcpy_fromio(void *dest, const volatile void __iomem *src, +static inline void eeh_memcpy_fromio(void *dest, const
+ volatile void __iomem *src,
unsigned long n)
{
- void *vsrc = (void __force *) src;
- void *destsave = dest;
- unsigned long nsave = n;
-
- __asm__ __volatile__ ("sync" : : : "memory");
- while(n && (!EEH_CHECK_ALIGN(vsrc, 4) || !EEH_CHECK_ALIGN(dest, 4))) {
- *((u8 *)dest) = *((volatile u8 *)vsrc);
- __asm__ __volatile__ ("eieio" : : : "memory");
- vsrc++;
- dest++;
- n--;
- }
- while(n > 4) {
- *((u32 *)dest) = *((volatile u32 *)vsrc);
- __asm__ __volatile__ ("eieio" : : : "memory");
- vsrc += 4;
- dest += 4;
- n -= 4;
- }
- while(n) {
- *((u8 *)dest) = *((volatile u8 *)vsrc);
- __asm__ __volatile__ ("eieio" : : : "memory");
- vsrc++;
- dest++;
- n--;
- }
- __asm__ __volatile__ ("sync" : : : "memory");
+ _memcpy_fromio(dest, src, n);

/* Look for ffff's here at dest[n]. Assume that at least 4 bytes
* were copied. Check all four bytes.
*/
- if ((nsave >= 4) &&
- (EEH_POSSIBLE_ERROR((*((u32 *) destsave+nsave-4)), u32))) {
- eeh_check_failure(src, (*((u32 *) destsave+nsave-4)));
- }
+ if (n >= 4 && EEH_POSSIBLE_ERROR(*((u32 *)(dest + n - 4)), u32))
+ eeh_check_failure(src, *((u32 *)(dest + n - 4)));
}

Quoted 35 lines
---
  arch/powerpc/kernel/io.c | 3 ---
  1 file changed, 3 deletions(-)
arch/powerpc/kernel/io.c +0 -4
index 6af535905984..81e5d54260a1 100644
@@ -155,21 +155,18 @@ void _memcpy_fromio(void *dest, const volatile void __iomem *src,
         __asm__ __volatile__ ("sync" : : : "memory");
         while(n && (!IO_CHECK_ALIGN(vsrc, 4) || !IO_CHECK_ALIGN(dest, 4))) {
                 *((u8 *)dest) = *((volatile u8 *)vsrc);
-               eieio();
                 vsrc++;
                 dest++;
                 n--;
         }
         while(n >= 4) {
                 *((u32 *)dest) = *((volatile u32 *)vsrc);
-               eieio();
                 vsrc += 4;
                 dest += 4;
                 n -= 4;
         }
         while(n) {
                 *((u8 *)dest) = *((volatile u8 *)vsrc);
-               eieio();
                 vsrc++;
                 dest++;
                 n--;
--

2.34.1

#2 lore raw
Quoted 12 lines · Christophe Leroy

Le 28/01/2025 à 14:57, Julian Vetter a écrit :

Quoted 4 lines

Remove the eieio() calls in _memcpy_fromio, to bring its implementation closer to the one from lib/iomem_copy.c. These eieio() calls don't seem to be necessary, because the _memcpy_toio completely omits them. Also the legacy code from ppc was not doing them.

What do you mean exactly by "legacy code" ?

As far as I can see they were already there before commit 68a64357d15a ("[POWERPC] Merge 32 and 64 bits asm-powerpc/io.h"):

With 'ppc' I was refering to 'include/asm-ppc/io.h'. But you're right, when going back a bit, in the 'include/asm-powerpc/io.h' there are two cases, one (eeh_memcpy_fromio) which does the the 'eieio', and a second, i.e., 'iSeries_memcpy_fromio' which does a byte-wise copy. But in the ppc code ('include/asm-ppc/io.h') there is a simple memcpy. I was referring to this one. But my description is not very clear. Sorry for that.

Quoted 85 lines

-static inline void eeh_memcpy_fromio(void *dest, const volatile void __iomem *src,

(quoted diff) +5 -31
+static inline void eeh_memcpy_fromio(void *dest, const
+                     volatile void __iomem *src,
                       unsigned long n)
  {
-    void *vsrc = (void __force *) src;
-    void *destsave = dest;
-    unsigned long nsave = n;
-
-    __asm__ __volatile__ ("sync" : : : "memory");
-    while(n && (!EEH_CHECK_ALIGN(vsrc, 4) || !EEH_CHECK_ALIGN(dest, 4))) {
-        *((u8 *)dest) = *((volatile u8 *)vsrc);
-        __asm__ __volatile__ ("eieio" : : : "memory");
-        vsrc++;
-        dest++;
-        n--;
-    }
-    while(n > 4) {
-        *((u32 *)dest) = *((volatile u32 *)vsrc);
-        __asm__ __volatile__ ("eieio" : : : "memory");
-        vsrc += 4;
-        dest += 4;
-        n -= 4;
-    }
-    while(n) {
-        *((u8 *)dest) = *((volatile u8 *)vsrc);
-        __asm__ __volatile__ ("eieio" : : : "memory");
-        vsrc++;
-        dest++;
-        n--;
-    }
-    __asm__ __volatile__ ("sync" : : : "memory");
+    _memcpy_fromio(dest, src, n);
 
      /* Look for ffff's here at dest[n].  Assume that at least 4 bytes
       * were copied. Check all four bytes.
       */
-    if ((nsave >= 4) &&
-        (EEH_POSSIBLE_ERROR((*((u32 *) destsave+nsave-4)), u32))) {
-        eeh_check_failure(src, (*((u32 *) destsave+nsave-4)));
-    }
+    if (n >= 4 && EEH_POSSIBLE_ERROR(*((u32 *)(dest + n - 4)), u32))
+        eeh_check_failure(src, *((u32 *)(dest + n - 4)));
  }
Quoted 39 lines

---
  arch/powerpc/kernel/io.c | 3 ---

  1 file changed, 3 deletions(-)
arch/powerpc/kernel/io.c +0 -3
index 6af535905984..81e5d54260a1 100644
@@ -155,21 +155,18 @@ void _memcpy_fromio(void *dest, const volatile 
 void __iomem *src,
          __asm__ __volatile__ ("sync" : : : "memory");
          while(n && (!IO_CHECK_ALIGN(vsrc, 4) || !IO_CHECK_ALIGN(dest, 4))) {
                  *((u8 *)dest) = *((volatile u8 *)vsrc);
-               eieio();
                  vsrc++;
                  dest++;
                  n--;
          }
          while(n >= 4) {
                  *((u32 *)dest) = *((volatile u32 *)vsrc);
-               eieio();
                  vsrc += 4;
                  dest += 4;
                  n -= 4;
          }
          while(n) {
                  *((u8 *)dest) = *((volatile u8 *)vsrc);
-               eieio();
                  vsrc++;
                  dest++;

                 n--;

Signature · 1 line
2.34.1
#3 lore raw

Le 28/01/2025 à 16:07, Julian Vetter a écrit :

Quoted 17 lines

[Vous ne recevez pas souvent de courriers de [email protected]. Découvrez pourquoi ceci est important à https://aka.ms/ LearnAboutSenderIdentification ]

Quoted 8 lines · Christophe Leroy
Quoted 4 lines · Julian Vetter

Remove the eieio() calls in _memcpy_fromio, to bring its implementation closer to the one from lib/iomem_copy.c. These eieio() calls don't seem to be necessary, because the _memcpy_toio completely omits them. Also the legacy code from ppc was not doing them.

Quoted 5 lines

What do you mean exactly by "legacy code" ?

As far as I can see they were already there before commit 68a64357d15a ("[POWERPC] Merge 32 and 64 bits asm-powerpc/io.h"):

Quoted 6 lines

With 'ppc' I was refering to 'include/asm-ppc/io.h'. But you're right, when going back a bit, in the 'include/asm-powerpc/io.h' there are two cases, one (eeh_memcpy_fromio) which does the the 'eieio', and a second, i.e., 'iSeries_memcpy_fromio' which does a byte-wise copy. But in the ppc code ('include/asm-ppc/io.h') there is a simple memcpy. I was referring to this one. But my description is not very clear. Sorry for that.

But then is your change still valid ? Isn't there some corner case that still need it ? Is it a valid argument that because memcpy_toio() doesn't need it memcpy_fromio() doesn't need it either ?

Quoted 88 lines
Quoted 88 lines

-static inline void eeh_memcpy_fromio(void *dest, const volatile void __iomem *src,
+static inline void eeh_memcpy_fromio(void *dest, const
+                     volatile void __iomem *src,
                       unsigned long n)
  {
-    void *vsrc = (void __force *) src;
-    void *destsave = dest;
-    unsigned long nsave = n;
-
-    __asm__ __volatile__ ("sync" : : : "memory");
-    while(n && (!EEH_CHECK_ALIGN(vsrc, 4) || !EEH_CHECK_ALIGN(dest, 4))) {
-        *((u8 *)dest) = *((volatile u8 *)vsrc);
-        __asm__ __volatile__ ("eieio" : : : "memory");
-        vsrc++;
-        dest++;
-        n--;
-    }
-    while(n > 4) {
-        *((u32 *)dest) = *((volatile u32 *)vsrc);
-        __asm__ __volatile__ ("eieio" : : : "memory");
-        vsrc += 4;
-        dest += 4;
-        n -= 4;
-    }
-    while(n) {
-        *((u8 *)dest) = *((volatile u8 *)vsrc);
-        __asm__ __volatile__ ("eieio" : : : "memory");
-        vsrc++;
-        dest++;
-        n--;
-    }
-    __asm__ __volatile__ ("sync" : : : "memory");
+    _memcpy_fromio(dest, src, n);

      /* Look for ffff's here at dest[n].  Assume that at least 4 bytes
       * were copied. Check all four bytes.
       */
-    if ((nsave >= 4) &&
-        (EEH_POSSIBLE_ERROR((*((u32 *) destsave+nsave-4)), u32))) { -        eeh_check_failure(src, (*((u32 *) destsave+nsave-4))); -    }
+    if (n >= 4 && EEH_POSSIBLE_ERROR(*((u32 *)(dest + n - 4)), u32)) +        eeh_check_failure(src, *((u32 *)(dest + n - 4)));
  }

Quoted 37 lines

---
  arch/powerpc/kernel/io.c | 3 ---

  1 file changed, 3 deletions(-)
arch/powerpc/kernel/io.c +0 -3
index 6af535905984..81e5d54260a1 100644
@@ -155,21 +155,18 @@ void _memcpy_fromio(void *dest, const volatile
 void __iomem *src,
          __asm__ __volatile__ ("sync" : : : "memory");
          while(n && (!IO_CHECK_ALIGN(vsrc, 4) || !IO_CHECK_ALIGN(dest,
 4))) {
                  *((u8 *)dest) = *((volatile u8 *)vsrc);
-               eieio();
                  vsrc++;
                  dest++;
                  n--;
          }
          while(n >= 4) {
                  *((u32 *)dest) = *((volatile u32 *)vsrc);
-               eieio();
                  vsrc += 4;
                  dest += 4;
                  n -= 4;
          }
          while(n) {
                  *((u8 *)dest) = *((volatile u8 *)vsrc);
-               eieio();
                  vsrc++;

                 dest++;
                 n--;

Signature · 1 line
2.34.1
#4 lore raw

Le 28/01/2025 à 16:24, Christophe Leroy a écrit :

Quoted 20 lines

Le 28/01/2025 à 16:07, Julian Vetter a écrit :

Quoted 17 lines

[Vous ne recevez pas souvent de courriers de [email protected]. Découvrez pourquoi ceci est important à https://aka.ms/ LearnAboutSenderIdentification ]

Quoted 13 lines · Christophe Leroy
Quoted 4 lines · Julian Vetter

Remove the eieio() calls in _memcpy_fromio, to bring its implementation closer to the one from lib/iomem_copy.c. These eieio() calls don't seem to be necessary, because the _memcpy_toio completely omits them. Also the legacy code from ppc was not doing them.

What do you mean exactly by "legacy code" ?

As far as I can see they were already there before commit 68a64357d15a ("[POWERPC] Merge 32 and 64 bits asm-powerpc/io.h"):

Quoted 8 lines
Quoted 6 lines

With 'ppc' I was refering to 'include/asm-ppc/io.h'. But you're right, when going back a bit, in the 'include/asm-powerpc/io.h' there are two cases, one (eeh_memcpy_fromio) which does the the 'eieio', and a second, i.e., 'iSeries_memcpy_fromio' which does a byte-wise copy. But in the ppc code ('include/asm-ppc/io.h') there is a simple memcpy. I was referring to this one. But my description is not very clear. Sorry for that.

But then is your change still valid ? Isn't there some corner case that still need it ? Is it a valid argument that because memcpy_toio() doesn't need it memcpy_fromio() doesn't need it either ?

I see that _insb(), _insw_ns() and _insl_ns() also have eieio() while _outsb(), _outsw_ns() and _outsl_ns() don't. Why not change those as well if you think eieio() is not needed ?

#5 lore raw
Quoted 10 lines · Christophe Leroy

Le 28/01/2025 à 16:24, Christophe Leroy a écrit :

Quoted 9 lines

Le 28/01/2025 à 16:07, Julian Vetter a écrit :

Quoted 7 lines

With 'ppc' I was refering to 'include/asm-ppc/io.h'. But you're right, when going back a bit, in the 'include/asm-powerpc/io.h' there are two cases, one (eeh_memcpy_fromio) which does the the 'eieio', and a second, i.e., 'iSeries_memcpy_fromio' which does a byte-wise copy. But in the ppc code ('include/asm-ppc/io.h') there is a simple memcpy. I was referring to this one. But my description is not very clear. Sorry for that.

Quoted 7 lines
Quoted 3 lines

But then is your change still valid ? Isn't there some corner case that still need it ? Is it a valid argument that because memcpy_toio() doesn't need it memcpy_fromio() doesn't need it either ?

I see that _insb(), _insw_ns() and _insl_ns() also have eieio() while _outsb(), _outsw_ns() and _outsl_ns() don't. Why not change those as well if you think eieio() is not needed ?

I think that makes sense, even if it's beyond the scope of Julian's work to unify the memcpy/memset I/O helpers across architectures.

I looked into the pre-2.6.12 history of arch/powerpc64 to see how the eieio got in there originally and found that at the time the string functions got added, this is what the readl() etc functions did. readl() itself went through a longer set of changes to end up with the current sync/twi/isync version, but the string functions were never updated again during any of the later changes.

The bit that needs to be captured in the changelog here is that on all other architectures, strcpy_fromio/strcpy_toio are written to allow prefetching/combining/reordering, while the powerpc version prevents this in strcpy_fromio for apparently only history reasons.

Arnd