qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] hppa: allow max ram size upto 4Gb


From: Igor Mammedov
Subject: Re: [PATCH v2] hppa: allow max ram size upto 4Gb
Date: Tue, 7 Jan 2020 12:21:27 +0100

On Mon, 6 Jan 2020 18:03:49 +0100
Helge Deller <address@hidden> wrote:

> On 06.01.20 17:24, Igor Mammedov wrote:
> > On Mon, 6 Jan 2020 12:28:51 +0100
> > Helge Deller <address@hidden> wrote:
> >  
> >> On 06.01.20 11:48, Igor Mammedov wrote:  
> >>> On Sat, 4 Jan 2020 16:00:19 +0100
> >>> Philippe Mathieu-Daudé <address@hidden> wrote:
> >>>  
> >>>> On 1/3/20 10:54 AM, Igor Mammedov wrote:  
> >>>>> On Thu, 2 Jan 2020 21:22:12 +0100
> >>>>> Helge Deller <address@hidden> wrote:
> >>>>>  
> >>>>>> On 02.01.20 18:46, Igor Mammedov wrote:  
> >>>>>>> Previous patch drops silent ram_size fixup and makes
> >>>>>>> QEMU error out with:
> >>>>>>>
> >>>>>>>   "RAM size more than 3840m is not supported"
> >>>>>>>
> >>>>>>> when user specified -m X more than supported value.
> >>>>>>>
> >>>>>>> User shouldn't be bothered with starting QEMU with valid CLI,
> >>>>>>> so for the sake of user convenience allow using -m 4G vs -m 3840M.
> >>>>>>>
> >>>>>>> Requested-by: Helge Deller <address@hidden>
> >>>>>>> Signed-off-by: Igor Mammedov <address@hidden>
> >>>>>>> ---
> >>>>>>> v2:
> >>>>>>>    - make main ram -1 prio, so it wouldn't conflict with other regions
> >>>>>>>      starting from 0xf9000000
> >>>>>>>
> >>>>>>> I dislike it but if you feel it's really necessary feel free to ack 
> >>>>>>> it.  
> >>>>
> >>>> Hard to find the v2 buried in the other series with my email client.
> >>>>  
> >>>>>>>
> >>>>>>> should be applied on top of:
> >>>>>>>    "hppa: drop RAM size fixup"  
> >>>>>>
> >>>>>> Hello Igor,
> >>>>>> I appreciate that you are trying to make it more cleaner.
> >>>>>> But, can't you merge both of your patches to one patch?
> >>>>>> Right now you have one patch "hppa: drop RAM size fixup", which is
> >>>>>> what I think is wrong. Then you add another one which somehow
> >>>>>> fixes it up again and adds other stuff.  
> >>>>> 1st patch bring it in line with other boards adding
> >>>>> proper error check but without changing RAM size.
> >>>>> While 2nd is changing device model (mapped RAM size) and
> >>>>> clearly documents that it's a hack for user convenience,
> >>>>> Hence I'd prefer to keep both separated.
> >>>>>  
> >>>>>> Having everything in one single patch makes your full change more
> >>>>>> understandable.
> >>>>>>
> >>>>>> Is it necessary to introduce clamped_ram_size and not continue with
> >>>>>> ram_size (even if you would add it as static local variable)?  
> >>>>> it's necessary since ram_size is global which should be kept == 
> >>>>> MachineState::ram_size.
> >>>>> Later on I plan to remove the former altogether and maybe
> >>>>> MachineState::ram_size aa well, since it could be read with
> >>>>> memory_region_size(MachineState::ram).  
> >>>>
> >>>> Why insist on clamping the ram? We recommend to model what the hardware
> >>>> does, and the hardware uses a full DIMM of DRAM, so 4GB, not less.  
> >>> I'm not adding 4Gb support here (it's out of scope of this series),
> >>> all this patch does is making pre-existing global ram_size fixup,
> >>> this board only business and naming it clamped_ram_size to match
> >>> its current usage  
> >>
> >> Ok.
> >>  
> >>> (along with explicitly documenting the deviation from
> >>> other boards why it was requested to keep fixup 'for user convenience'
> >>> instead of going for correct and simpler error message telling
> >>> how much RAM user could specify on CLI).  
> >>
> >> No, here you are wrong.
> >> This machine, same as all 32-bit x86 based machines, expect users
> >> to insert memory modules of e.g. 1GB, 2GB and so on.
> >> And ROM memory and other regions overlap the RAM in some regions
> >> if required.
> >> So, it's not "user convenience", but it's correct behaviour of the
> >> code to simply allow 4GB and then don't blend in the memory which can't
> >> be accessed.
> >> Giving a error message that "you can only insert 3841MB" would be WRONG.
> >>  
> >>>> What are the new problem introduced by using 4GB? I only see advantages
> >>>> doing so. This doesn't break your series. This doesn't break the CLI.
> >>>> Am I missing something?  
> >>>
> >>> Well, board was fixing up global ram_size and then used it to
> >>>  - pass clamped value to guest via register
> >>>  - pass it to load load_image_targphys()
> >>>  - perform various checks
> >>>  - affects reset sequence  
> >>
> >> ... which is all OK, because it mimics the real hardware.
> >>  
> >>> This patch keeps all of that in the same state
> >>> (I'd suspect changing above points, would break guest)  
> >>
> >> Yep (unless I change the SeaBIOS ROM code).  
> 
> > Does real HW pass in cpu[0]->env.gr[26] full 4Gb or clamped size?  
> 
> No, because of the simple reason that real hardware uses a
> propriatary HP Firmware, and that it's not started from some emulation
> layer like qemu. So it has to find way itself to detect how much RAM
> was plugged into the machine.
> 
> The functionality of giving the ram size in %r26 was done by me,
> otherwise I don't know how SeaBIOS should detect how much RAM the
> user wanted the machine to have. That's changeable if you have another
> idea. Doesn't on x86 the ram size is given in some emulated RTC register?

In x86 case, there is RTC value and there is memory map provided via
paravirt fwcfg.

Using register is fine for passing total RAM size and
Since it's QEMU invention, we could pass full 4Gb in register as
a starting point to support 4Gb of RAM (which removes fixup) and
let SeaBIOS to deduce memory map from that.

Then this patch cloud be amended to:
"
hpp: support 4G of RAM

Real hardware allows to plug in up to 4Gb of RAM
into memory slots, add support for this.
"

> >> Anyway, I'm tired to discuss this.
> >> Your patch isn't wrong by itself, I just think it's changing unnecessary
> >> too much code and uses wrong wording for the commit message.  
> 
> > Let me prepare v3 which hopefully will make is smaller and
> > with commit message corrected.
> > How about following wording:
> > "
> >     hppa: allow max ram size upto 4Gb
> >
> >     Previous patch drops silent ram_size fixup and makes
> >     QEMU error out with:
> >
> >      "RAM size more than 3840m is not supported"
> >
> >     when user specified -m X more than currently supported
> >     value.
> >
> >     However real hardware allows to plug in up to 4Gb RAM
> >     into memory slots. So allow user specify up to 4Gb and
> >     map all of it into guest address space.
> >
> > PS:
> >     guest will still see 3840m being reported in
> >     cpu[0]->env.gr[26] and loose ~248Mb, as it doesn't
> >     have other means to discover RAM above firmware ROM.
> > "  
> 
> Why make it so complicated?

It describes what exactly patch does without masking any
consequences of used approach (since we are not really telling
guest that it has more RAM and guest has other means to discover
it).

If you are asking why I'm making it hard error, see cover letter.
(in short main RAM allocation is total mess and series fixes
that by consolidating, de-duplicating and replacing ad hoc allocation
with a centralized approach that allows user to specify used
RAM backend in generic case).

> I see:
> +    if (machine->ram_size > 4 * GiB) {
> +        error_report("RAM size more than 4Gb is not supported");
> 
> what type is machine->ram_size?
> If it's a 32bit unsigned integer this check is useless, and if it's a 64bit
> integer it would be too big for a 32bit-only platform anyway.

it's ram_addr_t, which is mutable depending on the host
it could be 32-bit or 64-bit.

Currently QEMU doesn't have a generic code to do such
checks and QEMU accumulated a whole zoo where some boards
do checks, some mask incorrect -m values and some do don't
do any checks. But cleaning up that is out of scope of
this already big enough re-factoring.
Hence I'm adding checks/removing fixups where they were
missing/present as it's a minimum effort needed to generalize
main RAM allocation.

> So, I'd suggest to drop your wrong patch #43.
As you noted in your first reply, patch is correct.
All it's doing is validating user input versus RAM size
actually supported by the current code, telling user
current supported limit and enforcing it.

I agree it's inconvenience for the users since they
won't be able to specify non-sense values and still
get board running, but that's clear user error and
should be corrected on user side and not by QEMU
magically masking wrong CLI values.
Since it could be fixed on user side, I care less
about user convenience when it comes to correctness
and unified code.
 
> If you don't want to drop it, my suggestion for a commit message is:
> 
> hppa: Revert last wrong patch and give warning if user specified > 4GB RAM

I have to disagree on definition of wrong here,
in my opinion covering up user errors is wrong especially
when all users have to do is to adapt their CLI.

Supporting 4Gb is another story, which is extending current
impl. and could be done on top of the ram_size check.

> Helge
> 
> >  
> >> But just apply it as long as it doesn't break anything.
> >>
> >> Helge
> >>  
> >>> If you have an alternative patch that enables to use full 4Gb,
> >>> I'd include on respin as far as it doesn't change user supplied
> >>> global ram_size && ms->ram_size && uses generic ms->ram &&
> >>> preferably on top of
> >>>  "[PATCH 44/86] hppa: use memdev for RAM"
> >>> so it would be easier to drop it if there would opposition to it
> >>> without affecting series.
> >>>  
> >>>>>>> ---
> >>>>>>>   hw/hppa/machine.c | 21 +++++++++++----------
> >>>>>>>   1 file changed, 11 insertions(+), 10 deletions(-)
> >>>>>>>
> >>>>>>> diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c
> >>>>>>> index ebbf44f..0302983 100644
> >>>>>>> --- a/hw/hppa/machine.c
> >>>>>>> +++ b/hw/hppa/machine.c
> >>>>>>> @@ -54,6 +54,7 @@ static uint64_t cpu_hppa_to_phys(void *opaque, 
> >>>>>>> uint64_t addr)
> >>>>>>>
> >>>>>>>   static HPPACPU *cpu[HPPA_MAX_CPUS];
> >>>>>>>   static uint64_t firmware_entry;
> >>>>>>> +static ram_addr_t clamped_ram_size;
> >>>>>>>
> >>>>>>>   static void machine_hppa_init(MachineState *machine)
> >>>>>>>   {
> >>>>>>> @@ -74,8 +75,6 @@ static void machine_hppa_init(MachineState *machine)
> >>>>>>>       long i;
> >>>>>>>       unsigned int smp_cpus = machine->smp.cpus;
> >>>>>>>
> >>>>>>> -    ram_size = machine->ram_size;
> >>>>>>> -
> >>>>>>>       /* Create CPUs.  */
> >>>>>>>       for (i = 0; i < smp_cpus; i++) {
> >>>>>>>           char *name = g_strdup_printf("cpu%ld-io-eir", i);
> >>>>>>> @@ -90,12 +89,14 @@ static void machine_hppa_init(MachineState 
> >>>>>>> *machine)
> >>>>>>>       }
> >>>>>>>
> >>>>>>>       /* Limit main memory. */
> >>>>>>> -    if (ram_size > FIRMWARE_START) {
> >>>>>>> -        error_report("RAM size more than %d is not supported", 
> >>>>>>> FIRMWARE_START);
> >>>>>>> +    if (machine->ram_size > 4 * GiB) {
> >>>>>>> +        error_report("RAM size more than 4Gb is not supported");
> >>>>>>>           exit(EXIT_FAILURE);
> >>>>>>>       }
> >>>>>>> +    clamped_ram_size = machine->ram_size > FIRMWARE_START ?
> >>>>>>> +        FIRMWARE_START : machine->ram_size;
> >>>>>>>
> >>>>>>> -    memory_region_add_subregion(addr_space, 0, machine->ram);
> >>>>>>> +    memory_region_add_subregion_overlap(addr_space, 0, machine->ram, 
> >>>>>>> -1);
> >>>>>>>
> >>>>>>>       /* Init Dino (PCI host bus chip).  */
> >>>>>>>       pci_bus = dino_init(addr_space, &rtc_irq, &serial_irq);
> >>>>>>> @@ -151,7 +152,7 @@ static void machine_hppa_init(MachineState 
> >>>>>>> *machine)
> >>>>>>>       qemu_log_mask(CPU_LOG_PAGE, "Firmware loaded at 0x%08" PRIx64
> >>>>>>>                     "-0x%08" PRIx64 ", entry at 0x%08" PRIx64 ".\n",
> >>>>>>>                     firmware_low, firmware_high, firmware_entry);
> >>>>>>> -    if (firmware_low < ram_size || firmware_high >= FIRMWARE_END) {
> >>>>>>> +    if (firmware_low < clamped_ram_size || firmware_high >= 
> >>>>>>> FIRMWARE_END) {
> >>>>>>>           error_report("Firmware overlaps with memory or IO space");
> >>>>>>>           exit(1);
> >>>>>>>       }
> >>>>>>> @@ -204,7 +205,7 @@ static void machine_hppa_init(MachineState 
> >>>>>>> *machine)
> >>>>>>>                  (1) Due to sign-extension problems and PDC,
> >>>>>>>                  put the initrd no higher than 1G.
> >>>>>>>                  (2) Reserve 64k for stack.  */
> >>>>>>> -            initrd_base = MIN(ram_size, 1 * GiB);
> >>>>>>> +            initrd_base = MIN(clamped_ram_size, 1 * GiB);
> >>>>>>>               initrd_base = initrd_base - 64 * KiB;
> >>>>>>>               initrd_base = (initrd_base - initrd_size) & 
> >>>>>>> TARGET_PAGE_MASK;
> >>>>>>>
> >>>>>>> @@ -232,7 +233,7 @@ static void machine_hppa_init(MachineState 
> >>>>>>> *machine)
> >>>>>>>        * various parameters in registers. After firmware 
> >>>>>>> initialization,
> >>>>>>>        * firmware will start the Linux kernel with ramdisk and 
> >>>>>>> cmdline.
> >>>>>>>        */
> >>>>>>> -    cpu[0]->env.gr[26] = ram_size;
> >>>>>>> +    cpu[0]->env.gr[26] = clamped_ram_size;  
> >>>>
> >>>> Helge, is this the code using this register?
> >>>>
> >>>> https://github.com/hdeller/seabios-hppa/blob/parisc-qemu-5.0/src/parisc/head.S#L139
> >>>>  
> >>>>>>>       cpu[0]->env.gr[25] = kernel_entry;
> >>>>>>>
> >>>>>>>       /* tell firmware how many SMP CPUs to present in inventory 
> >>>>>>> table */
> >>>>>>> @@ -255,11 +256,11 @@ static void hppa_machine_reset(MachineState *ms)
> >>>>>>>       }
> >>>>>>>
> >>>>>>>       /* already initialized by machine_hppa_init()? */
> >>>>>>> -    if (cpu[0]->env.gr[26] == ram_size) {
> >>>>>>> +    if (cpu[0]->env.gr[26] == clamped_ram_size) {
> >>>>>>>           return;
> >>>>>>>       }
> >>>>>>>
> >>>>>>> -    cpu[0]->env.gr[26] = ram_size;
> >>>>>>> +    cpu[0]->env.gr[26] = clamped_ram_size;
> >>>>>>>       cpu[0]->env.gr[25] = 0; /* no firmware boot menu */
> >>>>>>>       cpu[0]->env.gr[24] = 'c';
> >>>>>>>       /* gr22/gr23 unused, no initrd while reboot. */
> >>>>>>>  
> >>>>>>  
> >>>>>  
> >>>>  
> >>>  
> >>
> >>  
> >  
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]