The patch titled Subject: z3fold: protect handle reads has been added to the -mm tree. Its filename is z3fold-protect-handle-reads.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/z3fold-protect-handle-reads.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/z3fold-protect-handle-reads.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Vitaly Wool <vitalywool@xxxxxxxxx> Subject: z3fold: protect handle reads We need to make sure slots are protected on reading a handle. Since handles are modified by free_handle() which only takes slot rwlock, that lock should be used when handles are read. Link: http://lkml.kernel.org/r/20191127152345.8059852f60947686674d726d@xxxxxxxxx Signed-off-by: Vitaly Wool <vitaly.vul@xxxxxxxx> Cc: Dan Streetman <ddstreet@xxxxxxxx> Cc: Henry Burns <henrywolfeburns@xxxxxxxxx> Cc: Shakeel Butt <shakeelb@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/z3fold.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/mm/z3fold.c~z3fold-protect-handle-reads +++ a/mm/z3fold.c @@ -486,8 +486,12 @@ static unsigned long encode_handle(struc /* only for LAST bud, returns zero otherwise */ static unsigned short handle_to_chunks(unsigned long handle) { - unsigned long addr = *(unsigned long *)handle; + struct z3fold_buddy_slots *slots = handle_to_slots(handle); + unsigned long addr; + read_lock(&slots->lock); + addr = *(unsigned long *)handle; + read_unlock(&slots->lock); return (addr & ~PAGE_MASK) >> BUDDY_SHIFT; } @@ -499,10 +503,13 @@ static unsigned short handle_to_chunks(u static enum buddy handle_to_buddy(unsigned long handle) { struct z3fold_header *zhdr; + struct z3fold_buddy_slots *slots = handle_to_slots(handle); unsigned long addr; + read_lock(&slots->lock); WARN_ON(handle & (1 << PAGE_HEADLESS)); addr = *(unsigned long *)handle; + read_unlock(&slots->lock); zhdr = (struct z3fold_header *)(addr & PAGE_MASK); return (addr - zhdr->first_num) & BUDDY_MASK; } _ Patches currently in -mm which might be from vitalywool@xxxxxxxxx are z3fold-avoid-subtle-race-when-freeing-slots.patch z3fold-compact-objects-more-accurately.patch z3fold-protect-handle-reads.patch