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

Re: [PATCH v1] xen/riscv: make calculation of stack address PC-relative


  • To: Oleksii <oleksii.kurochko@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 15 Mar 2023 08:35:11 +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=0hnuMzbqRd78MO1Ngzuc4RU7zLKlSx1G047bZaXZYsE=; b=TuHqWzFjUfMLso2v5MSe7IpVqchi4lnszGHDvGdqnW9mM7Xa0zmuVZBiek+2lxgRqj3avTjQsQ3KrB/HWy58cq4wEm4CdQC/9a6R3gWeDx/3RqeG6TfcJgc4SfX0w5gl7FS8tN7E4JYhI1CRQuPkpdykHRWYkSsY99NJAHSC+T+kNluLmRYIGQJxwA8mot+AH4v5mcNvuomGtnUJq3Vj7xZCg2bK6h+zVFUL2iI1KyPJngb40wyiWHAnESSiak6FVyPJf8AOCadTgCMbE/qg404Vm3Yt6bcYu2nbHHEXhUPsrvdn6kn0StEFQRJuAM5njZBIoLTzde2wXH9UjcZ8vA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WxdsJIaA540hYQXOUBGA/U9q6g95bwyYHn9gnUvQCNL5PvkbaZw57ozi6c4BdmeK2Hzd5gVb0gqoeefHPM5PG7dZEqG59da7FqQWcs4ia2D1xIAs+CofNqTdOahOWCTCj5LRQyuwdiGz++fwwUh51P21KZ+jaxLqAsoXyCj14JngDhpNQhwji6hNmqrcjfarvzxmh1MktD3qkfYQv+YBtuWJXied71bBdvg/nzbi9UpTT58PH1k6yLs4NHDdr5wNtbJBTAxMzZ1AZquZoKu2xlVDQcHPB05Pu5yKXI9P2tdwbO62hWI0oBu5gzHqgjnjaHhNUVwNTAl3GnkEM1MjJg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Gianluca Guida <gianluca@xxxxxxxxxxxx>, Bob Eshleman <bobbyeshleman@xxxxxxxxx>, Alistair Francis <alistair.francis@xxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Wed, 15 Mar 2023 07:35:22 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 14.03.2023 21:16, Oleksii wrote:
> On Tue, 2023-03-14 at 17:09 +0000, Andrew Cooper wrote:
>> On 14/03/2023 4:00 pm, Oleksii Kurochko wrote:
>>> The patch is needed to keep all addresses PC-relative.
>>>
>>> Pseudoinstruction 'la' can be transformed to 'auipc/addi' or
>>> 'auipc/l{w|d}'. It depends on the .option directive: nopic and pic.
>>>
>>> Right now, 'la' transforms to 'auipc/l{w|d}', which in case of
>>> cpu0_boot_stack[] will lead to the usage of _GLOBAL_OFFSET_TABLE_
>>> where all addresses will be without counting that it might happen
>>> that linker address != load address.
>>>
>>> To be sure that SP is loaded always PC-relative address
>>> 'la' should be changed to 'lla', which always transforms to
>>> 'auipc/addi'.
>>>
>>> Signed-off-by: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
>>> ---
>>>  xen/arch/riscv/riscv64/head.S | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/xen/arch/riscv/riscv64/head.S
>>> b/xen/arch/riscv/riscv64/head.S
>>> index 8887f0cbd4..e12d2a7cf3 100644
>>> --- a/xen/arch/riscv/riscv64/head.S
>>> +++ b/xen/arch/riscv/riscv64/head.S
>>> @@ -27,7 +27,7 @@ ENTRY(start)
>>>          add     t3, t3, __SIZEOF_POINTER__
>>>          bltu    t3, t4, .L_clear_bss
>>>  
>>> -        la      sp, cpu0_boot_stack
>>> +        lla     sp, cpu0_boot_stack
>>
>> I don't think this is the appropriate way forward.  It's very much
>> smells like duct tape hiding the real bug.
>>
> As an option, I thought to add in head.S '.option nopic' directive to
> make la translated to auipc/addi [1] pair.
> As an alternative option, adds to AFLAGS += -fno-PIC... but still...
> 
> I checked in Linux binary how 'la' instruction is transformed, and it
> looks like it is translated as I expect to auipc/addi pair:
> ffffffe000001066: 00027517 auipc a0,0x27
> ffffffe00000106a: f9a50513 addi a0,a0,-102 # ffffffe000028000
> <early_pg_dir>
> 
> I checked compiler flags between Xen and Linux. The difference is in-
> fno-PIE (Linux also adds -mabi and -march to AFLAGS):
> 
> 1. Linux build command of head.S: riscv64-linux-gnu-gcc -Wp,-
> MD,arch/riscv/kernel/.head.o.d -nostdinc -isystem /usr/lib/gcc-
> cross/riscv64-linux-gnu/9/include -I./arch/riscv/include -
> I./arch/riscv/include/generated -I./include -I./arch/riscv/include/uapi
> -I./arch/riscv/include/generated/uapi -I./include/uapi -
> I./include/generated/uapi -include ./include/linux/kconfig.h -
> D__KERNEL__ -D__ASSEMBLY__ -fno-PIE -mabi=lp64 -march=rv64imafdc -c -o
> arch/riscv/kernel/head.o arch/riscv/kernel/head.S
> 
> 2. Xen build command of head.S:riscv64-linux-gnu-gcc -MMD -MP -MF
> arch/riscv/riscv64/.head.o.d -D__ASSEMBLY__ -Wa,--noexecstack -
> DBUILD_ID -fno-strict-aliasing -Wall -Wstrict-prototypes -Wdeclaration-
> after-statement -Wno-unused-but-set-variable -Wno-unused-local-typedefs
> -O1 -fno-omit-frame-pointer -nostdinc -fno-builtin -fno-common -Werror
> -Wredundant-decls -Wno-pointer-arith -Wvla -pipe -D__XEN__ -include
> ./include/xen/config.h -Wa,--strip-local-absolute -g -mabi=lp64 -
> I./include -I./arch/riscv/include -march=rv64gc -mstrict-align -
> mcmodel=medany - -c arch/riscv/riscv64/head.S -o
> arch/riscv/riscv64/head.o
> 
> So can we update AFLAGS in xen/arch/riscv/arch.mk with -fno-PIE or will
> it still be an incorrect fix?

Leaving aside the question of why you and I see different code being
generated, isn't it simply a matter of RISC-V, unlike Arm and x86,
not presently consuming EMBEDDED_EXTRA_CFLAGS in its arch.mk?

Jan



 


Rackspace

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