All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tpm, tpm_crb: fix control area resource mapping
@ 2016-01-29  7:13 Jarkko Sakkinen
  2016-01-29 20:48   ` Jason Gunthorpe
  0 siblings, 1 reply; 11+ messages in thread
From: Jarkko Sakkinen @ 2016-01-29  7:13 UTC (permalink / raw)
  To: Peter Huewe; +Cc: tpmdd-devel, linux-kernel, Jarkko Sakkinen

Control area does not always fall in the range of memory resource given
by the ACPI object. This patch fixes the issue by ioremapping the
buffers if this is the case.

Fixes: bb76f9ba49 ("tpm_crb: Use devm_ioremap_resource")
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 drivers/char/tpm/tpm_crb.c | 36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
index 8e46e40..a9688c7 100644
--- a/drivers/char/tpm/tpm_crb.c
+++ b/drivers/char/tpm/tpm_crb.c
@@ -233,27 +233,23 @@ static int crb_check_resource(struct acpi_resource *ares, void *data)
 	return 1;
 }
 
-static void __iomem *crb_access(struct device *dev, struct crb_priv *priv,
-				u64 start, u32 size)
+static void __iomem *crb_map_res(struct device *dev, struct crb_priv *priv,
+				 u64 start, u32 size)
 {
-	struct resource tmp = {};
-
-	tmp.start = start;
-	tmp.end = start + size - 1;
-	tmp.flags = IORESOURCE_MEM;
+	struct resource new_res = {
+		.start	= start,
+		.end	= size - 1,
+		.flags	= IORESOURCE_MEM,
+	};
 
 	/* Detect a 64 bit address on a 32 bit system */
-	if (start != tmp.start)
+	if (start != new_res.start)
 		return ERR_PTR(-EINVAL);
 
-	if (!resource_contains(&priv->res, &tmp)) {
-		dev_err(dev,
-			FW_BUG "TPM2 ACPI sub resource %pR is not in the device's region of %pR\n",
-			&tmp, &priv->res);
-		return ERR_PTR(-EINVAL);
-	}
+	if (!resource_contains(&priv->res, &new_res))
+		return devm_ioremap_resource(dev, &new_res);
 
-	return priv->iobase + (tmp.start - priv->res.start);
+	return priv->iobase + (new_res.start - priv->res.start);
 }
 
 static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
@@ -281,19 +277,19 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
 	if (IS_ERR(priv->iobase))
 		return PTR_ERR(priv->iobase);
 
-	priv->cca = crb_access(dev, priv, buf->control_address, 0x1000);
+	priv->cca = crb_map_res(dev, priv, buf->control_address, 0x1000);
 	if (IS_ERR(priv->cca))
 		return PTR_ERR(priv->cca);
 
-	pa = ((u64)ioread32(&priv->cca->cmd_pa_high) << 32) |
-	     (u64)ioread32(&priv->cca->cmd_pa_low);
-	priv->cmd = crb_access(dev, priv, pa, ioread32(&priv->cca->cmd_size));
+	pa = ((u64) ioread32(&priv->cca->cmd_pa_high) << 32) |
+	      (u64) ioread32(&priv->cca->cmd_pa_low);
+	priv->cmd = crb_map_res(dev, priv, pa, ioread32(&priv->cca->cmd_size));
 	if (IS_ERR(priv->cmd))
 		return PTR_ERR(priv->cmd);
 
 	memcpy_fromio(&pa, &priv->cca->rsp_pa, 8);
 	pa = le64_to_cpu(pa);
-	priv->rsp = crb_access(dev, priv, pa, ioread32(&priv->cca->rsp_size));
+	priv->rsp = crb_map_res(dev, priv, pa, ioread32(&priv->cca->rsp_size));
 	return PTR_ERR_OR_ZERO(priv->rsp);
 }
 
-- 
2.7.0.rc3

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [tpmdd-devel] [PATCH] tpm, tpm_crb: fix control area resource mapping
@ 2016-01-29 20:48   ` Jason Gunthorpe
  0 siblings, 0 replies; 11+ messages in thread
From: Jason Gunthorpe @ 2016-01-29 20:48 UTC (permalink / raw)
  To: Jarkko Sakkinen; +Cc: Peter Huewe, tpmdd-devel, linux-kernel

On Thu, Jan 28, 2016 at 11:13:59PM -0800, Jarkko Sakkinen wrote:

> -	struct resource tmp = {};
> -
> -	tmp.start = start;
> -	tmp.end = start + size - 1;
> -	tmp.flags = IORESOURCE_MEM;
> +	struct resource new_res = {
> +		.start	= start,
> +		.end	= size - 1,

That isn't right.

Jason

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] tpm, tpm_crb: fix control area resource mapping
@ 2016-01-29 20:48   ` Jason Gunthorpe
  0 siblings, 0 replies; 11+ messages in thread
From: Jason Gunthorpe @ 2016-01-29 20:48 UTC (permalink / raw)
  To: Jarkko Sakkinen
  Cc: tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Thu, Jan 28, 2016 at 11:13:59PM -0800, Jarkko Sakkinen wrote:

> -	struct resource tmp = {};
> -
> -	tmp.start = start;
> -	tmp.end = start + size - 1;
> -	tmp.flags = IORESOURCE_MEM;
> +	struct resource new_res = {
> +		.start	= start,
> +		.end	= size - 1,

That isn't right.

Jason

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [tpmdd-devel] [PATCH] tpm, tpm_crb: fix control area resource mapping
@ 2016-01-29 22:21     ` Jarkko Sakkinen
  0 siblings, 0 replies; 11+ messages in thread
From: Jarkko Sakkinen @ 2016-01-29 22:21 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Peter Huewe, tpmdd-devel, linux-kernel

On Fri, Jan 29, 2016 at 01:48:27PM -0700, Jason Gunthorpe wrote:
> On Thu, Jan 28, 2016 at 11:13:59PM -0800, Jarkko Sakkinen wrote:
> 
> > -	struct resource tmp = {};
> > -
> > -	tmp.start = start;
> > -	tmp.end = start + size - 1;
> > -	tmp.flags = IORESOURCE_MEM;
> > +	struct resource new_res = {
> > +		.start	= start,
> > +		.end	= size - 1,
> 
> That isn't right.

Whoops. Good catch, I'll update it before pull request. Thanks!

> Jason

/Jarkko

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] tpm, tpm_crb: fix control area resource mapping
@ 2016-01-29 22:21     ` Jarkko Sakkinen
  0 siblings, 0 replies; 11+ messages in thread
From: Jarkko Sakkinen @ 2016-01-29 22:21 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Fri, Jan 29, 2016 at 01:48:27PM -0700, Jason Gunthorpe wrote:
> On Thu, Jan 28, 2016 at 11:13:59PM -0800, Jarkko Sakkinen wrote:
> 
> > -	struct resource tmp = {};
> > -
> > -	tmp.start = start;
> > -	tmp.end = start + size - 1;
> > -	tmp.flags = IORESOURCE_MEM;
> > +	struct resource new_res = {
> > +		.start	= start,
> > +		.end	= size - 1,
> 
> That isn't right.

Whoops. Good catch, I'll update it before pull request. Thanks!

> Jason

/Jarkko

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [tpmdd-devel] [PATCH] tpm, tpm_crb: fix control area resource mapping
@ 2016-01-29 22:26       ` Jarkko Sakkinen
  0 siblings, 0 replies; 11+ messages in thread
From: Jarkko Sakkinen @ 2016-01-29 22:26 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Peter Huewe, tpmdd-devel, linux-kernel

On Fri, Jan 29, 2016 at 02:21:08PM -0800, Jarkko Sakkinen wrote:
> On Fri, Jan 29, 2016 at 01:48:27PM -0700, Jason Gunthorpe wrote:
> > On Thu, Jan 28, 2016 at 11:13:59PM -0800, Jarkko Sakkinen wrote:
> > 
> > > -	struct resource tmp = {};
> > > -
> > > -	tmp.start = start;
> > > -	tmp.end = start + size - 1;
> > > -	tmp.flags = IORESOURCE_MEM;
> > > +	struct resource new_res = {
> > > +		.start	= start,
> > > +		.end	= size - 1,
> > 
> > That isn't right.
> 
> Whoops. Good catch, I'll update it before pull request. Thanks!

github.com/jsakkine/linux-tpmdd/commit/5012960093774c49d81c612eb32f92cfa1f619bc

struct resource new_res = {
	.start	= start,
	.end	= start + size - 1,
	.flags	= IORESOURCE_MEM,
};

Better?

/Jarkko

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] tpm, tpm_crb: fix control area resource mapping
@ 2016-01-29 22:26       ` Jarkko Sakkinen
  0 siblings, 0 replies; 11+ messages in thread
From: Jarkko Sakkinen @ 2016-01-29 22:26 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Fri, Jan 29, 2016 at 02:21:08PM -0800, Jarkko Sakkinen wrote:
> On Fri, Jan 29, 2016 at 01:48:27PM -0700, Jason Gunthorpe wrote:
> > On Thu, Jan 28, 2016 at 11:13:59PM -0800, Jarkko Sakkinen wrote:
> > 
> > > -	struct resource tmp = {};
> > > -
> > > -	tmp.start = start;
> > > -	tmp.end = start + size - 1;
> > > -	tmp.flags = IORESOURCE_MEM;
> > > +	struct resource new_res = {
> > > +		.start	= start,
> > > +		.end	= size - 1,
> > 
> > That isn't right.
> 
> Whoops. Good catch, I'll update it before pull request. Thanks!

github.com/jsakkine/linux-tpmdd/commit/5012960093774c49d81c612eb32f92cfa1f619bc

struct resource new_res = {
	.start	= start,
	.end	= start + size - 1,
	.flags	= IORESOURCE_MEM,
};

Better?

/Jarkko

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [tpmdd-devel] [PATCH] tpm, tpm_crb: fix control area resource mapping
@ 2016-01-29 22:33         ` Jason Gunthorpe
  0 siblings, 0 replies; 11+ messages in thread
From: Jason Gunthorpe @ 2016-01-29 22:33 UTC (permalink / raw)
  To: Jarkko Sakkinen; +Cc: Peter Huewe, tpmdd-devel, linux-kernel

On Fri, Jan 29, 2016 at 02:26:54PM -0800, Jarkko Sakkinen wrote:
> On Fri, Jan 29, 2016 at 02:21:08PM -0800, Jarkko Sakkinen wrote:
> > On Fri, Jan 29, 2016 at 01:48:27PM -0700, Jason Gunthorpe wrote:
> > > On Thu, Jan 28, 2016 at 11:13:59PM -0800, Jarkko Sakkinen wrote:
> > > 
> > > > -	struct resource tmp = {};
> > > > -
> > > > -	tmp.start = start;
> > > > -	tmp.end = start + size - 1;
> > > > -	tmp.flags = IORESOURCE_MEM;
> > > > +	struct resource new_res = {
> > > > +		.start	= start,
> > > > +		.end	= size - 1,
> > > 
> > > That isn't right.
> > 
> > Whoops. Good catch, I'll update it before pull request. Thanks!
> 
> github.com/jsakkine/linux-tpmdd/commit/5012960093774c49d81c612eb32f92cfa1f619bc
> 
> struct resource new_res = {
> 	.start	= start,
> 	.end	= start + size - 1,
> 	.flags	= IORESOURCE_MEM,
> };
> 
> Better?

Yes that looks ok

Jason

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] tpm, tpm_crb: fix control area resource mapping
@ 2016-01-29 22:33         ` Jason Gunthorpe
  0 siblings, 0 replies; 11+ messages in thread
From: Jason Gunthorpe @ 2016-01-29 22:33 UTC (permalink / raw)
  To: Jarkko Sakkinen
  Cc: tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Fri, Jan 29, 2016 at 02:26:54PM -0800, Jarkko Sakkinen wrote:
> On Fri, Jan 29, 2016 at 02:21:08PM -0800, Jarkko Sakkinen wrote:
> > On Fri, Jan 29, 2016 at 01:48:27PM -0700, Jason Gunthorpe wrote:
> > > On Thu, Jan 28, 2016 at 11:13:59PM -0800, Jarkko Sakkinen wrote:
> > > 
> > > > -	struct resource tmp = {};
> > > > -
> > > > -	tmp.start = start;
> > > > -	tmp.end = start + size - 1;
> > > > -	tmp.flags = IORESOURCE_MEM;
> > > > +	struct resource new_res = {
> > > > +		.start	= start,
> > > > +		.end	= size - 1,
> > > 
> > > That isn't right.
> > 
> > Whoops. Good catch, I'll update it before pull request. Thanks!
> 
> github.com/jsakkine/linux-tpmdd/commit/5012960093774c49d81c612eb32f92cfa1f619bc
> 
> struct resource new_res = {
> 	.start	= start,
> 	.end	= start + size - 1,
> 	.flags	= IORESOURCE_MEM,
> };
> 
> Better?

Yes that looks ok

Jason

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [tpmdd-devel] [PATCH] tpm, tpm_crb: fix control area resource mapping
@ 2016-01-29 22:39           ` Jarkko Sakkinen
  0 siblings, 0 replies; 11+ messages in thread
From: Jarkko Sakkinen @ 2016-01-29 22:39 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Peter Huewe, tpmdd-devel, linux-kernel

On Fri, Jan 29, 2016 at 03:33:34PM -0700, Jason Gunthorpe wrote:
> On Fri, Jan 29, 2016 at 02:26:54PM -0800, Jarkko Sakkinen wrote:
> > On Fri, Jan 29, 2016 at 02:21:08PM -0800, Jarkko Sakkinen wrote:
> > > On Fri, Jan 29, 2016 at 01:48:27PM -0700, Jason Gunthorpe wrote:
> > > > On Thu, Jan 28, 2016 at 11:13:59PM -0800, Jarkko Sakkinen wrote:
> > > > 
> > > > > -	struct resource tmp = {};
> > > > > -
> > > > > -	tmp.start = start;
> > > > > -	tmp.end = start + size - 1;
> > > > > -	tmp.flags = IORESOURCE_MEM;
> > > > > +	struct resource new_res = {
> > > > > +		.start	= start,
> > > > > +		.end	= size - 1,
> > > > 
> > > > That isn't right.
> > > 
> > > Whoops. Good catch, I'll update it before pull request. Thanks!
> > 
> > github.com/jsakkine/linux-tpmdd/commit/5012960093774c49d81c612eb32f92cfa1f619bc
> > 
> > struct resource new_res = {
> > 	.start	= start,
> > 	.end	= start + size - 1,
> > 	.flags	= IORESOURCE_MEM,
> > };
> > 
> > Better?
> 
> Yes that looks ok

Thanks. To be extra sure I'll run smoke test and inject prints.

Acked-by?

> Jason

/Jarkko

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] tpm, tpm_crb: fix control area resource mapping
@ 2016-01-29 22:39           ` Jarkko Sakkinen
  0 siblings, 0 replies; 11+ messages in thread
From: Jarkko Sakkinen @ 2016-01-29 22:39 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Fri, Jan 29, 2016 at 03:33:34PM -0700, Jason Gunthorpe wrote:
> On Fri, Jan 29, 2016 at 02:26:54PM -0800, Jarkko Sakkinen wrote:
> > On Fri, Jan 29, 2016 at 02:21:08PM -0800, Jarkko Sakkinen wrote:
> > > On Fri, Jan 29, 2016 at 01:48:27PM -0700, Jason Gunthorpe wrote:
> > > > On Thu, Jan 28, 2016 at 11:13:59PM -0800, Jarkko Sakkinen wrote:
> > > > 
> > > > > -	struct resource tmp = {};
> > > > > -
> > > > > -	tmp.start = start;
> > > > > -	tmp.end = start + size - 1;
> > > > > -	tmp.flags = IORESOURCE_MEM;
> > > > > +	struct resource new_res = {
> > > > > +		.start	= start,
> > > > > +		.end	= size - 1,
> > > > 
> > > > That isn't right.
> > > 
> > > Whoops. Good catch, I'll update it before pull request. Thanks!
> > 
> > github.com/jsakkine/linux-tpmdd/commit/5012960093774c49d81c612eb32f92cfa1f619bc
> > 
> > struct resource new_res = {
> > 	.start	= start,
> > 	.end	= start + size - 1,
> > 	.flags	= IORESOURCE_MEM,
> > };
> > 
> > Better?
> 
> Yes that looks ok

Thanks. To be extra sure I'll run smoke test and inject prints.

Acked-by?

> Jason

/Jarkko

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-01-29 22:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-29  7:13 [PATCH] tpm, tpm_crb: fix control area resource mapping Jarkko Sakkinen
2016-01-29 20:48 ` [tpmdd-devel] " Jason Gunthorpe
2016-01-29 20:48   ` Jason Gunthorpe
2016-01-29 22:21   ` [tpmdd-devel] " Jarkko Sakkinen
2016-01-29 22:21     ` Jarkko Sakkinen
2016-01-29 22:26     ` [tpmdd-devel] " Jarkko Sakkinen
2016-01-29 22:26       ` Jarkko Sakkinen
2016-01-29 22:33       ` [tpmdd-devel] " Jason Gunthorpe
2016-01-29 22:33         ` Jason Gunthorpe
2016-01-29 22:39         ` [tpmdd-devel] " Jarkko Sakkinen
2016-01-29 22:39           ` Jarkko Sakkinen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.