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

Re: [PATCH] xen/riscv: read hart_id and dtb_base passed by bootloader


  • To: Oleksii <oleksii.kurochko@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 27 Feb 2023 10:17:33 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=j3qglYFZaUD1bDSZZCZB0gxJ7jhLbH3ufQj9cipEW30=; b=OZVYHZZXO/Tm4kYOwGSlcV643MoUiXL1mg6EuyC5eiq6nMPv1C3xhYJwWOGc81yoCHFtSZhYSX8LjPXXzc7IHIfr5k9hkKYYkthMrz+PB+HKMe38rIsLfoCNI20lGKeW08mFH9g0PoauO35u34BNscaDdQ/inRx8xsFNKuKw6CV1vVAFYieG25AIHx9SodW66tBbVj/P0ZbscN/MzLT86y8G8B0cboEwpxo5Vs/76b+bVxBJ3/ACwSGJKD43NwnqaXcH+13OmFzadsnCF0GE+UKJHCYpqDGB4VWaS03oRkfr/h1+xHCxul+/GEtluXFpZD+3G8f7hsVZ3R4jpr7MCg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I7vIUuAETdJhprn60R/Mo4Mi9t2L5LbqOb7HvCCk7dh/dO4lcjP1U2zLy0gd+RKnUbuFACJC9Y/fNCgy0mLO6hnN/tWc2jyadTDRQJC5u+jnaLc0S8cuZxpqtsWRNxMkzhbHn+1L5K9P9xSA7GeDryyoFTbIAaDFoFgC1DVjUQs4e9cH/EngaG/Ddf3A2HS0ce8Xbvyk8qHqQzKD7xOPnUVC/l1NPEQlAS9n2xjmc35JRtuzcAXnZa64mWkkT+F+DgS+iKhtfpgR9d5Ly7Dgbwrlx3qADMToNT1LF6E98Yd8HD8442Uy54zQ26Yqvz63C9L/KDYiFS9aMvO5mCmayg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Gianluca Guida <gianluca@xxxxxxxxxxxx>, Bob Eshleman <bobbyeshleman@xxxxxxxxx>, Alistair Francis <alistair.francis@xxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Mon, 27 Feb 2023 09:17:45 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 24.02.2023 17:36, Oleksii wrote:
> On Fri, 2023-02-24 at 16:04 +0100, Jan Beulich wrote:
>> On 24.02.2023 15:48, Oleksii Kurochko wrote:
>>> Signed-off-by: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
>>> ---
>>>  xen/arch/riscv/setup.c | 12 ++++++++++++
>>>  1 file changed, 12 insertions(+)
>>>
>>> diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c
>>> index b3f8b10f71..154bf3a0bc 100644
>>> --- a/xen/arch/riscv/setup.c
>>> +++ b/xen/arch/riscv/setup.c
>>> @@ -26,6 +26,18 @@ static void test_macros_from_bug_h(void)
>>>  
>>>  void __init noreturn start_xen(void)
>>>  {
>>> +    /*
>>> +     * The following things are passed by bootloader:
>>> +     *   a0 -> hart_id
>>> +     *   a1 -> dtb_base
>>> +    */
>>> +    register unsigned long hart_id  asm("a0");
>>> +    register unsigned long dtb_base asm("a1");
>>> +
>>> +    asm volatile( "mv %0, a0" : "=r" (hart_id) );
>>> +
>>> +    asm volatile( "mv %0, a1" : "=r" (dtb_base) );
>>
>> Are you sure this (a) works and (b) is what you want? You're
>> inserting
> Oh, yeah... it should be:
>   unsigned long hart_id;
>   unsigned long dtb_base;

As per below - no, I don't think so. I continue to think these want
to be function parameters.

> I did experiments with 'register' and 'asm()' and after rebase of my
> internal branches git backed these changes...
> 
> Sorry for that I have to double check patches next time.
> 
> It looks like it works only because the variables aren't used anywhere.
>> "mov a0, a0" and "mov a1, a1". I suppose as long as the two local
>> variables aren't used further down in the function, the compiler will
>> be able to recognize both registers as dead, and hence use them for
>> argument passing to later functions that you call. But I would expect
>> that to break once you actually consume either of the variables.
>>
>> Fundamentally I think this is the kind of thing you want do to in
>> assembly. However, in the specific case here, can't you simply have
>>
>> void __init noreturn start_xen(unsigned long hard_id,
>>                                unsigned long dtb_base)
>> {
>>     ...
>>
>> and all is going to be fine, without any asm()?
> One of the things that I would like to do is to not use an assembler as
> much as possible. And as we have C environment ready after a few
> assembly instructions in head.S I thought it would be OK to do it in C
> code somewhere at the start so someone/sonething doesn't alter register
> a0 and a1.

Avoiding assembly code where possible if of course appreciated, because
generally C code is easier to maintain. But of course this can only be
done if things can be expressed correctly. And you need to keep in mind
that asm() statements also are assembly code, just lower volume.

Jan



 


Rackspace

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