Re: [PATCH] acpi: Set maximum size to 64k for "etc/acpi/rsdp" blob

2023-01-31 Thread Feng Sun
Michael S. Tsirkin  于2023年1月30日周一 23:07写道:
>
> On Mon, Jan 30, 2023 at 10:47:25PM +0800, Feng Sun wrote:
> > Igor Mammedov  于2023年1月24日周二 18:30写道:
> > >
> > > On Tue, 17 Jan 2023 19:15:21 +0800
> > > Sun Feng  wrote:
> > >
> > > > Migrate from aarch64 host with PAGE_SIZE 64k to 4k failed with 
> > > > following errors:
> > > >
> > > > qmp_cmd_name: migrate-incoming, arguments: {"uri": "tcp:[::]:49152"}
> > > > {"timestamp": {"seconds": 1673922775, "microseconds": 534702}, "event": 
> > > > "MIGRATION", "data": {"status": "setup"}}
> > > > {"timestamp": {"seconds": 1673922776, "microseconds": 53003}, "event": 
> > > > "MIGRATION", "data": {"status": "active"}}
> > > > 2023-01-17T02:32:56.058827Z qemu-system-aarch64: Length too large: 
> > > > /rom@etc/acpi/rsdp: 0x1 > 0x1000: Invalid argument
> > >
> > > this should mention/explain why it's happening.
> > >
> > > i.e we now have 4k limit for RSDP, but then source somehow managed to 
> > > start with 64k
> > > allocated to for RSDP. It looks like limit isn't working as expected to 
> > > me.
> >
> > 4k limit should be romsize limit. I can see Rom '/rom@etc/acpi/rsdp'
> > with romsize:4096, datasize:36.
> > RAMBlock's used_length is set with datasize aligned to PAGE_SIZE, so
> > it become 64k when PAGE_SIZE is 64k.
> > ```
> > static
> > RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
> >   void (*resized)(const char*,
> >   uint64_t length,
> >   void *host),
> >   void *host, uint32_t ram_flags,
> >   MemoryRegion *mr, Error **errp)
> > {
> > RAMBlock *new_block;
> > Error *local_err = NULL;
> >
> > assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC |
> >   RAM_NORESERVE)) == 0);
> > assert(!host ^ (ram_flags & RAM_PREALLOC));
> >
> > size = HOST_PAGE_ALIGN(size);
> > max_size = HOST_PAGE_ALIGN(max_size);
> > new_block = g_malloc0(sizeof(*new_block));
> > new_block->mr = mr;
> > new_block->resized = resized;
> > new_block->used_length = size;
> > ```
> > So when migrate to 4k PAGE_SIZE, it will report the errors.
> >
> > ramblock information for PAGE_SIZE 64k and 4k.
> > ```
> > # getconf PAGE_SIZE
> > 65536
> > # virsh qemu-monitor-command testvm --hmp 'info ramblock'
> >   Block NamePSize  Offset
> > Used  Total
> >mach-virt.ram   64 KiB  0x
> > 0x4000 0x4000
> >  virt.flash0   64 KiB  0x4000
> > 0x0400 0x0400
> >  virt.flash1   64 KiB  0x4400
> > 0x0400 0x0400
> > /rom@etc/acpi/tables   64 KiB  0x4804
> > 0x0002 0x0020
> > :00:01.2:00.0/virtio-net-pci.rom   64 KiB  0x4800
> > 0x0004 0x0004
> >/rom@etc/table-loader   64 KiB  0x4824
> > 0x0001 0x0001
> >   /rom@etc/acpi/rsdp   64 KiB  0x4828
> > 0x0001 0x0001
> >
> > # getconf PAGE_SIZE
> > 4096
> > # virsh qemu-monitor-command testvm --hmp 'info ramblock'
> >   Block NamePSize  Offset
> > Used  Total
> >mach-virt.ram4 KiB  0x
> > 0x0008 0x0008
> >  virt.flash04 KiB  0x0008
> > 0x0400 0x0400
> >  virt.flash14 KiB  0x00080400
> > 0x0400 0x0400
> > /rom@etc/acpi/tables4 KiB  0x00080800
> > 0x0002 0x0020
> >/rom@etc/table-loader4 KiB  0x00080820
> > 0x1000 0x0001
> >   /rom@etc/acpi/rsdp4 KiB  0x00080824
> > 0x1000 0x1000
> > ```
>
> Oh interesting. I don't remember why I decided to align in.
> What does the followi

Re: [PATCH] acpi: Set maximum size to 64k for "etc/acpi/rsdp" blob

2023-01-30 Thread Feng Sun
Igor Mammedov  于2023年1月24日周二 18:30写道:
>
> On Tue, 17 Jan 2023 19:15:21 +0800
> Sun Feng  wrote:
>
> > Migrate from aarch64 host with PAGE_SIZE 64k to 4k failed with following 
> > errors:
> >
> > qmp_cmd_name: migrate-incoming, arguments: {"uri": "tcp:[::]:49152"}
> > {"timestamp": {"seconds": 1673922775, "microseconds": 534702}, "event": 
> > "MIGRATION", "data": {"status": "setup"}}
> > {"timestamp": {"seconds": 1673922776, "microseconds": 53003}, "event": 
> > "MIGRATION", "data": {"status": "active"}}
> > 2023-01-17T02:32:56.058827Z qemu-system-aarch64: Length too large: 
> > /rom@etc/acpi/rsdp: 0x1 > 0x1000: Invalid argument
>
> this should mention/explain why it's happening.
>
> i.e we now have 4k limit for RSDP, but then source somehow managed to start 
> with 64k
> allocated to for RSDP. It looks like limit isn't working as expected to me.

4k limit should be romsize limit. I can see Rom '/rom@etc/acpi/rsdp'
with romsize:4096, datasize:36.
RAMBlock's used_length is set with datasize aligned to PAGE_SIZE, so
it become 64k when PAGE_SIZE is 64k.
```
static
RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
  void (*resized)(const char*,
  uint64_t length,
  void *host),
  void *host, uint32_t ram_flags,
  MemoryRegion *mr, Error **errp)
{
RAMBlock *new_block;
Error *local_err = NULL;

assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC |
  RAM_NORESERVE)) == 0);
assert(!host ^ (ram_flags & RAM_PREALLOC));

size = HOST_PAGE_ALIGN(size);
max_size = HOST_PAGE_ALIGN(max_size);
new_block = g_malloc0(sizeof(*new_block));
new_block->mr = mr;
new_block->resized = resized;
new_block->used_length = size;
```
So when migrate to 4k PAGE_SIZE, it will report the errors.

ramblock information for PAGE_SIZE 64k and 4k.
```
# getconf PAGE_SIZE
65536
# virsh qemu-monitor-command testvm --hmp 'info ramblock'
  Block NamePSize  Offset
Used  Total
   mach-virt.ram   64 KiB  0x
0x4000 0x4000
 virt.flash0   64 KiB  0x4000
0x0400 0x0400
 virt.flash1   64 KiB  0x4400
0x0400 0x0400
/rom@etc/acpi/tables   64 KiB  0x4804
0x0002 0x0020
:00:01.2:00.0/virtio-net-pci.rom   64 KiB  0x4800
0x0004 0x0004
   /rom@etc/table-loader   64 KiB  0x4824
0x0001 0x0001
  /rom@etc/acpi/rsdp   64 KiB  0x4828
0x0001 0x0001

# getconf PAGE_SIZE
4096
# virsh qemu-monitor-command testvm --hmp 'info ramblock'
  Block NamePSize  Offset
Used  Total
   mach-virt.ram4 KiB  0x
0x0008 0x0008
 virt.flash04 KiB  0x0008
0x0400 0x0400
 virt.flash14 KiB  0x00080400
0x0400 0x0400
/rom@etc/acpi/tables4 KiB  0x00080800
0x0002 0x0020
   /rom@etc/table-loader4 KiB  0x00080820
0x1000 0x0001
  /rom@etc/acpi/rsdp4 KiB  0x00080824
0x1000 0x1000
```

-- 
Best wishes!