Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1980069ybh; Tue, 14 Jul 2020 12:11:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJ2CVuXsknPUlb5HxrOSkU9bA9D8VEDnbbSy3UsoMPKnh6kZlzLpUmZBJretZnj20+6KJp X-Received: by 2002:aa7:db11:: with SMTP id t17mr5820601eds.365.1594753879475; Tue, 14 Jul 2020 12:11:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594753879; cv=none; d=google.com; s=arc-20160816; b=tmaEFK/Ox715nRLzQ0XRAvsxat+IY6CAoIRbVIV3tkVxJHv1iszaVzvcAV38j7Z/YX UV77vStmYEa7xfkiRO+wdrCOtfn0BxbYU7HCTN/9RRonjbxWAktqPQbeHUzMtj0BvfhW 0VCSDIuvkJumQsOghGkRaMHKuezVZ3NaIcQlffMfw3qL4bDzqdtAwNNO3cePAI5Q1lV/ fkWDoZyk9d2o/r4tWG1zFygsui/yoWhbJ3pvAMiBgJqjFhBUlvNYh+wR8VbboR9PF28i df+3r+nhUwiffqSmeUNGZ6WbNUbvTVoAcL65nPLBQHzxI6UvQTx/IuGHxje5RWzHmAXD DC2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=Uh0RM+AVWd+jS7InDC8q/KeQmiilHQY+0+N1llZtFu4=; b=rABP6thcZb7O0uO1NTICbcpKcOhZRJJ2h6iy8D8NyDmlwKxt/37U4wIXgGDStMuaLD VM9He/qhaqoDBUmcsHF89M/AcsKh5lBunvZr+vbF/YRh8zIRZJ13Zo0W3b8Oo0f447pf GMM75eed193CL9cBJ0nZ9+KyYlUpwgF0JtKyKFto1PNglIYIQJCI7k3Q4xtrzzNBlXK/ bGrcYGwJ5aTyqLxRl+VDz1GP60NPX9GDbXmL7hqp9EnsZfhvDmue4wlAVWiDVxKoXEiF 5Zwhis3UJapLdARbQ8kVCfkcFYGP7DXTlAXfeQsTG7R83ws7vKTSFXTFJzd5hEl9dZIw 6h3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n6si12113289edb.96.2020.07.14.12.10.56; Tue, 14 Jul 2020 12:11:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731498AbgGNTKu (ORCPT + 99 others); Tue, 14 Jul 2020 15:10:50 -0400 Received: from mga12.intel.com ([192.55.52.136]:44617 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729740AbgGNTKs (ORCPT ); Tue, 14 Jul 2020 15:10:48 -0400 IronPort-SDR: aRltyJuDUAWNLWYG9L4QE5NcVtwR+o0I6oAsrfTCFWW7zwEKXRsIKbMn3/g3D4ZKj7B4RhAQtV p+Vp9Itfn7kQ== X-IronPort-AV: E=McAfee;i="6000,8403,9682"; a="128568509" X-IronPort-AV: E=Sophos;i="5.75,352,1589266800"; d="scan'208";a="128568509" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.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) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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