lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20150612081950.GB13868@gmail.com>
Date:	Fri, 12 Jun 2015 10:19:51 +0200
From:	Ingo Molnar <mingo@...nel.org>
To:	Boris Ostrovsky <boris.ostrovsky@...cle.com>
Cc:	linux-kernel@...r.kernel.org, linux-mml@...r.kernel.org,
	Andy Lutomirski <luto@...capital.net>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Denys Vlasenko <dvlasenk@...hat.com>,
	Brian Gerst <brgerst@...il.com>,
	Peter Zijlstra <peterz@...radead.org>,
	Borislav Petkov <bp@...en8.de>,
	"H. Peter Anvin" <hpa@...or.com>,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Oleg Nesterov <oleg@...hat.com>,
	Thomas Gleixner <tglx@...utronix.de>,
	Waiman Long <Waiman.Long@...com>,
	Konrad Rzeszutek Wilk <konrad.wilk@...cle.com>,
	David Vrabel <david.vrabel@...rix.com>
Subject: Re: [PATCH 06/12] x86/mm: Enable and use the arch_pgd_init_late()
 method


* Boris Ostrovsky <boris.ostrovsky@...cle.com> wrote:

> On 06/11/2015 10:07 AM, Ingo Molnar wrote:
> 
> >diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
> >index fb0a9dd1d6e4..e0bf90470d70 100644
> >--- a/arch/x86/mm/pgtable.c
> >+++ b/arch/x86/mm/pgtable.c
> >@@ -391,6 +391,63 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
> >  	return NULL;
> >  }
> >
> >+/*
> >+ * Initialize the kernel portion of the PGD.
> >+ *
> >+ * This is done separately, because pgd_alloc() happens when
> >+ * the task is not on the task list yet - and PGD updates
> >+ * happen by walking the task list.
> >+ *
> >+ * No locking is needed here, as we just copy over the reference
> >+ * PGD. The reference PGD (pgtable_init) is only ever expanded
> >+ * at the highest, PGD level. Thus any other task extending it
> >+ * will first update the reference PGD, then modify the task PGDs.
> >+ */
> >+void arch_pgd_init_late(struct mm_struct *mm, pgd_t *pgd)
> >+{
> >+	/*
> >+	 * This is called after a new MM has been made visible
> >+	 * in fork() or exec().
> >+	 *
> >+	 * This barrier makes sure the MM is visible to new RCU
> >+	 * walkers before we initialize it, so that we don't miss
> >+	 * updates:
> >+	 */
> >+	smp_wmb();
> >+
> >+	/*
> >+	 * If the pgd points to a shared pagetable level (either the
> >+	 * ptes in non-PAE, or shared PMD in PAE), then just copy the
> >+	 * references from swapper_pg_dir:
> >+	 */
> >+	if (CONFIG_PGTABLE_LEVELS == 2 ||
> >+	    (CONFIG_PGTABLE_LEVELS == 3 && SHARED_KERNEL_PMD) ||
> >+	    CONFIG_PGTABLE_LEVELS == 4) {
> >+
> >+		pgd_t *pgd_src = swapper_pg_dir + KERNEL_PGD_BOUNDARY;
> >+		pgd_t *pgd_dst =            pgd + KERNEL_PGD_BOUNDARY;
> >+		int i;
> >+
> >+		for (i = 0; i < KERNEL_PGD_PTRS; i++, pgd_src++, pgd_dst++) {
> >+			/*
> >+			 * This is lock-less, so it can race with PGD updates
> >+			 * coming from vmalloc() or CPA methods, but it's safe,
> >+			 * because:
> >+			 *
> >+			 * 1) this PGD is not in use yet, we have still not
> >+			 *    scheduled this task.
> >+			 * 2) we only ever extend PGD entries
> >+			 *
> >+			 * So if we observe a non-zero PGD entry we can copy it,
> >+			 * it won't change from under us. Parallel updates (new
> >+			 * allocations) will modify our (already visible) PGD:
> >+			 */
> >+			if (pgd_val(*pgd_src))
> >+				WRITE_ONCE(*pgd_dst, *pgd_src);
> 
> 
> This should be set_pgd(pgd_dst, *pgd_src) in order for it to work as a Xen
> PV guest.

Thanks, fixed.

> I don't know whether anything would need to be done wrt WRITE_ONCE. Perhaps put 
> it into native_set_pgd()?

So this was just write-tearing paranoia at the raw pgd value copy I did which is 
an unusual pattern - but I'll use set_pgd(), as it clearly works and has the 
paravirt callback as well.

Thanks,

	Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ