From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754465AbbK0KNr (ORCPT ); Fri, 27 Nov 2015 05:13:47 -0500 Received: from www.linutronix.de ([62.245.132.108]:42740 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751248AbbK0KNo (ORCPT ); Fri, 27 Nov 2015 05:13:44 -0500 Date: Fri, 27 Nov 2015 11:12:58 +0100 (CET) From: Thomas Gleixner To: Dave Hansen cc: linux-kernel@vger.kernel.org, x86@kernel.org, dave.hansen@linux.intel.com Subject: Re: [PATCH 19/37] x86, mm: simplify get_user_pages() PTE bit handling In-Reply-To: <20151117033537.C2DBB366@viggo.jf.intel.com> Message-ID: References: <20151117033511.BFFA1440@viggo.jf.intel.com> <20151117033537.C2DBB366@viggo.jf.intel.com> User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 16 Nov 2015, Dave Hansen wrote: > +static inline int pte_allows_gup(pte_t pte, int write) > +{ > + /* > + * 'entry_flags' can come from a pte, pmd or pud. Make > + * sure to only check flags here that are valid *and* the > + * same value on all 3 types. (PAT is currently the only > + * one where that is true and is not checked here). I have a hard time to understand that comment. /* * 'entry_flags' can come from a pte, pmd or pud. We only check * _PAGE_PRESENT, _PAGE_USER and _PAGE_RW here, which are the * same for all types. */ Is that what you wanted to say? > + */ > + if (!(pte_flags(pte) & (_PAGE_PRESENT|_PAGE_USER))) > + return 0; > + if (write && !(pte_write(pte))) > + return 0; > + return 1; > +} > + > +static inline int pmd_allows_gup(pmd_t pmd, int write) > +{ > + return pte_allows_gup(*(pte_t *)&pmd, write); > +} > + > +static inline int pud_allows_gup(pud_t pud, int write) > +{ > + return pte_allows_gup(*(pte_t *)&pud, write); > +} > + > static noinline int gup_huge_pmd(pmd_t pmd, unsigned long addr, > unsigned long end, int write, struct page **pages, int *nr) > { > - unsigned long mask; > struct page *head, *page; > int refs; > > - mask = _PAGE_PRESENT|_PAGE_USER; > - if (write) > - mask |= _PAGE_RW; > - if ((pmd_flags(pmd) & mask) != mask) > + if (!pmd_allows_gup(pmd, write)) Why do you need that extra indirection here of rereading the pmd? You have the pmd already. Thanks, tglx