[PATCH v2] riscv: probes: reject kprobes inside LR/SC sequences

Nam Cao namcao at linutronix.de
Tue Aug 25 00:02:07 PDT 2026


Xiaofeng Yuan <yuanxiaofeng at eswincomputing.com> writes:
> +/*
> + * A trap taken in the middle of an LR/SC sequence clears the load
> + * reservation, so an SC following the probed instruction would always
> + * fail and the enclosing retry loop would re-enter the breakpoint.
> + * Reject probes inside such a sequence.
> + *
> + * A constrained LR/SC loop (Zalrsc) must be contained within a 64-byte
> + * contiguous region of memory and comprise at most 16 instructions.
> + * Both bounds hold regardless of the C extension, so scanning back
> + * 64 bytes from the probed instruction always covers the enclosing
> + * sequence.
> + */
> +#define MAX_ATOMIC_CONTEXT_SIZE	64

Instead of 64 bytes, can we just do 16 instructions?

And instead of finding the start address to scan and then do a forward
scan, doing a backward scan of 16 instructions is probably cleaner and
more efficient?

Nam



More information about the linux-riscv mailing list