All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: Avi Kivity <avi@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [RFC] Memory API
Date: Wed, 18 May 2011 17:11:47 +0200	[thread overview]
Message-ID: <4DD3E1B3.3020405@siemens.com> (raw)
In-Reply-To: <4DD3D95E.2060105@redhat.com>

On 2011-05-18 16:36, Avi Kivity wrote:
>> I would add another drawback:
>>
>>   - Inability to identify the origin of a region accesses and handle them
>>     differently based on the source.
>>
>>     That is at least problematic for the x86 APIC which is CPU local. Our
>>     current way do deal with it is, well, very creative and falls to
>>     dust if a guest actually tries to remap the APIC.
>>
>> However, I'm unsure if that can easily be addressed. As long as only x86
>> is affected, it's tricky to ask for a big infrastructure to handle this
>> special case. Maybe there some other use cases, don't know.
> 
> We could implement it with a per-cpu MemoryRegion, with each cpu's 
> MemoryRegion populated by a different APIC sub-region.

The tricky part is wiring this up efficiently for TCG, ie. in QEMU's
softmmu. I played with passing the issuing CPUState (or NULL for
devices) down the MMIO handler chain. Not totally beautiful as
decentralized dispatching was still required, but at least only
moderately invasive. Maybe your API allows for cleaning up the
management and dispatching part, need to rethink...

> 
>>
>>>
>>>  To fix that, I propose an new API to replace the existing one:
>>>
>>>
>>>  #ifndef MEMORY_H
>>>  #define MEMORY_H
>>>
>>>  typedef struct MemoryRegionOps MemoryRegionOps;
>>>  typedef struct MemoryRegion MemoryRegion;
>>>
>>>  typedef uint32_t (*MemoryReadFunc)(MemoryRegion *mr, target_phys_addr_t
>>>  addr);
>>>  typedef void (*MemoryWriteFunc)(MemoryRegion *mr, target_phys_addr_t addr,
>>>                                  uint32_t data);
>>>
>>>  struct MemoryRegionOps {
>>>      MemoryReadFunc readb, readw, readl;
>>>      MemoryWriteFunc writeb, writew, writel;
>>>  };
>>>
>>>  struct MemoryRegion {
>>>      const MemoryRegionOps *ops;
>>>      target_phys_addr_t size;
>>>      target_phys_addr_t addr;
>>>  };
>>>
>>>  void memory_region_init(MemoryRegion *mr,
>>>                          target_phys_addr_t size);
>>
>> What use case would this abstract region cover?
> 
> An empty container, fill it with memory_region_add_subregion().

Yeah, of course.

> 
>>
>>>  void memory_region_init_io(MemoryRegion *mr,
>>>                             const MemoryRegionOps *ops,
>>>                             target_phys_addr_t size);
>>>  void memory_region_init_ram(MemoryRegion *mr,
>>>                              target_phys_addr_t size);
>>>  void memory_region_init_ram_ptr(MemoryRegion *mr,
>>>                                  target_phys_addr_t size,
>>>                                  void *ptr);
>>>  void memory_region_destroy(MemoryRegion *mr);
>>>  void memory_region_set_offset(MemoryRegion *mr, target_phys_addr_t offset);
>>>  void memory_region_set_log(MemoryRegion *mr, bool log);
>>>  void memory_region_clear_coalescing(MemoryRegion *mr);
>>>  void memory_region_add_coalescing(MemoryRegion *mr,
>>>                                    target_phys_addr_t offset,
>>>                                    target_phys_addr_t size);
>>>
>>>  void memory_region_add_subregion(MemoryRegion *mr,
>>>                                   target_phys_addr_t offset,
>>>                                   MemoryRegion *subregion);
>>>  void memory_region_del_subregion(MemoryRegion *mr,
>>>                                   target_phys_addr_t offset,
>>>                                   MemoryRegion *subregion);
>>>
>>>  void cpu_register_memory_region(MemoryRegion *mr, target_phys_addr_t addr);
>>
>> This could create overlaps. I would suggest to reject them, so we need a
>> return code.
> 
> There is nothing we can do with a return code.  You can't fail an mmio 
> that causes overlapping physical memory map.

We must fail such requests to make progress with the API. That may
happen either on caller side or in cpu_register_memory_region itself
(hwerror). Otherwise the new API will just be a shiny new facade for on
old and still fragile building.

> 
> 
>>
>>>  void cpu_unregister_memory_region(MemoryRegion *mr);
> 
> Instead, we need cpu_unregister_memory_region() to restore any 
> previously hidden ranges.

I disagree. Both approaches, rejecting overlaps or restoring them, imply
subtle semantical changes that exiting device models have to deal with.
We can't use any of both without some review and conversion work. So
better head for the clearer and, thus, cleaner approach.

> 
>>>
>>>  #endif
>>>
>>>  The API is nested: you can define, say, a PCI BAR containing RAM and
>>>  MMIO, and give it to the PCI subsystem.  PCI can then enable/disable the
>>>  BAR and move it to different addresses without calling any callbacks;
>>>  the client code can enable or disable logging or coalescing without
>>>  caring if the BAR is mapped or not.  For example:
>>
>> Interesting feature.
>>
>>>
>>>    MemoryRegion mr, mr_mmio, mr_ram;
>>>
>>>    memory_region_init(&mr);
>>>    memory_region_init_io(&mr_mmio,&mmio_ops, 0x1000);
>>>    memory_region_init_ram(&mr_ram, 0x100000);
>>>    memory_region_add_subregion(&mr, 0,&mr_ram);
>>>    memory_region_add_subregion(&mr, 0x10000,&mr_io);
>>>    memory_region_add_coalescing(&mr_ram, 0, 0x100000);
>>>    pci_register_bar(&pci_dev, 0,&mr);
>>>
>>>  at this point the PCI subsystem knows everything about the BAR and can
>>>  enable or disable it, or move it around, without further help from the
>>>  device code.  On the other hand, the device code can change logging or
>>>  coalescing, or even change the structure of the region, without caring
>>>  about whether the region is currently registered or not.
>>>
>>>  If we can agree on the API, then I think the way forward is to implement
>>>  it in terms of the old API, change over all devices, then fold the old
>>>  API into the new one.
>>
>> There are more aspects that should be clarified before moving forward:
>>   - How to maintain memory regions internally?
> 
> Not sure what you mean by the question, but my plan was to have the 
> client responsible for allocating the objects (and later use 
> container_of() in the callbacks - note there are no void *s any longer).
> 
>>   - Get rid of wasteful PhysPageDesc at this chance?
> 
> That's the intent, but not at this chance, rather later on.

The features you expose to the users somehow have to be mapped on data
structures internally. Those need to support both the
registration/deregistration as well as the lookup efficiently. By
postponing that internal design to the point when we already switched to
facade, the risk arises that a suboptimal interface was exposed and
conversion was done in vain.

>  But I want 
> the API to be compatible with the goal so we don't have to touch all 
> devices again.

We can't perform any proper change in the area without touching all
users, some a bit more, some only minimally.

> 
>>   - How to hook into the region maintenance (CPUPhysMemoryClient,
>>     listening vs. filtering or modifying changes)? How to simplify
>>     memory clients this way?
> 
> I'd leave things as is, at least for the beginning.  CPUPhysMemoryClient 
> is global in nature, whereas MemoryRegion is local (offsets are relative 
> to the containing region).

See [1]: We really need to get rid of slot management on
CPUPhysMemoryClient side. Your API provides a perfect opportunity to
establish the infrastructure of slot tracking at a central place. We can
then switch from reporting cpu_registering_memory events to reporting
coalesced changes to slots, those slot that also the core uses. So a new
CPUPhysMemoryClient API needs to be considered in this API change as
well - or we change twice in the end.

Jan

[1] http://thread.gmane.org/gmane.comp.emulators.qemu/102893

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux

  reply	other threads:[~2011-05-18 15:11 UTC|newest]

Thread overview: 187+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-18 13:12 [Qemu-devel] [RFC] Memory API Avi Kivity
2011-05-18 14:05 ` Jan Kiszka
2011-05-18 14:36   ` Avi Kivity
2011-05-18 15:11     ` Jan Kiszka [this message]
2011-05-18 15:17       ` Peter Maydell
2011-05-18 15:30         ` Jan Kiszka
2011-05-18 19:10           ` Anthony Liguori
2011-05-18 19:27             ` Jan Kiszka
2011-05-18 19:34               ` Anthony Liguori
2011-05-18 20:02                 ` Alex Williamson
2011-05-18 20:11                   ` Jan Kiszka
2011-05-18 20:13                     ` Alex Williamson
2011-05-18 20:07                 ` Jan Kiszka
2011-05-18 20:41                   ` Anthony Liguori
2011-05-19  8:26               ` Gleb Natapov
2011-05-19  8:30                 ` Jan Kiszka
2011-05-19  8:44                   ` Avi Kivity
2011-05-19 13:59                     ` Anthony Liguori
2011-05-19 13:52                   ` Anthony Liguori
2011-05-19 13:56                     ` Avi Kivity
2011-05-19 13:57                     ` Jan Kiszka
2011-05-19 14:04                       ` Anthony Liguori
2011-05-19 14:06                         ` Jan Kiszka
2011-05-19 14:11                         ` Avi Kivity
2011-05-19 18:18                           ` Anthony Liguori
2011-05-19 18:50                             ` Jan Kiszka
2011-05-19 19:02                               ` Anthony Liguori
2011-05-19 19:10                                 ` Jan Kiszka
2011-05-20  9:15                             ` Avi Kivity
2011-05-20 17:30                   ` Blue Swirl
2011-05-22  7:23                     ` Avi Kivity
2011-05-19  6:31             ` Jan Kiszka
2011-05-19 13:23               ` Anthony Liguori
2011-05-19 13:25                 ` Jan Kiszka
2011-05-19 13:26                 ` Avi Kivity
2011-05-19 13:35                   ` Anthony Liguori
2011-05-19 13:36                     ` Jan Kiszka
2011-05-19 13:43                       ` Avi Kivity
2011-05-19 13:39                     ` Avi Kivity
2011-05-19  8:09             ` Avi Kivity
2011-05-18 15:23       ` Avi Kivity
2011-05-18 15:36         ` Jan Kiszka
2011-05-18 15:42           ` Avi Kivity
2011-05-18 16:00             ` Jan Kiszka
2011-05-18 16:14               ` Avi Kivity
2011-05-18 16:39                 ` Jan Kiszka
2011-05-18 16:47                   ` Avi Kivity
2011-05-18 17:07                     ` Jan Kiszka
2011-05-18 17:15                       ` Avi Kivity
2011-05-18 17:40                         ` Jan Kiszka
2011-05-18 20:13                     ` Richard Henderson
2011-05-19  8:04                       ` Avi Kivity
2011-05-19  9:08             ` Gleb Natapov
2011-05-19  9:10               ` Avi Kivity
2011-05-19  9:14                 ` Gleb Natapov
2011-05-19 11:44                   ` Avi Kivity
2011-05-19 11:54                     ` Gleb Natapov
2011-05-19 11:57                       ` Jan Kiszka
2011-05-19 11:58                         ` Gleb Natapov
2011-05-19 12:02                           ` Avi Kivity
2011-05-19 12:21                             ` Gleb Natapov
2011-05-19 12:02                           ` Jan Kiszka
2011-05-19 11:57                       ` Avi Kivity
2011-05-19 12:20                         ` Jan Kiszka
2011-05-19 12:50                           ` Avi Kivity
2011-05-19 12:58                             ` Jan Kiszka
2011-05-19 13:00                               ` Avi Kivity
2011-05-19 13:03                                 ` Jan Kiszka
2011-05-19 13:07                                   ` Avi Kivity
2011-05-19 13:26                                     ` Jan Kiszka
2011-05-19 13:30                                       ` Avi Kivity
2011-05-19 13:43                                         ` Jan Kiszka
2011-05-19 13:47                                           ` Avi Kivity
2011-05-19 13:49                                         ` Anthony Liguori
2011-05-19 13:53                                           ` Avi Kivity
2011-05-19 14:15                                             ` Anthony Liguori
2011-05-19 14:20                                               ` Jan Kiszka
2011-05-19 14:25                                                 ` Anthony Liguori
2011-05-19 14:28                                                   ` Jan Kiszka
2011-05-19 14:31                                                     ` Avi Kivity
2011-05-19 14:37                                                     ` Anthony Liguori
2011-05-19 14:40                                                       ` Avi Kivity
2011-05-19 16:17                                                         ` Gleb Natapov
2011-05-19 16:25                                                           ` Jan Kiszka
2011-05-19 16:28                                                             ` Gleb Natapov
2011-05-19 16:30                                                               ` Jan Kiszka
2011-05-19 16:36                                                                 ` Anthony Liguori
2011-05-19 16:49                                                                   ` Jan Kiszka
2011-05-19 17:12                                                                     ` Gleb Natapov
2011-05-19 18:11                                                                       ` Jan Kiszka
2011-05-20  8:58                                                                     ` Avi Kivity
2011-05-20  8:56                                                                   ` Avi Kivity
2011-05-20 14:51                                                                     ` Anthony Liguori
2011-05-20 16:43                                                                       ` Olivier Galibert
2011-05-20 17:32                                                                         ` Anthony Liguori
2011-05-22  7:36                                                                       ` Avi Kivity
2011-05-19 16:43                                                                 ` Gleb Natapov
2011-05-19 16:51                                                                   ` Jan Kiszka
2011-05-19 16:27                                                         ` Gleb Natapov
2011-05-20  8:59                                                           ` Avi Kivity
2011-05-20 11:57                                                             ` Gleb Natapov
2011-05-22  7:37                                                               ` Avi Kivity
2011-05-22  8:06                                                                 ` Gleb Natapov
2011-05-22  8:09                                                                   ` Avi Kivity
2011-05-22  8:59                                                                     ` Gleb Natapov
2011-05-22 12:26                                                                       ` Avi Kivity
2011-05-19 16:32                                                         ` Anthony Liguori
2011-05-19 16:35                                                           ` Jan Kiszka
2011-05-19 16:38                                                             ` Anthony Liguori
2011-05-19 16:50                                                               ` Jan Kiszka
2011-05-20  9:03                                                               ` Avi Kivity
2011-05-20  9:01                                                           ` Avi Kivity
2011-05-20 15:33                                                             ` Anthony Liguori
2011-05-20 15:59                                                               ` Jan Kiszka
2011-05-22  7:38                                                                 ` Avi Kivity
2011-05-22 15:42                                                                   ` Anthony Liguori
2011-05-19 14:21                                               ` Avi Kivity
2011-05-19 13:44                 ` Anthony Liguori
2011-05-19 13:47                   ` Jan Kiszka
2011-05-19 13:50                     ` Anthony Liguori
2011-05-19 13:55                       ` Jan Kiszka
2011-05-19 13:55                       ` Avi Kivity
2011-05-19 18:06                         ` Anthony Liguori
2011-05-19 18:21                           ` Jan Kiszka
2011-05-19 13:49                   ` Avi Kivity
2011-05-19  9:24               ` Edgar E. Iglesias
2011-05-19 14:49                 ` Peter Maydell
2011-05-18 16:33         ` Anthony Liguori
2011-05-18 16:41           ` Avi Kivity
2011-05-18 17:04             ` Anthony Liguori
2011-05-18 17:13               ` Avi Kivity
2011-05-18 16:42           ` Jan Kiszka
2011-05-18 17:05             ` Avi Kivity
2011-05-18 15:14   ` Anthony Liguori
2011-05-18 15:26     ` Avi Kivity
2011-05-18 16:21       ` Avi Kivity
2011-05-18 16:42         ` Jan Kiszka
2011-05-18 16:49           ` Avi Kivity
2011-05-18 17:11             ` Anthony Liguori
2011-05-18 17:38               ` Jan Kiszka
2011-05-18 15:08 ` Anthony Liguori
2011-05-18 15:37   ` Avi Kivity
2011-05-18 19:36     ` Jan Kiszka
2011-05-18 15:47   ` Stefan Weil
2011-05-18 16:06     ` Avi Kivity
2011-05-18 16:51       ` Richard Henderson
2011-05-18 16:53         ` Avi Kivity
2011-05-18 17:03           ` Richard Henderson
2011-05-18 15:58 ` Avi Kivity
2011-05-18 16:26 ` Richard Henderson
2011-05-18 16:37   ` Avi Kivity
2011-05-18 17:17 ` Avi Kivity
2011-05-18 19:40 ` Jan Kiszka
2011-05-19  8:06   ` Avi Kivity
2011-05-19  8:08     ` Jan Kiszka
2011-05-19  8:13       ` Avi Kivity
2011-05-19  8:25         ` Jan Kiszka
2011-05-19  8:43           ` Avi Kivity
2011-05-19  9:24             ` Jan Kiszka
2011-05-19 11:58               ` Avi Kivity
2011-05-19 13:36   ` Anthony Liguori
2011-05-19 13:37     ` Jan Kiszka
2011-05-19 13:41       ` Avi Kivity
2011-05-19 17:39       ` Gleb Natapov
2011-05-19 18:03         ` Anthony Liguori
2011-05-19 18:28           ` Gleb Natapov
2011-05-19 18:33             ` Anthony Liguori
2011-05-19 18:11         ` Jan Kiszka
2011-05-19 18:22           ` Gleb Natapov
2011-05-19 18:27             ` Jan Kiszka
2011-05-19 18:40               ` Gleb Natapov
2011-05-19 18:45                 ` Jan Kiszka
2011-05-19 18:50                   ` Gleb Natapov
2011-05-19 18:55                     ` Jan Kiszka
2011-05-19 19:02                       ` Jan Kiszka
2011-05-20  7:23                       ` Gleb Natapov
2011-05-20  7:40                         ` Jan Kiszka
2011-05-20 11:25                           ` Gleb Natapov
2011-05-22  7:50                             ` Avi Kivity
2011-05-22  8:41                               ` Gleb Natapov
2011-05-22 10:53                                 ` Jan Kiszka
2011-05-22 11:29                                   ` Avi Kivity
2011-05-23  8:45                                     ` Gleb Natapov
2011-05-23 22:29                                 ` Jamie Lokier
2011-05-20  9:10             ` Avi Kivity
2011-05-20 12:08               ` Gleb Natapov
2011-05-22  7:56                 ` Avi Kivity

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=4DD3E1B3.3020405@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=avi@redhat.com \
    --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.