Re: [PATCH V8 30/44] mm/pkeys: Test setting a PKS key in a custom fault callback

Edgecombe, Rick P
2022-02-01T00:55:59Z

On Thu, 2022-01-27 at 09:54 -0800, ira.weiny@intel.com wrote:
> Add a test which does this.
>
> $ echo 5 > /sys/kernel/debug/x86/run_pks
> $ cat /sys/kernel/debug/x86/run_pks
> PASS

Hmm, when I run this on qemu TCG, I get:

root@(none):/# echo 5 > /sys/kernel/debug/x86/run_pks
[ 29.438159] pks_test: Failed to see the callback
root@(none):/# cat /sys/kernel/debug/x86/run_pks
FAIL

I think it's a problem with the test though. The generated code is not
expecting fault_callback_ctx.callback_seen to get changed in the
exception. The following fixed it for me:

diff --git a/lib/pks/pks_test.c b/lib/pks/pks_test.c
index 1528df0bb283..d979d2afe921 100644
--- a/lib/pks/pks_test.c
+++ b/lib/pks/pks_test.c
@@ -570,6 +570,7 @@ static bool run_fault_clear_test(void)
/* fault */
memcpy(test_page, ctx->data, 8);

+ barrier();
if (!fault_callback_ctx.callback_seen) {
pr_err("Failed to see the callback\n");
rc = false;

But, I wonder if volatile is also needed on the read to be fully
correct. I usually have to consult the docs when I deal with that
stuff...