From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933612AbdLRPww (ORCPT ); Mon, 18 Dec 2017 10:52:52 -0500 Received: from smtprelay0178.hostedemail.com ([216.40.44.178]:43615 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1759260AbdLRPwn (ORCPT ); Mon, 18 Dec 2017 10:52:43 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::,RULES_HIT:41:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2828:2898:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3868:3870:3871:3872:4250:4321:5007:6119:7875:7903:8660:10004:10400:10848:11026:11232:11233:11473:11658:11914:12043:12438:12679:12740:12760:12895:13069:13148:13230:13311:13357:13439:14181:14659:14721:21080:21611:21627:30054:30070:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: woman71_346d385461a02 X-Filterd-Recvd-Size: 2989 Message-ID: <1513612357.31581.82.camel@perches.com> Subject: Re: [PATCH v2] x86-64/Xen: eliminate W+X mappings From: Joe Perches To: Ingo Molnar , Jan Beulich Cc: Boris Ostrovsky , Juergen Gross , mingo@elte.hu, tglx@linutronix.de, xen-devel , linux-kernel@vger.kernel.org, hpa@zytor.com, Borislav Petkov Date: Mon, 18 Dec 2017 07:52:37 -0800 In-Reply-To: <20171218122825.6x33zeknoqbf3xcd@gmail.com> References: <5A2FAEB802000055000F9D66@prv-mh.provo.novell.com> <5A2FBE540200007800196B52@prv-mh.provo.novell.com> <5A37B0770200007800198130@prv-mh.provo.novell.com> <20171218122825.6x33zeknoqbf3xcd@gmail.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.26.1-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2017-12-18 at 13:28 +0100, Ingo Molnar wrote: > * Jan Beulich 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); } }