Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1699100 > unrolled thread

Re: [RFC v6 27/62] powerpc: helper to validate key-access permissions of a pte

Started byThiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
First post2017-07-28 23:10 +0200
Last post2017-07-30 02:40 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [RFC v6 27/62] powerpc: helper to validate key-access permissions of a pte Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> - 2017-07-28 23:10 +0200
    Re: [RFC v6 27/62] powerpc: helper to validate key-access  permissions of a pte Ram Pai <linuxram@us.ibm.com> - 2017-07-30 02:40 +0200

#1699100 — Re: [RFC v6 27/62] powerpc: helper to validate key-access permissions of a pte

FromThiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
Date2017-07-28 23:10 +0200
SubjectRe: [RFC v6 27/62] powerpc: helper to validate key-access permissions of a pte
Message-ID<u8kGe-C9-9@gated-at.bofh.it>
Ram Pai <linuxram@us.ibm.com> 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)".

-- 
Thiago Jung Bauermann
IBM Linux Technology Center

[toc] | [next] | [standalone]


#1699400 — Re: [RFC v6 27/62] powerpc: helper to validate key-access permissions of a pte

FromRam Pai <linuxram@us.ibm.com>
Date2017-07-30 02:40 +0200
SubjectRe: [RFC v6 27/62] powerpc: helper to validate key-access permissions of a pte
Message-ID<u8Kr1-1nn-19@gated-at.bofh.it>
In reply to#1699100
On Fri, Jul 28, 2017 at 06:00:02PM -0300, Thiago Jung Bauermann wrote:
> 
> Ram Pai <linuxram@us.ibm.com> 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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web