Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp153319ybh; Fri, 17 Jul 2020 22:51:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx231HBiL29Ejhd3GTIrd2HD6iZmOtFjKJ/3ljR3qUfhglpMEcIlpHq8OIcnixH4ETcaO6w X-Received: by 2002:a05:6402:1614:: with SMTP id f20mr12119193edv.129.1595051497519; Fri, 17 Jul 2020 22:51:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595051497; cv=none; d=google.com; s=arc-20160816; b=IhFpuU3PZB4nDzURCIXsWpUsa2o1PCWIe9ki9H2idz2R7STE0Oza199QOtVCWTrxF/ px252/5q/uKJ0gYwjn6CkkWKgrU6veTBgEAdXdrRLqv0UolLPaBQmOI2u+66D/vpLxtb jxW84GucJ3wsGk3pmy0IUn9JuG40D1qX9x8wwHCLrltrMjUk+VtlcQYbv/4UyoodYAkK +MmEK9/goIwdlClCUIlWq4ixxAmLOT0ZYazSRY/yXJgXfo2KLQdVpbxOZBAKrDtFX9o8 LXH2liqKiJpLos9JP/TdDDhqy7ofGy4rpjgokY2c8ORXW6eMSFSua+66Pc0b2bSit6jz M0vA== 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=VDqZdjvYyLv5T/RhvoxDIJD4TAEvoP0JhaPxN7W4RiQ=; b=ZHDUj2nWOssFJEZlLGdcgp/BJQJoFGB3prtGEMWM1m0E7YwxCjNKeSseJoJxUCqHz1 n6dBmtkJ826DXobbTiZ5igw5dxNpQzM4iWCaxezF3sQ6YiyKMUlAt4/ngNWgse71pHrJ QTXa63dgvASjxT1d9sYeQLKtvoX2L20JUMGGThjelRA7Tz8U0K0z91atuXuylJnCZGti 3s+UKUsDUBGWPxrSyPaNL81PXutzxaa06x0Gd9PrCmmfzL9cURpPnQA/S4Vmx3WSmkFI WO+m8cDaHvwEEzhIcqJK7EKHEJvmiKKKi7kaTMvDS+SLNJWXj5Vht3LQr5yv+ZE96hIf RNAw== 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 p13si6532869ejd.637.2020.07.17.22.51.14; Fri, 17 Jul 2020 22:51:37 -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 S1726614AbgGRFvG (ORCPT + 99 others); Sat, 18 Jul 2020 01:51:06 -0400 Received: from mga18.intel.com ([134.134.136.126]:11135 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726249AbgGRFvF (ORCPT ); Sat, 18 Jul 2020 01:51:05 -0400 IronPort-SDR: AYj5vi9SRqf90NzlG1PtvIWR5kP8GG2xKuSQJMNrukWUMpeW1xa+p5v6uCymiFzQveeMn9wzGH rTUZnN7GJfGw== X-IronPort-AV: E=McAfee;i="6000,8403,9685"; a="137186390" X-IronPort-AV: E=Sophos;i="5.75,365,1589266800"; d="scan'208";a="137186390" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jul 2020 22:51:04 -0700 IronPort-SDR: Bc8yS/Mga/P/JELyDS9maVNQZIck4wfEmlGO3VkOyOrNQb8SVgJAdVZL/lTq/KBuOwtXK2wrMt piSYLWsQeJ9A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,365,1589266800"; d="scan'208";a="282993538" Received: from iweiny-desk2.sc.intel.com ([10.3.52.147]) by orsmga003.jf.intel.com with ESMTP; 17 Jul 2020 22:51:04 -0700 Date: Fri, 17 Jul 2020 22:51:03 -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: [PATCH RFC V2 12/17] memremap: Add zone device access protection Message-ID: <20200718055103.GU3008823@iweiny-DESK2.sc.intel.com> References: <20200717072056.73134-1-ira.weiny@intel.com> <20200717072056.73134-13-ira.weiny@intel.com> <20200717091718.GA10769@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200717091718.GA10769@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 Fri, Jul 17, 2020 at 11:17:18AM +0200, Peter Zijlstra wrote: > On Fri, Jul 17, 2020 at 12:20:51AM -0700, ira.weiny@intel.com wrote: > > +void dev_access_disable(void) > > +{ > > + unsigned long flags; > > + > > + if (!static_branch_unlikely(&dev_protection_static_key)) > > + return; > > + > > + local_irq_save(flags); > > + current->dev_page_access_ref--; > > + if (current->dev_page_access_ref == 0) > > if (!--current->dev_page_access_ref) It's not my style but I'm ok with it. > > > + pks_update_protection(dev_page_pkey, PKEY_DISABLE_ACCESS); > > + local_irq_restore(flags); > > +} > > +EXPORT_SYMBOL_GPL(dev_access_disable); > > + > > +void dev_access_enable(void) > > +{ > > + unsigned long flags; > > + > > + if (!static_branch_unlikely(&dev_protection_static_key)) > > + return; > > + > > + local_irq_save(flags); > > + /* 0 clears the PKEY_DISABLE_ACCESS bit, allowing access */ > > + if (current->dev_page_access_ref == 0) > > + pks_update_protection(dev_page_pkey, 0); > > + current->dev_page_access_ref++; > > if (!current->dev_page_access_ref++) Sure. > > > + local_irq_restore(flags); > > +} > > +EXPORT_SYMBOL_GPL(dev_access_enable); > > > Also, you probably want something like: > > static __always_inline devm_access_disable(void) Yes that is better. However, again Dan and I agree devm is not the right prefix here. I've updated. Thanks! Ira > { > if (static_branch_unlikely(&dev_protection_static_key)) > __devm_access_disable(); > } > > static __always_inline devm_access_enable(void) > { > if (static_branch_unlikely(&dev_protection_static_key)) > __devm_access_enable(); > }