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=-9.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 324DFC433DF for ; Tue, 14 Jul 2020 08:45:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E88A921897 for ; Tue, 14 Jul 2020 08:45:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="nhtQVEUs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E88A921897 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8C2AF6B0002; Tue, 14 Jul 2020 04:45:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 872C76B0003; Tue, 14 Jul 2020 04:45:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 788AC6B0005; Tue, 14 Jul 2020 04:45:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0088.hostedemail.com [216.40.44.88]) by kanga.kvack.org (Postfix) with ESMTP id 6356F6B0002 for ; Tue, 14 Jul 2020 04:45:05 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 25C7D2DFA for ; Tue, 14 Jul 2020 08:45:05 +0000 (UTC) X-FDA: 77036046570.04.seed44_2002a6f26eef Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id EC8DC80048EE for ; Tue, 14 Jul 2020 08:45:04 +0000 (UTC) X-HE-Tag: seed44_2002a6f26eef X-Filterd-Recvd-Size: 4394 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Tue, 14 Jul 2020 08:45:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Yz4S4Ytxc1CzMw+qlvTi368donhX7MGtt2Akp1rQQ7Q=; b=nhtQVEUsKRiyabz5JvvGecobru nP8xGVVLoy5AyzJ5zGQu3dh5+dS9t2Uh/loFIeYYusdcKOAEa644zegzH+PnASDEKp9NN/liFG8aw xw8XCHC0tEZRdg6F9ZAsVzrQdOlikd/HuO5qANFw9yvqljFf9qcf673svzla/SooTOzwJDbWy6AX7 xbqGsKjQXdO956rc/SN1lldHbmIbje0c8OsnyqyFVEpsSFt7jfBNV6zhErXOXcKAUsl4N9Q4/cojz xANcGXBQHG0L+CD2pGC0z8pCkxwhImKF68ZTUcoh/hVzduX4xqA4tlQxQnv5RpbX0Zq6FapUFQnSA oUFXN5Fw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jvGYW-0000Ii-T5; Tue, 14 Jul 2020 08:44:53 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id E529C300130; Tue, 14 Jul 2020 10:44:51 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id D175128B91073; Tue, 14 Jul 2020 10:44:51 +0200 (CEST) Date: Tue, 14 Jul 2020 10:44:51 +0200 From: Peter Zijlstra To: ira.weiny@intel.com 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: <20200714084451.GQ10769@hirez.programming.kicks-ass.net> References: <20200714070220.3500839-1-ira.weiny@intel.com> <20200714070220.3500839-13-ira.weiny@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200714070220.3500839-13-ira.weiny@intel.com> X-Rspamd-Queue-Id: EC8DC80048EE X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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 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 :-(