diff mbox

174cc7187e6f ACPICA: Tables: Back port acpi_get_table_with_size() and early_acpi_os_unmap_memory() from Linux kernel

Message ID CAJZ5v0idFBHG=OKRiBqvsYPgUrWQsqjTKYXfKxfdG023qsCbkw@mail.gmail.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Rafael J. Wysocki Jan. 8, 2017, 2:20 a.m. UTC
On Sun, Jan 8, 2017 at 2:45 AM, Rafael J. Wysocki <rafael@kernel.org> wrote:
> On Sun, Jan 8, 2017 at 2:01 AM, Borislav Petkov <bp@alien8.de> wrote:
>> On Sun, Jan 08, 2017 at 01:52:50AM +0100, Rafael J. Wysocki wrote:
>>> So we get the table, but apparently we crash when we attempt to put it.
>>
>> Right, except on 4.10-rc2 we don't crash but we freeze early. These are
>> the last lines:
>>
>> ...
>> [    0.004778] mce: CPU supports 7 MCE banks
>> [    0.004861] LVT offset 1 assigned for vector 0xf9
>> [    0.004945] Last level iTLB entries: 4KB 512, 2MB 1024, 4MB 512
>> [    0.005025] Last level dTLB entries: 4KB 1024, 2MB 1024, 4MB 512, 1GB 0
>> [    0.005165] Freeing SMP alternatives memory: 24K
>> [    0.211154] ftrace: allocating 25022 entries in 98 pages
>> [    0.219614] smpboot: Max logical packages: 2
>> <EOF>
>>
>>> Let's try to check the obvious just to rule it out (see attached), but
>>> honestly I'm not sure what's going on in there.
>>
>> No change, same freeze.
>
> I was afraid that that would be the case.
>
> Can you try to comment out the acpi_put_table() in
> early_amd_iommu_init() and see if that makes any difference?

Well, there is a bug in early_amd_iommu_init() that may matter in
theory if the table checksum is incorrect.

Please see if the attached makes any difference.

Thanks,
Rafael

Comments

Borislav Petkov Jan. 8, 2017, 1:03 p.m. UTC | #1
On Sun, Jan 08, 2017 at 03:20:20AM +0100, Rafael J. Wysocki wrote:
>  drivers/iommu/amd_iommu_init.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Index: linux-pm/drivers/iommu/amd_iommu_init.c
> ===================================================================
> --- linux-pm.orig/drivers/iommu/amd_iommu_init.c
> +++ linux-pm/drivers/iommu/amd_iommu_init.c
> @@ -2230,7 +2230,7 @@ static int __init early_amd_iommu_init(v
>  	 */
>  	ret = check_ivrs_checksum(ivrs_base);
>  	if (ret)
> -		return ret;
> +		goto out;
>  
>  	amd_iommu_target_ivhd_type = get_highest_supported_ivhd_type(ivrs_base);
>  	DUMP_printk("Using IVHD type %#x\n", amd_iommu_target_ivhd_type);

Good catch, this one needs to be applied regardless.

However, it doesn't fix my issue though.

But I think I have it - I went and applied the well-proven debugging
technique of sprinkling printks around. Here's what I'm seeing:

early_amd_iommu_init()
|-> acpi_put_table(ivrs_base);
|-> acpi_tb_put_table(table_desc);
|-> acpi_tb_invalidate_table(table_desc);
|-> acpi_tb_release_table(...)
|-> acpi_os_unmap_memory
|-> acpi_os_unmap_iomem
|-> acpi_os_map_cleanup
|-> synchronize_rcu_expedited	<-- the kernel/rcu/tree_exp.h version with CONFIG_PREEMPT_RCU=y

Now that function goes and sends IPIs, i.e., schedule_work()
but this is too early - we haven't even done workqueue_init().
Actually, from looking at the callstack, we do
kernel_init_freeable->native_smp_prepare_cpus() and workqueue_init()
comes next.

And this makes sense because the splat rIP points to __queue_work() but
we haven't done that yet.

So that acpi_put_table() is happening too early. Looks like AMD IOMMU
should not put the table but WTH do I know?!

In any case, commenting out:

        acpi_put_table(ivrs_base);
        ivrs_base = NULL;

and the end of early_amd_iommu_init() makes the box boot again.
Lv Zheng Jan. 9, 2017, 1:58 a.m. UTC | #2
SGksDQoNCj4gRnJvbTogbGludXgtYWNwaS1vd25lckB2Z2VyLmtlcm5lbC5vcmcgW21haWx0bzps
aW51eC1hY3BpLW93bmVyQHZnZXIua2VybmVsLm9yZ10gT24gQmVoYWxmIE9mIEJvcmlzbGF2DQo+
IFBldGtvdg0KPiBTdWJqZWN0OiBSZTogMTc0Y2M3MTg3ZTZmIEFDUElDQTogVGFibGVzOiBCYWNr
IHBvcnQgYWNwaV9nZXRfdGFibGVfd2l0aF9z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Y2VzIGZvciA0MDA6
IGF2b2lkIHRvcC1wb3N0aW5nIGFuZCB0cmltIHRoZSByZXBseS4NCj4gLS0NCj4gVG8gdW5zdWJz
Y3JpYmUgZnJvbSB0aGlzIGxpc3Q6IHNlbmQgdGhlIGxpbmUgInVuc3Vic2NyaWJlIGxpbnV4LWFj
cGkiIGluDQo+IHRoZSBib2R5IG9mIGEgbWVzc2FnZSB0byBtYWpvcmRvbW9Admdlci5rZXJuZWwu
b3JnDQo+IE1vcmUgbWFqb3Jkb21vIGluZm8gYXQgIGh0dHA6Ly92Z2VyLmtlcm5lbC5vcmcvbWFq
b3Jkb21vLWluZm8uaHRtbA0K
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Lv Zheng Jan. 9, 2017, 2:36 a.m. UTC | #3
SGksDQoNCj4gRnJvbTogbGludXgtYWNwaS1vd25lckB2Z2VyLmtlcm5lbC5vcmcgW21haWx0bzps
aW51eC1hY3BpLW93bmVyQHZnZXIua2VybmVsLm9yZ10gT24gQmVoYWxmIE9mIFpoZW5nLA0KPiBM
dg0KPiBTdWJqZWN0OiBSRTogMTc0Y2M3MTg3ZTZmIEFDUElDQTogVGFibGVzOiBCYWNrIHBvcnQg
YWNwaV9nZXRfdGFibGVfd2l0aF9zaXplKCkgYW5kDQo+IGVhcmx5X2FjcGlfb3NfdW5tYXBfbWVt
b3J5KCkgZnJvbSBMaW51eCBrZXJuZWwNCj4gDQo+IEhpLA0KPiANCj4gPiBGcm9tOiBsaW51eC1h
Y3BpLW93bmVyQHZnZXIua2VybmVsLm9yZyBbbWFpbHRvOmxpbnV4LWFjcGktb3duZXJAdmdlci5r
ZXJuZWwub3JnXSBPbiBCZWhhbGYgT2YNCj4gQm9yaXNsYXYNCj4gPiBQZXRrb3YNCj4gPiBTdWJq
ZWN0OiBSZTogMTc0Y2M3MTg3ZTZmIEFDUElDQTogVGFibGVzOiBCYWNr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SBzdWNoIGFuIGVhcmx5IGNhc2UuDQoNCklNTywgc3luY2hyb25pemVfcmN1
X2V4cGVkaXRlZCgpIHNob3VsZCBiZSBpbXByb3ZlZDoNCklmIHJjdV9pbml0KCkgaXNuJ3QgY2Fs
bGVkIG9yIHRoZXJlIGlzIG5vdGhpbmcgdG8gc3luY2hyb25pemUsIHNjaGVkdWxlX3dvcmsoKSBz
aG91bGRuJ3QgYmUgaW52b2tlZC4NCg0KVGhhbmtzIGFuZCBiZXN0IHJlZ2FyZHMNCkx2DQoNCj4g
DQo+IFRoYW5rcyBhbmQgYmVzdCByZWdhcmRzDQo+IEx2DQo+IA0KPiA+DQo+ID4gLS0NCj4gPiBS
ZWdhcmRzL0dydXNzLA0KPiA+ICAgICBCb3Jpcy4NCj4gPg0KPiA+IEdvb2QgbWFpbGluZyBwcmFj
dGljZXMgZm9yIDQwMDogYXZvaWQgdG9wLXBvc3RpbmcgYW5kIHRyaW0gdGhlIHJlcGx5Lg0K
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Lv Zheng Jan. 9, 2017, 5:21 a.m. UTC | #4
Hi, Borislav

> From: Zheng, Lv

> Subject: RE: 174cc7187e6f ACPICA: Tables: Back port acpi_get_table_with_size() and

> early_acpi_os_unmap_memory() from Linux kernel

> 

> Hi,

> 

> > From: linux-acpi-owner@vger.kernel.org [mailto:linux-acpi-owner@vger.kernel.org] On Behalf Of Zheng,

> > Lv

> > Subject: RE: 174cc7187e6f ACPICA: Tables: Back port acpi_get_table_with_size() and

> > early_acpi_os_unmap_memory() from Linux kernel

> >

> > Hi,

> >

> > > From: linux-acpi-owner@vger.kernel.org [mailto:linux-acpi-owner@vger.kernel.org] On Behalf Of

> > Borislav

> > > Petkov

> > > Subject: Re: 174cc7187e6f ACPICA: Tables: Back port acpi_get_table_with_size() and

> > > early_acpi_os_unmap_memory() from Linux kernel

> > >

> > > On Sun, Jan 08, 2017 at 03:20:20AM +0100, Rafael J. Wysocki wrote:

> > > >  drivers/iommu/amd_iommu_init.c |    2 +-

> > > >  1 file changed, 1 insertion(+), 1 deletion(-)

> > > >

> > > > Index: linux-pm/drivers/iommu/amd_iommu_init.c

> > > > ===================================================================

> > > > --- linux-pm.orig/drivers/iommu/amd_iommu_init.c

> > > > +++ linux-pm/drivers/iommu/amd_iommu_init.c

> > > > @@ -2230,7 +2230,7 @@ static int __init early_amd_iommu_init(v

> > > >  	 */

> > > >  	ret = check_ivrs_checksum(ivrs_base);

> > > >  	if (ret)

> > > > -		return ret;

> > > > +		goto out;

> > > >

> > > >  	amd_iommu_target_ivhd_type = get_highest_supported_ivhd_type(ivrs_base);

> > > >  	DUMP_printk("Using IVHD type %#x\n", amd_iommu_target_ivhd_type);

> > >

> > > Good catch, this one needs to be applied regardless.

> > >

> > > However, it doesn't fix my issue though.

> > >

> > > But I think I have it - I went and applied the well-proven debugging

> > > technique of sprinkling printks around. Here's what I'm seeing:

> > >

> > > early_amd_iommu_init()

> > > |-> acpi_put_table(ivrs_base);

> > > |-> acpi_tb_put_table(table_desc);

> > > |-> acpi_tb_invalidate_table(table_desc);

> > > |-> acpi_tb_release_table(...)

> > > |-> acpi_os_unmap_memory

> > > |-> acpi_os_unmap_iomem

> > > |-> acpi_os_map_cleanup

> > > |-> synchronize_rcu_expedited	<-- the kernel/rcu/tree_exp.h version with CONFIG_PREEMPT_RCU=y

> > >

> > > Now that function goes and sends IPIs, i.e., schedule_work()

> > > but this is too early - we haven't even done workqueue_init().

> > > Actually, from looking at the callstack, we do

> > > kernel_init_freeable->native_smp_prepare_cpus() and workqueue_init()

> > > comes next.

> > >

> > > And this makes sense because the splat rIP points to __queue_work() but

> > > we haven't done that yet.

> > >

> > > So that acpi_put_table() is happening too early. Looks like AMD IOMMU

> > > should not put the table but WTH do I know?!

> > >

> > > In any case, commenting out:

> > >

> > >         acpi_put_table(ivrs_base);

> > >         ivrs_base = NULL;

> > >

> > > and the end of early_amd_iommu_init() makes the box boot again.

> >

> > So please help to comment out these 2 lines (with descriptions and do not delete them).

> > Until acpi_os_unmap_memory() is able to handle such an early case.

> 

> IMO, synchronize_rcu_expedited() should be improved:

> If rcu_init() isn't called or there is nothing to synchronize, schedule_work() shouldn't be invoked.



Hmm, I think this problem has its history.
In APEI code, NMI handlers cannot utilize spinlock.
So the developers there used RCU to synchronize NMI handlers before the register region is unmapped.
At that time, there might not be pre-map/post-unmap code prepared in the APEI drivers.
So the APEI developers relied on map/unmap logics implemented in the ACPICA register read/write APIs where the OSL map/unmap is invoked.

That's why the RCU code is in acpi_os_xxx().
If:
1. there is map/unmap/read/write operations available for APEI developers to invoke;
2. RCU synchronization is invoked before invoking the last unmap operation;
3. map/unmap/read/write order is strictly ensured inside of the APEI drivers.
Then we can remove RCU stuffs from acpi_os_xxx.
And the root cause of this issue can be fixed.

I'm not sure if this approach is possible, but can give it a try.
Before that I think all such acpi_put_table() should just be commented out.

Thanks and best regards
Lv

> 

> Thanks and best regards

> Lv

> 

> >

> > Thanks and best regards

> > Lv

> >

> > >

> > > --

> > > Regards/Gruss,

> > >     Boris.

> > >

> > > Good mailing practices for 400: avoid top-posting and trim the reply.
Borislav Petkov Jan. 9, 2017, 9:33 a.m. UTC | #5
+ Paul for comment.

Leaving in the rest for him.

On Mon, Jan 09, 2017 at 02:36:33AM +0000, Zheng, Lv wrote:
> Hi,
> 
> > From: linux-acpi-owner@vger.kernel.org [mailto:linux-acpi-owner@vger.kernel.org] On Behalf Of Zheng,
> > Lv
> > Subject: RE: 174cc7187e6f ACPICA: Tables: Back port acpi_get_table_with_size() and
> > early_acpi_os_unmap_memory() from Linux kernel
> > 
> > Hi,
> > 
> > > From: linux-acpi-owner@vger.kernel.org [mailto:linux-acpi-owner@vger.kernel.org] On Behalf Of
> > Borislav
> > > Petkov
> > > Subject: Re: 174cc7187e6f ACPICA: Tables: Back port acpi_get_table_with_size() and
> > > early_acpi_os_unmap_memory() from Linux kernel
> > >
> > > On Sun, Jan 08, 2017 at 03:20:20AM +0100, Rafael J. Wysocki wrote:
> > > >  drivers/iommu/amd_iommu_init.c |    2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > Index: linux-pm/drivers/iommu/amd_iommu_init.c
> > > > ===================================================================
> > > > --- linux-pm.orig/drivers/iommu/amd_iommu_init.c
> > > > +++ linux-pm/drivers/iommu/amd_iommu_init.c
> > > > @@ -2230,7 +2230,7 @@ static int __init early_amd_iommu_init(v
> > > >  	 */
> > > >  	ret = check_ivrs_checksum(ivrs_base);
> > > >  	if (ret)
> > > > -		return ret;
> > > > +		goto out;
> > > >
> > > >  	amd_iommu_target_ivhd_type = get_highest_supported_ivhd_type(ivrs_base);
> > > >  	DUMP_printk("Using IVHD type %#x\n", amd_iommu_target_ivhd_type);
> > >
> > > Good catch, this one needs to be applied regardless.
> > >
> > > However, it doesn't fix my issue though.
> > >
> > > But I think I have it - I went and applied the well-proven debugging
> > > technique of sprinkling printks around. Here's what I'm seeing:
> > >
> > > early_amd_iommu_init()
> > > |-> acpi_put_table(ivrs_base);
> > > |-> acpi_tb_put_table(table_desc);
> > > |-> acpi_tb_invalidate_table(table_desc);
> > > |-> acpi_tb_release_table(...)
> > > |-> acpi_os_unmap_memory
> > > |-> acpi_os_unmap_iomem
> > > |-> acpi_os_map_cleanup
> > > |-> synchronize_rcu_expedited	<-- the kernel/rcu/tree_exp.h version with CONFIG_PREEMPT_RCU=y
> > >
> > > Now that function goes and sends IPIs, i.e., schedule_work()
> > > but this is too early - we haven't even done workqueue_init().
> > > Actually, from looking at the callstack, we do
> > > kernel_init_freeable->native_smp_prepare_cpus() and workqueue_init()
> > > comes next.
> > >
> > > And this makes sense because the splat rIP points to __queue_work() but
> > > we haven't done that yet.
> > >
> > > So that acpi_put_table() is happening too early. Looks like AMD IOMMU
> > > should not put the table but WTH do I know?!
> > >
> > > In any case, commenting out:
> > >
> > >         acpi_put_table(ivrs_base);
> > >         ivrs_base = NULL;
> > >
> > > and the end of early_amd_iommu_init() makes the box boot again.
> > 
> > So please help to comment out these 2 lines (with descriptions and do not delete them).
> > Until acpi_os_unmap_memory() is able to handle such an early case.
> 
> IMO, synchronize_rcu_expedited() should be improved:
> If rcu_init() isn't called or there is nothing to synchronize, schedule_work() shouldn't be invoked.
Joerg Roedel Jan. 9, 2017, 10:52 a.m. UTC | #6
Hi Rafael,

On Sun, Jan 08, 2017 at 03:20:20AM +0100, Rafael J. Wysocki wrote:
> ---
>  drivers/iommu/amd_iommu_init.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Index: linux-pm/drivers/iommu/amd_iommu_init.c
> ===================================================================
> --- linux-pm.orig/drivers/iommu/amd_iommu_init.c
> +++ linux-pm/drivers/iommu/amd_iommu_init.c
> @@ -2230,7 +2230,7 @@ static int __init early_amd_iommu_init(v
>  	 */
>  	ret = check_ivrs_checksum(ivrs_base);
>  	if (ret)
> -		return ret;
> +		goto out;
>  
>  	amd_iommu_target_ivhd_type = get_highest_supported_ivhd_type(ivrs_base);
>  	DUMP_printk("Using IVHD type %#x\n", amd_iommu_target_ivhd_type);

Yeah, good catch. Can you send me a patch for this and I am going to
send the fix upstream asap.


Thanks,

	Joerg

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

---
 drivers/iommu/amd_iommu_init.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-pm/drivers/iommu/amd_iommu_init.c
===================================================================
--- linux-pm.orig/drivers/iommu/amd_iommu_init.c
+++ linux-pm/drivers/iommu/amd_iommu_init.c
@@ -2230,7 +2230,7 @@  static int __init early_amd_iommu_init(v
 	 */
 	ret = check_ivrs_checksum(ivrs_base);
 	if (ret)
-		return ret;
+		goto out;
 
 	amd_iommu_target_ivhd_type = get_highest_supported_ivhd_type(ivrs_base);
 	DUMP_printk("Using IVHD type %#x\n", amd_iommu_target_ivhd_type);