Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1589534ybh; Tue, 14 Jul 2020 01:45:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPzFfAOBP3rVGfsNIaBNsaLgAIx7d8pI9l/FXrEwykvJWSmtYiJ09csT8z5qkP4yTxZ0CC X-Received: by 2002:aa7:d70f:: with SMTP id t15mr3263784edq.237.1594716341715; Tue, 14 Jul 2020 01:45:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594716341; cv=none; d=google.com; s=arc-20160816; b=qRrCMV0R3cfKbBA158J4FC3KEy5n5iHJQRHXF4+4pil6OqS1RBc78u49kahCPehJEY +ArnGF/u9fV3XjOljGpgI69UdGsCzRY54nZUuRePmZ01njiVF4mJmDHtxsCcFf7tjt26 hNx2AQXkbWd0nqfcwumvfiEIQ36HIrTkMRZ50MsBZu9f5XuevXQrMqIGk+D9XQ2BVCu2 PrB5KkAJqJzqOr3IJM8pclpWQy85gf8oaSFbNEpUnae5IbnOwUlu0sSuYhE4hzDv1a4m wfUHbLhkuZG0EnIdIonklBNyyo3U2wegev0OzaNygBunxlnsGGzqQwzByjZ5V/J/Le/k MD+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Yz4S4Ytxc1CzMw+qlvTi368donhX7MGtt2Akp1rQQ7Q=; b=E+ocnUyZzYwCvK3xrRwaDlm3YG8tkxn6I/XzGEwky/nGPHKuH3tCBLNSHXD3cGDZq7 Ja3drcYgNR8UgHTrwVOYD14Pl7CwzkiDdU3tI7Ayqu2P2oC9irja6zFWp6h5DTQZl54Y wUlFhbRKtRElxNmhHYxuRsGU1TH0S35LMO1HvkMK3WHU+ZjATUUpLz8cZl/bScRUI7Z0 ALgS6YSNErI9BDjdtP1zJ5teZmWy3ieed2G61jZ7rCBi3samdtJdJsGN08fr2VB1oM2G 0owJbtVcnIP5lCKhAuaPqqB2bHSLTbd11bZDo3O04RgKeuLSjJDlI4eVVR14gzGNFwj5 /qgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=nhtQVEUs; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bt10si10690541edb.146.2020.07.14.01.45.19; Tue, 14 Jul 2020 01:45:41 -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; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=nhtQVEUs; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726352AbgGNIpI (ORCPT + 99 others); Tue, 14 Jul 2020 04:45:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725820AbgGNIpI (ORCPT ); Tue, 14 Jul 2020 04:45:08 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 268A0C061755; Tue, 14 Jul 2020 01:45:08 -0700 (PDT) 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> 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 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 :-(