lkml.org 
[lkml]   [2020]   [Jul]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC PATCH 11/15] memremap: Add zone device access protection
On Tue, Jul 14, 2020 at 12:02:16AM -0700, ira.weiny@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}().

\
 
 \ /
  Last update: 2020-07-14 10:41    [W:0.131 / U:1.304 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site