2007-10-18 11:17:18

by Bernhard Walle

[permalink] [raw]
Subject: [patch 1/3] Add BSS to resource tree

This patch adds the BSS to the resource tree just as kernel text and kernel
data are in the resource tree. The main reason behind this is to avoid
crashkernel reservation in that area.

While it's not strictly necessary to have the BSS in the resource tree
(the actual collision detection is done in the reserve_bootmem() function
before), the usage of the BSS resource should be presented to the user
in /proc/iomem just as Kernel data and Kernel code.

Note: The patch currently is only implemented for x86 and ia64 (because
efi_initialize_iomem_resources() has the same signature on i386 and
ia64).


Signed-off-by: Bernhard Walle <[email protected]>

---
arch/ia64/kernel/efi.c | 4 +++-
arch/ia64/kernel/setup.c | 14 +++++++++++---
arch/x86/kernel/e820_32.c | 18 +++++++++++++++---
arch/x86/kernel/e820_64.c | 3 ++-
arch/x86/kernel/efi_32.c | 4 +++-
arch/x86/kernel/setup_32.c | 4 ++++
arch/x86/kernel/setup_64.c | 9 +++++++++
include/linux/efi.h | 2 +-
8 files changed, 48 insertions(+), 10 deletions(-)

--- a/arch/ia64/kernel/efi.c
+++ b/arch/ia64/kernel/efi.c
@@ -1090,7 +1090,8 @@ efi_memmap_init(unsigned long *s, unsign

void
efi_initialize_iomem_resources(struct resource *code_resource,
- struct resource *data_resource)
+ struct resource *data_resource,
+ struct resource *bss_resource)
{
struct resource *res;
void *efi_map_start, *efi_map_end, *p;
@@ -1171,6 +1172,7 @@ efi_initialize_iomem_resources(struct re
*/
insert_resource(res, code_resource);
insert_resource(res, data_resource);
+ insert_resource(res, bss_resource);
#ifdef CONFIG_KEXEC
insert_resource(res, &efi_memmap_res);
insert_resource(res, &boot_param_res);
--- a/arch/ia64/kernel/setup.c
+++ b/arch/ia64/kernel/setup.c
@@ -90,7 +90,12 @@ static struct resource code_resource = {
.name = "Kernel code",
.flags = IORESOURCE_BUSY | IORESOURCE_MEM
};
-extern char _text[], _end[], _etext[];
+
+static struct resource bss_resource = {
+ .name = "Kernel bss",
+ .flags = IORESOURCE_BUSY | IORESOURCE_MEM
+};
+extern char _text[], _end[], _etext[], _edata[], _bss[];

unsigned long ia64_max_cacheline_size;

@@ -200,8 +205,11 @@ static int __init register_memory(void)
code_resource.start = ia64_tpa(_text);
code_resource.end = ia64_tpa(_etext) - 1;
data_resource.start = ia64_tpa(_etext);
- data_resource.end = ia64_tpa(_end) - 1;
- efi_initialize_iomem_resources(&code_resource, &data_resource);
+ data_resource.end = ia64_tpa(_edata) - 1;
+ bss_resource.start = ia64_tpa(_bss);
+ bss_resource.end = ia64_tpa(_end) - 1;
+ efi_initialize_iomem_resources(&code_resource, &data_resource,
+ &bss_resource);

return 0;
}
--- a/arch/x86/kernel/e820_32.c
+++ b/arch/x86/kernel/e820_32.c
@@ -51,6 +51,13 @@ struct resource code_resource = {
.flags = IORESOURCE_BUSY | IORESOURCE_MEM
};

+struct resource bss_resource = {
+ .name = "Kernel bss",
+ .start = 0,
+ .end = 0,
+ .flags = IORESOURCE_BUSY | IORESOURCE_MEM
+};
+
static struct resource system_rom_resource = {
.name = "System ROM",
.start = 0xf0000,
@@ -254,7 +261,9 @@ static void __init probe_roms(void)
* and also for regions reported as reserved by the e820.
*/
static void __init
-legacy_init_iomem_resources(struct resource *code_resource, struct resource *data_resource)
+legacy_init_iomem_resources(struct resource *code_resource,
+ struct resource *data_resource,
+ struct resource *bss_resource)
{
int i;

@@ -287,6 +296,7 @@ legacy_init_iomem_resources(struct resou
*/
request_resource(res, code_resource);
request_resource(res, data_resource);
+ request_resource(res, bss_resource);
#ifdef CONFIG_KEXEC
if (crashk_res.start != crashk_res.end)
request_resource(res, &crashk_res);
@@ -307,9 +317,11 @@ static int __init request_standard_resou

printk("Setting up standard PCI resources\n");
if (efi_enabled)
- efi_initialize_iomem_resources(&code_resource, &data_resource);
+ efi_initialize_iomem_resources(&code_resource,
+ &data_resource, &bss_resource);
else
- legacy_init_iomem_resources(&code_resource, &data_resource);
+ legacy_init_iomem_resources(&code_resource,
+ &data_resource, &bss_resource);

/* EFI systems may still have VGA */
request_resource(&iomem_resource, &video_ram_resource);
--- a/arch/x86/kernel/e820_64.c
+++ b/arch/x86/kernel/e820_64.c
@@ -47,7 +47,7 @@ unsigned long end_pfn_map;
*/
static unsigned long __initdata end_user_pfn = MAXMEM>>PAGE_SHIFT;

-extern struct resource code_resource, data_resource;
+extern struct resource code_resource, data_resource, bss_resource;

/* Check for some hardcoded bad areas that early boot is not allowed to touch */
static inline int bad_addr(unsigned long *addrp, unsigned long size)
@@ -220,6 +220,7 @@ void __init e820_reserve_resources(void)
*/
request_resource(res, &code_resource);
request_resource(res, &data_resource);
+ request_resource(res, &bss_resource);
#ifdef CONFIG_KEXEC
if (crashk_res.start != crashk_res.end)
request_resource(res, &crashk_res);
--- a/arch/x86/kernel/efi_32.c
+++ b/arch/x86/kernel/efi_32.c
@@ -600,7 +600,8 @@ void __init efi_enter_virtual_mode(void)

void __init
efi_initialize_iomem_resources(struct resource *code_resource,
- struct resource *data_resource)
+ struct resource *data_resource,
+ struct resource *bss_resource)
{
struct resource *res;
efi_memory_desc_t *md;
@@ -672,6 +673,7 @@ efi_initialize_iomem_resources(struct re
if (md->type == EFI_CONVENTIONAL_MEMORY) {
request_resource(res, code_resource);
request_resource(res, data_resource);
+ request_resource(res, bss_resource);
#ifdef CONFIG_KEXEC
request_resource(res, &crashk_res);
#endif
--- a/arch/x86/kernel/setup_32.c
+++ b/arch/x86/kernel/setup_32.c
@@ -60,6 +60,7 @@
#include <asm/vmi.h>
#include <setup_arch.h>
#include <bios_ebda.h>
+#include <asm/cacheflush.h>

/* This value is set up by the early boot code to point to the value
immediately after the boot time page tables. It contains a *physical*
@@ -73,6 +74,7 @@ int disable_pse __devinitdata = 0;
*/
extern struct resource code_resource;
extern struct resource data_resource;
+extern struct resource bss_resource;

/* cpu data as detected by the assembly code in head.S */
struct cpuinfo_x86 new_cpu_data __cpuinitdata = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
@@ -595,6 +597,8 @@ void __init setup_arch(char **cmdline_p)
code_resource.end = virt_to_phys(_etext)-1;
data_resource.start = virt_to_phys(_etext);
data_resource.end = virt_to_phys(_edata)-1;
+ bss_resource.start = virt_to_phys(&__bss_start);
+ bss_resource.end = virt_to_phys(&__bss_stop)-1;

parse_early_param();

--- a/arch/x86/kernel/setup_64.c
+++ b/arch/x86/kernel/setup_64.c
@@ -59,6 +59,7 @@
#include <asm/numa.h>
#include <asm/sections.h>
#include <asm/dmi.h>
+#include <asm/cacheflush.h>

/*
* Machine setup..
@@ -134,6 +135,12 @@ struct resource code_resource = {
.end = 0,
.flags = IORESOURCE_RAM,
};
+struct resource bss_resource = {
+ .name = "Kernel bss",
+ .start = 0,
+ .end = 0,
+ .flags = IORESOURCE_RAM,
+};

#ifdef CONFIG_PROC_VMCORE
/* elfcorehdr= specifies the location of elf core header
@@ -276,6 +283,8 @@ void __init setup_arch(char **cmdline_p)
code_resource.end = virt_to_phys(&_etext)-1;
data_resource.start = virt_to_phys(&_etext);
data_resource.end = virt_to_phys(&_edata)-1;
+ bss_resource.start = virt_to_phys(&__bss_start);
+ bss_resource.end = virt_to_phys(&__bss_stop)-1;

early_identify_cpu(&boot_cpu_data);

--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -298,7 +298,7 @@ extern int efi_mem_attribute_range (unsi
u64 attr);
extern int __init efi_uart_console_only (void);
extern void efi_initialize_iomem_resources(struct resource *code_resource,
- struct resource *data_resource);
+ struct resource *data_resource, struct resource *bss_resource);
extern unsigned long efi_get_time(void);
extern int efi_set_rtc_mmss(unsigned long nowtime);
extern int is_available_memory(efi_memory_desc_t * md);

--


2007-10-18 21:27:28

by Andrew Morton

[permalink] [raw]
Subject: Re: [patch 1/3] Add BSS to resource tree

On Thu, 18 Oct 2007 13:15:36 +0200
Bernhard Walle <[email protected]> wrote:

> This patch adds the BSS to the resource tree just as kernel text and kernel
> data are in the resource tree. The main reason behind this is to avoid
> crashkernel reservation in that area.
>
> While it's not strictly necessary to have the BSS in the resource tree
> (the actual collision detection is done in the reserve_bootmem() function
> before), the usage of the BSS resource should be presented to the user
> in /proc/iomem just as Kernel data and Kernel code.
>
> Note: The patch currently is only implemented for x86 and ia64 (because
> efi_initialize_iomem_resources() has the same signature on i386 and
> ia64).
>
>
> ...
>
> -extern char _text[], _end[], _etext[];
> +
> +static struct resource bss_resource = {
> + .name = "Kernel bss",
> + .flags = IORESOURCE_BUSY | IORESOURCE_MEM
> +};
> +extern char _text[], _end[], _etext[], _edata[], _bss[];

These should be in a header file.

> --- a/arch/x86/kernel/e820_64.c
> +++ b/arch/x86/kernel/e820_64.c
> @@ -47,7 +47,7 @@ unsigned long end_pfn_map;
> */
> static unsigned long __initdata end_user_pfn = MAXMEM>>PAGE_SHIFT;
>
> -extern struct resource code_resource, data_resource;
> +extern struct resource code_resource, data_resource, bss_resource;

As should these. afaik they're the same on all architectures and even if
they have different names on some weird arch, an unused declaration won't
hurt.

> --- a/arch/x86/kernel/setup_32.c
> +++ b/arch/x86/kernel/setup_32.c
> @@ -73,6 +74,7 @@ int disable_pse __devinitdata = 0;
> */
> extern struct resource code_resource;
> extern struct resource data_resource;
> +extern struct resource bss_resource;

See, we keep on adding the same thing over and over again.


These problems are not introduced by your changes, of course. But we really
should degunk this stuff sometime.

2007-10-18 21:48:48

by Andi Kleen

[permalink] [raw]
Subject: Re: [patch 1/3] Add BSS to resource tree

> > +extern char _text[], _end[], _etext[], _edata[], _bss[];
>
> These should be in a header file.

Normally the "no externs in .c" rule doesn't apply to assembler or linker
script defined labels. That's because the point of the header file is to
type check them, but there is nothing to type check here.

-Andi

2007-10-18 21:57:05

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [patch 1/3] Add BSS to resource tree

On Thu, Oct 18, 2007 at 11:48:37PM +0200, Andi Kleen wrote:
> > > +extern char _text[], _end[], _etext[], _edata[], _bss[];
> >
> > These should be in a header file.
>
> Normally the "no externs in .c" rule doesn't apply to assembler or linker
> script defined labels. That's because the point of the header file is to
> type check them, but there is nothing to type check here.

For linker generated symbols we have sections.h for this purpose.
The above symbols are all available if we do an:
#include <asm/sections.h>

This is the right fix in this case.

Sam

2007-10-18 22:00:58

by Andi Kleen

[permalink] [raw]
Subject: Re: [patch 1/3] Add BSS to resource tree

On Thu, Oct 18, 2007 at 11:58:27PM +0200, Sam Ravnborg wrote:
> On Thu, Oct 18, 2007 at 11:48:37PM +0200, Andi Kleen wrote:
> > > > +extern char _text[], _end[], _etext[], _edata[], _bss[];
> > >
> > > These should be in a header file.
> >
> > Normally the "no externs in .c" rule doesn't apply to assembler or linker
> > script defined labels. That's because the point of the header file is to
> > type check them, but there is nothing to type check here.
>
> For linker generated symbols we have sections.h for this purpose.
> The above symbols are all available if we do an:
> #include <asm/sections.h>
>
> This is the right fix in this case.

The problem is that they're often the wrong type here. E.g. wrong signedness
etc. I ran into problems in the past where using this required ugly casts.

-Andi

2007-10-18 22:16:52

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [patch 1/3] Add BSS to resource tree

On Fri, Oct 19, 2007 at 12:00:48AM +0200, Andi Kleen wrote:
> On Thu, Oct 18, 2007 at 11:58:27PM +0200, Sam Ravnborg wrote:
> > On Thu, Oct 18, 2007 at 11:48:37PM +0200, Andi Kleen wrote:
> > > > > +extern char _text[], _end[], _etext[], _edata[], _bss[];
> > > >
> > > > These should be in a header file.
> > >
> > > Normally the "no externs in .c" rule doesn't apply to assembler or linker
> > > script defined labels. That's because the point of the header file is to
> > > type check them, but there is nothing to type check here.
> >
> > For linker generated symbols we have sections.h for this purpose.
> > The above symbols are all available if we do an:
> > #include <asm/sections.h>
> >
> > This is the right fix in this case.
>
> The problem is that they're often the wrong type here. E.g. wrong signedness
> etc. I ran into problems in the past where using this required ugly casts.

But then we should fix them instead of working around the problem - no?

Grepping for _text shows that there are plenty of different ways to declare
that symbol extern - this does not look correct.

And I recall that extern char sym[] is considered correct by binutils
people - but I'm not 100% sure and google did not give me an appropriate hit.

Sam

2007-10-18 22:20:49

by Andi Kleen

[permalink] [raw]
Subject: Re: [patch 1/3] Add BSS to resource tree

> Grepping for _text shows that there are plenty of different ways to declare
> that symbol extern - this does not look correct.

They really don't have a specific type and using the type that happens to be convenient
to whatever calculation you want to do with it is useful.

-Andi

2007-10-18 22:38:29

by Andrew Morton

[permalink] [raw]
Subject: Re: [patch 1/3] Add BSS to resource tree

On Fri, 19 Oct 2007 00:18:13 +0200
Sam Ravnborg <[email protected]> wrote:

> And I recall that extern char sym[] is considered correct by binutils
> people - but I'm not 100% sure and google did not give me an appropriate hit.

An ancient memory tells me that these things are traditionally
declared as plain old int:

extern int start;
extern int edata;

etc.

However
http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=0650&db=man&fname=/usr/share/catman/p_man/cat3/standard/_rt_symbol_table_size.z
disagrees with me.

http://www.psych.upenn.edu/~saul/parasite/man/man3/end.3.html agrees with me

http://docsrv.sco.com:507/en/man/html.S/end.S.html agrees with me

http://www.rocketaware.com/man/man3/end.3.htm agrees with me

http://bama.ua.edu/cgi-bin/man-cgi?etext+3C agrees with me


2007-10-18 22:46:00

by Andi Kleen

[permalink] [raw]
Subject: Re: [patch 1/3] Add BSS to resource tree

On Thu, Oct 18, 2007 at 03:37:51PM -0700, Andrew Morton wrote:
> On Fri, 19 Oct 2007 00:18:13 +0200
> Sam Ravnborg <[email protected]> wrote:
>
> > And I recall that extern char sym[] is considered correct by binutils
> > people - but I'm not 100% sure and google did not give me an appropriate hit.
>
> An ancient memory tells me that these things are traditionally
> declared as plain old int:
>
> extern int start;
> extern int edata;

int is probably one of the less useful types. Typical operation is computing
the difference between two symbols in bytes. &int without cast would give
you a useless scaled size.

-Andi

2007-10-19 00:27:31

by Jeremy Fitzhardinge

[permalink] [raw]
Subject: Re: [patch 1/3] Add BSS to resource tree

Sam Ravnborg wrote:
> And I recall that extern char sym[] is considered correct by binutils
> people - but I'm not 100% sure and google did not give me an appropriate hit.

Yes, I generally prefer char[] - but only because gcc irritatingly
rejects void []...

J

2007-10-19 12:53:16

by Bernhard Walle

[permalink] [raw]
Subject: Re: [patch 1/3] Add BSS to resource tree

* Andrew Morton <[email protected]> [2007-10-18 23:26]:
>
> > --- a/arch/x86/kernel/e820_64.c
> > +++ b/arch/x86/kernel/e820_64.c
> > @@ -47,7 +47,7 @@ unsigned long end_pfn_map;
> > */
> > static unsigned long __initdata end_user_pfn = MAXMEM>>PAGE_SHIFT;
> >
> > -extern struct resource code_resource, data_resource;
> > +extern struct resource code_resource, data_resource, bss_resource;
>
> As should these. afaik they're the same on all architectures and even if
> they have different names on some weird arch, an unused declaration won't
> hurt.

It's different on every architectures. Some don't have it at all (like
PPC64), and most of them have code_resource and data_resource static.
Instead of making the data on all architectures (that have it) global,
I'd like to make it static on x86.

See my attached patch.



Thanks,
Bernhard

---

[PATCH] Remove extern declarations for code/data/bss resource

This patch removes the extern struct resource declarations for
data_resource, code_resource and bss_resource on x86 and declares
that three structures as static as done on other architectures like IA64.

On i386, these structures are moved to setup_32.c (from e820_32.c) because
that's code that is not specific to e820 and also required on EFI systems.
That makes the "extern" reference superfluous.

On x86_64, data_resource, code_resource and bss_resource are passed to
e820_reserve_resources() as arguments just as done on i386 and IA64. That also
avoids the "extern" reference and it's possible to make it static.


Signed-off-by: Bernhard Walle <[email protected]>

---
arch/x86/kernel/e820_32.c | 49 --------------------
arch/x86/kernel/e820_64.c | 11 ++--
arch/x86/kernel/setup_32.c | 106 +++++++++++++++++++++++++++++++++++++++++++--
arch/x86/kernel/setup_64.c | 6 +-
4 files changed, 111 insertions(+), 61 deletions(-)

--- a/arch/x86/kernel/e820_32.c
+++ b/arch/x86/kernel/e820_32.c
@@ -37,26 +37,6 @@ unsigned long pci_mem_start = 0x10000000
EXPORT_SYMBOL(pci_mem_start);
#endif
extern int user_defined_memmap;
-struct resource data_resource = {
- .name = "Kernel data",
- .start = 0,
- .end = 0,
- .flags = IORESOURCE_BUSY | IORESOURCE_MEM
-};
-
-struct resource code_resource = {
- .name = "Kernel code",
- .start = 0,
- .end = 0,
- .flags = IORESOURCE_BUSY | IORESOURCE_MEM
-};
-
-struct resource bss_resource = {
- .name = "Kernel bss",
- .start = 0,
- .end = 0,
- .flags = IORESOURCE_BUSY | IORESOURCE_MEM
-};

static struct resource system_rom_resource = {
.name = "System ROM",
@@ -111,60 +91,6 @@ static struct resource video_rom_resourc
.flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
};

-static struct resource video_ram_resource = {
- .name = "Video RAM area",
- .start = 0xa0000,
- .end = 0xbffff,
- .flags = IORESOURCE_BUSY | IORESOURCE_MEM
-};
-
-static struct resource standard_io_resources[] = { {
- .name = "dma1",
- .start = 0x0000,
- .end = 0x001f,
- .flags = IORESOURCE_BUSY | IORESOURCE_IO
-}, {
- .name = "pic1",
- .start = 0x0020,
- .end = 0x0021,
- .flags = IORESOURCE_BUSY | IORESOURCE_IO
-}, {
- .name = "timer0",
- .start = 0x0040,
- .end = 0x0043,
- .flags = IORESOURCE_BUSY | IORESOURCE_IO
-}, {
- .name = "timer1",
- .start = 0x0050,
- .end = 0x0053,
- .flags = IORESOURCE_BUSY | IORESOURCE_IO
-}, {
- .name = "keyboard",
- .start = 0x0060,
- .end = 0x006f,
- .flags = IORESOURCE_BUSY | IORESOURCE_IO
-}, {
- .name = "dma page reg",
- .start = 0x0080,
- .end = 0x008f,
- .flags = IORESOURCE_BUSY | IORESOURCE_IO
-}, {
- .name = "pic2",
- .start = 0x00a0,
- .end = 0x00a1,
- .flags = IORESOURCE_BUSY | IORESOURCE_IO
-}, {
- .name = "dma2",
- .start = 0x00c0,
- .end = 0x00df,
- .flags = IORESOURCE_BUSY | IORESOURCE_IO
-}, {
- .name = "fpu",
- .start = 0x00f0,
- .end = 0x00ff,
- .flags = IORESOURCE_BUSY | IORESOURCE_IO
-} };
-
#define ROMSIGNATURE 0xaa55

static int __init romsignature(const unsigned char *rom)
@@ -260,10 +186,9 @@ static void __init probe_roms(void)
* Request address space for all standard RAM and ROM resources
* and also for regions reported as reserved by the e820.
*/
-static void __init
-legacy_init_iomem_resources(struct resource *code_resource,
- struct resource *data_resource,
- struct resource *bss_resource)
+void __init legacy_init_iomem_resources(struct resource *code_resource,
+ struct resource *data_resource,
+ struct resource *bss_resource)
{
int i;

@@ -305,35 +230,6 @@ legacy_init_iomem_resources(struct resou
}
}

-/*
- * Request address space for all standard resources
- *
- * This is called just before pcibios_init(), which is also a
- * subsys_initcall, but is linked in later (in arch/i386/pci/common.c).
- */
-static int __init request_standard_resources(void)
-{
- int i;
-
- printk("Setting up standard PCI resources\n");
- if (efi_enabled)
- efi_initialize_iomem_resources(&code_resource,
- &data_resource, &bss_resource);
- else
- legacy_init_iomem_resources(&code_resource,
- &data_resource, &bss_resource);
-
- /* EFI systems may still have VGA */
- request_resource(&iomem_resource, &video_ram_resource);
-
- /* request I/O space for devices used on all i[345]86 PCs */
- for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
- request_resource(&ioport_resource, &standard_io_resources[i]);
- return 0;
-}
-
-subsys_initcall(request_standard_resources);
-
#if defined(CONFIG_PM) && defined(CONFIG_HIBERNATION)
/**
* e820_mark_nosave_regions - Find the ranges of physical addresses that do not
--- a/arch/x86/kernel/e820_64.c
+++ b/arch/x86/kernel/e820_64.c
@@ -47,8 +47,6 @@ unsigned long end_pfn_map;
*/
static unsigned long __initdata end_user_pfn = MAXMEM>>PAGE_SHIFT;

-extern struct resource code_resource, data_resource, bss_resource;
-
/* Check for some hardcoded bad areas that early boot is not allowed to touch */
static inline int bad_addr(unsigned long *addrp, unsigned long size)
{
@@ -201,7 +199,8 @@ unsigned long __init e820_end_of_ram(voi
/*
* Mark e820 reserved areas as busy for the resource manager.
*/
-void __init e820_reserve_resources(void)
+void __init e820_reserve_resources(struct resource *code_resource,
+ struct resource *data_resource, struct resource *bss_resource)
{
int i;
for (i = 0; i < e820.nr_map; i++) {
@@ -223,9 +222,9 @@ void __init e820_reserve_resources(void)
* so we try it repeatedly and let the resource manager
* test it.
*/
- request_resource(res, &code_resource);
- request_resource(res, &data_resource);
- request_resource(res, &bss_resource);
+ request_resource(res, code_resource);
+ request_resource(res, data_resource);
+ request_resource(res, bss_resource);
#ifdef CONFIG_KEXEC
if (crashk_res.start != crashk_res.end)
request_resource(res, &crashk_res);
--- a/arch/x86/kernel/setup_32.c
+++ b/arch/x86/kernel/setup_32.c
@@ -72,9 +72,80 @@ int disable_pse __devinitdata = 0;
/*
* Machine setup..
*/
-extern struct resource code_resource;
-extern struct resource data_resource;
-extern struct resource bss_resource;
+static struct resource data_resource = {
+ .name = "Kernel data",
+ .start = 0,
+ .end = 0,
+ .flags = IORESOURCE_BUSY | IORESOURCE_MEM
+};
+
+static struct resource code_resource = {
+ .name = "Kernel code",
+ .start = 0,
+ .end = 0,
+ .flags = IORESOURCE_BUSY | IORESOURCE_MEM
+};
+
+static struct resource bss_resource = {
+ .name = "Kernel bss",
+ .start = 0,
+ .end = 0,
+ .flags = IORESOURCE_BUSY | IORESOURCE_MEM
+};
+
+static struct resource video_ram_resource = {
+ .name = "Video RAM area",
+ .start = 0xa0000,
+ .end = 0xbffff,
+ .flags = IORESOURCE_BUSY | IORESOURCE_MEM
+};
+
+static struct resource standard_io_resources[] = { {
+ .name = "dma1",
+ .start = 0x0000,
+ .end = 0x001f,
+ .flags = IORESOURCE_BUSY | IORESOURCE_IO
+}, {
+ .name = "pic1",
+ .start = 0x0020,
+ .end = 0x0021,
+ .flags = IORESOURCE_BUSY | IORESOURCE_IO
+}, {
+ .name = "timer0",
+ .start = 0x0040,
+ .end = 0x0043,
+ .flags = IORESOURCE_BUSY | IORESOURCE_IO
+}, {
+ .name = "timer1",
+ .start = 0x0050,
+ .end = 0x0053,
+ .flags = IORESOURCE_BUSY | IORESOURCE_IO
+}, {
+ .name = "keyboard",
+ .start = 0x0060,
+ .end = 0x006f,
+ .flags = IORESOURCE_BUSY | IORESOURCE_IO
+}, {
+ .name = "dma page reg",
+ .start = 0x0080,
+ .end = 0x008f,
+ .flags = IORESOURCE_BUSY | IORESOURCE_IO
+}, {
+ .name = "pic2",
+ .start = 0x00a0,
+ .end = 0x00a1,
+ .flags = IORESOURCE_BUSY | IORESOURCE_IO
+}, {
+ .name = "dma2",
+ .start = 0x00c0,
+ .end = 0x00df,
+ .flags = IORESOURCE_BUSY | IORESOURCE_IO
+}, {
+ .name = "fpu",
+ .start = 0x00f0,
+ .end = 0x00ff,
+ .flags = IORESOURCE_BUSY | IORESOURCE_IO
+} };

/* cpu data as detected by the assembly code in head.S */
struct cpuinfo_x86 new_cpu_data __cpuinitdata = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
@@ -706,3 +777,32 @@ void __init setup_arch(char **cmdline_p)
#endif
#endif
}
+
+/*
+ * Request address space for all standard resources
+ *
+ * This is called just before pcibios_init(), which is also a
+ * subsys_initcall, but is linked in later (in arch/i386/pci/common.c).
+ */
+static int __init request_standard_resources(void)
+{
+ int i;
+
+ printk(KERN_INFO "Setting up standard PCI resources\n");
+ if (efi_enabled)
+ efi_initialize_iomem_resources(&code_resource,
+ &data_resource, &bss_resource);
+ else
+ legacy_init_iomem_resources(&code_resource,
+ &data_resource, &bss_resource);
+
+ /* EFI systems may still have VGA */
+ request_resource(&iomem_resource, &video_ram_resource);
+
+ /* request I/O space for devices used on all i[345]86 PCs */
+ for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
+ request_resource(&ioport_resource, &standard_io_resources[i]);
+ return 0;
+}
+
+subsys_initcall(request_standard_resources);
--- a/arch/x86/kernel/setup_64.c
+++ b/arch/x86/kernel/setup_64.c
@@ -122,19 +122,19 @@ struct resource standard_io_resources[]

#define IORESOURCE_RAM (IORESOURCE_BUSY | IORESOURCE_MEM)

-struct resource data_resource = {
+static struct resource data_resource = {
.name = "Kernel data",
.start = 0,
.end = 0,
.flags = IORESOURCE_RAM,
};
-struct resource code_resource = {
+static struct resource code_resource = {
.name = "Kernel code",
.start = 0,
.end = 0,
.flags = IORESOURCE_RAM,
};
-struct resource bss_resource = {
+static struct resource bss_resource = {
.name = "Kernel bss",
.start = 0,
.end = 0,
@@ -437,7 +437,7 @@ void __init setup_arch(char **cmdline_p)
/*
* We trust e820 completely. No explicit ROM probing in memory.
*/
- e820_reserve_resources();
+ e820_reserve_resources(&code_resource, &data_resource, &bss_resource);
e820_mark_nosave_regions();

{
--- a/include/asm-x86/e820_32.h
+++ b/include/asm-x86/e820_32.h
@@ -12,6 +12,8 @@
#ifndef __E820_HEADER
#define __E820_HEADER

+#include <linux/ioport.h>
+
#define E820MAP 0x2d0 /* our map */
#define E820MAX 128 /* number of entries in E820MAP */
#define E820NR 0x1e8 /* # entries in E820MAP */
@@ -46,6 +48,9 @@ extern void register_bootmem_low_pages(u
extern void e820_register_memory(void);
extern void limit_regions(unsigned long long size);
extern void print_memory_map(char *who);
+extern void legacy_init_iomem_resources(struct resource *code_resource,
+ struct resource *data_resource,
+ struct resource *bss_resource);

#if defined(CONFIG_PM) && defined(CONFIG_HIBERNATION)
extern void e820_mark_nosave_regions(void);
@@ -55,6 +60,7 @@ static inline void e820_mark_nosave_regi
}
#endif

+
#endif/*!__ASSEMBLY__*/

#endif/*__E820_HEADER*/
--- a/include/asm-x86/e820_64.h
+++ b/include/asm-x86/e820_64.h
@@ -11,6 +11,8 @@
#ifndef __E820_HEADER
#define __E820_HEADER

+#include <linux/ioport.h>
+
#define E820MAP 0x2d0 /* our map */
#define E820MAX 128 /* number of entries in E820MAP */
#define E820NR 0x1e8 /* # entries in E820MAP */
@@ -39,7 +41,8 @@ extern void add_memory_region(unsigned l
extern void setup_memory_region(void);
extern void contig_e820_setup(void);
extern unsigned long e820_end_of_ram(void);
-extern void e820_reserve_resources(void);
+extern void e820_reserve_resources(struct resource *code_resource,
+ struct resource *data_resource, struct resource *bss_resource);
extern void e820_mark_nosave_regions(void);
extern void e820_print_map(char *who);
extern int e820_any_mapped(unsigned long start, unsigned long end, unsigned type);
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -8,6 +8,7 @@
#ifndef _LINUX_IOPORT_H
#define _LINUX_IOPORT_H

+#ifndef __ASSEMBLY__
#include <linux/compiler.h>
#include <linux/types.h>
/*
@@ -153,4 +154,5 @@ extern struct resource * __devm_request_
extern void __devm_release_region(struct device *dev, struct resource *parent,
resource_size_t start, resource_size_t n);

+#endif /* __ASSEMBLY__ */
#endif /* _LINUX_IOPORT_H */

2007-10-19 14:48:40

by Bernhard Walle

[permalink] [raw]
Subject: Re: [patch 1/3] Add BSS to resource tree

* Andrew Morton <[email protected]> [2007-10-18 23:26]:
> On Thu, 18 Oct 2007 13:15:36 +0200
> Bernhard Walle <[email protected]> wrote:
>
> > This patch adds the BSS to the resource tree just as kernel text and kernel
> > data are in the resource tree. The main reason behind this is to avoid
> > crashkernel reservation in that area.
> >
> > While it's not strictly necessary to have the BSS in the resource tree
> > (the actual collision detection is done in the reserve_bootmem() function
> > before), the usage of the BSS resource should be presented to the user
> > in /proc/iomem just as Kernel data and Kernel code.
> >
> > Note: The patch currently is only implemented for x86 and ia64 (because
> > efi_initialize_iomem_resources() has the same signature on i386 and
> > ia64).
> >
> >
> > ...
> >
> > -extern char _text[], _end[], _etext[];
> > +
> > +static struct resource bss_resource = {
> > + .name = "Kernel bss",
> > + .flags = IORESOURCE_BUSY | IORESOURCE_MEM
> > +};
> > +extern char _text[], _end[], _etext[], _edata[], _bss[];
>
> These should be in a header file.

It's already ... the problem just was that IA64 uses _bss instead of
__bss_start. So I think we should change this. I verified that the
kernel still compiles with the patch below.


Thanks,
Bernhard

---
[PATCH] Rename _bss to __bss_start

Rename _bss to __bss_start as on other architectures. That makes it possible to
use the <linux/sections.h> instead of own declarations. Also add __bss_stop
because that symbol exists on other architectures.

That patch applies to current git plus kexec-add-bss-to-resource-tree.patch in
-mm tree.


Signed-off-by: Bernhard Walle <[email protected]>

---
arch/ia64/hp/sim/boot/bootloader.lds | 3 ++-
arch/ia64/kernel/setup.c | 3 +--
arch/ia64/kernel/vmlinux.lds.S | 3 ++-
3 files changed, 5 insertions(+), 4 deletions(-)

--- a/arch/ia64/hp/sim/boot/bootloader.lds
+++ b/arch/ia64/hp/sim/boot/bootloader.lds
@@ -22,10 +22,11 @@ SECTIONS
.sdata : { *(.sdata) }
_edata = .;

- _bss = .;
+ __bss_start = .;
.sbss : { *(.sbss) *(.scommon) }
.bss : { *(.bss) *(COMMON) }
. = ALIGN(64 / 8);
+ __bss_stop = .;
_end = . ;

/* Stabs debugging sections. */
--- a/arch/ia64/kernel/setup.c
+++ b/arch/ia64/kernel/setup.c
@@ -95,7 +95,6 @@ static struct resource bss_resource = {
.name = "Kernel bss",
.flags = IORESOURCE_BUSY | IORESOURCE_MEM
};
-extern char _text[], _end[], _etext[], _edata[], _bss[];

unsigned long ia64_max_cacheline_size;

@@ -206,7 +205,7 @@ static int __init register_memory(void)
code_resource.end = ia64_tpa(_etext) - 1;
data_resource.start = ia64_tpa(_etext);
data_resource.end = ia64_tpa(_edata) - 1;
- bss_resource.start = ia64_tpa(_bss);
+ bss_resource.start = ia64_tpa(__bss_start);
bss_resource.end = ia64_tpa(_end) - 1;
efi_initialize_iomem_resources(&code_resource, &data_resource,
&bss_resource);
--- a/arch/ia64/kernel/vmlinux.lds.S
+++ b/arch/ia64/kernel/vmlinux.lds.S
@@ -240,11 +240,12 @@ SECTIONS
.sdata : AT(ADDR(.sdata) - LOAD_OFFSET)
{ *(.sdata) *(.sdata1) *(.srdata) }
_edata = .;
- _bss = .;
+ __bss_start = .;
.sbss : AT(ADDR(.sbss) - LOAD_OFFSET)
{ *(.sbss) *(.scommon) }
.bss : AT(ADDR(.bss) - LOAD_OFFSET)
{ *(.bss) *(COMMON) }
+ __bss_stop = .;

_end = .;