Re: [PATCH] [8/8] RFC: Fix some EFI problems
Thomas Gleixner wrote: > On Tue, 12 Feb 2008, Andi Kleen wrote: > >> On Tuesday 12 February 2008 21:04:06 Thomas Gleixner wrote: >> >>> And you just copied the real bug in that logic as well: >>> >>> set_memory_uc(md->virt_addr, size); >> Oops you're right. I wanted to fix that, but didn't. Ok I'll put up >> my brown paper back tonight when I go out. >> >>> >>> >>> which is initialized a couple of lines down. >>> >>> md->virt_addr = (u64) (unsigned long) va; >>> >>> The reordering/optimizing needs to be a separate patch. >> What optimizing? It wasn't intended to be an optimization. >> It fixes a bug. > > No, it does not. Please go back and read my mail. I describe the problem again: - efi_ioremap on 64bit returns a fixmap address: void __iomem * __init efi_ioremap(unsigned long phys_addr, unsigned long size) { ... return (void __iomem *)__fix_to_virt(FIX_EFI_IO_MAP_FIRST_PAGE - (pages_mapped - pages)); } - __fix_to_virt is: (FIXADDR_TOP - ((x) << PAGE_SHIFT)) and x is a small integer <30 or so. - Fixmap is #define VSYSCALL_END (-2UL << 20) #define FIXADDR_TOP (VSYSCALL_END-PAGE_SIZE) that gives e.g. 0xffdf for the top fixmap; the efi fixmap is only slightly pages below. - You pass that into set_memory_uc() - That eventually calls __pa() on it several times (in static_protections and in change_page_attr_addr for 64bit to check for the kernel mapping) - __pa calls __phys_addr which does unsigned long __phys_addr(unsigned long x) { if (x >= __START_KERNEL_map) return x - __START_KERNEL_map + phys_base; return x - PAGE_OFFSET; } - Now __START_KERNEL_map is 0x8000. - That ends up with x = 0xffdf - smallnumber*PAGE_SIZE if (x >= 0x8000)(evaluates to true) return x - 0x8000 + phys_addr - This ends up with some fictional number in cpa (but likely one looking like a valid pa address) that has nothing to do with the address that is mapped below the fixmap - cpa() does weird things to random unrelated memory then or might clear rw if you're really unlucky. - I think on 32bit with a real ioremap it's also not completely kosher with the right __PAGE_OFFSET (but I have not double checked that step by step) This is why I avoided calling set_memory_uc for the fixmap and instead changed the code to set the correct PAT attribute into the fixmap directly to avoid this. I believe the full original change or some Thomasized variant of it is still needed. -Andi -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] [8/8] RFC: Fix some EFI problems
On Tue, 12 Feb 2008, Andi Kleen wrote: > On Tuesday 12 February 2008 21:04:06 Thomas Gleixner wrote: > > > > > And you just copied the real bug in that logic as well: > > > > set_memory_uc(md->virt_addr, size); > > Oops you're right. I wanted to fix that, but didn't. Ok I'll put up > my brown paper back tonight when I go out. > > > > > > > which is initialized a couple of lines down. > > > > md->virt_addr = (u64) (unsigned long) va; > > > > The reordering/optimizing needs to be a separate patch. > > What optimizing? It wasn't intended to be an optimization. > It fixes a bug. No, it does not. Please go back and read my mail. The code had exactly two bugs: 1) the logic of checking EFI_MEMORY_WB was wrong 2) the uninitialized variable The fix is: arch/x86/kernel/efi.c |6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) Index: linux-2.6/arch/x86/kernel/efi.c === --- linux-2.6.orig/arch/x86/kernel/efi.c +++ linux-2.6/arch/x86/kernel/efi.c @@ -428,9 +428,6 @@ void __init efi_enter_virtual_mode(void) else va = efi_ioremap(md->phys_addr, size); - if (md->attribute & EFI_MEMORY_WB) - set_memory_uc(md->virt_addr, size); - md->virt_addr = (u64) (unsigned long) va; if (!va) { @@ -439,6 +436,9 @@ void __init efi_enter_virtual_mode(void) continue; } + if (!(md->attribute & EFI_MEMORY_WB)) + set_memory_uc(md->virt_addr, size); + systab = (u64) (unsigned long) efi_phys.systab; if (md->phys_addr <= systab && systab < end) { systab += md->virt_addr - md->phys_addr; The reordering of code is completely irrelevant. It can be done, but in a separate patch. Thanks, tglx -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] [8/8] RFC: Fix some EFI problems
On Tuesday 12 February 2008 21:04:06 Thomas Gleixner wrote: > > And you just copied the real bug in that logic as well: > > set_memory_uc(md->virt_addr, size); Oops you're right. I wanted to fix that, but didn't. Ok I'll put up my brown paper back tonight when I go out. > > > which is initialized a couple of lines down. > > md->virt_addr = (u64) (unsigned long) va; > > The reordering/optimizing needs to be a separate patch. What optimizing? It wasn't intended to be an optimization. It fixes a bug. Not doing set_memory_uc on efi_ioremap output is needed because set_memory_uc doesn't work on fixmap which is what efi_ioremap returns. (see previous mails on that topic -- i fixed the 'x' case, but fixing "uc" is too hard imho) So I fixed efi_ioremap instead to set the correct caching mode directly. That is ok because there can be no overlap with the direct mapping, so no aliases to fix up. > Please keep bugfixes and other changes separate. > > > + /* RED-PEN does not handle overlapped areas */ > > Can you please use CHECKME/FIXME which is used everywhere else. No need to > invent an extra marker. I've always used RED-PEN % grep -r RED-PEN arch/x86/* | wc -l 12 % It comes originally from network code I hacked a long time ago, although most of those got lost over time (only 2 left, sniff) Sorry I don't want to change this now and I doubt that will really cause a problem for anybody. I'll send an updated patch with the va thing fixed. -Andi -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] [8/8] RFC: Fix some EFI problems
On Mon, 11 Feb 2008, Andi Kleen wrote: > >From code review the EFI memory map handling has a couple of problems: > > - The test for _WB memory was reversed so it would set cache able memory > to uncached > - It would always set a wrong uninitialized zero address to uncached > (so I suspect it always set the first few pages in phys memory to uncached, > that is why it may have gone unnoticed) > - It would call set_memory_x() on a fixmap address that it doesn't > handle correct. > - Some other problems I commented in the code (but was unable to solve > for now) > > I changed the ioremaps to set the correct caching attributes > and also corrected the ordering so it looks roughly correct now. The only effective change is: - if (md->attribute & EFI_MEMORY_WB) + if (!(md->attribute & EFI_MEMORY_WB)) I appreciate that you noticed the reverse logic, which I messed up when I fixed up rejects. I pulled this out as it is a real fix. The rest of this patch is just turning code in circles for nothing, simply because it is functionally completely irrelevant whether does simply: if ((end >> PAGE_SHIFT) <= max_pfn_mapped) va = __va(md->phys_addr); else va = efi_ioremap(md->phys_addr, size); if (!(md->attribute & EFI_MEMORY_WB)) set_memory_uc(md->virt_addr, size); or if ((end >> PAGE_SHIFT) <= max_pfn_mapped) { va = __va(md->phys_addr); if (!(md->attribute & EFI_MEMORY_WB)) set_memory_uc(md->virt_addr, size); } else va = efi_ioremap(md->phys_addr, size, !!(md->attribute & EFI_MEMORY_WB)); And you just copied the real bug in that logic as well: set_memory_uc(md->virt_addr, size); which is initialized a couple of lines down. md->virt_addr = (u64) (unsigned long) va; The reordering/optimizing needs to be a separate patch. Please keep bugfixes and other changes separate. > + /* RED-PEN does not handle overlapped areas */ Can you please use CHECKME/FIXME which is used everywhere else. No need to invent an extra marker. Thanks, tglx -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] [8/8] RFC: Fix some EFI problems
On Tue, 12 Feb 2008, Andi Kleen wrote: On Tuesday 12 February 2008 21:04:06 Thomas Gleixner wrote: And you just copied the real bug in that logic as well: set_memory_uc(md-virt_addr, size); Oops you're right. I wanted to fix that, but didn't. Ok I'll put up my brown paper back tonight when I go out. which is initialized a couple of lines down. md-virt_addr = (u64) (unsigned long) va; The reordering/optimizing needs to be a separate patch. What optimizing? It wasn't intended to be an optimization. It fixes a bug. No, it does not. Please go back and read my mail. The code had exactly two bugs: 1) the logic of checking EFI_MEMORY_WB was wrong 2) the uninitialized variable The fix is: arch/x86/kernel/efi.c |6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) Index: linux-2.6/arch/x86/kernel/efi.c === --- linux-2.6.orig/arch/x86/kernel/efi.c +++ linux-2.6/arch/x86/kernel/efi.c @@ -428,9 +428,6 @@ void __init efi_enter_virtual_mode(void) else va = efi_ioremap(md-phys_addr, size); - if (md-attribute EFI_MEMORY_WB) - set_memory_uc(md-virt_addr, size); - md-virt_addr = (u64) (unsigned long) va; if (!va) { @@ -439,6 +436,9 @@ void __init efi_enter_virtual_mode(void) continue; } + if (!(md-attribute EFI_MEMORY_WB)) + set_memory_uc(md-virt_addr, size); + systab = (u64) (unsigned long) efi_phys.systab; if (md-phys_addr = systab systab end) { systab += md-virt_addr - md-phys_addr; The reordering of code is completely irrelevant. It can be done, but in a separate patch. Thanks, tglx -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] [8/8] RFC: Fix some EFI problems
On Mon, 11 Feb 2008, Andi Kleen wrote: From code review the EFI memory map handling has a couple of problems: - The test for _WB memory was reversed so it would set cache able memory to uncached - It would always set a wrong uninitialized zero address to uncached (so I suspect it always set the first few pages in phys memory to uncached, that is why it may have gone unnoticed) - It would call set_memory_x() on a fixmap address that it doesn't handle correct. - Some other problems I commented in the code (but was unable to solve for now) I changed the ioremaps to set the correct caching attributes and also corrected the ordering so it looks roughly correct now. The only effective change is: - if (md-attribute EFI_MEMORY_WB) + if (!(md-attribute EFI_MEMORY_WB)) I appreciate that you noticed the reverse logic, which I messed up when I fixed up rejects. I pulled this out as it is a real fix. The rest of this patch is just turning code in circles for nothing, simply because it is functionally completely irrelevant whether does simply: if ((end PAGE_SHIFT) = max_pfn_mapped) va = __va(md-phys_addr); else va = efi_ioremap(md-phys_addr, size); if (!(md-attribute EFI_MEMORY_WB)) set_memory_uc(md-virt_addr, size); or if ((end PAGE_SHIFT) = max_pfn_mapped) { va = __va(md-phys_addr); if (!(md-attribute EFI_MEMORY_WB)) set_memory_uc(md-virt_addr, size); } else va = efi_ioremap(md-phys_addr, size, !!(md-attribute EFI_MEMORY_WB)); And you just copied the real bug in that logic as well: set_memory_uc(md-virt_addr, size); which is initialized a couple of lines down. md-virt_addr = (u64) (unsigned long) va; The reordering/optimizing needs to be a separate patch. Please keep bugfixes and other changes separate. + /* RED-PEN does not handle overlapped areas */ Can you please use CHECKME/FIXME which is used everywhere else. No need to invent an extra marker. Thanks, tglx -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH] [8/8] RFC: Fix some EFI problems
>From code review the EFI memory map handling has a couple of problems: - The test for _WB memory was reversed so it would set cache able memory to uncached - It would always set a wrong uninitialized zero address to uncached (so I suspect it always set the first few pages in phys memory to uncached, that is why it may have gone unnoticed) - It would call set_memory_x() on a fixmap address that it doesn't handle correct. - Some other problems I commented in the code (but was unable to solve for now) I changed the ioremaps to set the correct caching attributes and also corrected the ordering so it looks roughly correct now. This is an RFC, because I don't have a EFI system to test. Cc: [EMAIL PROTECTED] Signed-off-by: Andi Kleen <[EMAIL PROTECTED]> --- arch/x86/kernel/efi.c| 14 -- arch/x86/kernel/efi_64.c |6 -- include/asm-x86/efi.h|5 +++-- 3 files changed, 15 insertions(+), 10 deletions(-) Index: linux/arch/x86/kernel/efi.c === --- linux.orig/arch/x86/kernel/efi.c +++ linux/arch/x86/kernel/efi.c @@ -423,13 +423,15 @@ void __init efi_enter_virtual_mode(void) size = md->num_pages << EFI_PAGE_SHIFT; end = md->phys_addr + size; - if ((end >> PAGE_SHIFT) <= max_pfn_mapped) + /* RED-PEN does not handle overlapped areas */ + if ((end >> PAGE_SHIFT) <= max_pfn_mapped) { va = __va(md->phys_addr); - else - va = efi_ioremap(md->phys_addr, size); - - if (md->attribute & EFI_MEMORY_WB) - set_memory_uc(md->virt_addr, size); + /* RED-PEN spec and ia64 have a lot more flags */ + if (!(md->attribute & EFI_MEMORY_WB)) + set_memory_uc(md->virt_addr, size); + } else + va = efi_ioremap(md->phys_addr, size, + !!(md->attribute & EFI_MEMORY_WB)); md->virt_addr = (u64) (unsigned long) va; Index: linux/arch/x86/kernel/efi_64.c === --- linux.orig/arch/x86/kernel/efi_64.c +++ linux/arch/x86/kernel/efi_64.c @@ -109,7 +109,8 @@ void __init efi_reserve_bootmem(void) memmap.nr_map * memmap.desc_size); } -void __iomem * __init efi_ioremap(unsigned long phys_addr, unsigned long size) +void __iomem * __init efi_ioremap(unsigned long phys_addr, unsigned long size, + int cache) { static unsigned pages_mapped; unsigned i, pages; @@ -124,7 +125,8 @@ void __iomem * __init efi_ioremap(unsign for (i = 0; i < pages; i++) { __set_fixmap(FIX_EFI_IO_MAP_FIRST_PAGE - pages_mapped, -phys_addr, PAGE_KERNEL); +phys_addr, +cache ? PAGE_KERNEL : PAGE_KERNEL_NOCACHE); phys_addr += PAGE_SIZE; pages_mapped++; } Index: linux/include/asm-x86/efi.h === --- linux.orig/include/asm-x86/efi.h +++ linux/include/asm-x86/efi.h @@ -33,7 +33,8 @@ extern unsigned long asmlinkage efi_call #define efi_call_virt6(f, a1, a2, a3, a4, a5, a6) \ efi_call_virt(f, a1, a2, a3, a4, a5, a6) -#define efi_ioremap(addr, size)ioremap_cache(addr, size) +#define efi_ioremap(addr, size, cache) \ + (cache ? ioremap_cache(addr, size) : ioremap_nocache(addr, size)) #else /* !CONFIG_X86_32 */ @@ -86,7 +87,7 @@ extern u64 efi_call6(void *fp, u64 arg1, efi_call6((void *)(efi.systab->runtime->f), (u64)(a1), (u64)(a2), \ (u64)(a3), (u64)(a4), (u64)(a5), (u64)(a6)) -extern void *efi_ioremap(unsigned long addr, unsigned long size); +extern void *efi_ioremap(unsigned long addr, unsigned long size, int cache); #endif /* CONFIG_X86_32 */ -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH] [8/8] RFC: Fix some EFI problems
From code review the EFI memory map handling has a couple of problems: - The test for _WB memory was reversed so it would set cache able memory to uncached - It would always set a wrong uninitialized zero address to uncached (so I suspect it always set the first few pages in phys memory to uncached, that is why it may have gone unnoticed) - It would call set_memory_x() on a fixmap address that it doesn't handle correct. - Some other problems I commented in the code (but was unable to solve for now) I changed the ioremaps to set the correct caching attributes and also corrected the ordering so it looks roughly correct now. This is an RFC, because I don't have a EFI system to test. Cc: [EMAIL PROTECTED] Signed-off-by: Andi Kleen [EMAIL PROTECTED] --- arch/x86/kernel/efi.c| 14 -- arch/x86/kernel/efi_64.c |6 -- include/asm-x86/efi.h|5 +++-- 3 files changed, 15 insertions(+), 10 deletions(-) Index: linux/arch/x86/kernel/efi.c === --- linux.orig/arch/x86/kernel/efi.c +++ linux/arch/x86/kernel/efi.c @@ -423,13 +423,15 @@ void __init efi_enter_virtual_mode(void) size = md-num_pages EFI_PAGE_SHIFT; end = md-phys_addr + size; - if ((end PAGE_SHIFT) = max_pfn_mapped) + /* RED-PEN does not handle overlapped areas */ + if ((end PAGE_SHIFT) = max_pfn_mapped) { va = __va(md-phys_addr); - else - va = efi_ioremap(md-phys_addr, size); - - if (md-attribute EFI_MEMORY_WB) - set_memory_uc(md-virt_addr, size); + /* RED-PEN spec and ia64 have a lot more flags */ + if (!(md-attribute EFI_MEMORY_WB)) + set_memory_uc(md-virt_addr, size); + } else + va = efi_ioremap(md-phys_addr, size, + !!(md-attribute EFI_MEMORY_WB)); md-virt_addr = (u64) (unsigned long) va; Index: linux/arch/x86/kernel/efi_64.c === --- linux.orig/arch/x86/kernel/efi_64.c +++ linux/arch/x86/kernel/efi_64.c @@ -109,7 +109,8 @@ void __init efi_reserve_bootmem(void) memmap.nr_map * memmap.desc_size); } -void __iomem * __init efi_ioremap(unsigned long phys_addr, unsigned long size) +void __iomem * __init efi_ioremap(unsigned long phys_addr, unsigned long size, + int cache) { static unsigned pages_mapped; unsigned i, pages; @@ -124,7 +125,8 @@ void __iomem * __init efi_ioremap(unsign for (i = 0; i pages; i++) { __set_fixmap(FIX_EFI_IO_MAP_FIRST_PAGE - pages_mapped, -phys_addr, PAGE_KERNEL); +phys_addr, +cache ? PAGE_KERNEL : PAGE_KERNEL_NOCACHE); phys_addr += PAGE_SIZE; pages_mapped++; } Index: linux/include/asm-x86/efi.h === --- linux.orig/include/asm-x86/efi.h +++ linux/include/asm-x86/efi.h @@ -33,7 +33,8 @@ extern unsigned long asmlinkage efi_call #define efi_call_virt6(f, a1, a2, a3, a4, a5, a6) \ efi_call_virt(f, a1, a2, a3, a4, a5, a6) -#define efi_ioremap(addr, size)ioremap_cache(addr, size) +#define efi_ioremap(addr, size, cache) \ + (cache ? ioremap_cache(addr, size) : ioremap_nocache(addr, size)) #else /* !CONFIG_X86_32 */ @@ -86,7 +87,7 @@ extern u64 efi_call6(void *fp, u64 arg1, efi_call6((void *)(efi.systab-runtime-f), (u64)(a1), (u64)(a2), \ (u64)(a3), (u64)(a4), (u64)(a5), (u64)(a6)) -extern void *efi_ioremap(unsigned long addr, unsigned long size); +extern void *efi_ioremap(unsigned long addr, unsigned long size, int cache); #endif /* CONFIG_X86_32 */ -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/