[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <fd507c3259da765f4c6b42dc6b319d7f5ce29ce6.camel@intel.com>
Date: Tue, 1 Feb 2022 17:43:17 +0000
From: "Edgecombe, Rick P" <rick.p.edgecombe@...el.com>
To: "hpa@...or.com" <hpa@...or.com>,
"Williams, Dan J" <dan.j.williams@...el.com>,
"Weiny, Ira" <ira.weiny@...el.com>,
"dave.hansen@...ux.intel.com" <dave.hansen@...ux.intel.com>
CC: "Yu, Fenghua" <fenghua.yu@...el.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH V8 20/44] mm/pkeys: Add PKS test for context switching
On Thu, 2022-01-27 at 09:54 -0800, ira.weiny@...el.com wrote:
> +int check_context_switch(int cpu)
> +{
> + int switch_done[2];
> + int setup_done[2];
> + cpu_set_t cpuset;
> + char result[32];
> + int rc = 0;
> + pid_t pid;
> + int fd;
> +
> + CPU_ZERO(&cpuset);
> + CPU_SET(cpu, &cpuset);
> + /*
> + * Ensure the two processes run on the same CPU so that they
> go through
> + * a context switch.
> + */
> + sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpuset);
> +
> + if (pipe(setup_done)) {
> + printf("ERROR: Failed to create pipe\n");
> + return -1;
> + }
> + if (pipe(switch_done)) {
> + printf("ERROR: Failed to create pipe\n");
> + return -1;
> + }
> +
> + pid = fork();
> + if (pid == 0) {
> + char done = 'y';
> +
> + fd = open(PKS_TEST_FILE, O_RDWR);
> + if (fd < 0) {
> + printf("ERROR: cannot open %s\n",
> PKS_TEST_FILE);
> + return -1;
When this happens, the error is printed, but the parent process just
hangs forever. Might make it hard to script running all the selftests.
Also, the other x86 selftests mostly use [RUN], [INFO], [OK], [FAIL],
[SKIP] and [OK] in their print statements. Probably should stick to the
pattern across all the print statements. This is probably a "[SKIP]".
Just realized I've omitted the "[]" in the CET series too.
> + }
> +
> + cpu = sched_getcpu();
> + printf("Child running on cpu %d...\n", cpu);
> +
> + /* Allocate and run test. */
> + write(fd, RUN_SINGLE, 1);
> +
> + /* Arm for context switch test */
> + write(fd, ARM_CTX_SWITCH, 1);
> +
> + printf(" tell parent to go\n");
> + write(setup_done[1], &done, sizeof(done));
> +
> + /* Context switch out... */
> + printf(" Waiting for parent...\n");
> + read(switch_done[0], &done, sizeof(done));
> +
> + /* Check msr restored */
> + printf("Checking result\n");
> + write(fd, CHECK_CTX_SWITCH, 1);
> +
> + read(fd, result, 10);
> + printf(" #PF, context switch, pkey allocation and
> free tests: %s\n", result);
> + if (!strncmp(result, "PASS", 10)) {
> + rc = -1;
> + done = 'F';
> + }
> +
> + /* Signal result */
> + write(setup_done[1], &done, sizeof(done));
> + } else {
> + char done = 'y';
> +
> + read(setup_done[0], &done, sizeof(done));
> + cpu = sched_getcpu();
> + printf("Parent running on cpu %d\n", cpu);
> +
> + fd = open(PKS_TEST_FILE, O_RDWR);
> + if (fd < 0) {
> + printf("ERROR: cannot open %s\n",
> PKS_TEST_FILE);
> + return -1;
> + }
> +
> + /* run test with the same pkey */
> + write(fd, RUN_SINGLE, 1);
> +
> + printf(" Signaling child.\n");
> + write(switch_done[1], &done, sizeof(done));
> +
> + /* Wait for result */
> + read(setup_done[0], &done, sizeof(done));
> + if (done == 'F')
> + rc = -1;
> + }
Powered by blists - more mailing lists