All of lore.kernel.org
 help / color / mirror / Atom feed
From: Davide Guerri <davide.guerri-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Jason Gunthorpe
	<jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
Cc: tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: Intel NUC and fTPM issue on 4.9.2
Date: Thu, 16 Feb 2017 19:11:55 +0000	[thread overview]
Message-ID: <B5581EEC-859B-4950-9D48-8CD6806A4801@gmail.com> (raw)
In-Reply-To: <20170216190329.GC7257-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>

Yes.
I tried to crop the 2 sizes manually and it worked.
I tested a couple of user space commands and it seems to be working.

Later I will try with your patch.

Thanks!



Sent from my iPhone
> On 16 Feb 2017, at 19:03, Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> wrote:
> 
>> On Thu, Feb 16, 2017 at 06:40:02PM +0000, Davide Guerri wrote:
>>   Sorry I missed 1 line:
>> 
>>   [20417.678952] ACPI resource is [mem 0xfed40000-0xfed4087f flags 0x200]
> 
> The BIOS is broken.. That range declared in the ACPI is too small
> 
> Or the cmd_size is too big:
> 
>>   [20417.678990] map request is is [mem 0xfed40080-0xfed40fff flags 0x200]
> 
> I have no idea which.
> 
> If we trust the ACPI table then the cmd_size is 2047 bytes
> 
> If we trust the register then it is 3967..
> 
> Try this?
> 
> diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
> index a7c870af916c3d..2d16cc4aa0f43b 100644
> --- a/drivers/char/tpm/tpm_crb.c
> +++ b/drivers/char/tpm/tpm_crb.c
> @@ -233,6 +233,8 @@ static void __iomem *crb_map_res(struct device *dev, struct crb_priv *priv,
>        .flags    = IORESOURCE_MEM,
>    };
> 
> +    printk("map request is is %pr\n",&new_res);
> +
>    /* Detect a 64 bit address on a 32 bit system */
>    if (start != new_res.start)
>        return (void __iomem *) ERR_PTR(-EINVAL);
> @@ -243,6 +245,26 @@ static void __iomem *crb_map_res(struct device *dev, struct crb_priv *priv,
>    return priv->iobase + (new_res.start - io_res->start);
> }
> 
> +/*
> + * Work around broken BIOSs that return inconsistent values from the ACPI
> + * region vs the registers. Trust the ACPI region.
> + */
> +static u64 crb_clamp_cmd_size(struct device *dev, struct resource *io_res,
> +                  u64 start, u64 size)
> +{
> +    if (io_res->start > start || io_res->end < start)
> +        return size;
> +
> +    if (start + size - 1 <= io_res->end)
> +        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);
> +
> +    return io_res->end - start + 1;
> +}
> +
> static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
>              struct acpi_table_tpm2 *buf)
> {
> @@ -267,6 +289,8 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
>        return -EINVAL;
>    }
> 
> +    printk("ACPI resource is %pr\n",&io_res);
> +
>    priv->iobase = devm_ioremap_resource(dev, &io_res);
>    if (IS_ERR(priv->iobase))
>        return PTR_ERR(priv->iobase);
> @@ -278,14 +302,16 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
> 
>    cmd_pa = ((u64) ioread32(&priv->cca->cmd_pa_high) << 32) |
>          (u64) ioread32(&priv->cca->cmd_pa_low);
> -    cmd_size = ioread32(&priv->cca->cmd_size);
> +    cmd_size = crb_clamp_cmd_size(dev, &io_res, cmd_pa,
> +                      ioread32(&priv->cca->cmd_size));
>    priv->cmd = crb_map_res(dev, priv, &io_res, cmd_pa, cmd_size);
>    if (IS_ERR(priv->cmd))
>        return PTR_ERR(priv->cmd);
> 
>    memcpy_fromio(&rsp_pa, &priv->cca->rsp_pa, 8);
>    rsp_pa = le64_to_cpu(rsp_pa);
> -    rsp_size = ioread32(&priv->cca->rsp_size);
> +    rsp_size = crb_clamp_cmd_size(dev, &io_res, rsp_pa,
> +                      ioread32(&priv->cca->rsp_size));
> 
>    if (cmd_pa != rsp_pa) {
>        priv->rsp = crb_map_res(dev, priv, &io_res, rsp_pa, rsp_size);

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot

  parent reply	other threads:[~2017-02-16 19:11 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-16 11:15 Intel NUC and fTPM issue on 4.9.2 Davide Guerri
     [not found] ` <CAH=yMtLydrTfn3_RkzZFpRL-sASUsHPdxX9m-HJUTyjv=D3ksg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-16 18:01   ` Jason Gunthorpe
     [not found]     ` <20170216180116.GA7145-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-02-16 18:10       ` Davide Guerri
     [not found]         ` <CAH=yMtJkmxxm6sn=1DmakXW+P=E7rsBd3iwqsSwaVBvxazE29w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-16 18:19           ` Jason Gunthorpe
     [not found]             ` <20170216181905.GA7257-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-02-16 18:26               ` Davide Guerri
     [not found]                 ` <CAH=yMt+tWWDMban86H53Or+KngYLUw5hN0aB=+DaJ+MQOK4=4g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-16 18:39                   ` Davide Guerri
     [not found]                     ` <CAH=yMtJ7qWq=YpRaUPh2zzOECjFGiwV3jfBc+4HuvW3wOYt_Vg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-16 18:40                       ` Davide Guerri
     [not found]                         ` <CAH=yMtLLrsyqLr9tOm+D2qvcCDNRO3P36hp8hCdJFVtDyJPWGQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-16 19:03                           ` Jason Gunthorpe
     [not found]                             ` <20170216190329.GC7257-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-02-16 19:11                               ` Davide Guerri [this message]
2017-02-16 20:00                               ` Jarkko Sakkinen
2017-02-16 22:36                           ` Winkler, Tomas
     [not found]                             ` <5B8DA87D05A7694D9FA63FD143655C1B54395CD5-Jy8z56yoSI8MvF1YICWikbfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2017-02-17 16:43                               ` Jason Gunthorpe
     [not found]                                 ` <20170217164332.GB30677-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-02-17 18:28                                   ` Sakkinen, Jarkko
     [not found]                                     ` <1487356105.6424.1.camel-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2017-02-17 19:01                                       ` Jason Gunthorpe
     [not found]                                         ` <20170217190125.GA5984-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-02-17 21:14                                           ` Davide Guerri
     [not found]                                             ` <0FB78E3E-1E73-46EC-9ABD-FD05E1E8B0E2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-02-19 22:28                                               ` Winkler, Tomas
     [not found]                                                 ` <5B8DA87D05A7694D9FA63FD143655C1B54398ADC-Jy8z56yoSI8MvF1YICWikbfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2017-02-20 10:36                                                   ` Jarkko Sakkinen
2017-02-20 10:47                                           ` Jarkko Sakkinen
2017-04-18 14:49                                             ` [tpmdd-devel] " Winkler, Tomas
2017-04-18 14:49                                               ` Winkler, Tomas
2017-02-16 20:27                   ` Jarkko Sakkinen
     [not found]                     ` <20170216202754.zokzcn6l4pd7hvbm-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2017-02-16 21:01                       ` Davide Guerri
2017-02-16 19:59   ` 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=B5581EEC-859B-4950-9D48-8CD6806A4801@gmail.com \
    --to=davide.guerri-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org \
    --cc=tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    /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 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.