The patch titled Subject: mm/memremap.c: convert devmap static branch to {inc,dec} has been added to the -mm tree. Its filename is memremap-convert-devmap-static-branch-to-incdec.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/memremap-convert-devmap-static-branch-to-incdec.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/memremap-convert-devmap-static-branch-to-incdec.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: Ira Weiny <ira.weiny@xxxxxxxxx> Subject: mm/memremap.c: convert devmap static branch to {inc,dec} While reviewing Protection Key Supervisor support it was pointed out that using a counter to track static branch enable was an anti-pattern which was better solved using the provided static_branch_{inc,dec} functions.[1] Fix up devmap_managed_key to work the same way. Also this should be safer because there is a very small (very unlikely) race when multiple callers try to enable at the same time. [1] https://lore.kernel.org/lkml/20200714194031.GI5523@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/ Link: https://lkml.kernel.org/r/20200810235319.2796597-1-ira.weiny@xxxxxxxxx Signed-off-by: Ira Weiny <ira.weiny@xxxxxxxxx> Reviewed-by: William Kucharski <william.kucharski@xxxxxxxxxx> Cc: Dan Williams <dan.j.williams@xxxxxxxxx> Cc: Vishal Verma <vishal.l.verma@xxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/memremap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) --- a/mm/memremap.c~memremap-convert-devmap-static-branch-to-incdec +++ a/mm/memremap.c @@ -40,12 +40,10 @@ EXPORT_SYMBOL_GPL(memremap_compat_align) #ifdef CONFIG_DEV_PAGEMAP_OPS DEFINE_STATIC_KEY_FALSE(devmap_managed_key); EXPORT_SYMBOL(devmap_managed_key); -static atomic_t devmap_managed_enable; static void devmap_managed_enable_put(void) { - if (atomic_dec_and_test(&devmap_managed_enable)) - static_branch_disable(&devmap_managed_key); + static_branch_dec(&devmap_managed_key); } static int devmap_managed_enable_get(struct dev_pagemap *pgmap) @@ -56,8 +54,7 @@ static int devmap_managed_enable_get(str return -EINVAL; } - if (atomic_inc_return(&devmap_managed_enable) == 1) - static_branch_enable(&devmap_managed_key); + static_branch_inc(&devmap_managed_key); return 0; } #else _ Patches currently in -mm which might be from ira.weiny@xxxxxxxxx are memremap-convert-devmap-static-branch-to-incdec.patch mm-highmem-clean-up-endif-comments.patch