public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Ingo Molnar <mingo@kernel.org>, Jan Beulich <JBeulich@suse.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Juergen Gross <jgross@suse.com>,
	mingo@elte.hu, tglx@linutronix.de,
	xen-devel <xen-devel@lists.xenproject.org>,
	linux-kernel@vger.kernel.org, hpa@zytor.com,
	Borislav Petkov <bp@alien8.de>
Subject: Re: [PATCH v2] x86-64/Xen: eliminate W+X mappings
Date: Mon, 18 Dec 2017 07:52:37 -0800	[thread overview]
Message-ID: <1513612357.31581.82.camel@perches.com> (raw)
In-Reply-To: <20171218122825.6x33zeknoqbf3xcd@gmail.com>

On Mon, 2017-12-18 at 13:28 +0100, Ingo Molnar wrote:
> * Jan Beulich <JBeulich@suse.com> wrote:
> 
> > A few thousand such pages are usually left around due to the re-use of
> > L1 tables having been provided by the hypervisor (Dom0) or tool stack
> > (DomU). Set NX in the direct map variant, which needs to be done in L2
> > due to the dual use of the re-used L1s.
> > 
> > For x86_configure_nx() to actually do what it is supposed to do, call
> > get_cpu_cap() first. This was broken by commit 4763ed4d45 ("x86, mm:
> > Clean up and simplify NX enablement") when switching away from the
> > direct EFER read.
[]
> > --- 4.15-rc4/arch/x86/xen/mmu_pv.c
> > +++ 4.15-rc4-x86_64-Xen-avoid-W+X/arch/x86/xen/mmu_pv.c
> > @@ -1902,6 +1902,18 @@ void __init xen_setup_kernel_pagetable(p
> >  	/* Graft it onto L4[511][510] */
> >  	copy_page(level2_kernel_pgt, l2);
> >  
> > +	/*
> > +	 * Zap execute permission from the ident map. Due to the sharing of
> > +	 * L1 entries we need to do this in the L2.
> > +	 */
> > +	if (__supported_pte_mask & _PAGE_NX)
> > +		for (i = 0; i < PTRS_PER_PMD; ++i) {
> > +			if (pmd_none(level2_ident_pgt[i]))
> > +				continue;
> > +			level2_ident_pgt[i] = pmd_set_flags(level2_ident_pgt[i],
> > +							    _PAGE_NX);
> > +		}
> > +
> 
> This chunk has two stylistic problems:
> 
>  - Curly braces need to be added
>  - Line broken in an ugly fashion: just make it long and ignore the checkpatch col80 warning
> 
> looks good otherwise.

stylistic trivia:

Instead of repeating level2_ident_pgt[i] multiple times,
it might be nicer to use temporaries and not use i at all.

Something like:

	if (__supported_pte_mask & _PAGE_NX) {
		pmd_t *pmd = level2_ident_pgt;
		pmd_t *end = pmd + PTRS_PER_PMD;

		for (; pmd < end; pmd++) {
			if (!pmd_none(pmd))
				*pmd = pmd_set_flags(pmd, _PAGE_NX);
		}
	}

  reply	other threads:[~2017-12-18 15:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-12 10:24 [PATCH 0/2] x86: deal with remaining W+X pages on Xen Jan Beulich
2017-12-12 10:31 ` [PATCH 1/2] x86: consider effective protection attributes in W+X check Jan Beulich
2017-12-12 10:36   ` Ingo Molnar
2017-12-12 10:43     ` Jan Beulich
2017-12-12 10:32 ` [PATCH 2/2] x86-64/Xen: eliminate W+X mappings Jan Beulich
2017-12-12 10:38   ` Ingo Molnar
2017-12-12 10:48     ` Jan Beulich
2017-12-12 10:54       ` Ingo Molnar
     [not found]     ` <5A2FC2280200007800196BB8@suse.com>
2017-12-12 13:14       ` Juergen Gross
2017-12-18 11:11   ` [PATCH v2] " Jan Beulich
2017-12-18 12:28     ` Ingo Molnar
2017-12-18 15:52       ` Joe Perches [this message]
2017-12-18 16:37   ` [PATCH v3] " Jan Beulich
     [not found] ` <5A2FBE0A0200007800196B4F@suse.com>
2017-12-14 14:04   ` [PATCH 1/2] x86: consider effective protection attributes in W+X check Juergen Gross
2017-12-14 14:12     ` Thomas Gleixner
2017-12-14 14:15     ` Jan Beulich
2017-12-14 14:17       ` Thomas Gleixner
2017-12-14 14:21       ` Juergen Gross
     [not found] <5A2FAEB802000055000F9D66@suse.com>
     [not found] ` <5A2FBE540200007800196B52@suse.com>
     [not found]   ` <5A37B0770200007800198130@suse.com>
2017-12-18 11:50     ` [PATCH v2] x86-64/Xen: eliminate W+X mappings Juergen Gross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1513612357.31581.82.camel@perches.com \
    --to=joe@perches.com \
    --cc=JBeulich@suse.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox