[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200714191047.GE3008823@iweiny-DESK2.sc.intel.com>
Date: Tue, 14 Jul 2020 12:10:47 -0700
From: Ira Weiny <ira.weiny@...el.com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Andy Lutomirski <luto@...nel.org>, x86@...nel.org,
Dave Hansen <dave.hansen@...ux.intel.com>,
Dan Williams <dan.j.williams@...el.com>,
Vishal Verma <vishal.l.verma@...el.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Fenghua Yu <fenghua.yu@...el.com>, linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-nvdimm@...ts.01.org,
linux-fsdevel@...r.kernel.org, linux-mm@...ck.org,
linux-kselftest@...r.kernel.org
Subject: Re: [RFC PATCH 11/15] memremap: Add zone device access protection
On Tue, Jul 14, 2020 at 10:40:57AM +0200, Peter Zijlstra wrote:
> On Tue, Jul 14, 2020 at 12:02:16AM -0700, ira.weiny@...el.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}().
Thanks. I'll go read the doc for those as I'm not familiar with them.
Ira
Powered by blists - more mailing lists