Re: [RFC PATCH 11/15] memremap: Add zone device access protection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jul 14, 2020 at 12:02:16AM -0700, ira.weiny@xxxxxxxxx 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}().




[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux