From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753321AbdLNUpF (ORCPT ); Thu, 14 Dec 2017 15:45:05 -0500 Received: from mga04.intel.com ([192.55.52.120]:39228 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753256AbdLNUpA (ORCPT ); Thu, 14 Dec 2017 15:45:00 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,401,1508828400"; d="scan'208";a="2781924" Subject: Re: [PATCH v2 01/17] mm/gup: Fixup p*_access_permitted() To: Peter Zijlstra , linux-kernel@vger.kernel.org, tglx@linutronix.de References: <20171214112726.742649793@infradead.org> <20171214113851.146259969@infradead.org> <20171214124117.wfzcjdczyta2sery@hirez.programming.kicks-ass.net> <20171214143730.s6w7sd6c7b5t6fqp@hirez.programming.kicks-ass.net> Cc: x86@kernel.org, Linus Torvalds , Andy Lutomirsky , Borislav Petkov , Greg KH , keescook@google.com, hughd@google.com, Brian Gerst , Josh Poimboeuf , Denys Vlasenko , Boris Ostrovsky , Juergen Gross , David Laight , Eduardo Valentin , aliguori@amazon.com, Will Deacon , linux-mm@kvack.org, kirill.shutemov@linux.intel.com, dan.j.williams@intel.com From: Dave Hansen Message-ID: Date: Thu, 14 Dec 2017 12:44:58 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <20171214143730.s6w7sd6c7b5t6fqp@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/14/2017 06:37 AM, Peter Zijlstra wrote: > I'm also looking at pte_access_permitted() in handle_pte_fault(); that > looks very dodgy to me. How does that not result in endlessly CoW'ing > the same page over and over when we have a PKEY disallowing write access > on that page? I'm not seeing the pte_access_permitted() in handle_pte_fault(). I assume that's something you added in this series. But, one of the ways that we keep pkeys from causing these kinds of repeating loops when interacting with other things is this hunk in the page fault code: > static inline int > access_error(unsigned long error_code, struct vm_area_struct *vma) > { ... > /* > * Read or write was blocked by protection keys. This is > * always an unconditional error and can never result in > * a follow-up action to resolve the fault, like a COW. > */ > if (error_code & PF_PK) > return 1; That short-circuits the page fault pretty quickly. So, basically, the rule is: if the hardware says you tripped over pkey permissions, you die. We don't try to do anything to the underlying page *before* saying that you die.