ACPI, APEI, BUG fixes for 2.6.36
Subsystems (3)
cover ACPI, APEI, BUG fixes for 2.6.36
Hi, Len,
This patchset is some BUG fixes about APEI for 2.6.36. Can you merge it?
[PATCH 1/5] ACPI, APEI, Fix APEI related table size checking [PATCH 2/5] ACPI, APEI, Fix acpi_pre_map() return value [PATCH 3/5] ACPI, APEI, HEST Fix the unsuitable usage of platform_data [PATCH 4/5] ACPI, APEI, Fix error path for memory allocation [PATCH 5/5] ACPI, APEI, Fix ERST MOVE_DATA instruction implementation
Best Regards,
Huang Ying
PATCH 1/5 ACPI, APEI, Fix APEI related table size checking
From: Yinghai Lu <[email protected]>
Both ERST and EINJ table size checking is fixed.
--- drivers/acpi/apei/einj.c | 3 ++- drivers/acpi/apei/erst.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/acpi/apei/einj.c +2 -1
@@ -426,7 +426,8 @@ DEFINE_SIMPLE_ATTRIBUTE(error_inject_fops, NULL,static int einj_check_table (struct acpi_table_einj *einj_tab) { -if (einj_tab->header_length !=sizeof (struct acpi_table_einj )) +if (einj_tab->header_length != + (sizeof (struct acpi_table_einj ) -sizeof (einj_tab->header)))return -EINVAL ;if (einj_tab->header.length <sizeof (struct acpi_table_einj ))return -EINVAL ;
drivers/acpi/apei/erst.c +2 -1
@@ -750,7 +750,8 @@ __setup("erst_disable", setup_erst_disable);static int erst_check_table (struct acpi_table_erst *erst_tab) { -if (erst_tab->header_length !=sizeof (struct acpi_table_erst )) +if (erst_tab->header_length != + (sizeof (struct acpi_table_erst ) -sizeof (erst_tab->header)))return -EINVAL ;if (erst_tab->header.length <sizeof (struct acpi_table_erst ))return -EINVAL ;
Signature · 1 line
1.7.1
Re: [PATCH 1/5] ACPI, APEI, Fix APEI related table size checking
Quoted 3 lines · Huang Ying
From: Yinghai Lu <[email protected]>
Both ERST and EINJ table size checking is fixed.
Needs a better description.
Quoted 10 lines
--- drivers/acpi/apei/einj.c | 3 ++- drivers/acpi/apei/erst.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)drivers/acpi/apei/einj.c +0
-0
drivers/acpi/apei/einj.c DEFINE_SIMPLE_ATTRIBUTE(error_inject_fops, NULL, · line 430
Quoted 6 lines
drivers/acpi/apei/einj.c +2
-1@@ -426,7 +426,8 @@ DEFINE_SIMPLE_ATTRIBUTE(error_inject_fops, NULL,static int einj_check_table (struct acpi_table_einj *einj_tab) { -if (einj_tab->header_length !=sizeof (struct acpi_table_einj )) +if (einj_tab->header_length != + (sizeof (struct acpi_table_einj ) -sizeof (einj_tab->header)))
I don't understand these changes. So on any system where the old check worked before it won't work anymore? Since the code has been presumably tested before this would break systems, won't it?
Same with the other changes.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Re: [PATCH 1/5] ACPI, APEI, Fix APEI related table size checking
Quoted 27 lines · Andi Kleen
Quoted 3 lines · Huang Ying
From: Yinghai Lu <[email protected]>
Both ERST and EINJ table size checking is fixed.
Needs a better description.
Quoted 10 lines
--- drivers/acpi/apei/einj.c | 3 ++- drivers/acpi/apei/erst.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)drivers/acpi/apei/einj.c +0
-0drivers/acpi/apei/einj.c DEFINE_SIMPLE_ATTRIBUTE(error_inject_fops, NULL, · line 430
Quoted 6 lines
drivers/acpi/apei/einj.c +2
-1@@ -426,7 +426,8 @@ DEFINE_SIMPLE_ATTRIBUTE(error_inject_fops, NULL,static int einj_check_table (struct acpi_table_einj *einj_tab) { -if (einj_tab->header_length !=sizeof (struct acpi_table_einj )) +if (einj_tab->header_length != + (sizeof (struct acpi_table_einj ) -sizeof (einj_tab->header)))I don't understand these changes. So on any system where the old check worked before it won't work anymore? Since the code has been presumably tested before this would break systems, won't it?
Quoted 1 line
Same with the other changes.
Yes. It seems that old check works on my testing machine but not on Yinghai's machine, while the new check works on Yinghai's machine and not on my testing machine.
So I think it is better to remove the checks. Apparently, Windows does not check that.
Best Regards,
Huang Ying
PATCH 2/5 ACPI, APEI, Fix acpi_pre_map() return value
In reply to Huang YingFrom: Jin Dongming <[email protected]>
After we ioremap() a new region, we call __acpi_try_ioremap() to see whether another thread has already mapped the same region. This check clobbers "vaddr", so compute the return value of acpi_pre_map() using the ioremap() result "map->vaddr" instead.
v2:
Modified the unsuitable description of patch.
v3:
Removed unlikely() check and made description simpler.
--- drivers/acpi/atomicio.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/acpi/atomicio.c +1 -1
@@ -142,7 +142,7 @@ static void __iomem *acpi_pre_map(phys_addr_t paddr,list_add_tail_rcu (&map->list, &acpi_iomaps);spin_unlock_irqrestore (&acpi_iomaps_lock, flags); -return vaddr + (paddr - pg_off); +return map->vaddr + (paddr - map->paddr); err_unmap:iounmap (vaddr);return NULL ;
Signature · 1 line
1.7.1
Re: [PATCH 2/5] ACPI, APEI, Fix acpi_pre_map() return value
Quoted 7 lines · Huang Ying
From: Jin Dongming <[email protected]>
After we
ioremap()a new region, we call__acpi_try_ioremap()to see whether another thread has already mapped the same region. This check clobbers "vaddr", so compute the return value ofacpi_pre_map()using theioremap()result "map->vaddr" instead.
Quoted 5 lines
v2:
Modified the unsuitable description of patch.v3:
Removedunlikely()check and made description simpler.
-Andi
PATCH 3/5 ACPI, APEI, HEST Fix the unsuitable usage of platform_data
In reply to Huang YingFrom: Jin Dongming <[email protected]>
platform_data in hest_parse_ghes() is used for saving the address of entry information of erst_tab. When the device is failed to be added, platform_data will be freed by platform_device_put(). But the value saved in platform_data should not be freed here. If it is done, it will make system panic.
So I think platform_data should save the address of allocated memory which saves entry information of erst_tab.
This patch fixed it and I confirmed it on x86_64 next-tree.
v2:
Transport the pointer of hest_hdr to platform_data using platform_device_add_data()
--- drivers/acpi/apei/ghes.c | 2 +- drivers/acpi/apei/hest.c | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/acpi/apei/ghes.c +1 -1
@@ -302,7 +302,7 @@ static int __devinit ghes_probe(struct platform_device *ghes_dev)struct ghes *ghes =NULL ;int rc = -EINVAL ; - generic = ghes_dev->dev.platform_data; + generic = *(struct acpi_hest_generic **)ghes_dev->dev.platform_data;if (!generic->enabled)return -ENODEV ;
drivers/acpi/apei/hest.c +7 -4
@@ -137,20 +137,23 @@ static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data)static int hest_parse_ghes (struct acpi_hest_header *hest_hdr,void *data) { -struct acpi_hest_generic *generic;struct platform_device *ghes_dev;struct ghes_arr *ghes_arr = data;int rc;if (hest_hdr->type !=ACPI_HEST_TYPE_GENERIC_ERROR )return 0 ; - generic = (struct acpi_hest_generic *)hest_hdr; -if (!generic->enabled) + +if (!((struct acpi_hest_generic *)hest_hdr)->enabled)return 0 ; ghes_dev =platform_device_alloc ("GHES" , hest_hdr->source_id);if (!ghes_dev)return -ENOMEM ; - ghes_dev->dev.platform_data = generic; + + rc =platform_device_add_data (ghes_dev, &hest_hdr,sizeof (void *)); +if (rc) + goto err; + rc =platform_device_add (ghes_dev);if (rc) goto err;
Signature · 1 line
1.7.1
Re: [PATCH 3/5] ACPI, APEI, HEST Fix the unsuitable usage of platform_data
drivers/acpi/apei/hest.c static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data) · line 138
Quoted 7 lines · Huang Ying
drivers/acpi/apei/hest.c +0
-0@@ -137,20 +137,23 @@ static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data)static int hest_parse_ghes (struct acpi_hest_header *hest_hdr,void *data)
hest_hdr is a local variable on the stack.
drivers/acpi/apei/hest.c static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data) · line 155
Quoted 4 lines
drivers/acpi/apei/hest.c +4
-0+ + rc =platform_device_add_data (ghes_dev, &hest_hdr,sizeof (void *)); +if (rc) + goto err;
Now you put the address of that local variable in some global data structure.
And then you likely return and later the access accesses random stack space?
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Re: [PATCH 3/5] ACPI, APEI, HEST Fix the unsuitable usage of platform_data
Hi, Andi
Quoted 11 lines · Andi Kleen
drivers/acpi/apei/hest.c static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data) · line 138
Quoted 7 lines · Huang Ying
drivers/acpi/apei/hest.c +0
-0@@ -137,20 +137,23 @@ static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data)static int hest_parse_ghes (struct acpi_hest_header *hest_hdr,void *data)
hest_hdris a local variable on the stack.
Yes, you are right. Exactly what hest_hdr pointed is ghes address of global static variable hest_tab.
Quoted 10 lines
drivers/acpi/apei/hest.c static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data) · line 155
Quoted 5 lines
drivers/acpi/apei/hest.c +4
-0+ + rc =platform_device_add_data (ghes_dev, &hest_hdr,sizeof (void *)); +if (rc) + goto err;Now you put the address of that local variable in some global data structure.
And then you likely return and later the access accesses random stack space?
No, I don't think so.
Here the value(ghes address) of hest_hdr is saved into the private area of ghes_dev, not the address of hest_hdr itself. So what you described will not happen.
Best Regards,
Jin Dongming
Quoted 3 lines
-Andi
Re: [PATCH 3/5] ACPI, APEI, HEST Fix the unsuitable usage of platform_data
In reply to Andi KleenHi, Andi,
Quoted 12 lines · Andi Kleen
drivers/acpi/apei/hest.c static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data) · line 138
Quoted 7 lines · Huang Ying
drivers/acpi/apei/hest.c +0
-0@@ -137,20 +137,23 @@ static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data) static int hest_parse_ghes(struct acpi_hest_header *hest_hdr, void *data)
hest_hdris a local variable on the stack.
Quoted 8 lines
drivers/acpi/apei/hest.c static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data) · line 155
Quoted 4 lines
drivers/acpi/apei/hest.c +4
-0+ + rc = platform_device_add_data(ghes_dev, &hest_hdr, sizeof(void *)); + if (rc) + goto err;Now you put the address of that local variable in some global data structure.
And then you likely return and later the access accesses random stack space?
platform_device_add_data will allocate some new memory, and copy hest_hdr to there, so this is safe.
Best Regards,
Huang Ying
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 4/5 ACPI, APEI, Fix error path for memory allocation
In reply to Huang YingIn ERST debug/test support patch, a dynamic allocated buffer is used. The may-failed memory allocation should be tried firstly before free the previous buffer.
APEI resource management memory allocation related error path is fixed too.
--- drivers/acpi/apei/apei-base.c | 25 ++++++++++++++++++++----- drivers/acpi/apei/erst-dbg.c | 16 ++++++++++------ 2 files changed, 30 insertions(+), 11 deletions(-)
drivers/acpi/apei/apei-base.c +20 -5
@@ -445,11 +445,15 @@ EXPORT_SYMBOL_GPL(apei_resources_sub);int apei_resources_request (struct apei_resources *resources,const char *desc) { -struct apei_res *res, *res_bak; +struct apei_res *res, *res_bak =NULL ;struct resource *r; +int rc; -apei_resources_sub (resources, &apei_resources_all); + rc =apei_resources_sub (resources, &apei_resources_all); +if (rc) +return rc; + rc = -EINVAL ;list_for_each_entry (res, &resources->iomem, list) { r =request_mem_region (res->start, res->end - res->start, desc);
@@ -475,7 +479,13 @@ int apei_resources_request(struct apei_resources *resources, } } -apei_resources_merge (&apei_resources_all, resources); + rc =apei_resources_merge (&apei_resources_all, resources); +if (rc) { +pr_err (APEI_PFX +"Error in APEI internal resource management, there may be inconsistent " +"between APEI internal and system resource management." ); + goto err_unmap_ioport; + }return 0 ; err_unmap_ioport:
@@ -491,12 +501,13 @@ err_unmap_iomem:break ;release_mem_region (res->start, res->end - res->start); } -return -EINVAL ; +return rc; }EXPORT_SYMBOL_GPL (apei_resources_request);void apei_resources_release (struct apei_resources *resources) { +int rc;struct apei_res *res;list_for_each_entry (res, &resources->iomem, list)
@@ -504,7 +515,11 @@ void apei_resources_release(struct apei_resources *resources)list_for_each_entry (res, &resources->ioport, list)release_region (res->start, res->end - res->start); -apei_resources_sub (&apei_resources_all, resources); + rc =apei_resources_sub (&apei_resources_all, resources); +if (rc) +pr_err (APEI_PFX +"Error in APEI internal resource management, there may be inconsistent " +"between APEI internal and system resource management." ); }EXPORT_SYMBOL_GPL (apei_resources_release);
drivers/acpi/apei/erst-dbg.c +10 -6
@@ -111,11 +111,13 @@ retry: goto out; }if (len > erst_dbg_buf_len) { -kfree (erst_dbg_buf); +void *p; rc = -ENOMEM ; - erst_dbg_buf =kmalloc (len,GFP_KERNEL ); -if (!erst_dbg_buf) + p =kmalloc (len,GFP_KERNEL ); +if (!p) goto out; +kfree (erst_dbg_buf); + erst_dbg_buf = p; erst_dbg_buf_len = len; goto retry; }
@@ -150,11 +152,13 @@ static ssize_t erst_dbg_write(struct file *filp, const char __user *ubuf,if (mutex_lock_interruptible (&erst_dbg_mutex))return -EINTR ;if (usize > erst_dbg_buf_len) { -kfree (erst_dbg_buf); +void *p; rc = -ENOMEM ; - erst_dbg_buf =kmalloc (usize,GFP_KERNEL ); -if (!erst_dbg_buf) + p =kmalloc (usize,GFP_KERNEL ); +if (!p) goto out; +kfree (erst_dbg_buf); + erst_dbg_buf = p; erst_dbg_buf_len = usize; } rc =copy_from_user (erst_dbg_buf, ubuf, usize);
Signature · 1 line
1.7.1
Re: [PATCH 4/5] ACPI, APEI, Fix error path for memory allocation
drivers/acpi/apei/apei-base.c int apei_resources_request(struct apei_resources *resources, · line 486
Quoted 10 lines · Huang Ying
drivers/acpi/apei/apei-base.c +5
-1@@ -475,7 +479,13 @@ int apei_resources_request(struct apei_resources *resources, } } -apei_resources_merge (&apei_resources_all, resources); + rc =apei_resources_merge (&apei_resources_all, resources); +if (rc) { +pr_err (APEI_PFX +"Error in APEI internal resource management, there may be inconsistent " +"between APEI internal and system resource management." );
Please fix the English. This will wrap in the syslog without \ns no? Kernel messges should be not wider than 80 characters.
drivers/acpi/apei/apei-base.c void apei_resources_release(struct apei_resources *resources) · line 522
Quoted 5 lines
drivers/acpi/apei/apei-base.c +5
-0+ rc =apei_resources_sub (&apei_resources_all, resources); +if (rc) +pr_err (APEI_PFX +"Error in APEI internal resource management, there may be inconsistent " +"between APEI internal and system resource management." );
Same.
Also instead of Error it would be better just say what is wrong and don't try to analyze the problem.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Re: [PATCH 4/5] ACPI, APEI, Fix error path for memory allocation
Hi, Andi,
Quoted 21 lines · Andi Kleen
drivers/acpi/apei/apei-base.c int apei_resources_request(struct apei_resources *resources, · line 486
Quoted 10 lines · Huang Ying
drivers/acpi/apei/apei-base.c +5
-1@@ -475,7 +479,13 @@ int apei_resources_request(struct apei_resources *resources, } } - apei_resources_merge(&apei_resources_all, resources); + rc = apei_resources_merge(&apei_resources_all, resources); + if (rc) { + pr_err(APEI_PFX +"Error in APEI internal resource management, there may be inconsistent " +"between APEI internal and system resource management." );Please fix the English. This will wrap in the syslog without \ns no? Kernel messges should be not wider than 80 characters.
drivers/acpi/apei/apei-base.c void apei_resources_release(struct apei_resources *resources) · line 522
Quoted 5 lines
drivers/acpi/apei/apei-base.c +5
-0+ rc = apei_resources_sub(&apei_resources_all, resources); + if (rc) + pr_err(APEI_PFX +"Error in APEI internal resource management, there may be inconsistent " +"between APEI internal and system resource management." );
Quoted 4 lines
Same.
Also instead of Error it would be better just say what is wrong and don't try to analyze the problem.
OK, I will do it.
Best Regards,
Huang Ying
PATCH 5/5 ACPI, APEI, Fix ERST MOVE_DATA instruction implementation
In reply to Huang YingThe src_base and dst_base fields in apei_exec_context are physical address, so they should be ioremaped before being used in ERST MOVE_DATA instruction.
--- drivers/acpi/apei/erst.c | 20 +++++++++++++++++--- 1 files changed, 17 insertions(+), 3 deletions(-)
drivers/acpi/apei/erst.c +17 -3
@@ -266,13 +266,27 @@ static int erst_exec_move_data(struct apei_exec_context *ctx, {int rc;u64 offset; +void *src, *dst; + +/* ioremap does not work in interrupt context */ +if (in_interrupt ()) +return -EBUSY ; rc =__apei_exec_read_register (entry, &offset);if (rc)return rc; -memmove ((void *)ctx->dst_base + offset, - (void *)ctx->src_base + offset, - ctx->var2); + + src =ioremap (ctx->src_base + offset, ctx->var2); +if (!src) +return -ENOMEM ; + dst =ioremap (ctx->dst_base + offset, ctx->var2); +if (!dst) +return -ENOMEM ; + +memmove (dst, src, ctx->var2); + +iounmap (src); +iounmap (dst);return 0 ; }
Signature · 1 line
1.7.1
Re: [PATCH 5/5] ACPI, APEI, Fix ERST MOVE_DATA instruction implementation
drivers/acpi/apei/erst.c static int erst_exec_move_data(struct apei_exec_context *ctx, · line 273
Quoted 13 lines · Huang Ying
drivers/acpi/apei/erst.c +5
-0@@ -266,13 +266,27 @@ static int erst_exec_move_data(struct apei_exec_context *ctx, {int rc;u64 offset; +void *src, *dst; + +/* ioremap does not work in interrupt context */ +if (in_interrupt ()) +return -EBUSY ;
That breaks serialization of machine checks no? If the BIOS uses MOVE_DATA How about using kmap_atomic instead?
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Re: [PATCH 5/5] ACPI, APEI, Fix ERST MOVE_DATA instruction implementation
Hi,
Quoted 17 lines · Andi Kleen
drivers/acpi/apei/erst.c static int erst_exec_move_data(struct apei_exec_context *ctx, · line 273
Quoted 13 lines · Huang Ying
drivers/acpi/apei/erst.c +5
-0@@ -266,13 +266,27 @@ static int erst_exec_move_data(struct apei_exec_context *ctx, { int rc; u64 offset; + void *src, *dst; + + /* ioremap does not work in interrupt context */ + if (in_interrupt()) + return -EBUSY;That breaks serialization of machine checks no? If the BIOS uses
MOVE_DATAHow about usingkmap_atomicinstead?
In my test machine, MOVE_DATA is not used. So this does not breaks serialization of machine checks.
We can not use kmap_atomic or kmap_atomic_pfn here. Because kmap_atomic_xxx needs struct page, but the address provided by BIOS may be in E820_RESERVED area, that is, the corresponding page may have no struct page. Maybe we need another kmap_atomic implementation for E820_RESERVED area.
Best Regards,
Huang Ying
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 5/5] ACPI, APEI, Fix ERST MOVE_DATA instruction implementation
Quoted 2 lines
In my test machine,
MOVE_DATAis not used. So this does not breaks serialization of machine checks.
Ok. But we don't know what other systems are doing.
Quoted 6 lines
We can not use
kmap_atomicorkmap_atomic_pfnhere. Becausekmap_atomic_xxxneeds struct page, but the address provided by BIOS may be inE820_RESERVEDarea, that is, the corresponding page may have no struct page. Maybe we need anotherkmap_atomicimplementation forE820_RESERVEDarea.
Yes, at some point that may be needed.
It would be good to have some kind of warning that gets reported back to us when this happens. This should happen on panicing situations anyways, so we can printk.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.