tpm: tpm_crb: Add an AMD fTPM support feature
Subsystems (3)
PATCH 1/1 tpm: tpm_crb: Add an AMD fTPM support feature
I'm Seunghun Han and work at the Affiliated Institute of ETRI. I got an AMD system which had a Ryzen Threadripper 1950X and MSI mainboard, and I had a problem with AMD's fTPM. My machine showed an error message below, and the fTPM didn't work because of it.
[ 5.732084] tpm_crb MSFT0101:00: can't request region for resource
[mem 0x79b4f000-0x79b4ffff]
[ 5.732089] tpm_crb: probe of MSFT0101:00 failed with error -16When I saw the iomem areas and found two TPM CRB regions were in the ACPI NVS area. The iomem regions are below.
79a39000-79b6afff : ACPI Non-volatile Storage
79b4b000-79b4bfff : MSFT0101:00
79b4f000-79b4ffff : MSFT0101:00
After analyzing this issue, I found out that a busy bit was set to the ACPI NVS area, and the current Linux kernel allowed nothing to be assigned in it. I also found that the kernel couldn't calculate the sizes of command and response buffers correctly when the TPM regions were two or more.
To support AMD's fTPM, I removed the busy bit from the ACPI NVS area so that AMD's fTPM regions could be assigned in it. I also fixed the bug that did not calculate the sizes of command and response buffer correctly.
--- arch/x86/kernel/e820.c | 2 +- drivers/char/tpm/tpm_crb.c | 50 ++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 17 deletions(-)
arch/x86/kernel/e820.c +1 -1
@@ -1085,11 +1085,11 @@ static bool __init do_mark_busy(enum e820_type type, struct resource *res)case E820_TYPE_RESERVED :case E820_TYPE_PRAM :case E820_TYPE_PMEM : +case E820_TYPE_NVS :return false;case E820_TYPE_RESERVED_KERN :case E820_TYPE_RAM :case E820_TYPE_ACPI : -case E820_TYPE_NVS :case E820_TYPE_UNUSABLE :default :return true;
drivers/char/tpm/tpm_crb.c +34 -16
103 lines not on this page · raw message
Signature · 1 line
2.21.0
Quoted 21 lines · Seunghun Han
I'm Seunghun Han and work at the Affiliated Institute of ETRI. I got an AMD system which had a Ryzen Threadripper 1950X and MSI mainboard, and I had a problem with AMD's fTPM. My machine showed an error message below, and the fTPM didn't work because of it.
[ 5.732084] tpm_crb MSFT0101:00: can't request region for resource [mem 0x79b4f000-0x79b4ffff] [ 5.732089] tpm_crb: probe of MSFT0101:00 failed with error -16When I saw the iomem areas and found two TPM CRB regions were in the ACPI NVS area. The iomem regions are below.
79a39000-79b6afff : ACPI Non-volatile Storage
79b4b000-79b4bfff : MSFT0101:00
79b4f000-79b4ffff : MSFT0101:00After analyzing this issue, I found out that a busy bit was set to the ACPI NVS area, and the current Linux kernel allowed nothing to be assigned in it. I also found that the kernel couldn't calculate the sizes of command and response buffers correctly when the TPM regions were two or more.
Quoted 5 lines
To support AMD's fTPM, I removed the busy bit from the ACPI NVS area so that AMD's fTPM regions could be assigned in it. I also fixed the bug that did not calculate the sizes of command and response buffer correctly.
Signed-off-by Seunghun Han <[email protected]>
You need to split this into multiple patches e.g. if you think you've fixed a bug, please write a patch with just the bug fix and nothing else.
For further information, read the section three of
https://www.kernel.org/doc/html/latest/process/submitting-patches.html
I'd also recommend to check out the earlier discussion on ACPI NVS:
/Jarkko
Quoted 35 lines · Seunghun Han
Quoted 21 lines
I'm Seunghun Han and work at the Affiliated Institute of ETRI. I got an AMD system which had a Ryzen Threadripper 1950X and MSI mainboard, and I had a problem with AMD's fTPM. My machine showed an error message below, and the fTPM didn't work because of it.
[ 5.732084] tpm_crb MSFT0101:00: can't request region for resource [mem 0x79b4f000-0x79b4ffff] [ 5.732089] tpm_crb: probe of MSFT0101:00 failed with error -16When I saw the iomem areas and found two TPM CRB regions were in the ACPI NVS area. The iomem regions are below.
79a39000-79b6afff : ACPI Non-volatile Storage
79b4b000-79b4bfff : MSFT0101:00
79b4f000-79b4ffff : MSFT0101:00After analyzing this issue, I found out that a busy bit was set to the ACPI NVS area, and the current Linux kernel allowed nothing to be assigned in it. I also found that the kernel couldn't calculate the sizes of command and response buffers correctly when the TPM regions were two or more.
Quoted 5 lines
To support AMD's fTPM, I removed the busy bit from the ACPI NVS area so that AMD's fTPM regions could be assigned in it. I also fixed the bug that did not calculate the sizes of command and response buffer correctly.
Signed-off-by Seunghun Han <[email protected]>You need to split this into multiple patches e.g. if you think you've fixed a bug, please write a patch with just the bug fix and nothing else.
For further information, read the section three of
Quoted 7 lines
https://www.kernel.org/doc/html/latest/process/submitting-patches.html
I'd also recommend to check out the earlier discussion on ACPI NVS:
/Jarkko
Thank you for your advice. I have made two separated patches on your advice. Please check these patches, https://lkml.org/lkml/2019/8/26/125 and
https://lkml.org/lkml/2019/8/26/163.
In my opinion, the last link you gave me had two problems with AMD's fTPM. One problem was the ACPI NVS area was set to the busy area, and TPM regions of the ACPI table were in it. Therefore, TPM CRB driver couldn't allocate command and response buffers in it because ACPI NVS area was busy. The other problem was buffer size calculation bugs. Because of it, TPM CRB driver requested larger than the size ACPI table described. So, TPM CRB driver also couldn't map command and response buffers even though the reserved area was not busy.
It seems that my separated patches could handle those two problems and enable AMD's fTPM in any case.
Seunghun
PATCH 1/1 tpm: tpm_crb: Add an AMD fTPM support feature
In reply to Jarkko SakkinenQuoted 30 lines
From: [email protected] <linux-integrity- [email protected]> On Behalf Of Jarkko Sakkinen
Sent: Monday, August 26, 2019 1:59 AM
To: Seunghun Han <[email protected]>
Cc: Peter Huewe <[email protected]>; Thomas Gleixner <[email protected]>; [email protected]; linux- [email protected]
Subject: EXT: Re: [PATCH] tpm:tpm_crb: Add an AMD fTPM support featureQuoted 12 lines · Seunghun Han
I'm Seunghun Han and work at the Affiliated Institute of ETRI. I got an AMD system which had a Ryzen Threadripper 1950X and MSI mainboard, and I had a problem with AMD's fTPM. My machine showed an error message below, and the fTPM didn't work because of it.
[ 5.732084] tpm_crb MSFT0101:00: can't request region for resource [mem 0x79b4f000-0x79b4ffff] [ 5.732089] tpm_crb: probe of MSFT0101:00 failed with error -16When I saw the iomem areas and found two TPM CRB regions were in the ACPI NVS area. The iomem regions are below.
Quoted 8 lines
79a39000-79b6afff : ACPI Non-volatile Storage
79b4b000-79b4bfff : MSFT0101:00
79b4f000-79b4ffff : MSFT0101:00After analyzing this issue, I found out that a busy bit was set to the ACPI NVS area, and the current Linux kernel allowed nothing to be assigned in it. I also found that the kernel couldn't calculate the sizes of command and response buffers correctly when the TPM regions
Quoted 6 lines
were two or more.
Quoted 4 lines
To support AMD's fTPM, I removed the busy bit from the ACPI NVS area so that AMD's fTPM regions could be assigned in it. I also fixed the bug that did not calculate the sizes of command and response buffer
correctly.
The problem is that the acpi tables are _wrong_ in this and other cases. They not only incorrectly report the area as reserved, but also report the command and response buffer sizes incorrectly. If you look at the addresses for the buffers listed in the crb control area, the sizes are correct (4Kbytes). My patch uses the control area values, and everything works. The remaining problem is that if acpi reports the area as NVS, then the linux nvs driver will try to use the space. I'm looking at how to fix that. I'm not sure, if simply removing the busy bit is sufficient.
Dave
Quoted 17 lines
Quoted 2 lines
Signed-off-by Seunghun Han <[email protected]>You need to split this into multiple patches e.g. if you think you've fixed a bug, please write a patch with just the bug fix and nothing else.
For further information, read the section three of
https://www.kernel.org/doc/html/latest/process/submitting-patches.html
I'd also recommend to check out the earlier discussion on ACPI NVS:
https://lore.kernel.org/linux-
integrity/[email protected] 2k.ad.ge.com//Jarkko
Quoted 37 lines
Quoted 30 lines
From: [email protected] <linux-integrity- [email protected]> On Behalf Of Jarkko Sakkinen
Sent: Monday, August 26, 2019 1:59 AM
To: Seunghun Han <[email protected]>
Cc: Peter Huewe <[email protected]>; Thomas Gleixner <[email protected]>; [email protected]; linux- [email protected]
Subject: EXT: Re: [PATCH] tpm:tpm_crb: Add an AMD fTPM support featureQuoted 12 lines · Seunghun Han
I'm Seunghun Han and work at the Affiliated Institute of ETRI. I got an AMD system which had a Ryzen Threadripper 1950X and MSI mainboard, and I had a problem with AMD's fTPM. My machine showed an error message below, and the fTPM didn't work because of it.
[ 5.732084] tpm_crb MSFT0101:00: can't request region for resource [mem 0x79b4f000-0x79b4ffff] [ 5.732089] tpm_crb: probe of MSFT0101:00 failed with error -16When I saw the iomem areas and found two TPM CRB regions were in the ACPI NVS area. The iomem regions are below.
Quoted 8 lines
79a39000-79b6afff : ACPI Non-volatile Storage
79b4b000-79b4bfff : MSFT0101:00
79b4f000-79b4ffff : MSFT0101:00After analyzing this issue, I found out that a busy bit was set to the ACPI NVS area, and the current Linux kernel allowed nothing to be assigned in it. I also found that the kernel couldn't calculate the sizes of command and response buffers correctly when the TPM regions
Quoted 6 lines
were two or more.
Quoted 4 lines
To support AMD's fTPM, I removed the busy bit from the ACPI NVS area so that AMD's fTPM regions could be assigned in it. I also fixed the bug that did not calculate the sizes of command and response buffer
correctly.
Quoted 10 lines
The problem is that the acpi tables are _wrong_ in this and other cases. They not only incorrectly report the area as reserved, but also report the command and response buffer sizes incorrectly. If you look at the addresses for the buffers listed in the crb control area, the sizes are correct (4Kbytes). My patch uses the control area values, and everything works. The remaining problem is that if acpi reports the area as NVS, then the linux nvs driver will try to use the space. I'm looking at how to fix that. I'm not sure, if simply removing the busy bit is sufficient.
Dave
Thank you for your reply. I have read your patch. However, I would like to solve this problem without a kernel parameter. In my view, I'd better change the crb_fixup_cmd_size() function because the TPM CRB driver wants to get the command buffer and response buffer sizes by using the function.
I agree on that removing the busy bit is sufficient.
Seunghun
Quoted 18 lines
Quoted 18 lines
Quoted 3 lines
Signed-off-by Seunghun Han <[email protected]>You need to split this into multiple patches e.g. if you think you've fixed a bug, please write a patch with just the bug fix and nothing else.
For further information, read the section three of
https://www.kernel.org/doc/html/latest/process/submitting-patches.html
I'd also recommend to check out the earlier discussion on ACPI NVS:
https://lore.kernel.org/linux-
integrity/[email protected] 2k.ad.ge.com//Jarkko