From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756213AbdLOK0C (ORCPT ); Fri, 15 Dec 2017 05:26:02 -0500 Received: from merlin.infradead.org ([205.233.59.134]:41410 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756105AbdLOKZ4 (ORCPT ); Fri, 15 Dec 2017 05:25:56 -0500 Date: Fri, 15 Dec 2017 11:25:29 +0100 From: Peter Zijlstra To: Dave Hansen Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de, 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 Subject: Re: [PATCH v2 01/17] mm/gup: Fixup p*_access_permitted() Message-ID: <20171215102529.vtsjhb7h7jiufkr3@hirez.programming.kicks-ass.net> References: <20171214112726.742649793@infradead.org> <20171214113851.146259969@infradead.org> <20171214124117.wfzcjdczyta2sery@hirez.programming.kicks-ass.net> <20171214143730.s6w7sd6c7b5t6fqp@hirez.programming.kicks-ass.net> <20171214205450.GI3326@worktop> <8eedb9a3-0ba2-52df-58f6-3ed869d18ca3@intel.com> <20171215080041.zftzuxdonxrtmssq@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171215080041.zftzuxdonxrtmssq@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 15, 2017 at 09:00:41AM +0100, Peter Zijlstra wrote: > On Thu, Dec 14, 2017 at 09:04:56PM -0800, Dave Hansen wrote: > > > > I've got some additions to the selftests and a fix where we pass FOLL_* > > flags around a bit more instead of just 'write'. I'll get those out as > > soon as I do a bit more testing. > > Try the below; I have more in the works, but this already fixes a whole > bunch of obvious fail and should fix the case I described. > > The thing is, you should _never_ return NULL for an access error, that's > complete crap. > > You should also not blindly change every pte_write() test to > pte_access_permitted(), that's also wrong, because then you're missing > the read-access tests. > > Basically you need to very carefully audit each and every > p??_access_permitted() call; they're currently mostly wrong. I think we also want this: diff --git a/fs/dax.c b/fs/dax.c index 78b72c48374e..95981591977a 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -627,8 +627,7 @@ static void dax_mapping_entry_mkclean(struct address_space *mapping, if (pfn != pmd_pfn(*pmdp)) goto unlock_pmd; - if (!pmd_dirty(*pmdp) - && !pmd_access_permitted(*pmdp, WRITE)) + if (!pmd_dirty(*pmdp) && !pmd_write(*pmdp)) goto unlock_pmd; flush_cache_page(vma, address, pfn); diff --git a/mm/memory.c b/mm/memory.c index 5eb3d2524bdc..6ce3ba12e07d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3948,7 +3948,7 @@ static int handle_pte_fault(struct vm_fault *vmf) if (unlikely(!pte_same(*vmf->pte, entry))) goto unlock; if (vmf->flags & FAULT_FLAG_WRITE) { - if (!pte_access_permitted(entry, WRITE)) + if (!pte_write(entry)) return do_wp_page(vmf); entry = pte_mkdirty(entry); } the DAX one is both inconsistent (only the PMD case, not also the PTE case) and just wrong; you don't want PKEYs to avoid cleaning pages, that's crazy. The memory one is also clearly wrong, not having access does not a write fault make. If we have pte_write() set we should not do_wp_page() just because we don't have access. This falls under the "doing anything other than hard failure for !access is crazy" header. Still looking at __handle_mm_fault(), they smell bad, but I can't get my brain started today :/