s390/cmma: cleanup inline assemblies
authorHeiko Carstens <hca@linux.ibm.com>
Fri, 27 Oct 2023 12:12:35 +0000 (14:12 +0200)
committerVasily Gorbik <gor@linux.ibm.com>
Sun, 5 Nov 2023 21:34:57 +0000 (22:34 +0100)
Cleanup cmma related inline assemblies:
- consolidate inline assemblies
- use symbolic names
- add same white space where missing
- add braces to for-loops which contain a multi-line statement

Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
arch/s390/mm/page-states.c

index a31acb2c4ef24c387ed5536457de5a61a03fef4a..202dacdf17db01a811f0b9bb1d3ccfe8144bf322 100644 (file)
@@ -40,7 +40,7 @@ static inline int cmma_test_essa(void)
                "       .insn   rrf,0xb9ab0000,%[tmp],%[tmp],%[cmd],0\n"
                "0:     la      %[rc],0\n"
                "1:\n"
-               EX_TABLE(0b,1b)
+               EX_TABLE(0b, 1b)
                : [rc] "+&d" (rc), [tmp] "+&d" (tmp)
                : [cmd] "i" (ESSA_GET_STATE));
        return rc;
@@ -58,37 +58,41 @@ void __init cmma_init(void)
                cmma_flag = 2;
 }
 
-static inline void set_page_unused(struct page *page, int order)
+static __always_inline void essa(unsigned long paddr, unsigned char cmd)
 {
-       int i, rc;
+       unsigned long rc;
 
-       for (i = 0; i < (1 << order); i++)
-               asm volatile(".insn rrf,0xb9ab0000,%0,%1,%2,0"
-                            : "=&d" (rc)
-                            : "a" (page_to_phys(page + i)),
-                              "i" (ESSA_SET_UNUSED));
+       asm volatile(
+               "       .insn   rrf,0xb9ab0000,%[rc],%[paddr],%[cmd],0"
+               : [rc] "=d" (rc)
+               : [paddr] "d" (paddr),
+                 [cmd] "i" (cmd));
 }
 
-static inline void set_page_stable_dat(struct page *page, int order)
+static __always_inline void __set_page_state(struct page *page, int order, unsigned char cmd)
 {
-       int i, rc;
+       unsigned long paddr = page_to_phys(page);
+       unsigned long num_pages = 1UL << order;
 
-       for (i = 0; i < (1 << order); i++)
-               asm volatile(".insn rrf,0xb9ab0000,%0,%1,%2,0"
-                            : "=&d" (rc)
-                            : "a" (page_to_phys(page + i)),
-                              "i" (ESSA_SET_STABLE));
+       while (num_pages--) {
+               essa(paddr, cmd);
+               paddr += PAGE_SIZE;
+       }
 }
 
-static inline void set_page_stable_nodat(struct page *page, int order)
+static inline void set_page_unused(struct page *page, int order)
 {
-       int i, rc;
+       __set_page_state(page, order, ESSA_SET_UNUSED);
+}
 
-       for (i = 0; i < (1 << order); i++)
-               asm volatile(".insn rrf,0xb9ab0000,%0,%1,%2,0"
-                            : "=&d" (rc)
-                            : "a" (page_to_phys(page + i)),
-                              "i" (ESSA_SET_STABLE_NODAT));
+static inline void set_page_stable_dat(struct page *page, int order)
+{
+       __set_page_state(page, order, ESSA_SET_STABLE);
+}
+
+static inline void set_page_stable_nodat(struct page *page, int order)
+{
+       __set_page_state(page, order, ESSA_SET_STABLE_NODAT);
 }
 
 static void mark_kernel_pmd(pud_t *pud, unsigned long addr, unsigned long end)