All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
Cc: figlesia@xilinx.com, "Edgar Iglesias" <edgar.iglesias@xilinx.com>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Sai Pavan Boddu" <sai.pavan.boddu@xilinx.com>,
	"Francisco Iglesias" <frasse.iglesias@gmail.com>,
	"Alistair Francis" <alistair@alistair23.me>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	"KONRAD Frederic" <frederic.konrad@adacore.com>,
	qemu-arm <qemu-arm@nongnu.org>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Luc Michel" <luc.michel@greensocs.com>
Subject: Re: [PATCH v1 5/5] dma/xlnx-zdma: Reorg to fix CUR_DSCR
Date: Fri, 3 Apr 2020 19:39:52 +0100	[thread overview]
Message-ID: <CAFEAcA99fjZwYJzhypCxyqDMN9NR-BEd8Q21R-5Ge3tv1EwEkQ@mail.gmail.com> (raw)
In-Reply-To: <20200402134721.27863-6-edgar.iglesias@gmail.com>

On Thu, 2 Apr 2020 at 14:46, Edgar E. Iglesias <edgar.iglesias@gmail.com> wrote:
>
> From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>
>
> Reorganize the descriptor handling so that CUR_DSCR always
> points to the next descriptor to be processed.
>
> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
> ---

This is just moved-code in this patch so I think it's
a separate issue, but it looks like you have an endianness
bug here:

> +static void zdma_update_descr_addr(XlnxZDMA *s, bool type,
> +                                   unsigned int basereg)
> +{
> +    uint64_t addr, next;
> +
> +    if (type == DTYPE_LINEAR) {
> +        addr = zdma_get_regaddr64(s, basereg);
> +        next = addr + sizeof(s->dsc_dst);
> +    } else {
> +        addr = zdma_get_regaddr64(s, basereg);
> +        addr += sizeof(s->dsc_dst);
> +        address_space_read(s->dma_as, addr, s->attr, (void *) &next, 8);

This reads 8 bytes into the uint64_t 'next', which means
that the value from C's point of view will be different
for big-endian and little-endian hosts. You probably wanted
address_space_ldq_le(), assuming the h/w always does
little-endian reads and that these get_regaddr64 and
put_regaddr64 functions work with host-endian integers.

There's a similar problem elsewhere in the device where
it does this:
    address_space_read(s->dma_as, addr, s->attr, buf, sizeof(XlnxZDMADescr));
and assumes the guest structure is the same layout and
endianness as the host struct XlnxDMADescr.

I'm not a huge fan of defining host C structs to match
guest data structures, but if you want to go that way
you ought to (a) be byteswapping the contents appropriately
and (b) have a compile-time assert that the size of the
struct is what you think it is and the compiler hasn't
inserted any helpful extra padding.

thanks
-- PMM


  parent reply	other threads:[~2020-04-03 18:42 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-02 13:47 [PATCH v1 0/5] dma/xlnx-zdma: Bug fixes Edgar E. Iglesias
2020-04-02 13:47 ` [PATCH v1 1/5] dma/xlnx-zdma: Remove comment Edgar E. Iglesias
2020-04-02 16:57   ` Alistair Francis
2020-04-03  6:48   ` Francisco Iglesias
2020-04-02 13:47 ` [PATCH v1 2/5] dma/xlnx-zdma: Populate DBG0.CMN_BUF_FREE Edgar E. Iglesias
2020-04-02 17:13   ` Alistair Francis
2020-04-03  6:48   ` Francisco Iglesias
2020-04-02 13:47 ` [PATCH v1 3/5] dma/xlnx-zdma: Clear DMA_DONE when halting Edgar E. Iglesias
2020-04-02 17:15   ` Alistair Francis
2020-04-03  6:49   ` Francisco Iglesias
2020-04-02 13:47 ` [PATCH v1 4/5] dma/xlnx-zdma: Advance the descriptor address when stopping Edgar E. Iglesias
2020-04-02 17:16   ` Alistair Francis
2020-04-03  6:49   ` Francisco Iglesias
2020-04-02 13:47 ` [PATCH v1 5/5] dma/xlnx-zdma: Reorg to fix CUR_DSCR Edgar E. Iglesias
2020-04-02 22:47   ` Alistair Francis
2020-04-03  6:50   ` Francisco Iglesias
2020-04-03 18:39   ` Peter Maydell [this message]
2020-04-03 18:53 ` [PATCH v1 0/5] dma/xlnx-zdma: Bug fixes Peter Maydell
2020-04-04 12:29   ` Edgar E. Iglesias

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=CAFEAcA99fjZwYJzhypCxyqDMN9NR-BEd8Q21R-5Ge3tv1EwEkQ@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=alistair@alistair23.me \
    --cc=edgar.iglesias@gmail.com \
    --cc=edgar.iglesias@xilinx.com \
    --cc=figlesia@xilinx.com \
    --cc=frasse.iglesias@gmail.com \
    --cc=frederic.konrad@adacore.com \
    --cc=luc.michel@greensocs.com \
    --cc=philmd@redhat.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=sai.pavan.boddu@xilinx.com \
    --cc=sstabellini@kernel.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.