From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B32E4C433F5 for ; Tue, 22 Feb 2022 21:42:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235845AbiBVVmq (ORCPT ); Tue, 22 Feb 2022 16:42:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235836AbiBVVmn (ORCPT ); Tue, 22 Feb 2022 16:42:43 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF0135E758 for ; Tue, 22 Feb 2022 13:42:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645566137; x=1677102137; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=a47fUvwmAELWOtL2YGU5gBEiWT9a8JiqnHsi5bV5vvY=; b=GiPfvctO7tPB9pzeBmAtffSsW21lc09tk78Wx8xNpwXKhtNroRdQYOP5 IOHjqM/ONN0oaZnV5MUDOS90LYxz7fDO8Y8PZJfTcNSGKAI0XCEH/WzUX KnaQ5oEnVLPaPxxsCZuRUc83jrYV1eKk41/nguJeOgSD9jgFlvNooFELF M+Jl0XObkfuuByGz6l5YcrmHvAeg95tl9PdsCjCqNMQC/DdohMxZ/WEx5 iDPRz0z+3/BKeEA4PkicNismG0v7/hPKL1EsURxaujfb4/HNLfqArBmEC /n5kn/x6Du7cx0UvoUXyIPRoqr/jKEHFvLbU13/z0EKuAKulndr1Gig+G Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10266"; a="338256915" X-IronPort-AV: E=Sophos;i="5.88,389,1635231600"; d="scan'208";a="338256915" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2022 13:42:17 -0800 X-IronPort-AV: E=Sophos;i="5.88,389,1635231600"; d="scan'208";a="490950449" Received: from psillosx-mobl.amr.corp.intel.com (HELO localhost) ([10.134.65.119]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2022 13:42:16 -0800 Date: Tue, 22 Feb 2022 13:42:16 -0800 From: Ira Weiny To: "Edgecombe, Rick P" Cc: "hpa@zytor.com" , "Williams, Dan J" , "dave.hansen@linux.intel.com" , "Yu, Fenghua" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH V8 20/44] mm/pkeys: Add PKS test for context switching Message-ID: References: <20220127175505.851391-1-ira.weiny@intel.com> <20220127175505.851391-21-ira.weiny@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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@intel.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; > > + } > >