[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: Jan Beulich <jbeulich@xxxxxxxx>, Oleksii <oleksii.kurochko@xxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Wed, 15 Mar 2023 21:12:52 +0000
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.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=HJ2+jdfdbk0dsdjbDZzDJYagxTg2K7zg8bfeBXb6NFk=; b=HrdN6rNAdWvXHAxPnRNDkyvt4+kokJkk5Jhy0pxxGNJZlrbwmHUPaoZslczWUgiRprq90UnmKcGhSgPHLz9i2szFILe/1SquERWF6s7barG1vHvgvvawdUFPbt8132d+naWQ298OBWOssarAu15+53QiUz/U/JlhpgFrrqF+JRAAuKSoeCbIXqGwuoAS2Nn+X8AxKQKQA8tIEIV4TPrphFEBcGchvOLo9vUjv1RgbTmnB2aVGsGa30AudeFgoSfTB7b55iS6sjxyRt2Si2GHRXnV9vNPtEgWejFXXipmUBD5YfDDtcVYetHURxHUbUFRDWgj9FRi1RQmt/gzPoyhlg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ES5jtogeCKgB19iY0naByfyBfpvHQjJ33zwp/OBMkqIT8Rmxd98hvP2Xb+LBQ9g6OzJSGvRIMpasyZfBjFXdWBIT//mbdOB+3jk/UUfRi5D6vm4C6dCvlJwrFUacX6uW5GjWJRPJCHAZxbhlAht3bPOPOrvH8OdbOarufUfiXbVXOkvl3MhKzqcPrItGj0IXhJ3jNtdQc+NJrgRDLnJ4I55sjFvPfmJb8aCaTF8Pb2+dJwa0Zad6EiIJ5oBqXq0/zHWWKxm1khu4ze9AF9wajVttYzQwzOaZzklMOIKXMOd7RZGbvXd2oEOqwiVy6EpCV1UtGPZ2mdojGXxcxMRTQA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: 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: Wed, 15 Mar 2023 21:13:15 +0000
  • Ironport-data: A9a23:aqhSjq7i5Qb91/buAmoNdQxRtIzGchMFZxGqfqrLsTDasY5as4F+v jQcW2yPbKuDMzbxfo9+Pd++oRgCvsXSxt9nSQdpqSpjHi5G8cbLO4+Ufxz6V8+wwm8vb2o8t plDNYOQRCwQZiWBzvt4GuG59RGQ7YnRGvynTraCYnsrLeNdYH9JoQp5nOIkiZJfj9G8Agec0 fv/uMSaM1K+s9JOGjt8B5mr9VU+7JwehBtC5gZlPasS4QeE/5UoJMl3yZ+ZfiOQrrZ8RoZWd 86bpJml82XQ+QsaC9/Nut4XpWVTH9Y+lSDX4pZnc/DKbipq/0Te4Y5iXBYoUm9Fii3hojxE4 I4lWapc6+seFvakdOw1C3G0GszlVEFM0OevzXOX6aR/w6BaGpdFLjoH4EweZOUlFuhL7W5m8 vkSczlWZy65wM2ux7ahFONHvt0JM5y+VG8fkikIITDxK98DGMiGZpqQoNhS0XE3m9xEGuvYa 4wBcz1zYR/cYhpJfFAKFJY5m+TujX76G9FagAvN+exrvC6OkUooiOSF3Nn9I7RmQe18mEqCq 32A1GP+GhwAb/SUyCaf82LqjejK9c/+cNtKTeHjr6Ex2TV/wERULgYsT1+npcWmm2+4ft52M kMf8Xoh+P1aGEuDC4OVsweDiHyOswMYWtFQO/Yn8wzLwa3Riy6eAmUHVT9ALt87rsg9RT8t/ lCMltLtQzdotdW9UmmB/72ZqTezPyk9LmIYYyIACwwf7LHLr4A6iBbSRd9LCq+ricb0Hzq2y DePxAA0gL8ZnMMQ16G2+FnBqz2pr5nNCAUy423/V2ak9R9wZZTjaZah71Pa9t5fII3fRV6E1 FAPnM6Y6+ICBI+MjwSCRewMGPei4PPtGC3RhxtjEocs8xyp+mW/ZsZA7TdmPkBrP80YPzjzb yfuVRh54ZZSOD6vcvVxaofoU8Ayl/G4SZLiS+zeacdIbt5pbgib8SpyZEmWmWfwjEwrlqJ5M pCeGSqxMUsn5W1c5GLeb48gPXUDnEjSGUu7qUjH8ima
  • Ironport-hdrordr: A9a23:fEIqKq2ak8zuBC5qUPtXqgqjBJ8kLtp133Aq2lEZdPU1SL3kqy nKpp4mPHDP+VIssR0b6LO90ey7MBXhHP1OkPMs1MmZLW7bUQKTRekIjbcKgQeQYhEWkNQtrZ uIG5IeNDSaNykesS+V2njbLz9t+qj9zElqv4vjJrVWID2Cp5sO0+6xMGimLnE=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 15/03/2023 7:59 am, Jan Beulich wrote:
> On 14.03.2023 21:16, Oleksii wrote:
>> 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
> Looking into why you see different code generated than I: Nothing in
> here directs gcc to pass -fpic to gas; in upstream gcc (consistent
> from gcc7 through gcc12, which are the versions I've checked; the
> actual range may be wider) there is
>
> #define ASM_SPEC "\
> %(subtarget_asm_debugging_spec) \
> %{" FPIE_OR_FPIC_SPEC ":-fpic} \
> ...
>
> Can you check whether your gcc passes -fpic to gas even when there's
> no -fPIC / -fPIE (or alike) on the gcc command line? Or whether your
> gas (unlike upstream's) defaults to PIC mode? (For .S files ASM_SPEC
> is all that counts. For .c files gcc is redundantly passing -fpic
> along with also emitting ".option pic" or, in the opposite case, it
> is omitting -fpic along with emitting ".option nopic".)
>
> You gcc may have been configured with --enable-default-pie, while I
> know mine hasn't been (simply because that's the default).

>From the thread, the difference is clearly around the pie option, but I
have to admit that I'm confused.

With GCC 10 from Debian repos and current staging (modulo the build
fix), we end up with:

0000000080200000 <_start>:
    80200000:   10401073                csrw    sie,zero
    80200004:   00002117                auipc   sp,0x2
    80200008:   00413103                ld      sp,4(sp) # 80202008
<_GLOBAL_OFFSET_TABLE_+0x8>
    8020000c:   6285                    lui     t0,0x1
    8020000e:   9116                    add     sp,sp,t0
    80200010:   7f10206f                j       80203000 <start_xen>

In this case, the auipc/ld pair makes a PC-relative reference into the
GOT, but the pointer spilled into the GOT is the link time address of
cpu0_boot_stack.

For the executable as a whole, we've got:

[ 6] .got              PROGBITS        0000000080202000 003000 000010
08  WA  0   0  8
[ 7] .got.plt          PROGBITS        0000000080202010 003010 000010
08  WA  0   0  8

i.e. both nonzero in size, so presumably with expectations of something
else to fix up the references.

I suspect we want to extend the x86 section asserts into the other
architectures too, alongside figuring out how exactly to disable code
generation of this form.

~Andrew



 


Rackspace

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