Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Olivain <ju.o@free.fr>
To: Dave Young <dyoung@redhat.com>
Cc: kexec@lists.infradead.org
Subject: Re: [PATCH 1/1] kexec: provide a memfd_create() wrapper if not present in libc
Date: Sat, 30 Sep 2023 13:46:55 +0200	[thread overview]
Message-ID: <4e1afe7fc304c2582a91afa2c1b32f24@free.fr> (raw)
In-Reply-To: <CALu+AoQw_kwWi97ntkmQ+VCrkQdPSFhjwCuc-9BZso=op11PWw@mail.gmail.com>

Hi Dave,

On 27/09/2023 08:45, Dave Young wrote:
> On Sun, 24 Sept 2023 at 00:47, Julien Olivain <ju.o@free.fr> wrote:
>> 
>> Commit 714fa115 "kexec/arm64: Simplify the code for zImage" introduced
>> a use of the memfd_create() system call, included in version
>> kexec-tools v2.0.27.
>> 
>> This system call was introduced in kernel commit [1], first included
>> in kernel v3.17 (released on 2014-10-05).
>> 
>> The memfd_create() glibc wrapper function was added much later in
>> commit [2], first included in glibc version 2.27 (released on
>> 2018-02-01).
>> 
>> This direct use memfd_create() introduced a requirement on
>> Kernel >= 3.17 and glibc >= 2.27.
>> 
>> There is old toolchains like [3] for example (which ships gcc 7.3.1,
>> glibc 2.25 and includes kernel v4.10 headers), that can still be used
>> to build newer kernels. Even if such toolchains can be seen as
>> outdated, they are is still claimed as supported by recent kernel.
>> For example, Kernel v6.5.5 has a requirement on gcc version 5.1 and
>> greater. See [4].
>> 
>> Moreover, kexec-tools <= 2.0.26 could be compiled using recent
>> toolchains with alternative libc (e.g. uclibc-ng, musl) which are not
>> providing the memfd_create() wrapper.
>> 
>> When compiling kexec-tools v2.0.27 with a toolchain not providing the
>> memfd_create() syscall wrapper, the compilation fail with message:
>> 
>>     kexec/kexec.c: In function 'copybuf_memfd':
>>     kexec/kexec.c:645:7: warning: implicit declaration of function 
>> 'memfd_create'; did you mean 'SYS_memfd_create'? 
>> [-Wimplicit-function-declaration]
>>       fd = memfd_create("kernel", MFD_ALLOW_SEALING);
>>            ^~~~~~~~~~~~
>>            SYS_memfd_create
>>     kexec/kexec.c:645:30: error: 'MFD_ALLOW_SEALING' undeclared (first 
>> use in this function); did you mean '_PC_ALLOC_SIZE_MIN'?
>>       fd = memfd_create("kernel", MFD_ALLOW_SEALING);
>>                                   ^~~~~~~~~~~~~~~~~
>>                                   _PC_ALLOC_SIZE_MIN
>> 
>> In order to let kexec-tools compile in a wider range of 
>> configurations,
>> this commit adds a memfd_create() function check in autoconf configure
>> script, and adds a system call wrapper which will be used if the
>> function is not available. With this commit, the environment
>> requirement is relaxed to only kernel >= v3.17.
>> 
>> Note: this issue was found in kexec-tools integration in Buildroot [5]
>> using the command "utils/test-pkg -a -p kexec", which tests many
>> toolchain/arch combinations.
> 
> I guess maybe the test was done on non x86 arch,  when I tried to
> build on old versions
> I got another failure of lacking "getrandom".    Only quickly did a
> build test with commenting out
> the getrandom code, the build passed with your patch.

Thanks for testing!

Regarding the getrandom() issue: according to [1], it requires
Kernel 3.17 and glibc 2.25. It is also implemented in uclibc-ng
and musl which is why I didn't see the issue.

getrandom() being a GNU extension, it needs '_GNU_SOURCE' to be
defined in uclibc-ng. Patch [2] was proposed a while back to fix
builds on m68k and uclibc-ng.

> Thanks
> Dave

Best regards,

Julien.

[1] https://man7.org/linux/man-pages/man2/getrandom.2.html#HISTORY
[2] 
https://lore.kernel.org/kexec/20230422095904.1303434-1-laurent@vivier.eu/

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  reply	other threads:[~2023-09-30 11:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-23 16:46 [PATCH 1/1] kexec: provide a memfd_create() wrapper if not present in libc Julien Olivain
2023-09-27  6:45 ` Dave Young
2023-09-30 11:46   ` Julien Olivain [this message]
2023-10-04 12:09 ` Simon Horman

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=4e1afe7fc304c2582a91afa2c1b32f24@free.fr \
    --to=ju.o@free.fr \
    --cc=dyoung@redhat.com \
    --cc=kexec@lists.infradead.org \
    /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