Skip to content

Commit a3483c3

Browse files
chleroympe
authored andcommitted
powerpc/code-patching: Fix unmap_patch_area() error handling
pXd_offset() doesn't return NULL. When the base is NULL, it still adds the offset. Use pXd_none() to check validity instead. It also improves performance by folding out none existing levels as pXd_none() always returns 0 in that case. Such an error is unexpected, use WARN_ON() so that the caller doesn't have to worry about it, and drop the returned value. And now that unmap_patch_area() doesn't return error, we can take into account the error returned by __patch_instruction(). While at it, remove the 'inline' property which is useless. Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/299804b117fae35c786c827536c91f25352e279b.1638446239.git.christophe.leroy@csgroup.eu
1 parent 285672f commit a3483c3

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

arch/powerpc/lib/code-patching.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static int map_patch_area(void *addr, unsigned long text_poke_addr)
9494
return map_kernel_page(text_poke_addr, (pfn << PAGE_SHIFT), PAGE_KERNEL);
9595
}
9696

97-
static inline int unmap_patch_area(unsigned long addr)
97+
static void unmap_patch_area(unsigned long addr)
9898
{
9999
pte_t *ptep;
100100
pmd_t *pmdp;
@@ -103,32 +103,30 @@ static inline int unmap_patch_area(unsigned long addr)
103103
pgd_t *pgdp;
104104

105105
pgdp = pgd_offset_k(addr);
106-
if (unlikely(!pgdp))
107-
return -EINVAL;
106+
if (WARN_ON(pgd_none(*pgdp)))
107+
return;
108108

109109
p4dp = p4d_offset(pgdp, addr);
110-
if (unlikely(!p4dp))
111-
return -EINVAL;
110+
if (WARN_ON(p4d_none(*p4dp)))
111+
return;
112112

113113
pudp = pud_offset(p4dp, addr);
114-
if (unlikely(!pudp))
115-
return -EINVAL;
114+
if (WARN_ON(pud_none(*pudp)))
115+
return;
116116

117117
pmdp = pmd_offset(pudp, addr);
118-
if (unlikely(!pmdp))
119-
return -EINVAL;
118+
if (WARN_ON(pmd_none(*pmdp)))
119+
return;
120120

121121
ptep = pte_offset_kernel(pmdp, addr);
122-
if (unlikely(!ptep))
123-
return -EINVAL;
122+
if (WARN_ON(pte_none(*ptep)))
123+
return;
124124

125125
/*
126126
* In hash, pte_clear flushes the tlb, in radix, we have to
127127
*/
128128
pte_clear(&init_mm, addr, ptep);
129129
flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
130-
131-
return 0;
132130
}
133131

134132
static int do_patch_instruction(u32 *addr, ppc_inst_t instr)
@@ -156,11 +154,9 @@ static int do_patch_instruction(u32 *addr, ppc_inst_t instr)
156154

157155
patch_addr = (u32 *)(text_poke_addr + (kaddr & ~PAGE_MASK));
158156

159-
__patch_instruction(addr, instr, patch_addr);
157+
err = __patch_instruction(addr, instr, patch_addr);
160158

161-
err = unmap_patch_area(text_poke_addr);
162-
if (err)
163-
pr_warn("failed to unmap %lx\n", text_poke_addr);
159+
unmap_patch_area(text_poke_addr);
164160

165161
out:
166162
local_irq_restore(flags);

0 commit comments

Comments
 (0)