Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753719AbdG3Aju (ORCPT ); Sat, 29 Jul 2017 20:39:50 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:53662 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752710AbdG3Ajq (ORCPT ); Sat, 29 Jul 2017 20:39:46 -0400 Date: Sat, 29 Jul 2017 17:39:24 -0700 From: Ram Pai To: Thiago Jung Bauermann Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, arnd@arndb.de, corbet@lwn.net, mhocko@kernel.org, dave.hansen@intel.com, mingo@redhat.com, paulus@samba.org, aneesh.kumar@linux.vnet.ibm.com, akpm@linux-foundation.org, khandual@linux.vnet.ibm.com Subject: Re: [RFC v6 27/62] powerpc: helper to validate key-access permissions of a pte Reply-To: Ram Pai References: <1500177424-13695-1-git-send-email-linuxram@us.ibm.com> <1500177424-13695-28-git-send-email-linuxram@us.ibm.com> <87tw1we0q5.fsf@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87tw1we0q5.fsf@linux.vnet.ibm.com> User-Agent: Mutt/1.5.20 (2009-12-10) X-TM-AS-GCONF: 00 x-cbid: 17073000-0024-0000-0000-000002B78951 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007450; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000214; SDB=6.00894820; UDB=6.00447466; IPR=6.00674987; BA=6.00005499; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00016445; XFM=3.00000015; UTC=2017-07-30 00:39:45 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17073000-0025-0000-0000-000044EC1413 Message-Id: <20170730003924.GJ5664@ram.oc3035372033.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-07-29_13:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1706020000 definitions=main-1707300010 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1298 Lines: 52 On Fri, Jul 28, 2017 at 06:00:02PM -0300, Thiago Jung Bauermann wrote: > > Ram Pai writes: > > --- a/arch/powerpc/mm/pkeys.c > > +++ b/arch/powerpc/mm/pkeys.c > > @@ -201,3 +201,36 @@ int __arch_override_mprotect_pkey(struct vm_area_struct *vma, int prot, > > */ > > return vma_pkey(vma); > > } > > + > > +static bool pkey_access_permitted(int pkey, bool write, bool execute) > > +{ > > + int pkey_shift; > > + u64 amr; > > + > > + if (!pkey) > > + return true; > > + > > + pkey_shift = pkeyshift(pkey); > > + if (!(read_uamor() & (0x3UL << pkey_shift))) > > + return true; > > + > > + if (execute && !(read_iamr() & (IAMR_EX_BIT << pkey_shift))) > > + return true; > > + > > + if (!write) { > > + amr = read_amr(); > > + if (!(amr & (AMR_RD_BIT << pkey_shift))) > > + return true; > > + } > > + > > + amr = read_amr(); /* delay reading amr uptil absolutely needed */ > > Actually, this is causing amr to be read twice in case control enters > the "if (!write)" block above but doesn't enter the other if block nested > in it. > > read_amr should be called only once, right before "if (!write)". the code can be simplified without having to read amr twice. will fix it. thanks, RP > > -- > Thiago Jung Bauermann > IBM Linux Technology Center -- Ram Pai