From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F917C433F2 for ; Tue, 14 Jul 2020 19:10:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1F59C2255F for ; Tue, 14 Jul 2020 19:10:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1F59C2255F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B0CC58D0002; Tue, 14 Jul 2020 15:10:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ABF758D0001; Tue, 14 Jul 2020 15:10:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FB898D0002; Tue, 14 Jul 2020 15:10:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0228.hostedemail.com [216.40.44.228]) by kanga.kvack.org (Postfix) with ESMTP id 8BCD68D0001 for ; Tue, 14 Jul 2020 15:10:50 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 506F5181AC9CC for ; Tue, 14 Jul 2020 19:10:50 +0000 (UTC) X-FDA: 77037623460.02.vest73_4b00cfb26ef3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 33CAD2000384CF1D for ; Tue, 14 Jul 2020 19:10:50 +0000 (UTC) X-HE-Tag: vest73_4b00cfb26ef3 X-Filterd-Recvd-Size: 3540 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Tue, 14 Jul 2020 19:10:49 +0000 (UTC) IronPort-SDR: mfbih9jznVuYAl8ekOT+P1X0aVNeYn0KFuCwzjtLysUkNPpdepDmzSX4P1gDrwhyZLK6ZMCBN/ FzDja/+Ms5Kw== X-IronPort-AV: E=McAfee;i="6000,8403,9682"; a="233867071" X-IronPort-AV: E=Sophos;i="5.75,352,1589266800"; d="scan'208";a="233867071" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2020 12:10:48 -0700 IronPort-SDR: ynd6Lt5TNvbdI+beUCIxuy6WUQInSo1MvaulrgHmRMdJk8pzs6c5iZa/GKm6K4HDRY3ph5QM5F 8i7mRSpTTt1w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,352,1589266800"; d="scan'208";a="390568284" Received: from iweiny-desk2.sc.intel.com ([10.3.52.147]) by fmsmga001.fm.intel.com with ESMTP; 14 Jul 2020 12:10:47 -0700 Date: Tue, 14 Jul 2020 12:10:47 -0700 From: Ira Weiny To: Peter Zijlstra Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , x86@kernel.org, Dave Hansen , Dan Williams , Vishal Verma , Andrew Morton , Fenghua Yu , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Subject: Re: [RFC PATCH 11/15] memremap: Add zone device access protection Message-ID: <20200714191047.GE3008823@iweiny-DESK2.sc.intel.com> References: <20200714070220.3500839-1-ira.weiny@intel.com> <20200714070220.3500839-12-ira.weiny@intel.com> <20200714084057.GP10769@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200714084057.GP10769@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.11.1 (2018-12-01) X-Rspamd-Queue-Id: 33CAD2000384CF1D X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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@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}(). Thanks. I'll go read the doc for those as I'm not familiar with them. Ira