All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: BALATON Zoltan <balaton@eik.bme.hu>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	qemu-devel@nongnu.org,
	"Akihiko Odaki" <odaki@rsg.ci.i.u-tokyo.ac.jp>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Max Filippov" <jcmvbkbc@gmail.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: Re: [PATCH v5 1/7] memory: Export memory_region_set_ops()
Date: Thu, 28 May 2026 09:39:06 -0400	[thread overview]
Message-ID: <ahhFepYkLT-uXbf7@x1.local> (raw)
In-Reply-To: <ec2a907a-9fab-d56a-83a2-409254146209@eik.bme.hu>

On Mon, May 25, 2026 at 10:57:39PM +0200, BALATON Zoltan wrote:
> On Mon, 25 May 2026, Peter Maydell wrote:
> > On Mon, 25 May 2026 at 16:47, BALATON Zoltan <balaton@eik.bme.hu> wrote:
> > > 
> > > Make memory_region_set_ops() function public. In some cases such as
> > > when devices have configurable endianness or different behaviour based
> > > on settings it is necessary to change the ops callback after the
> > > memory region is created. Export memory_region_set_ops() function for
> > > this.
> > 
> > If some other CPU is in the middle of using the old MemoryRegionOps
> > when the device swaps them out under its feet, what happens?
> 
> In my limited test with PPC and ati-vga this seems to work and the switch
> would happen in device register write so nothing else is expected to run
> accessing the device at the same time at that point. I can't tell for all
> possible cases but that would then be a problem in the caller not in this
> function. Callers are expected to call it when appropriate which I could
> mention in the doc comment if needed.
> 
> > You could also remove the old MR from its container and add a different
> > one with the different behaviour when the guest changes the config,
> > or have both of them in the container and toggle which is visible
> > with memory_region_set_enabled(). That might potentially be more
> > awkward but it would avoid having to look into the memory region
> > API internals.
> 
> That could also work if I had a container but it's switching the endianness
> of a PCI BAR which is registered with pci_register_bar() so it's easiest to
> switch the ops on the region than hacking around it using two more otherwise
> unneeded memory regions as I also can't swap PCI BARs so it would need a
> container aditionally to two regions using the same callbacks just with
> different endianness. Allowing setting the ops of a single region seems
> simpler.

I think PeterM's proposal makes more sense.

Having two MRs registered under the same offset of parent and dynamically
enable/disable seems to be a common way to solve similar problems in QEMU.
I don't see why it is hacky if we can allow dynamic flip of mr->ops, which
smells more risky.

Exporting that API may invite more abuse, which I'm not sure it's good.

The other thing I want to mention is having ops flippable relies on "BQL
serializes everything", but it's already not true with exceptions like
HPET, see memory_region_enable_lockless_io().  I think this will introduce
tech debts that we don't necessarily need.

Thanks,

-- 
Peter Xu



  reply	other threads:[~2026-05-28 13:40 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-25 15:47 [PATCH v5 0/7] Implement memory_region_new_* functions BALATON Zoltan
2026-05-25 15:47 ` [PATCH v5 1/7] memory: Export memory_region_set_ops() BALATON Zoltan
2026-05-25 20:01   ` Peter Maydell
2026-05-25 20:57     ` BALATON Zoltan
2026-05-28 13:39       ` Peter Xu [this message]
2026-05-25 15:47 ` [PATCH v5 2/7] memory: Add memory_region_new* functions BALATON Zoltan
2026-05-25 15:47 ` [PATCH v5 3/7] memory: Update documentation for memory_region_new*() BALATON Zoltan
2026-05-25 15:47 ` [PATCH v5 4/7] hw/ide/sii3112: Use memory_region_new to avoid leaking regions BALATON Zoltan
2026-05-25 15:47 ` [PATCH v5 5/7] hw/pci-host/articia: Map PCI memory windows in realize BALATON Zoltan
2026-05-25 15:47 ` [PATCH v5 6/7] hw/pci-host/articia: Add variable for common type cast BALATON Zoltan
2026-05-25 15:47 ` [PATCH v5 7/7] hw/xtensa/xtfpga: Fix leaking memory region BALATON Zoltan
2026-05-25 16:06 ` [PATCH v5 0/7] Implement memory_region_new_* functions Paolo Bonzini
2026-05-25 16:58   ` BALATON Zoltan

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=ahhFepYkLT-uXbf7@x1.local \
    --to=peterx@redhat.com \
    --cc=balaton@eik.bme.hu \
    --cc=jcmvbkbc@gmail.com \
    --cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --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.