linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: Ian Campbell <ijc@hellion.org.uk>
Cc: linux-kernel@vger.kernel.org,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	"Eric W. Biederman" <ebiederm@xmission.com>
Subject: Re: [PATCH] x86: Construct 32 bit boot time page tables in native format.
Date: 20 Jan 2008 00:07:09 +0100	[thread overview]
Message-ID: <87prvxct42.fsf@basil.nowhere.org> (raw)
In-Reply-To: <1200758937-22386-2-git-send-email-ijc@hellion.org.uk>

Ian Campbell <ijc@hellion.org.uk> writes:
> +1:
> +#ifdef CONFIG_X86_PAE
> +	btl $5, %eax
> +	jnc err_no_pae
> +#endif
>  
>  	xorl %ebx,%ebx				/* This is the boot CPU (BSP) */
>  	jmp 3f
> +
> +#ifdef CONFIG_X86_PAE
> +err_no_pae:
> +	/* It is probably too early but we might as well try... */

Without a low identity mapping early_printk will not work and printk
definitely not.

> +#ifdef CONFIG_PRINTK

You should do the test in the 16 bit boot code. In fact it should
already do it by testing the CPUID REQUIRED_MASK.

The only way this could be entered is if someone skips the 16bit boot code
by using kexec, but has the wrong flags. I'm not sure how to handle
it there.

> +/*
> + * Since a paravirt guest will never come down this path we want
> + * native style page table accessors here.
> + */
> +#undef CONFIG_PARAVIRT

Seems quite fragile. I'm sure that would hurt later.


> +
> +static inline __init pud_t *early_pud_offset(pgd_t *pgd, unsigned long vaddr)
> +{
> +	return (pud_t *)(pgd + pgd_index(vaddr));
> +}
> +
> +static inline __init pmd_t *early_pmd_offset(pud_t *pud, unsigned long vaddr)
> +{
> +#ifndef CONFIG_X86_PAE
> +	return (pmd_t *)pud;
> +#else
> +	return ((pmd_t *)(u32)(pud_val(*pud) & PAGE_MASK))
> +		+ pmd_index(vaddr);
> +#endif
> +}
> +
> +static inline __init pte_t *early_pte_offset(pmd_t *pmd, unsigned long vaddr)
> +{
> +	return ((pte_t *)(u32)(pmd_val(*pmd) & PAGE_MASK))

That will break if the kernel is > 4GB won't it? Also same for pmd.

Also not handling NX is dubious, although you can probably get away from it there.

> +		+ pte_index(vaddr);
> +}
> +
> +static inline __init pmd_t *
> +early_pmd_alloc(pgd_t *pgd_base, unsigned long vaddr, unsigned long *end)
> +{
> +	pud_t *pud = early_pud_offset(pgd_base, vaddr);
> +
> +#ifdef CONFIG_X86_PAE
> +	if (!(pud_val(*pud) & _PAGE_PRESENT)) {


Why not set it in the pgd which is identical? Also the proper test is !pgd_none()



> +{
> +	pmd_t *pmd;
> +
> +	pmd = early_pmd_alloc(pgd_base, vaddr, end);
> +	if (!(pmd_val(*pmd) & _PAGE_PRESENT)) {

!pmd_none()

> +		unsigned long phys = *end;
> +		memset((void *)phys, 0, PAGE_SIZE);
> +		set_pmd(pmd, __pmd(phys | _PAGE_TABLE));
> +		*end += PAGE_SIZE;
> +	}
> +	return early_pte_offset(pmd, vaddr);
> +}
> +
> +static __init void early_set_pte_phys(pgd_t *pgd_base, unsigned long vaddr,
> +				      unsigned long phys, unsigned long *end)
> +{
> +	pte_t *pte;
> +	pte = early_pte_alloc(pgd_base, vaddr, end);
> +	set_pte(pte, __pte(phys | _PAGE_KERNEL_EXEC));
> +}
> +
> +void __init early_pgtable_init(void)
> +{
> +	unsigned long addr, end;
> +	pgd_t *pgd_base;
> +
> +	pgd_base = __pavar(swapper_pg_dir);
> +	end = __pa_symbol(pg0);

Are you sure there will be enough memory here? You might need to use
an e820 allocator similar to x86-64.

Typical problems is you running into some other memory used by
someone else.

>  {
>  	enum fixed_addresses idx;
> -	unsigned long *pte, phys, addr;
> +	unsigned long addr, phys;
> +	pte_t *pte;
>  
>  	after_paging_init = 1;
>  	for (idx = FIX_BTMAP_BEGIN; idx <= FIX_BTMAP_END; idx--) {
>  		addr = fix_to_virt(idx);
>  		pte = early_ioremap_pte(addr);
> -		if (!*pte & _PAGE_PRESENT) {
> -			phys = *pte & PAGE_MASK;
> +		if (!(pte_val(*pte) & _PAGE_PRESENT)) {

pte_present(). Ok the old code was wrong too, but no need to do that again.

>  			set_fixmap(idx, phys);
>  		}
>  	}
> @@ -298,7 +304,8 @@ void __init early_ioremap_reset(void)
>  static void __init __early_set_fixmap(enum fixed_addresses idx,
>  				   unsigned long phys, pgprot_t flags)
>  {
> -	unsigned long *pte, addr = __fix_to_virt(idx);
> +	unsigned long addr = __fix_to_virt(idx);
> +	pte_t *pte;

Unrelated?

-Andi

  reply	other threads:[~2008-01-19 23:23 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-19 16:08 [PATCH] x86/voyager: Switch voyager memory detection to early_ioremap Ian Campbell
2008-01-19 16:08 ` [PATCH] x86: Construct 32 bit boot time page tables in native format Ian Campbell
2008-01-19 23:07   ` Andi Kleen [this message]
2008-01-19 23:50     ` H. Peter Anvin
2008-01-20 16:44     ` Ian Campbell
2008-01-20 17:39       ` Andi Kleen
2008-01-20 18:48         ` H. Peter Anvin
2008-01-20 18:55           ` Andi Kleen
2008-01-20 18:54             ` H. Peter Anvin
2008-01-22 10:05           ` Ingo Molnar
2008-01-22 16:23             ` H. Peter Anvin
2008-01-20 18:30   ` Mika Penttilä
2008-01-21 21:23     ` Ian Campbell
2008-01-21 21:38       ` H. Peter Anvin
2008-01-21 21:46         ` Ian Campbell
2008-01-22  2:16           ` H. Peter Anvin
2008-01-22 17:36             ` Ian Campbell
2008-01-22 18:23               ` H. Peter Anvin
2008-01-22 19:48                 ` Ian Campbell
2008-01-22 20:00                   ` H. Peter Anvin
2008-01-22 20:36                     ` Ingo Molnar
2008-01-22 20:43                       ` H. Peter Anvin
2008-01-22 20:45                         ` Ingo Molnar
2008-01-22 20:52                       ` Ian Campbell
2008-01-22 21:00                         ` H. Peter Anvin
2008-01-22 22:21                           ` Ian Campbell
2008-01-22 21:00                       ` [PATCH] x86: make nx_enabled conditional on CONFIG_X86_PAE Harvey Harrison
2008-01-22 21:04                         ` Ingo Molnar
2008-01-22 21:35                           ` Harvey Harrison
2008-01-22 21:07                         ` Harvey Harrison
     [not found]                         ` <p73odbdlyiu.fsf@crumb.suse.de>
2008-01-23 11:21                           ` Harvey Harrison
2008-01-23 20:52                       ` [PATCH] x86: Construct 32 bit boot time page tables in native format Ian Campbell
2008-01-24  1:06                         ` Jeremy Fitzhardinge
2008-01-24  9:39                           ` Ian Campbell
2008-01-24 22:06                             ` H. Peter Anvin
2008-01-24 22:35                               ` Jeremy Fitzhardinge
2008-01-24 22:39                                 ` H. Peter Anvin
2008-01-24 22:58                                   ` Jeremy Fitzhardinge
2008-01-24 23:08                                     ` H. Peter Anvin
2008-01-24 23:40                                       ` Jeremy Fitzhardinge
2008-01-24 23:44                                         ` H. Peter Anvin
2008-01-24 23:51                                           ` Jeremy Fitzhardinge
2008-01-25  0:02                                             ` H. Peter Anvin
2008-01-25  0:11                                               ` Jeremy Fitzhardinge
2008-01-25  0:15                                                 ` H. Peter Anvin
2008-01-25  0:31                                                   ` Jeremy Fitzhardinge
2008-01-25  0:37                                                     ` H. Peter Anvin
2008-01-25  2:56                                                       ` Eric W. Biederman
2008-01-25  4:41                                                         ` Jeremy Fitzhardinge
2008-01-25 11:07                                                           ` Eric W. Biederman
2008-01-24 23:51                                         ` H. Peter Anvin
2008-01-25  0:20                                           ` Pavel Machek
2008-01-25  0:27                                             ` H. Peter Anvin
2008-01-25  0:46                                               ` Rafael J. Wysocki
2008-01-25  1:08                                                 ` H. Peter Anvin
2008-01-25  2:16                                               ` Eric W. Biederman
2008-01-25  2:25                                                 ` H. Peter Anvin
2008-01-25  7:49                                               ` Pavel Machek
2008-01-25 22:02                                                 ` Rafael J. Wysocki
2008-01-25 22:11                                                   ` Pavel Machek
2008-01-28 15:00                                                   ` Ingo Molnar
2008-01-28 15:25                                                     ` Rafael J. Wysocki
2008-01-28 19:40                                                       ` Pavel Machek
2008-01-28 19:51                                                         ` H. Peter Anvin
2008-01-28 20:03                                                           ` Jeremy Fitzhardinge
2008-01-28 20:06                                                             ` H. Peter Anvin
2008-01-28 20:28                                                               ` Rafael J. Wysocki
2008-01-28 20:26                                                         ` Rafael J. Wysocki
2008-01-28 20:31                                                           ` H. Peter Anvin
2008-01-28 20:59                                                             ` Rafael J. Wysocki
2008-01-28 20:44                                                           ` Jeremy Fitzhardinge
2008-01-28 20:50                                                             ` Rafael J. Wysocki
2008-01-28 21:28                                                               ` H. Peter Anvin
2008-01-28 22:02                                                                 ` Rafael J. Wysocki
2008-01-28 16:12                                                     ` Ingo Molnar
2008-01-28 17:02                                                       ` Rafael J. Wysocki
2008-02-01 13:51                                                         ` Ingo Molnar
2008-02-01 14:28                                                           ` Rafael J. Wysocki
2008-02-01 14:54                                                             ` Ingo Molnar
2008-02-01 22:55                                                               ` Len Brown

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=87prvxct42.fsf@basil.nowhere.org \
    --to=andi@firstfloor.org \
    --cc=ebiederm@xmission.com \
    --cc=hpa@zytor.com \
    --cc=ijc@hellion.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).