[PATCH] ARM: Add SWP/SWPB emulation for ARMv7 processors (v2)

Catalin Marinas catalin.marinas at arm.com
Sat Dec 19 12:18:42 EST 2009


On Fri, 2009-12-18 at 18:20 +0000, Russell King - ARM Linux wrote:
> On Fri, Dec 18, 2009 at 06:04:06PM +0000, Leif Lindholm wrote:
> > +static int swp_handler(struct pt_regs *regs, unsigned int instr)
> > +{
> > +     unsigned int address, destreg, data;
> > +     unsigned int res = 0;
> > +     long current_pid = sys_getpid();
> 
> Kernel functions calling system calls like this is frowned upon.  We
> know what the current PID is - it's available from current->pid.  No
> function call required.

Actually, current->pid together with get_task_comm() would be even more
useful since the task may die by the time you check the running apps.

> > +       NOTE: when accessing uncached shared regions, LDREX/STREX rely
> > +       on an external transaction monitoring block called a global
> > +       monitor to maintain update atomicity. If your system does not
> > +       implement a global monitor, this option is not safe for programs
> > +       that are permitted to map uncached memory (CAP_SYS_RAWIO).
> 
> We can trap this case by looking at the L_PTE_MT_* bits in the pte
> for the page we're going to be accessing - that's probably a good
> idea to ensure that such accesses are trapped, rather than going
> head and possibly risking silent corruption.

I wonder if there could be an exploit with Leif's current
implementation. The LDREX/STREX pair to uncached or device memory may
never complete. This way a user SWP to something like the frame buffer
would lock the kernel.

There's also TI's issue with SWP to some memory shared with devices
outside the CPU coherency domain where SWP may still be needed. Is this
usage in user space or kernel device drivers?

The major issue I see with SWP is that it isn't guaranteed to always
work in an SMP shareability domain (bus locking not implemented), hence
the LDREX/STREX emulation.

But Leif is away for the rest of the year, so we won't see an updated
patch before January.

-- 
Catalin




More information about the linux-arm-kernel mailing list