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=-11.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable 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 686B3C433E0 for ; Tue, 14 Jul 2020 19:06:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3925022AAB for ; Tue, 14 Jul 2020 19:06:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3925022AAB 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 DA7C78D0003; Tue, 14 Jul 2020 15:06:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D32F78D0001; Tue, 14 Jul 2020 15:06:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF9618D0003; Tue, 14 Jul 2020 15:06:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0079.hostedemail.com [216.40.44.79]) by kanga.kvack.org (Postfix) with ESMTP id AB0008D0001 for ; Tue, 14 Jul 2020 15:06:27 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 6527C1EFD for ; Tue, 14 Jul 2020 19:06:27 +0000 (UTC) X-FDA: 77037612414.30.wind08_290cc9426ef3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 9FA61180B31B9 for ; Tue, 14 Jul 2020 19:06:19 +0000 (UTC) X-HE-Tag: wind08_290cc9426ef3 X-Filterd-Recvd-Size: 4363 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Tue, 14 Jul 2020 19:06:18 +0000 (UTC) IronPort-SDR: 1Zc3vwTRWYSxYf9UyBYF8LXL7n2t/KcKMrSFboLgntAr2+SiXiTY7zOz+tuGZDTBHcy+SFljpY kWU36ykHSCGQ== X-IronPort-AV: E=McAfee;i="6000,8403,9682"; a="167128346" X-IronPort-AV: E=Sophos;i="5.75,352,1589266800"; d="scan'208";a="167128346" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.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) X-Rspamd-Queue-Id: 9FA61180B31B9 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: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