lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 22 Feb 2022 13:42:16 -0800
From:   Ira Weiny <ira.weiny@...el.com>
To:     "Edgecombe, Rick P" <rick.p.edgecombe@...el.com>
Cc:     "hpa@...or.com" <hpa@...or.com>,
        "Williams, Dan J" <dan.j.williams@...el.com>,
        "dave.hansen@...ux.intel.com" <dave.hansen@...ux.intel.com>,
        "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 Tue, Feb 01, 2022 at 09:43:17AM -0800, Edgecombe, Rick P wrote:
> 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.

Good point.  I've fixed this up.

> 
> 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.

Thanks, fixed.

Ira

> 
> > +               }
> > +
> > +               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

Powered by Openwall GNU/*/Linux Powered by OpenVZ