From: Xi Ruoyao <xry111@xry111.site>
To: WANG Rui <wangrui@loongson.cn>
Cc: Huacai Chen <chenhuacai@kernel.org>,
WANG Xuerui <kernel@xen0n.name>,
linux-kernel@vger.kernel.org, loongarch@lists.linux.dev,
linux-kbuild@vger.kernel.org, llvm@lists.linux.dev,
loongson-kernel@lists.loongnix.cn,
Fangrui Song <maskray@google.com>
Subject: Re: [PATCH] LoongArch: Disable module from accessing external data directly
Date: Wed, 08 Nov 2023 17:46:46 +0800 [thread overview]
Message-ID: <de7c80a1e297fb1cddbca3972fe8c09a3b551b7a.camel@xry111.site> (raw)
In-Reply-To: <CAHirt9jRH1CKE=BUWpML_jNgTBvMfJiYoAYPnVS3E=89oBUVyw@mail.gmail.com>
On Wed, 2023-11-08 at 17:36 +0800, WANG Rui wrote:
> > xry111@nanmen2 ~ $ clang t1.c -O2 -fno-pie -no-pie
> > xry111@nanmen2 ~ $ ./a.out
> > Bus error (core dumped)
> >
> > I'll consider it a Clang bug then.
https://github.com/llvm/llvm-project/issues/71645
> That's it, no copy relocations. As far as I know, copying relocations
> has some issues and is not recommended by Fangrui.
>
> For modules, if distance is not a problem, `no-pic` and
> `direct-access-external-data` can be together because the code is
> writable. Does it seem reasonable to exist?
It may be usable, but the result is generally worse than relying on GOT.
For example, consider a module referring two data symbols in vmlinux,
foo and bar. The symbol foo is referred 10 times and bar is referred 8
times.
With the current GOT-based approach, the total space usage is (2 GOT
entry * (8 bytes / GOT entry)) + ((10 + 8) * 2 instruction * 4 (bytes /
instruction)) = 160 bytes.
With -fdirect-access-external-data, we must add -mcmodel=extreme too
because the modules are too far away from vmlinux in the kernel address
space, then the total space usage will be (10 + 8) * 5 instruction * 4
(bytes / instruction) = 360 bytes.
One possible approach to resolve the issue is relocating vmlinux from
XKPRANGE to XKVRANGE and fit vmlinux + all modules into a 2GiB range.
Then the total space usage will be (10 + 8) * 2 instruction * 4 (bytes /
instruction) = 144 bytes. But I don't know how to implement this, and
running vmlinux in XKVRANGE may have a performance penalty.
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
prev parent reply other threads:[~2023-11-08 9:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-08 4:04 WANG Rui
2023-11-08 8:30 ` Xi Ruoyao
2023-11-08 9:20 ` WANG Rui
2023-11-08 9:25 ` Xi Ruoyao
2023-11-08 9:36 ` WANG Rui
2023-11-08 9:39 ` WANG Rui
2023-11-08 9:46 ` Xi Ruoyao [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=de7c80a1e297fb1cddbca3972fe8c09a3b551b7a.camel@xry111.site \
--to=xry111@xry111.site \
--cc=chenhuacai@kernel.org \
--cc=kernel@xen0n.name \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=loongarch@lists.linux.dev \
--cc=loongson-kernel@lists.loongnix.cn \
--cc=maskray@google.com \
--cc=wangrui@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®