Skip to content

Commit 007a794

Browse files
Christophe Leroy (CS GROUP)maddy-kerneldev
authored andcommitted
powerpc/align: Convert emulate_spe() to scoped user access
Commit 861574d ("powerpc/uaccess: Implement masked user access") provides optimised user access by avoiding the cost of access_ok(). Convert emulate_spe() to scoped user access to benefit from masked user access. Scoped user access also make the code simpler. Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org> Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com> Link: https://patch.msgid.link/4ff83cb240da4e2d0c34e2bce4b8b6ef19a33777.1773136880.git.chleroy@kernel.org
1 parent 22154e7 commit 007a794

1 file changed

Lines changed: 33 additions & 42 deletions

File tree

arch/powerpc/kernel/align.c

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -165,25 +165,23 @@ static int emulate_spe(struct pt_regs *regs, unsigned int reg,
165165
temp.ll = data.ll = 0;
166166
p = addr;
167167

168-
if (!user_read_access_begin(addr, nb))
169-
return -EFAULT;
170-
171-
switch (nb) {
172-
case 8:
173-
unsafe_get_user(temp.v[0], p++, Efault_read);
174-
unsafe_get_user(temp.v[1], p++, Efault_read);
175-
unsafe_get_user(temp.v[2], p++, Efault_read);
176-
unsafe_get_user(temp.v[3], p++, Efault_read);
177-
fallthrough;
178-
case 4:
179-
unsafe_get_user(temp.v[4], p++, Efault_read);
180-
unsafe_get_user(temp.v[5], p++, Efault_read);
181-
fallthrough;
182-
case 2:
183-
unsafe_get_user(temp.v[6], p++, Efault_read);
184-
unsafe_get_user(temp.v[7], p++, Efault_read);
168+
scoped_user_read_access_size(addr, nb, efault) {
169+
switch (nb) {
170+
case 8:
171+
unsafe_get_user(temp.v[0], p++, efault);
172+
unsafe_get_user(temp.v[1], p++, efault);
173+
unsafe_get_user(temp.v[2], p++, efault);
174+
unsafe_get_user(temp.v[3], p++, efault);
175+
fallthrough;
176+
case 4:
177+
unsafe_get_user(temp.v[4], p++, efault);
178+
unsafe_get_user(temp.v[5], p++, efault);
179+
fallthrough;
180+
case 2:
181+
unsafe_get_user(temp.v[6], p++, efault);
182+
unsafe_get_user(temp.v[7], p++, efault);
183+
}
185184
}
186-
user_read_access_end();
187185

188186
switch (instr) {
189187
case EVLDD:
@@ -252,38 +250,31 @@ static int emulate_spe(struct pt_regs *regs, unsigned int reg,
252250
if (flags & ST) {
253251
p = addr;
254252

255-
if (!user_write_access_begin(addr, nb))
256-
return -EFAULT;
257-
258-
switch (nb) {
259-
case 8:
260-
unsafe_put_user(data.v[0], p++, Efault_write);
261-
unsafe_put_user(data.v[1], p++, Efault_write);
262-
unsafe_put_user(data.v[2], p++, Efault_write);
263-
unsafe_put_user(data.v[3], p++, Efault_write);
264-
fallthrough;
265-
case 4:
266-
unsafe_put_user(data.v[4], p++, Efault_write);
267-
unsafe_put_user(data.v[5], p++, Efault_write);
268-
fallthrough;
269-
case 2:
270-
unsafe_put_user(data.v[6], p++, Efault_write);
271-
unsafe_put_user(data.v[7], p++, Efault_write);
253+
scoped_user_write_access_size(addr, nb, efault) {
254+
switch (nb) {
255+
case 8:
256+
unsafe_put_user(data.v[0], p++, efault);
257+
unsafe_put_user(data.v[1], p++, efault);
258+
unsafe_put_user(data.v[2], p++, efault);
259+
unsafe_put_user(data.v[3], p++, efault);
260+
fallthrough;
261+
case 4:
262+
unsafe_put_user(data.v[4], p++, efault);
263+
unsafe_put_user(data.v[5], p++, efault);
264+
fallthrough;
265+
case 2:
266+
unsafe_put_user(data.v[6], p++, efault);
267+
unsafe_put_user(data.v[7], p++, efault);
268+
}
272269
}
273-
user_write_access_end();
274270
} else {
275271
*evr = data.w[0];
276272
regs->gpr[reg] = data.w[1];
277273
}
278274

279275
return 1;
280276

281-
Efault_read:
282-
user_read_access_end();
283-
return -EFAULT;
284-
285-
Efault_write:
286-
user_write_access_end();
277+
efault:
287278
return -EFAULT;
288279
}
289280
#endif /* CONFIG_SPE */

0 commit comments

Comments
 (0)