Skip to contentSkip to conversation

livepatch: core: Return EOPNOTSUPP instead of ENOSYS

PATCH Applied Alice Ferrazzi 5 participants 11 messages Feb 4, 2019 – Feb 8, 2019 Live patching

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 livepatch: core: Return EOPNOTSUPP instead of ENOSYS

From: Alice Ferrazzi <[email protected]>

As a result of an unsupported operation is better to use EOPNOTSUPP as error code.
ENOSYS is only used for 'invalid syscall nr' and nothing else.

---
Changes v1->v2:
- Use EOPNOTSUPP instead of ENOTSUPP (Petr)

 kernel/livepatch/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/livepatch/core.c +1 -1
index fe1993399823..075eb5c0813d 100644
@@ -1004,7 +1004,7 @@ int klp_enable_patch(struct klp_patch *patch)
 
 	if (!klp_have_reliable_stack()) {
 		pr_err("This architecture doesn't have support for the livepatch consistency model.\n");
-		return -ENOSYS;
+		return -EOPNOTSUPP;
 	}
 
 
Signature · 1 line
2.19.2
#5 lore raw
Quoted 8 lines · Petr Mladek
Quoted 7 lines · Josh Poimboeuf
Quoted 6 lines · Alice Ferrazzi

From: Alice Ferrazzi <[email protected]>

As a result of an unsupported operation is better to use EOPNOTSUPP as error code.
ENOSYS is only used for 'invalid syscall nr' and nothing else.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

I have applied the patch into for-5.1/atomic-replace branch.

Sorry to jump into the discussion so late. Thinking a little more about the check itself, previously with immediate flag an architecture can do livepatching with limitations and without the reliable stack trace implemented yet.

After removal of the immediate flag by
commit d0807da78e11 ("livepatch: Remove immediate feature"), every architecture enabling livepatching is required to have implemented reliable stack trace. Is it a better idea to make HAVE_RELIABLE_STACKTRACE a config dependency, which will disable livepatching support for architectures without reliable stack trace function during kernel build?

The idea is to remove klp_have_reliable_stack() by moving CONFIG_HAVE_RELIABLE_STACKTRACE as a config dependency to Kconfig file and adding the other CONFIG_STACKTRACE as a config dependency is not required, as it's selected via CONFIG_DYNAMIC_FTRACE_WITH_REGS dependency chain. With the patch on architecture without HAVE_RELIABLE_STACKTRACE, the user should see:

# insmod ./livepatch-sample.ko 
insmod: ERROR: could not insert module ./livepatch-sample.ko: Invalid module format
# dmesg
...
[  286.453463] livepatch_sample: module is marked as livepatch module, but livepatch support is disabled

I have done limited testing on PowerPC and to test the unsupported case, the config dependency HAVE_RELIABLE_STACKTRACE was misspelled in Kconfig file. If the idea sounds ok I will send a formal patch.

-------8<----------------------------

include/linux/livepatch.h +0 -6
index 53551f470722..7848c7bbffbb 100644
@@ -214,12 +214,6 @@ static inline bool klp_patch_pending(struct task_struct *task)
        return test_tsk_thread_flag(task, TIF_PATCH_PENDING);
 }
 
-static inline bool klp_have_reliable_stack(void)
-{
-       return IS_ENABLED(CONFIG_STACKTRACE) &&
-              IS_ENABLED(CONFIG_HAVE_RELIABLE_STACKTRACE);
-}
-
 typedef int (*klp_shadow_ctor_t)(void *obj,
                                 void *shadow_data,
                                 void *ctor_data);
kernel/livepatch/Kconfig +1 -0
index ec4565122e65..16b3692ddf9f 100644
@@ -9,6 +9,7 @@ config LIVEPATCH
        depends on MODULES
        depends on SYSFS
        depends on KALLSYMS_ALL
+       depends on HAVE_RELIABLE_STACKTRACE
        depends on HAVE_LIVEPATCH
        depends on !TRIM_UNUSED_KSYMS
        help
kernel/livepatch/core.c +0 -6
index fe1993399823..9a80f7574d75 100644
@@ -1002,12 +1002,6 @@ int klp_enable_patch(struct klp_patch *patch)
        if (!klp_initialized())
                return -ENODEV;
 
-       if (!klp_have_reliable_stack()) {
-               pr_err("This architecture doesn't have support for the livepatch consistency model.\n");
-               return -ENOSYS;
-       }
-
-
        mutex_lock(&klp_mutex);
 
        ret = klp_init_patch_early(patch);
maintainer
#6 lore raw

Hi Kamalesh,

Quoted 20 lines · Kamalesh Babulal
Quoted 8 lines · Petr Mladek
Quoted 7 lines · Josh Poimboeuf
Quoted 6 lines · Alice Ferrazzi

From: Alice Ferrazzi <[email protected]>

As a result of an unsupported operation is better to use EOPNOTSUPP as error code.
ENOSYS is only used for 'invalid syscall nr' and nothing else.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

I have applied the patch into for-5.1/atomic-replace branch.

Sorry to jump into the discussion so late. Thinking a little more about the check itself, previously with immediate flag an architecture can do livepatching with limitations and without the reliable stack trace implemented yet.

Quoted 7 lines

After removal of the immediate flag by
commit d0807da78e11 ("livepatch: Remove immediate feature"), every architecture enabling livepatching is required to have implemented reliable stack trace. Is it a better idea to make HAVE_RELIABLE_STACKTRACE a config dependency, which will disable livepatching support for architectures without reliable stack trace function during kernel build?

if I am not mistaken, s390x is currently the only one which is supported (the redirection works) but has no reliable stacktraces (so far, it is my plan to take a look soon).

Theoretically, it could still work. We have the fake signal and we can force the remaining tasks (kthreads). It is not something to be used in production but it could make sense for a limited testing.

Quoted 56 lines

The idea is to remove klp_have_reliable_stack() by moving CONFIG_HAVE_RELIABLE_STACKTRACE as a config dependency to Kconfig file and adding the other CONFIG_STACKTRACE as a config dependency is not required, as it's selected via CONFIG_DYNAMIC_FTRACE_WITH_REGS dependency chain. With the patch on architecture without HAVE_RELIABLE_STACKTRACE, the user should see:

# insmod ./livepatch-sample.ko 
insmod: ERROR: could not insert module ./livepatch-sample.ko: Invalid module format
# dmesg
...
[  286.453463] livepatch_sample: module is marked as livepatch module, but livepatch support is disabled

I have done limited testing on PowerPC and to test the unsupported case, the config dependency HAVE_RELIABLE_STACKTRACE was misspelled in Kconfig file. If the idea sounds ok I will send a formal patch.

-------8<----------------------------

include/linux/livepatch.h +0 -6
index 53551f470722..7848c7bbffbb 100644
@@ -214,12 +214,6 @@ static inline bool klp_patch_pending(struct task_struct *task)
        return test_tsk_thread_flag(task, TIF_PATCH_PENDING);
 }
 
-static inline bool klp_have_reliable_stack(void)
-{
-       return IS_ENABLED(CONFIG_STACKTRACE) &&
-              IS_ENABLED(CONFIG_HAVE_RELIABLE_STACKTRACE);
-}
-
 typedef int (*klp_shadow_ctor_t)(void *obj,
                                 void *shadow_data,
                                 void *ctor_data);
kernel/livepatch/Kconfig +1 -0
index ec4565122e65..16b3692ddf9f 100644
@@ -9,6 +9,7 @@ config LIVEPATCH
        depends on MODULES
        depends on SYSFS
        depends on KALLSYMS_ALL
+       depends on HAVE_RELIABLE_STACKTRACE
        depends on HAVE_LIVEPATCH
        depends on !TRIM_UNUSED_KSYMS
        help
kernel/livepatch/core.c +0 -0
index fe1993399823..9a80f7574d75 100644
@@ -1002,12 +1002,6 @@ int klp_enable_patch(struct klp_patch *patch)
        if (!klp_initialized())
                return -ENODEV;

kernel/livepatch/core.c int klp_enable_patch(struct klp_patch *patch) · line 1007

Quoted 10 lines
kernel/livepatch/core.c +0 -6
 
-       if (!klp_have_reliable_stack()) {
-               pr_err("This architecture doesn't have support for the livepatch consistency model.\n");
-               return -ENOSYS;
-       }
-
-
        mutex_lock(&klp_mutex);
 
        ret = klp_init_patch_early(patch);

On the other hand, I like this change. So we have two options, I think. We can apply this and wait if someone complains (because of s390x testing), or we can wait for the full support of s390x and then enforce it.

Thanks,
Miroslav

#7 lore raw

Hi Miroslav,

Quoted 12 lines · Miroslav Benes

Hi Kamalesh,

Quoted 8 lines · Kamalesh Babulal
Quoted 7 lines · Petr Mladek
Quoted 6 lines · Josh Poimboeuf
Quoted 5 lines · Alice Ferrazzi

From: Alice Ferrazzi <[email protected]>

As a result of an unsupported operation is better to use EOPNOTSUPP as error code.
ENOSYS is only used for 'invalid syscall nr' and nothing else.

[...]

Quoted 8 lines
Quoted 7 lines

After removal of the immediate flag by
commit d0807da78e11 ("livepatch: Remove immediate feature"), every architecture enabling livepatching is required to have implemented reliable stack trace. Is it a better idea to make HAVE_RELIABLE_STACKTRACE a config dependency, which will disable livepatching support for architectures without reliable stack trace function during kernel build?

Quoted 7 lines

if I am not mistaken, s390x is currently the only one which is supported (the redirection works) but has no reliable stacktraces (so far, it is my plan to take a look soon).

Theoretically, it could still work. We have the fake signal and we can force the remaining tasks (kthreads). It is not something to be used in production but it could make sense for a limited testing.

That was my understanding too, s390 doesn't set HAVE_RELIABLE_STACKTRACE.

(below output is right trimmed for readability)

arch $ find . -name 'Kconfig'|xargs egrep -an "HAVE_LIVEPATCH"

./powerpc/Kconfig:209:  select HAVE_LIVEPATCH ...
./x86/Kconfig:171:      select HAVE_LIVEPATCH ...
./s390/Kconfig:161:     select HAVE_LIVEPATCH

arch $ find . -name 'Kconfig'|xargs egrep -an "HAVE_RELIABLE_STACKTRACE" ./powerpc/Kconfig:223: select HAVE_RELIABLE_STACKTRACE ...
./x86/Kconfig:189: select HAVE_RELIABLE_STACKTRACE ...
./Kconfig:690:config HAVE_RELIABLE_STACKTRACE

klp_have_reliable_stack() will guard against loading of livepatching module on s390, for the same reason being that HAVE_RELIABLE_STACKTRACE is not set. My explanation is purely based on the above grep output on Kconfig files, which might be partial. Am I missing something here?

Quoted 6 lines
Quoted 6 lines

The idea is to remove klp_have_reliable_stack() by moving CONFIG_HAVE_RELIABLE_STACKTRACE as a config dependency to Kconfig file and adding the other CONFIG_STACKTRACE as a config dependency is not required, as it's selected via CONFIG_DYNAMIC_FTRACE_WITH_REGS dependency chain. With the patch on architecture without HAVE_RELIABLE_STACKTRACE, the user should see:

[...]

Quoted 16 lines
Quoted 16 lines
kernel/livepatch/core.c +0 -6
index fe1993399823..9a80f7574d75 100644
@@ -1002,12 +1002,6 @@ int klp_enable_patch(struct klp_patch *patch)
        if (!klp_initialized())
                return -ENODEV;
 
-       if (!klp_have_reliable_stack()) {
-               pr_err("This architecture doesn't have support for the livepatch consistency model.\n");
-               return -ENOSYS;
-       }
-
-
        mutex_lock(&klp_mutex);
 
Quoted 6 lines

kernel/livepatch/core.c int klp_enable_patch(struct klp_patch *patch) · line 1007

Quoted 1 line
kernel/livepatch/core.c +0 -0
        ret = klp_init_patch_early(patch);

On the other hand, I like this change. So we have two options, I think. We can apply this and wait if someone complains (because of s390x testing), or we can wait for the full support of s390x and then enforce it.

Thanks, I am ok with either of the options. We could enforce the config dependency, in case the above assumption in regard to s390 is correct.

Thanks,
Kamalesh

maintainer
#8 lore raw
Quoted 48 lines · Kamalesh Babulal

Hi Miroslav,

Quoted 12 lines · Miroslav Benes

Hi Kamalesh,

Quoted 8 lines · Kamalesh Babulal
Quoted 7 lines · Petr Mladek
Quoted 6 lines · Josh Poimboeuf
Quoted 5 lines · Alice Ferrazzi

From: Alice Ferrazzi <[email protected]>

As a result of an unsupported operation is better to use EOPNOTSUPP as error code.
ENOSYS is only used for 'invalid syscall nr' and nothing else.

[...]

Quoted 8 lines
Quoted 7 lines

After removal of the immediate flag by
commit d0807da78e11 ("livepatch: Remove immediate feature"), every architecture enabling livepatching is required to have implemented reliable stack trace. Is it a better idea to make HAVE_RELIABLE_STACKTRACE a config dependency, which will disable livepatching support for architectures without reliable stack trace function during kernel build?

Quoted 7 lines

if I am not mistaken, s390x is currently the only one which is supported (the redirection works) but has no reliable stacktraces (so far, it is my plan to take a look soon).

Theoretically, it could still work. We have the fake signal and we can force the remaining tasks (kthreads). It is not something to be used in production but it could make sense for a limited testing.

That was my understanding too, s390 doesn't set HAVE_RELIABLE_STACKTRACE.

(below output is right trimmed for readability)

arch $ find . -name 'Kconfig'|xargs egrep -an "HAVE_LIVEPATCH"

./powerpc/Kconfig:209:  select HAVE_LIVEPATCH ...
./x86/Kconfig:171:      select HAVE_LIVEPATCH ...
./s390/Kconfig:161:     select HAVE_LIVEPATCH

arch $ find . -name 'Kconfig'|xargs egrep -an "HAVE_RELIABLE_STACKTRACE" ./powerpc/Kconfig:223: select HAVE_RELIABLE_STACKTRACE ...
./x86/Kconfig:189: select HAVE_RELIABLE_STACKTRACE ...
./Kconfig:690:config HAVE_RELIABLE_STACKTRACE

Quoted 4 lines

klp_have_reliable_stack() will guard against loading of livepatching module on s390, for the same reason being that HAVE_RELIABLE_STACKTRACE is not set. My explanation is purely based on the above grep output on Kconfig files, which might be partial. Am I missing something here?

No, I don't think so.

I think I mentioned the theoretical possibility at the time the check was introduced and we came to the conclusion that it is worth it and we should enforce the reliable stacktraces.

Quoted 25 lines
Quoted 6 lines
Quoted 6 lines

The idea is to remove klp_have_reliable_stack() by moving CONFIG_HAVE_RELIABLE_STACKTRACE as a config dependency to Kconfig file and adding the other CONFIG_STACKTRACE as a config dependency is not required, as it's selected via CONFIG_DYNAMIC_FTRACE_WITH_REGS dependency chain. With the patch on architecture without HAVE_RELIABLE_STACKTRACE, the user should see:

[...]

Quoted 16 lines
Quoted 16 lines
kernel/livepatch/core.c +0 -6
index fe1993399823..9a80f7574d75 100644
@@ -1002,12 +1002,6 @@ int klp_enable_patch(struct klp_patch *patch)
        if (!klp_initialized())
                return -ENODEV;
 
-       if (!klp_have_reliable_stack()) {
-               pr_err("This architecture doesn't have support for the livepatch consistency model.\n");
-               return -ENOSYS;
-       }
-
-
        mutex_lock(&klp_mutex);
 
Quoted 6 lines
Quoted 6 lines

kernel/livepatch/core.c int klp_enable_patch(struct klp_patch *patch) · line 1007

Quoted 1 line
kernel/livepatch/core.c +0 -0
        ret = klp_init_patch_early(patch);

On the other hand, I like this change. So we have two options, I think. We can apply this and wait if someone complains (because of s390x testing), or we can wait for the full support of s390x and then enforce it.

Scratch this. It is enforced even now.

Quoted 2 lines

Thanks, I am ok with either of the options. We could enforce the config dependency, in case the above assumption in regard to s390 is correct.

Yes, I think it is a nice cleanup.

Miroslav

maintainer
#9 lore raw
In reply to Kamalesh Babulal
Quoted 28 lines · Kamalesh Babulal
Quoted 8 lines · Petr Mladek
Quoted 7 lines · Josh Poimboeuf
Quoted 6 lines · Alice Ferrazzi

From: Alice Ferrazzi <[email protected]>

As a result of an unsupported operation is better to use EOPNOTSUPP as error code.
ENOSYS is only used for 'invalid syscall nr' and nothing else.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

I have applied the patch into for-5.1/atomic-replace branch.

Sorry to jump into the discussion so late. Thinking a little more about the check itself, previously with immediate flag an architecture can do livepatching with limitations and without the reliable stack trace implemented yet.

After removal of the immediate flag by
commit d0807da78e11 ("livepatch: Remove immediate feature"), every architecture enabling livepatching is required to have implemented reliable stack trace. Is it a better idea to make HAVE_RELIABLE_STACKTRACE a config dependency, which will disable livepatching support for architectures without reliable stack trace function during kernel build?

Quoted 3 lines

The idea is to remove klp_have_reliable_stack() by moving CONFIG_HAVE_RELIABLE_STACKTRACE as a config dependency to Kconfig file

Looks like a nice cleanup.

Quoted 4 lines

and adding the other CONFIG_STACKTRACE as a config dependency is not required, as it's selected via CONFIG_DYNAMIC_FTRACE_WITH_REGS dependency chain. With the patch on architecture without HAVE_RELIABLE_STACKTRACE, the user should see:

Hmm, I see the following in kernel/trace/Kconfig:

config TRACING
[...]
select STACKTRACE if STACKTRACE_SUPPORT

It seems that the depency is not guaranted. Or do I miss anything?

Anyway, it is pretty indirect. I would prefer to add dependency on STACKTRACE explicitly into config LIVEPATCH.

Best Regards,
Petr

#10 lore raw
Quoted 15 lines · Petr Mladek
Quoted 14 lines · Kamalesh Babulal
Quoted 13 lines · Petr Mladek
Quoted 10 lines · Josh Poimboeuf
Quoted 7 lines · Alice Ferrazzi

From: Alice Ferrazzi <[email protected]>

As a result of an unsupported operation is better to use EOPNOTSUPP as error code.
ENOSYS is only used for 'invalid syscall nr' and nothing else.

I have applied the patch into for-5.1/atomic-replace branch.

[...]

Quoted 8 lines
Quoted 8 lines

After removal of the immediate flag by
commit d0807da78e11 ("livepatch: Remove immediate feature"), every architecture enabling livepatching is required to have implemented reliable stack trace. Is it a better idea to make HAVE_RELIABLE_STACKTRACE a config dependency, which will disable livepatching support for architectures without reliable stack trace function during kernel build?

Quoted 5 lines
Quoted 3 lines

The idea is to remove klp_have_reliable_stack() by moving CONFIG_HAVE_RELIABLE_STACKTRACE as a config dependency to Kconfig file

Looks like a nice cleanup.

Thanks

Quoted 6 lines
Quoted 5 lines

and adding the other CONFIG_STACKTRACE as a config dependency is not required, as it's selected via CONFIG_DYNAMIC_FTRACE_WITH_REGS dependency chain. With the patch on architecture without HAVE_RELIABLE_STACKTRACE, the user should see:

Quoted 7 lines

Hmm, I see the following in kernel/trace/Kconfig:

config TRACING
[...]
select STACKTRACE if STACKTRACE_SUPPORT

It seems that the depency is not guaranted. Or do I miss anything?

I should have tried drawing the config dependency of CONFIG_STACKTRACE in the mail. It would saved me from nagivating wrong indirections in tricky Kconfigs. You are right, CONFIG_STACKTRACE is not selected via CONFIG_DYNAMIC_FTRACE_WITH_REGS config dependency chain.

Quoted 3 lines

Anyway, it is pretty indirect. I would prefer to add dependency on STACKTRACE explicitly into config LIVEPATCH.

Agree, explicitly listing CONFIG_STACKTRACE as one of the dependencies under config LIVEPATCH will guarantee the dependency is met. On the curious note, digging through the git logs, CONFIG_STACKTRACE_SUPPORT is enabled by default on x86/PowerPC for quite long now.

Thanks,
Kamalesh