linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Safford, David (GE Global Research, US)" <david.safford@ge.com>
To: "linux-integrity@vger.kernel.org"
	<linux-integrity@vger.kernel.org>,
	"jarkko.sakkinen@linux.intel.com"
	<jarkko.sakkinen@linux.intel.com>,
	"Wiseman, Monty (GE Global Research, US)" <monty.wiseman@ge.com>
Subject: [PATCH] tpm_crb - workaround broken ACPI tables
Date: Thu, 11 Jul 2019 12:29:30 +0000	[thread overview]
Message-ID: <BCA04D5D9A3B764C9B7405BBA4D4A3C035EF7BC7@ALPMBAPA12.e2k.ad.ge.com> (raw)

Most x86 desktops and laptops have firmware TPMs which support the
CRB interface. Unfortunately, the linux tpm_crb driver depends on
perfectly correct ACPI tables, and there are a *lot* of systems out
there with broken tpm_crb entries. (Not one of my five tpm_crb
systems works with the existing driver.) While it is good to
encourage vendors to fix their firmware, many refuse ("It works on
Windows"), leaving users in the lurch.

This patch adds a kernel parameter "tpm_crb.force=1" that works
around the problem in every case I have tested so far. Basically
it does two things:
	- it trusts the cmd and resp addresses in the CRB registers
	- it ignores all alleged IO resource conflicts

Both workarounds make sense. If there really were an address conflict,
or if the register values really were wrong, the device would not be
working at all. And testing with this patch has shown that in every
case (so far), the problem has been bogus ACPI entries.

This patch is against the upstream 5.2 kernel.

Signed-off-by: David Safford <david.safford@ge.com>

--- a/drivers/char/tpm/tpm_crb.c	2019-07-07 18:41:56.000000000 -0400
+++ b/drivers/char/tpm/tpm_crb.c	2019-07-10 11:12:37.269766833 -0400
@@ -108,6 +108,12 @@
 	u32 smc_func_id;
 };
 
+static bool force;
+#ifdef CONFIG_X86
+module_param(force, bool, 0444);
+MODULE_PARM_DESC(force, "Force register provided mappings to overcome broken acpi tables");
+#endif
+
 static bool crb_wait_for_reg_32(u32 __iomem *reg, u32 mask, u32 value,
 				unsigned long timeout)
 {
@@ -460,9 +466,12 @@
 	if (start != new_res.start)
 		return (void __iomem *) ERR_PTR(-EINVAL);
 
-	if (!resource_contains(io_res, &new_res))
-		return devm_ioremap_resource(dev, &new_res);
-
+	if (!resource_contains(io_res, &new_res)){
+		if (force)
+			return ioremap(start, size);
+		else
+			return devm_ioremap_resource(dev, &new_res);
+	}
 	return priv->iobase + (new_res.start - io_res->start);
 }
 
@@ -480,6 +489,11 @@
 	if (start + size - 1 <= io_res->end)
 		return size;
 
+	if (force) {
+		dev_err(dev, FW_BUG "ACPI cmd size broken. Using %llX\n", size);
+		return size;
+	}
+
 	dev_err(dev,
 		FW_BUG "ACPI region does not cover the entire command/response buffer. %pr vs %llx %llx\n",
 		io_res, start, size);
@@ -512,8 +526,11 @@
 		dev_err(dev, FW_BUG "TPM2 ACPI table does not define a memory resource\n");
 		return -EINVAL;
 	}
+	if (force)
+		priv->iobase = ioremap(io_res.start, io_res.end - io_res.start + 1);
+	else
+		priv->iobase = devm_ioremap_resource(dev, &io_res);
 
-	priv->iobase = devm_ioremap_resource(dev, &io_res);
 	if (IS_ERR(priv->iobase))
 		return PTR_ERR(priv->iobase);


             reply	other threads:[~2019-07-11 14:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-11 12:29 Safford, David (GE Global Research, US) [this message]
2019-07-11 14:10 ` [PATCH] tpm_crb - workaround broken ACPI tables Jarkko Sakkinen
2019-07-11 14:58 ` Jason Gunthorpe
2019-07-11 16:44   ` Safford, David (GE Global Research, US)
2019-07-11 18:50     ` Jason Gunthorpe
2019-07-11 19:31       ` Safford, David (GE Global Research, US)
2019-07-11 20:33         ` Matthew Garrett
2019-07-12 12:41           ` Safford, David (GE Global Research, US)
2019-07-12 15:06             ` Jason Gunthorpe
2019-07-12 15:48               ` Jarkko Sakkinen
2019-07-12 18:24             ` Matthew Garrett
2019-07-12 19:05               ` Safford, David (GE Global Research, US)
2019-07-12 20:36                 ` Matthew Garrett
2019-07-14 19:28                   ` Safford, David (GE Global Research, US)
2019-07-14 23:48                     ` Matthew Garrett
2019-07-15 19:44                       ` Matthew Garrett
2019-07-11 19:16 ` Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BCA04D5D9A3B764C9B7405BBA4D4A3C035EF7BC7@ALPMBAPA12.e2k.ad.ge.com \
    --to=david.safford@ge.com \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=linux-integrity@vger.kernel.org \
    --cc=monty.wiseman@ge.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).