Skip to contentSkip to conversation

powerpc/tm: Clean up duplication of code

PATCH Superseded Rashmica Gupta 3 participants 4 messages May 11, 2016 PowerPC

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/tm: Clean up duplication of code

The same logic for tm_abort appears twice, so pull it out into a function.

---
 arch/powerpc/mm/hash_utils_64.c | 47 ++++++++++++++++++-----------------------
 1 file changed, 21 insertions(+), 26 deletions(-)
arch/powerpc/mm/hash_utils_64.c +21 -26
index 7635b1c6b5da..1cef8f5aee9b 100644
@@ -1318,6 +1318,25 @@ out_exit:
 	local_irq_restore(flags);
 }
 
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+	/* Transactions are not aborted by tlbiel, only tlbie.
+	 * Without, syncing a page back to a block device w/ PIO could pick up
+	 * transactional data (bad!) so we force an abort here.  Before the
+	 * sync the page will be made read-only, which will flush_hash_page.
+	 * BIG ISSUE here: if the kernel uses a page from userspace without
+	 * unmapping it first, it may see the speculated version.
+	 */
+static inline void abort_tm(int local)
+{
+	if (local && cpu_has_feature(CPU_FTR_TM) &&
+	    current->thread.regs &&
+	    MSR_TM_ACTIVE(current->thread.regs->msr)) {
+		tm_enable();
+		tm_abort(TM_CAUSE_TLBI);
+	}
+}
+#endif
+
 /* WARNING: This is called from hash_low_64.S, if you change this prototype,
  *          do not forget to update the assembly call site !
  */
@@ -1344,19 +1363,7 @@ void flush_hash_page(unsigned long vpn, real_pte_t pte, int psize, int ssize,
 	} pte_iterate_hashed_end();
 
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
-	/* Transactions are not aborted by tlbiel, only tlbie.
-	 * Without, syncing a page back to a block device w/ PIO could pick up
-	 * transactional data (bad!) so we force an abort here.  Before the
-	 * sync the page will be made read-only, which will flush_hash_page.
-	 * BIG ISSUE here: if the kernel uses a page from userspace without
-	 * unmapping it first, it may see the speculated version.
-	 */
-	if (local && cpu_has_feature(CPU_FTR_TM) &&
-	    current->thread.regs &&
-	    MSR_TM_ACTIVE(current->thread.regs->msr)) {
-		tm_enable();
-		tm_abort(TM_CAUSE_TLBI);
-	}
+	abort_tm(local);
 #endif
 }
 
@@ -1415,19 +1422,7 @@ void flush_hash_hugepage(unsigned long vsid, unsigned long addr,
 	}
 tm_abort:
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
-	/* Transactions are not aborted by tlbiel, only tlbie.
-	 * Without, syncing a page back to a block device w/ PIO could pick up
-	 * transactional data (bad!) so we force an abort here.  Before the
-	 * sync the page will be made read-only, which will flush_hash_page.
-	 * BIG ISSUE here: if the kernel uses a page from userspace without
-	 * unmapping it first, it may see the speculated version.
-	 */
-	if (local && cpu_has_feature(CPU_FTR_TM) &&
-	    current->thread.regs &&
-	    MSR_TM_ACTIVE(current->thread.regs->msr)) {
-		tm_enable();
-		tm_abort(TM_CAUSE_TLBI);
-	}
+	abort_tm(local);
 #endif
 	return;
 }
Signature · 1 line
2.5.0
#1 lore raw
Quoted 23 lines · Rashmica Gupta

The same logic for tm_abort appears twice, so pull it out into a function.

---
 arch/powerpc/mm/hash_utils_64.c | 47 ++++++++++++++++++-----------------------
 1 file changed, 21 insertions(+), 26 deletions(-)
arch/powerpc/mm/hash_utils_64.c +7 -0
index 7635b1c6b5da..1cef8f5aee9b 100644
@@ -1318,6 +1318,25 @@ out_exit:
 	local_irq_restore(flags);
 }
 
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+	/* Transactions are not aborted by tlbiel, only tlbie.
+	 * Without, syncing a page back to a block device w/ PIO could pick up
+	 * transactional data (bad!) so we force an abort here.  Before the
+	 * sync the page will be made read-only, which will flush_hash_page.
+	 * BIG ISSUE here: if the kernel uses a page from userspace without
+	 * unmapping it first, it may see the speculated version.

arch/powerpc/mm/hash_utils_64.c out_exit: · line 1337

Quoted 10 lines
arch/powerpc/mm/hash_utils_64.c +10 -0
+	 */
+static inline void abort_tm(int local)
+{
+	if (local && cpu_has_feature(CPU_FTR_TM) &&
+	    current->thread.regs &&
+	    MSR_TM_ACTIVE(current->thread.regs->msr)) {
+		tm_enable();
+		tm_abort(TM_CAUSE_TLBI);
+	}
+}

While your at this do

#else

static inline void abort_tm(int local)
{
}

arch/powerpc/mm/hash_utils_64.c void flush_hash_page(unsigned long vpn, real_pte_t pte, int psize, int ssize, · line 1365

Quoted 9 lines
arch/powerpc/mm/hash_utils_64.c +2 -0
+#endif
+
 /* WARNING: This is called from hash_low_64.S, if you change this prototype,
  *          do not forget to update the assembly call site !
  */
@@ -1344,19 +1363,7 @@ void flush_hash_page(unsigned long vpn, real_pte_t pte, int psize, int ssize,
 	} pte_iterate_hashed_end();
 
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM

Then remove these extra #ifdef

Quoted 18 lines
arch/powerpc/mm/hash_utils_64.c +1 -13
-	/* Transactions are not aborted by tlbiel, only tlbie.
-	 * Without, syncing a page back to a block device w/ PIO could pick up
-	 * transactional data (bad!) so we force an abort here.  Before the
-	 * sync the page will be made read-only, which will flush_hash_page.
-	 * BIG ISSUE here: if the kernel uses a page from userspace without
-	 * unmapping it first, it may see the speculated version.
-	 */
-	if (local && cpu_has_feature(CPU_FTR_TM) &&
-	    current->thread.regs &&
-	    MSR_TM_ACTIVE(current->thread.regs->msr)) {
-		tm_enable();
-		tm_abort(TM_CAUSE_TLBI);
-	}
+	abort_tm(local);
 #endif
 }
 

arch/powerpc/mm/hash_utils_64.c void flush_hash_hugepage(unsigned long vsid, unsigned long addr, · line 1424

Quoted 3 lines
arch/powerpc/mm/hash_utils_64.c +0 -0
@@ -1415,19 +1422,7 @@ void flush_hash_hugepage(unsigned long vsid, unsigned long addr,
 	}
 tm_abort:
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM

Then remove these extra #ifdef

Quoted 18 lines
arch/powerpc/mm/hash_utils_64.c +1 -13
-	/* Transactions are not aborted by tlbiel, only tlbie.
-	 * Without, syncing a page back to a block device w/ PIO could pick up
-	 * transactional data (bad!) so we force an abort here.  Before the
-	 * sync the page will be made read-only, which will flush_hash_page.
-	 * BIG ISSUE here: if the kernel uses a page from userspace without
-	 * unmapping it first, it may see the speculated version.
-	 */
-	if (local && cpu_has_feature(CPU_FTR_TM) &&
-	    current->thread.regs &&
-	    MSR_TM_ACTIVE(current->thread.regs->msr)) {
-		tm_enable();
-		tm_abort(TM_CAUSE_TLBI);
-	}
+	abort_tm(local);
 #endif
 	return;
 }
author
#2 lore raw
Quoted 37 lines · Balbir Singh
Quoted 23 lines · Rashmica Gupta

The same logic for tm_abort appears twice, so pull it out into a function.

---
  arch/powerpc/mm/hash_utils_64.c | 47 ++++++++++++++++++-----------------------
  1 file changed, 21 insertions(+), 26 deletions(-)
arch/powerpc/mm/hash_utils_64.c +7 -0
index 7635b1c6b5da..1cef8f5aee9b 100644
@@ -1318,6 +1318,25 @@ out_exit:
  	local_irq_restore(flags);
  }
 
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+	/* Transactions are not aborted by tlbiel, only tlbie.
+	 * Without, syncing a page back to a block device w/ PIO could pick up
+	 * transactional data (bad!) so we force an abort here.  Before the
+	 * sync the page will be made read-only, which will flush_hash_page.
+	 * BIG ISSUE here: if the kernel uses a page from userspace without
+	 * unmapping it first, it may see the speculated version.

arch/powerpc/mm/hash_utils_64.c out_exit: · line 1337

Quoted 10 lines
arch/powerpc/mm/hash_utils_64.c +10 -0
+	 */
+static inline void abort_tm(int local)
+{
+	if (local && cpu_has_feature(CPU_FTR_TM) &&
+	    current->thread.regs &&
+	    MSR_TM_ACTIVE(current->thread.regs->msr)) {
+		tm_enable();
+		tm_abort(TM_CAUSE_TLBI);
+	}
+}

While your at this do

Quoted 5 lines

#else

static inline void abort_tm(int local)
{
}

If I'm doing that, wouldn't it make more sense to write:

+static inline void abort_tm(int local)
+{
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+ if (local && cpu_has_feature(CPU_FTR_TM) &&
+ current->thread.regs &&
+ MSR_TM_ACTIVE(current->thread.regs->msr)) {
+ tm_enable();
+ tm_abort(TM_CAUSE_TLBI);
+ }
+#endif
+}

Quoted 50 lines

arch/powerpc/mm/hash_utils_64.c void flush_hash_page(unsigned long vpn, real_pte_t pte, int psize, int ssize, · line 1365

Quoted 9 lines
arch/powerpc/mm/hash_utils_64.c +2 -0
+#endif
+
  /* WARNING: This is called from hash_low_64.S, if you change this prototype,
   *          do not forget to update the assembly call site !
   */
@@ -1344,19 +1363,7 @@ void flush_hash_page(unsigned long vpn, real_pte_t pte, int psize, int ssize,
  	} pte_iterate_hashed_end();
 
  #ifdef CONFIG_PPC_TRANSACTIONAL_MEM

Then remove these extra #ifdef

Quoted 18 lines
arch/powerpc/mm/hash_utils_64.c +1 -13
-	/* Transactions are not aborted by tlbiel, only tlbie.
-	 * Without, syncing a page back to a block device w/ PIO could pick up
-	 * transactional data (bad!) so we force an abort here.  Before the
-	 * sync the page will be made read-only, which will flush_hash_page.
-	 * BIG ISSUE here: if the kernel uses a page from userspace without
-	 * unmapping it first, it may see the speculated version.
-	 */
-	if (local && cpu_has_feature(CPU_FTR_TM) &&
-	    current->thread.regs &&
-	    MSR_TM_ACTIVE(current->thread.regs->msr)) {
-		tm_enable();
-		tm_abort(TM_CAUSE_TLBI);
-	}
+	abort_tm(local);
  #endif
  }
 

arch/powerpc/mm/hash_utils_64.c void flush_hash_hugepage(unsigned long vsid, unsigned long addr, · line 1424

Quoted 3 lines
arch/powerpc/mm/hash_utils_64.c +0 -0
@@ -1415,19 +1422,7 @@ void flush_hash_hugepage(unsigned long vsid, unsigned long addr,
  	}
  tm_abort:
  #ifdef CONFIG_PPC_TRANSACTIONAL_MEM

Then remove these extra #ifdef

Quoted 18 lines
arch/powerpc/mm/hash_utils_64.c +1 -13
-	/* Transactions are not aborted by tlbiel, only tlbie.
-	 * Without, syncing a page back to a block device w/ PIO could pick up
-	 * transactional data (bad!) so we force an abort here.  Before the
-	 * sync the page will be made read-only, which will flush_hash_page.
-	 * BIG ISSUE here: if the kernel uses a page from userspace without
-	 * unmapping it first, it may see the speculated version.
-	 */
-	if (local && cpu_has_feature(CPU_FTR_TM) &&
-	    current->thread.regs &&
-	    MSR_TM_ACTIVE(current->thread.regs->msr)) {
-		tm_enable();
-		tm_abort(TM_CAUSE_TLBI);
-	}
+	abort_tm(local);
  #endif
  	return;
  }
#3 lore raw
Quoted 13 lines · Rashmica
Quoted 12 lines · Balbir Singh
Quoted 11 lines · Rashmica Gupta

The same logic for tm_abort appears twice, so pull it out into a function.

arch/powerpc/mm/hash_utils_64.c +0 -0
index 7635b1c6b5da..1cef8f5aee9b 100644
@@ -1318,6 +1318,25 @@ out_exit:
  	local_irq_restore(flags);
  }
 
Quoted 2 lines
Quoted 2 lines

arch/powerpc/mm/hash_utils_64.c out_exit: · line 1322

Quoted 2 lines
arch/powerpc/mm/hash_utils_64.c +2 -0
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+	/* Transactions are not aborted by tlbiel, only tlbie.

Can you fix up the comment formatting while you're there, should be:

/*
* Transactions are not aborted by tlbiel, only tlbie.

Quoted 17 lines
Quoted 17 lines
Quoted 5 lines
arch/powerpc/mm/hash_utils_64.c +5 -0
+	 * Without, syncing a page back to a block device w/ PIO could pick up
+	 * transactional data (bad!) so we force an abort here.  Before the
+	 * sync the page will be made read-only, which will flush_hash_page.
+	 * BIG ISSUE here: if the kernel uses a page from userspace without
+	 * unmapping it first, it may see the speculated version.

arch/powerpc/mm/hash_utils_64.c out_exit: · line 1337

Quoted 10 lines
arch/powerpc/mm/hash_utils_64.c +10 -0
+	 */
+static inline void abort_tm(int local)
+{
+	if (local && cpu_has_feature(CPU_FTR_TM) &&
+	    current->thread.regs &&
+	    MSR_TM_ACTIVE(current->thread.regs->msr)) {
+		tm_enable();
+		tm_abort(TM_CAUSE_TLBI);
+	}
+}

While your at this do

Quoted 8 lines
Quoted 5 lines

#else

static inline void abort_tm(int local)
{
}

If I'm doing that, wouldn't it make more sense to write:

+static inline void abort_tm(int local)

It needs a better name. Perhaps tlb_flush_abort_tm() ?

arch/powerpc/mm/hash_utils_64.c out_exit:

Quoted 10 lines
arch/powerpc/mm/hash_utils_64.c +10 -0
+{
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+	if (local && cpu_has_feature(CPU_FTR_TM) &&
+	    current->thread.regs &&
+	    MSR_TM_ACTIVE(current->thread.regs->msr)) {
+		tm_enable();
+		tm_abort(TM_CAUSE_TLBI);
+	}
+#endif
+}

In this case it would make some sense.

But the goal is "no #ifdef's in C code", which that would violate.

And if you have two functions that need to be inside the #ifdef then the above doesn't work anymore.

So the preferred style is:

  #ifdef CONFIG_FOO
  static void foo(int bar)
  {
  	...
  }
  #else /* !CONFIG_FOO */
  static inline foo(int bar) { }
  #endif

And when it expands you end up with:

  #ifdef CONFIG_FOO
  static void foo(int bar)
  {
  	...
  }

  static void foo_new(int bar)
  {
  	...
  }
  #else /* !CONFIG_FOO */
  static inline foo(int bar) { }
  static inline foo_new(int bar) { }
  #endif

cheers