Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1978329ybh; Tue, 14 Jul 2020 12:08:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyPikxNKAmhAZ6tiw4mlQ9N2E3mL5HqSiwHNHzJ05jprFtizHJfQlnTV0qlYCu4iL6En7p X-Received: by 2002:a17:907:4003:: with SMTP id nj3mr5829809ejb.278.1594753726176; Tue, 14 Jul 2020 12:08:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594753726; cv=none; d=google.com; s=arc-20160816; b=YnlEbGdMxwzRs7+c+PBjjV4TmVPrLBBHvv695xXuKbFS/wezYxcTGvorAqZUq1iS9A dLRmgxBDCNbQnYus2aBdIMPgbDppj/biUi28/Nip4bFPr5emz/uxMOCOCj3MIYoVrzHO wQutyrI84k7BuQQEvFTo2MC81dGKngTOUNnMB7hbgXbuQSO4WwNiuLl8H/Ee9g0cPX0M 4PIjBu4Hi6Ys9BTixrBT8FrrfNkM69fUbci2+FNhVdupy9llHPxaLSk9gZp0j8ePt/Q9 eaUIVwjSjU8nc6K4KbSRyQeoSup9MyLo5OFstAVA4t0rF6+RLwYkpbkew0FfApm24AWH PMcA== 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=R7znKETcPdZMQWvnli4HQjgA25b2drC5Ffc5S0JMpHM=; b=WRY4sK+synvXPnuBFbJ7KgCcEZE5FhrsDk9Nf9NrCy3Yys3+GbqUtruFOik53ckR+E ueioeE6TBul2k7Ep/VrlS+L8nwbQqb/qDcqCGF8mR5FFQw/9O+BguX+6B38s4wGvzPAW AMLPmXYLWKPxbocKxCxLZoh/Ld4vffN2Rr7t7OkyxTpDjeWPYhrbsMVFJVOIhUR0IEAv eXzE/VDRdYLYcHLu/PgI8AlexQ8PGOWMq6yN4NxMV2z+gFi6VLX+ZzrFNOix1HfNzQou rKCy3Y4UF6oOktE+WVMQyEtZNCsm9nUlPQlT5fQoT4Kcp0Zb+d5COvr8wN4yxKBzBTIA V80w== 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 h1si11775236edv.246.2020.07.14.12.08.22; Tue, 14 Jul 2020 12:08:46 -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 S1731256AbgGNTG0 (ORCPT + 99 others); Tue, 14 Jul 2020 15:06:26 -0400 Received: from mga14.intel.com ([192.55.52.115]:45257 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731196AbgGNTGR (ORCPT ); Tue, 14 Jul 2020 15:06:17 -0400 IronPort-SDR: 27iBeCfoeLRrVUeRTy/BI0zBGPcmN+PmJoub48PPOgpH+618PXlf6ue/5i8667iiPyfSDqvbOY ES4o41RqYn5w== X-IronPort-AV: E=McAfee;i="6000,8403,9682"; a="148148363" X-IronPort-AV: E=Sophos;i="5.75,352,1589266800"; d="scan'208";a="148148363" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2020 12:06:16 -0700 IronPort-SDR: 372ah54Muur1nzmIJ6WpFVvasq6EKc/XBygmqwb4njk9NqFeHdl/Vb7u58xf0Grd72pTvNiTPg ndEouPAOrQ8w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,352,1589266800"; d="scan'208";a="324632815" Received: from iweiny-desk2.sc.intel.com ([10.3.52.147]) by FMSMGA003.fm.intel.com with ESMTP; 14 Jul 2020 12:06:16 -0700 Date: Tue, 14 Jul 2020 12:06:16 -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 12/15] kmap: Add stray write protection for device pages Message-ID: <20200714190615.GC3008823@iweiny-DESK2.sc.intel.com> References: <20200714070220.3500839-1-ira.weiny@intel.com> <20200714070220.3500839-13-ira.weiny@intel.com> <20200714084451.GQ10769@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200714084451.GQ10769@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:44:51AM +0200, Peter Zijlstra wrote: > On Tue, Jul 14, 2020 at 12:02:17AM -0700, ira.weiny@intel.com wrote: > > From: Ira Weiny > > > > Device managed pages may have additional protections. These protections > > need to be removed prior to valid use by kernel users. > > > > Check for special treatment of device managed pages in kmap and take > > action if needed. We use kmap as an interface for generic kernel code > > because under normal circumstances it would be a bug for general kernel > > code to not use kmap prior to accessing kernel memory. Therefore, this > > should allow any valid kernel users to seamlessly use these pages > > without issues. > > > > Signed-off-by: Ira Weiny > > --- > > include/linux/highmem.h | 32 +++++++++++++++++++++++++++++++- > > 1 file changed, 31 insertions(+), 1 deletion(-) > > > > diff --git a/include/linux/highmem.h b/include/linux/highmem.h > > index d6e82e3de027..7f809d8d5a94 100644 > > --- a/include/linux/highmem.h > > +++ b/include/linux/highmem.h > > @@ -8,6 +8,7 @@ > > #include > > #include > > #include > > +#include > > > > #include > > > > @@ -31,6 +32,20 @@ static inline void invalidate_kernel_vmap_range(void *vaddr, int size) > > > > #include > > > > +static inline void enable_access(struct page *page) > > +{ > > + if (!page_is_access_protected(page)) > > + return; > > + dev_access_enable(); > > +} > > + > > +static inline void disable_access(struct page *page) > > +{ > > + if (!page_is_access_protected(page)) > > + return; > > + dev_access_disable(); > > +} > > So, if I followed along correctly, you're proposing to do a WRMSR per > k{,un}map{_atomic}(), sounds like excellent performance all-round :-( Only to pages which have this additional protection, ie not DRAM. User mappings of this memory is not affected (would be covered by User PKeys if desired). User mappings to persistent memory are the primary use case and the performant path. Ira