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

Re: [PATCH v4] xen/riscv: PE/COFF image header for RISC-V target


  • To: Milan Đokić <milandjokic1995@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 10 Jul 2024 17:13:11 +0200
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: milan.djokic@xxxxxxxxx, Alistair Francis <alistair.francis@xxxxxxx>, Bob Eshleman <bobbyeshleman@xxxxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, Nikola Jelic <nikola.jelic@xxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx, Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
  • Delivery-date: Wed, 10 Jul 2024 15:13:23 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 10.07.2024 16:44, Milan Đokić wrote:
> On Mon, Jul 8, 2024 at 11:32 AM Jan Beulich <jbeulich@xxxxxxxx> wrote:
>> On 04.07.2024 19:21, Milan Đokić wrote:
>>> On Wed, Jul 3, 2024 at 5:55 PM Jan Beulich <jbeulich@xxxxxxxx> wrote:
>>>> On 03.07.2024 02:04, Milan Djokic wrote:
>>>>> +#ifdef CONFIG_RISCV_EFI
>>>>> +        /*
>>>>> +         * This instruction decodes to "MZ" ASCII required by UEFI.
>>>>> +         */
>>>>> +        c.li s4,-13
>>>>> +        c.j xen_start
>>>>> +#else
>>>>> +        /* jump to start kernel */
>>>>> +        jal xen_start
>>>>
>>>> JAL, not J? Why?
>>>>
>>> We use jal explicitly here to highlight that we want to occupy 32 bits
>>> in order to align with header format (and EFI case where we use two
>>> 16-bits instructions). Although it will also work by using "j"
>>> directly, it could be implicitly compressed to 16 bits (if C extension
>>> is available) which would make header layout less obvious imo.
>>
>> According to e.g. ...
>>
>>>>> +#endif
>>>>> +        .balign 8
>>>>
>>>> This won't do what you want unless "start" itself is also suitably aligned.
>>>> It'll be as long as it's first in the section, but better make such 
>>>> explicit.
>>>>
>>> I understand, we'll also explicitly align "start"
>>>
>>>>> +#ifdef CONFIG_RISCV_64
>>>>> +        /* Image load offset(2MB) from start of RAM */
>>>>> +        .quad 0x200000
>>>>> +#else
>>>>> +        /* Image load offset(4MB) from start of RAM */
>>>>> +        .quad 0x400000
>>>>> +#endif
>>
>> ... the #ifdef here, you aim at having code be suitable for RV32, too.
>> However, JAL has a compressed form there, so its use would make things
>> "less obvious" there as well. I'm inclined to say that since the
>> subsequent ".balign 8" adds padding NOPs anyway, there's no real
>> difference whether that adds 32 bits worth of NOPs or 48 bits. If you
>> really wanted to "hide" the difference, imo ".balign 4" would be the
>> way to go.
>>
>> In any event, if there would still be a reason to stick to JAL, you'd
>> want to name the reason(s) in a code comment.
>>
> No specific reason to use jal from a functional point of view, just
> aesthetic reasons as I mentioned in a previous comment. Also jal is
> used across head.S file, so we also keep some consistency in that
> manner. I just don't get the reason why "j" is more suitable as a
> pseudo instruction since it also comes down to jal as a base
> instruction.
> Of course, we can easily switch to "j" here, just want to know why we
> are doing so.

Consistency with the other path, which uses C.J. Plus avoiding questions
along the lines of mine: Why JAL when this isn't a function call, but a
plaing branch?

>>>>> --- /dev/null
>>>>> +++ b/xen/include/efi/pe.h
>>>>> [...]
>>> Regarding pe.h file content, we wanted to keep it as generic as
>>> possible (structures definition according to PE format which can be
>>> used for multiple architectures). Specifically for RISC-V as you
>>> noticed, we are not using lots of structures (data directories,
>>> relocation structures, certificates, etc.). Therefore, we can reduce
>>> it to only those used atm, but in that case we won't have a generic PE
>>> header definition anymore. Regarding structures which are already
>>> defined in common/efi/pe.c, meaning that with our change we have two
>>> versions of same structures, we can remove those, but in that case it
>>> could be confusing for someone who is trying to map fields from pe.h
>>> to actual image header in assembly code. Summary I would keep this
>>> header with its original content, but if you think that it contains
>>> too much overhead we can reduce it to relevant structures only.
>>
>> Actually I not only don't mind this header, but would consider it
>> superior to the present state of things. Just that then imo it would
>> want introducing in a separate commit, with suitable description /
>> justification. That could (should) then be followed by a patch using
>> this header's struct-s / definitions in pre-existing code, purging
>> any duplication from there.
>>
> So we should have one commit for pe.h only, a subsequent commit where
> x86 implementation is modified to use structures from pe.h and a third
> commit where we add EFI stub for RISC-V?

That's (in my view) the minimum level of splitting, yes.

> And we can submit the first two commits separately from the RISC-V EFI
> stub for which we'll wait on @Oleksii opinion on whether EFI
> application format is needed upstream?

Yes. I also wouldn't insist on the conversion part to be done right
away, just as long as it gets done not too far in the future.

However, since you say "whether": Imo the question isn't whether we need
that (the answer there is Yes as long as EFI exists for RISC-V), but
what form it should take. If we can properly link an EFI binary, I'd
generally consider this preferable over any hand crafting. Yet of course
there may be reasons why using the tool chain has to be ruled out.

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.