All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "Mattias Nissler" <mnissler@rivosinc.com>,
	"Peter Xu" <peterx@redhat.com>, "Cédric Le Goater" <clg@kaod.org>,
	qemu-devel@nongnu.org, "Fabiano Rosas" <farosas@suse.de>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: Re: [PULL 1/9] softmmu: Support concurrent bounce buffers
Date: Mon, 16 Sep 2024 13:13:53 +0100	[thread overview]
Message-ID: <10b76006-4cb5-485e-aff2-87c9e511ad2b@ilande.co.uk> (raw)
In-Reply-To: <CAFEAcA80SmMbNOhUqgB8h+16RR+d_hOeoVqUCJQZJHvDUtCaYw@mail.gmail.com>

On 16/09/2024 12:44, Peter Maydell wrote:

> On Mon, 16 Sept 2024 at 12:29, Mark Cave-Ayland
> <mark.cave-ayland@ilande.co.uk> wrote:
>>
>> On 16/09/2024 09:23, Mattias Nissler wrote:
>>> Looking at the code, the dma_memory_unmap calls in hw/ide/macio.c seem
>>> to be passing buffer=NULL unconditionally, since the dma_mem field in
>>> struct DBDMA_io is never set to anything non-zero. In fact, I believe
>>> after commit be1e343995ef81fc05d9a4e1ec263ca171d842e7 "macio: switch
>>> over to new byte-aligned DMA helpers", the dma_memory_unmap calls in
>>> hw/ide/macio.c aren't doing anything and should probably have been
>>> removed together with the dma_mem, dma_len and dir fields in struct
>>> DBDMA_io. Speculative patch:
>>>
>>> diff --git a/hw/ide/macio.c b/hw/ide/macio.c
>>> index e84bf2c9f6..15dd40138e 100644
>>> --- a/hw/ide/macio.c
>>> +++ b/hw/ide/macio.c
>>> @@ -119,9 +119,6 @@ static void pmac_ide_atapi_transfer_cb(void
>>> *opaque, int ret)
>>>        return;
>>>
>>>    done:
>>> -    dma_memory_unmap(&address_space_memory, io->dma_mem, io->dma_len,
>>> -                     io->dir, io->dma_len);
>>> -
>>>        if (ret < 0) {
>>>            block_acct_failed(blk_get_stats(s->blk), &s->acct);
>>>        } else {
>>> @@ -202,9 +199,6 @@ static void pmac_ide_transfer_cb(void *opaque, int ret)
>>>        return;
>>>
>>>    done:
>>> -    dma_memory_unmap(&address_space_memory, io->dma_mem, io->dma_len,
>>> -                     io->dir, io->dma_len);
>>> -
>>>        if (s->dma_cmd == IDE_DMA_READ || s->dma_cmd == IDE_DMA_WRITE) {
>>>            if (ret < 0) {
>>>                block_acct_failed(blk_get_stats(s->blk), &s->acct);
>>> diff --git a/include/hw/ppc/mac_dbdma.h b/include/hw/ppc/mac_dbdma.h
>>> index 4a3f644516..c774f6bf84 100644
>>> --- a/include/hw/ppc/mac_dbdma.h
>>> +++ b/include/hw/ppc/mac_dbdma.h
>>> @@ -44,10 +44,6 @@ struct DBDMA_io {
>>>        DBDMA_end dma_end;
>>>        /* DMA is in progress, don't start another one */
>>>        bool processing;
>>> -    /* DMA request */
>>> -    void *dma_mem;
>>> -    dma_addr_t dma_len;
>>> -    DMADirection dir;
>>>    };
>>>
>>>    /*
>>>
>>> Cédric, can you try with the above patch and/or share more details of
>>> your setup so I can verify (I tried booting a ppc64el-pseries dqib
>>> image but didn't see the issue)?
>>
>> I'm fairly sure that this patch would break MacOS 9 which was the reason that
>> dma_memory_unmap() was added here in the first place: what I was finding was that
>> without the dma_memory_unmap() the destination RAM wasn't being invalidated (or
>> marked dirty), causing random crashes during boot.
> 
> dma_memory_unmap() of something you never mapped is
> definitely wrong. Whatever is going on here, leaving the unmap
> call in after you removed the dma_memory_map() call is just
> papering over the actual cause of the crashes.
> 
>> Would the issue be solved by adding a corresponding dma_memory_map() beforehand at
>> the relevant places in hw/ide/macio.c? If that's required as part of the setup for
>> bounce buffers then I can see how not having this present could cause problems.
> 
> The only purpose of this API is sequences of:
>    host_ptr = dma_memory_map(...);
>    access the host_ptr directly;
>    dma_memory_unmap(...);
> 
> The bounce-buffer stuff is an internal implementation detail
> of making this API work when the DMA is going to a device.
> 
> We need to find whatever the actual cause of the macos failure is.
> Mattias' suggested change looks right to me.
> 
> I do wonder if something needs the memory barrier than
> unmap does as part of its operation, e.g. in the
> implementation of the dma_blk_* functions.

It has been a few years now, but I'm fairly sure the issue was that dma_blk_read() 
didn't mark RAM containing code as dirty/invalid, and since MacOS 9 used overlays 
then it would crash randomly trying to execute stale memory. dma_memory_unmap() 
checks to see if the direction was to RAM, and then marks the memory dirty allowing 
the new code to get picked up after a MMU fault.

If the memory barriers are already in place for the dma_blk_*() functions then the 
analysis could be correct, in which case the bug is a misunderstanding I made in 
be1e343995 ("macio: switch over to new byte-aligned DMA helpers") back in 2016.


ATB,

Mark.



  reply	other threads:[~2024-09-16 12:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-09 20:11 [PULL 0/9] Migration 20240909 patches Peter Xu
2024-09-09 20:11 ` [PULL 1/9] softmmu: Support concurrent bounce buffers Peter Xu
2024-09-13 14:35   ` Cédric Le Goater
2024-09-13 14:47     ` Peter Xu
2024-09-16  8:23       ` Mattias Nissler
2024-09-16 11:29         ` Mark Cave-Ayland
2024-09-16 11:44           ` Peter Maydell
2024-09-16 12:13             ` Mark Cave-Ayland [this message]
2024-09-16 12:28               ` Peter Maydell
2024-09-16 12:44                 ` Mattias Nissler
2024-09-16 12:13         ` Cédric Le Goater
2024-09-16 12:28           ` Cédric Le Goater
2024-09-16 12:41             ` Mattias Nissler
2024-09-16 13:06               ` Cédric Le Goater
2024-09-16 17:47                 ` Mattias Nissler
2024-09-09 20:11 ` [PULL 2/9] softmmu/physmem: fix memory leak in dirty_memory_extend() Peter Xu
2024-09-09 20:11 ` [PULL 3/9] ci: migration: Don't run python tests in the compat job Peter Xu
2024-09-09 20:11 ` [PULL 4/9] docs/migration: add qatzip compression feature Peter Xu
2024-09-09 20:11 ` [PULL 5/9] meson: Introduce 'qatzip' feature to the build system Peter Xu
2024-09-09 20:11 ` [PULL 6/9] migration: Add migration parameters for QATzip Peter Xu
2024-09-09 20:11 ` [PULL 7/9] migration: Introduce 'qatzip' compression method Peter Xu
2024-09-09 20:11 ` [PULL 8/9] tests/migration: Add integration test for " Peter Xu
2024-09-09 20:11 ` [PULL 9/9] system: improve migration debug Peter Xu
2024-09-10 14:46 ` [PULL 0/9] Migration 20240909 patches Peter Maydell

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=10b76006-4cb5-485e-aff2-87c9e511ad2b@ilande.co.uk \
    --to=mark.cave-ayland@ilande.co.uk \
    --cc=clg@kaod.org \
    --cc=farosas@suse.de \
    --cc=mnissler@rivosinc.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.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.