linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
To: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>
Cc: Kishon Vijay Abraham I <kishon@ti.com>,
	Chris Paterson <Chris.Paterson2@renesas.com>,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	linux-pci <linux-pci@vger.kernel.org>
Subject: RE: PCIe EPF
Date: Wed, 1 Apr 2020 08:50:39 +0000	[thread overview]
Message-ID: <TYAPR01MB4544972970249F317DEBE5AAD8C90@TYAPR01MB4544.jpnprd01.prod.outlook.com> (raw)
In-Reply-To: <CA+V-a8vK36es7Q6AB-t2wkyF-DNJa6GP5HZ41YgJG-PopxuHfw@mail.gmail.com>

Hi Prabhakar-san,

> From: Lad, Prabhakar, Sent: Wednesday, April 1, 2020 5:00 PM
<snip>
> > > root@hihope-rzg2m:~# pcitest -r -s 2176
> > <snip>
> > > [  528.556991] pci-endpoint-test 0000:01:00.0: pci_endpoint_test_read
> > > ffff0004b61f9000 7e951000 910c690d=910c690d
> >
> > I'd like to know how to print these crc values. Your report on the case 1
> > mentioned on pci-epf-test.c like below though.
> >
> > > +       dev_err(dev, "%s %llx %llx csum: %x = %x\n", __func__, reg->dst_addr,
> > > +               phys_addr, reg->checksum, crc32_le(~0, dst_addr, reg->size));
> >
> > Also, as I mentioned on previous email, this is possible to cause timing issue.
> > So, I'd like to where you added the hexdump on pci_endpoint_test.c.
> > Perhaps, copy and pasting your whole debug diff is useful to understand about it.
> >
> 
> Following is the complete diff:

Thanks!

> diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
> index 3c49514b4813..e7bf58a1fee8 100644
> --- a/drivers/misc/pci_endpoint_test.c
> +++ b/drivers/misc/pci_endpoint_test.c
> @@ -561,6 +561,23 @@ static bool pci_endpoint_test_write(struct
> pci_endpoint_test *test,
>      return ret;
>  }
> 
> +static void print_buffer(struct device *dev, void *buff_addr, size_t size)
> +{
> +    size_t i;
> +    u64 *addr = buff_addr;
> +
> +    for(i = 0; i < size; i += sizeof(addr))
> +        dev_err(dev, "buf[%zu] : %llx\n", i, *addr);
> +
> +    for(i = 0; i < size; i +=1) {
> +        if (0x910c690d == crc32_le(~0, buff_addr, i))
> +            dev_err(dev, "%x\n",
> +                crc32_le(~0, buff_addr, i));
> +    }
> +
> +    dev_err(dev, "\n\n\n\n");
> +}
> +
>  static bool pci_endpoint_test_read(struct pci_endpoint_test *test,
>                     unsigned long arg)
>  {
> @@ -608,7 +625,7 @@ static bool pci_endpoint_test_read(struct
> pci_endpoint_test *test,
>      }

I'd like to allocate temporary buffer here to copy data later...
	void *tmp;
	...
	tmp = kzalloc(size + alignment, GFP_KERNEL);

>      orig_phys_addr = dma_map_single(dev, orig_addr, size + alignment,
> -                    DMA_FROM_DEVICE);
> +                    DMA_BIDIRECTIONAL);
>      if (dma_mapping_error(dev, orig_phys_addr)) {
>          dev_err(dev, "failed to map source buffer address\n");
>          ret = false;
> @@ -640,12 +657,17 @@ static bool pci_endpoint_test_read(struct
> pci_endpoint_test *test,
>      wait_for_completion(&test->irq_raised);
> 
>      dma_unmap_single(dev, orig_phys_addr, size + alignment,
> -             DMA_FROM_DEVICE);
> +             DMA_BIDIRECTIONAL);

And then, I'd like to copy addr buffer to the tmp here.
	memcpy(tmp, addr, size);

>      crc32 = crc32_le(~0, addr, size);

And addr is replaced with tmp;

>      if (crc32 == pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_CHECKSUM))
>          ret = true;
> 
> +    print_buffer(dev, addr, size);

This addr is also replaced with tmp;

> +    dev_err(dev, "%s %px %llx %x=%x\n", __func__, orig_addr,
> +        orig_phys_addr, crc32,
> +        pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_CHECKSUM));

The crc32 value was calculated before print the buffer.
This means that timing is difference between crc32_le(addr) and print_buffer(addr).
So, I'd like to copy the addr buffer to tmp and use the tmp for crc32_le() and print_buffer().

> +
>  err_phys_addr:
>      kfree(orig_addr);
>  err:
> 
> Note: I have added DMA_BIDIRECTIONAL that is because I am also
> printing the buffer on ep
> and calulating the crc
> 
> > > READ (   2176 bytes):           OKAY
> > > root@hihope-rzg2m:~# pcitest -r -s 2176
> > <snip>
> > > [  533.457921] pci-endpoint-test 0000:01:00.0: pci_endpoint_test_read
> > > ffff0004b61f9000 7e959800  ce535039=910c690d
> > > READ (   2176 bytes):           NOT OKAY
> > >
> > > Note: for failure case the crc is always ce535039
> >
> > The value of ce535039 is from pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_CHECKSUM)?
> > If so, it's strange because all 0xdf values with 2176 bytes should be 910c690d by crc32_le().
> >
> The value ce535039 is the one which is calculated from the buffer and
> value 910c690d is the one
> which is passed from the BAR memory which is correct.

I got it. If my guess is correct, using the tmp buffer above can print
the buffer with wrong value(s).


By the way, your PCIe host environment (RZ/G2N) output the following log?

[    0.000000] software IO TLB: mapped [mem 0x7bfff000-0x7ffff000] (64MB)

If so, I guess this issue is related to this software IO TLB behavior.
IIUC, if we use coherent buffer or GPF_DMA buffer, the kernel will not
use software IO TLB for these buffers.

Best regards,
Yoshihiro Shimoda

> Cheers,
> --Prabhakar

  reply	other threads:[~2020-04-01  8:50 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-18 11:37 PCIe EPF Lad, Prabhakar
2020-03-20  5:28 ` Kishon Vijay Abraham I
2020-03-21 22:49   ` Lad, Prabhakar
2020-03-24  1:58     ` Kishon Vijay Abraham I
2020-03-24 14:41       ` Lad, Prabhakar
2020-03-28 18:44         ` Lad, Prabhakar
2020-03-29 14:04           ` Lad, Prabhakar
2020-03-30 11:59             ` Kishon Vijay Abraham I
2020-03-30 13:09               ` Lad, Prabhakar
2020-03-30 13:20                 ` Kishon Vijay Abraham I
2020-03-30 13:46                   ` Lad, Prabhakar
2020-03-31  7:10                     ` Yoshihiro Shimoda
2020-03-31 17:25                       ` Lad, Prabhakar
2020-04-01  1:25                         ` Yoshihiro Shimoda
2020-04-01  8:00                           ` Lad, Prabhakar
2020-04-01  8:50                             ` Yoshihiro Shimoda [this message]
2020-04-01  9:24                               ` Lad, Prabhakar
2020-04-02  1:22                                 ` Yoshihiro Shimoda
2020-04-02  4:58                                   ` Yoshihiro Shimoda
2020-04-02 17:44                                     ` Lad, Prabhakar

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=TYAPR01MB4544972970249F317DEBE5AAD8C90@TYAPR01MB4544.jpnprd01.prod.outlook.com \
    --to=yoshihiro.shimoda.uh@renesas.com \
    --cc=Chris.Paterson2@renesas.com \
    --cc=kishon@ti.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=prabhakar.csengg@gmail.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).