Skip to content

improve context handling

Johannes Berg linux-sparse 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 22 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3make sparse keep its promise about context trackinginline.c linearize.c linearize.h +8 more+860 -8519 replies
2/3sparse test suite: add test mixing __context__ and __attribute__((context(...)))validation/context-named.c+21 -00 replies
3/3sparse: simple conditional context trackinglinearize.c linearize.h parse.c +4 more+270 -330 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/3] improve context handling

Hi,

Here are three patches to improve context tracking in sparse. For example, with the patches, one could define

spin_lock_irqsave() __acquires(local_irq) __acquires(spinlock) spin_unlock_irqrestore() __releases(local_irq) __releases(spinlock)

local_irq_save() __acquires(local_irq)
local_irq_restore() __releases(local_irq)

spin_lock() __acquires(spinlock)
spin_unlock() __releases(spinlock)

spin_trylock() __attribute__((conditional_context(spinlock,0,1,0)))

and sparse should be able to check constructs like the one in sungem completely:

        local_irq_save(flags);
        if (!spin_trylock(&gp->tx_lock)) {
                /* Tell upper layer to requeue */
                local_irq_restore(flags);
                return ...;
        }
        if (..) {
                spin_unlock_irqrestore(&gp->tx_lock, flags);
                return ...;
        }
        [...]
        spin_unlock_irqrestore(&gp->tx_lock, flags);

I haven't tried this particular case, but I have tried simpler versions of all the primivites used, those are in the test suite.

Also, one can now define, as the sparse man page already suggests without patches:

/* needs irqs disabled */
void myfunc(void) __attribute__((context(local_irq,1,1))) {...}

and sparse will warn when the function is called from a context that doesn't have local_irq. Of course, if the context comes from outside the calling function then the calling function needs to use that attribute as well to indicate that it too needs irqs disabled.

Comments welcome!

johannes