On Tue, Jul 14, 2020 at 12:02:16AM -0700, ira.we...@intel.com wrote:

> +static pgprot_t dev_protection_enable_get(struct dev_pagemap *pgmap, 
> pgprot_t prot)
> +{
> +     if (pgmap->flags & PGMAP_PROT_ENABLED && dev_page_pkey != PKEY_INVALID) 
> {
> +             pgprotval_t val = pgprot_val(prot);
> +
> +             mutex_lock(&dev_prot_enable_lock);
> +             dev_protection_enable++;
> +             /* Only enable the static branch 1 time */
> +             if (dev_protection_enable == 1)
> +                     static_branch_enable(&dev_protection_static_key);
> +             mutex_unlock(&dev_prot_enable_lock);
> +
> +             prot = __pgprot(val | _PAGE_PKEY(dev_page_pkey));
> +     }
> +     return prot;
> +}
> +
> +static void dev_protection_enable_put(struct dev_pagemap *pgmap)
> +{
> +     if (pgmap->flags & PGMAP_PROT_ENABLED && dev_page_pkey != PKEY_INVALID) 
> {
> +             mutex_lock(&dev_prot_enable_lock);
> +             dev_protection_enable--;
> +             if (dev_protection_enable == 0)
> +                     static_branch_disable(&dev_protection_static_key);
> +             mutex_unlock(&dev_prot_enable_lock);
> +     }
> +}

That's an anti-pattern vs static_keys, I'm thinking you actually want
static_key_slow_{inc,dec}() instead of {enable,disable}().

Reply via email to