Re: [PATCH v1 1/1] arm64: remove unnecessary ifdefs around is_compat_task()

From: Arnd Bergmann
Date: Mon Jan 08 2024 - 11:27:02 EST


On Mon, Jan 8, 2024, at 17:04, Leonardo Bras wrote:
> On Mon, Jan 08, 2024 at 12:07:48PM -0300, Leonardo Bras wrote:
>> On Fri, Jan 05, 2024 at 03:38:05PM +0100, Arnd Bergmann wrote:
>> >
>> > I suspect it's enough to remove all of the other
>> > "#ifdef CONFIG_COMPAT" checks in this file and rely on
>> > dead code elimination to remove the rest, but there might
>> > be additional problems if some extern declarations are
>> > hidden in an #ifdef as well.
>
> I could remove all CONFIG_COMPAT ifdefs from this file, and for compiling
> it required a few extra defines (in other files) to be moved outside of
> their #ifdef CONFIG_COMPAT. Those being:
>
> #define VFP_STATE_SIZE ((32 * 8) + 4)
> #define VFP_FPSCR_STAT_MASK 0xf800009f
> #define VFP_FPSCR_CTRL_MASK 0x07f79f00
>
> #define COMPAT_ELF_NGREG 18
> typedef unsigned int compat_elf_greg_t;
> typedef compat_elf_greg_t compat_elf_gregset_t[COMPAT_ELF_NGREG];
>
>
> OTOH, the size of the final arch/arm64/kernel/ptrace.o went from 44768 to
> 56328 bytes, which I understand to be undesired.

Right, unfortunately it seems that compat_arch_ptrace() is
globally visible and consequently not dropped by the compiler
in dead code elimination.

> A different (and simpler) solution is to have an empty struct in case of
> !CONFIG_COMPAT, that will be optimized out in compile-time:
>
> diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
> index 9f8781f1fdfda..d2f275d8a3e6e 100644
> --- a/arch/arm64/kernel/ptrace.c
> +++ b/arch/arm64/kernel/ptrace.c
> @@ -2107,6 +2107,9 @@ long compat_arch_ptrace(struct task_struct
> *child, compat_long_t request,
>
> return ret;
> }
> +#else
> +static const struct user_regset_view user_aarch32_view = {};
> +static const struct user_regset_view user_aarch32_ptrace_view = {};
> #endif /* CONFIG_COMPAT */
>
> const struct user_regset_view *task_user_regset_view(struct task_struct *task)
>
> With this the patch will build successfully and arch/arm64/kernel/ptrace.o
> will be able to keep it's original size.
>
> Arnd, is that ok?

I don't see it being worth it if you add extra unused lines
in order to remove one more #ifdef. I would either leave the
task_user_regset_view() function unchanged here, or (if this
works) move the #ifdef down a few lines so the existing
user_regset_view structures can be shared:

@@ -1595,7 +1595,6 @@ static const struct user_regset_view user_aarch64_view = {
.regsets = aarch64_regsets, .n = ARRAY_SIZE(aarch64_regsets)
};

-#ifdef CONFIG_COMPAT
enum compat_regset {
REGSET_COMPAT_GPR,
REGSET_COMPAT_VFP,
@@ -1852,6 +1851,7 @@ static const struct user_regset_view user_aarch32_ptrace_view = {
.regsets = aarch32_ptrace_regsets, .n = ARRAY_SIZE(aarch32_ptrace_regsets)
};

+#ifdef CONFIG_COMPAT
static int compat_ptrace_read_user(struct task_struct *tsk, compat_ulong_t off,
compat_ulong_t __user *ret)
{


Arnd