s390/mm,fault: use static key for store indication
authorHeiko Carstens <hca@linux.ibm.com>
Thu, 12 Oct 2023 07:40:41 +0000 (09:40 +0200)
committerVasily Gorbik <gor@linux.ibm.com>
Mon, 23 Oct 2023 16:21:22 +0000 (18:21 +0200)
Generate slightly better code by using a static key to implement store
indication. This allows to get rid of a memory access on the hot path.

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/fault.c

index ba2056b35910925f6d930a0a775a7db504bcf37c..5466a30d1ec4a4490ad1698fa0e183c853518907 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/signal.h>
 #include <linux/sched.h>
 #include <linux/sched/debug.h>
+#include <linux/jump_label.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/string.h>
@@ -60,12 +61,12 @@ enum fault_type {
        GMAP_FAULT,
 };
 
-static unsigned long store_indication __read_mostly;
+static DEFINE_STATIC_KEY_FALSE(have_store_indication);
 
 static int __init fault_init(void)
 {
        if (test_facility(75))
-               store_indication = 0xc00;
+               static_branch_enable(&have_store_indication);
        return 0;
 }
 early_initcall(fault_init);
@@ -104,11 +105,13 @@ static unsigned long get_fault_address(struct pt_regs *regs)
        return trans_exc_code & __FAIL_ADDR_MASK;
 }
 
-static bool fault_is_write(struct pt_regs *regs)
+static __always_inline bool fault_is_write(struct pt_regs *regs)
 {
        unsigned long trans_exc_code = regs->int_parm_long;
 
-       return (trans_exc_code & store_indication) == 0x400;
+       if (static_branch_likely(&have_store_indication))
+               return (trans_exc_code & 0xc00) == 0x400;
+       return false;
 }
 
 static int bad_address(void *p)