From patchwork Wed Nov 14 19:50:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 151118 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6105454ljp; Wed, 14 Nov 2018 11:51:06 -0800 (PST) X-Google-Smtp-Source: AJdET5cck6U6GRdF7/OrZp9TcPlqzqNKWGKrplEuFgGRBsICYuRpgIDSzKhKrE40q0l8buEgK8AL X-Received: by 2002:a62:59cd:: with SMTP id k74-v6mr3289523pfj.243.1542225066396; Wed, 14 Nov 2018 11:51:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542225066; cv=none; d=google.com; s=arc-20160816; b=apEEHooZf7NtuyEy7s414835TO5uG61T9oM0O20TzJsNFnwTVdcnyjuZaYG6P18yLA P20K40glguLXPxE+U2UUp+IQmcrg6hvpm4sWpcOiOe3JOa+lB7M3KOfJjWrsJh6o/91N 8ljxJLzGyVqfd7pi9d+TX6xQN+N9Rt8x1MFK3HjFP83LBhSPXqdHG3GhosNV/+p3iYd7 BTmbLUAduMWUpN8eyjDdgtXQMojH40JDiwwXInHiCDRjGv6x/sWo5sQYmnvPXtQwCCZ8 7sbZbL+dZgsn7cQWKSbDuCY0gUShIFAPOJN7LW5OmtR+OlXLg7ulum89bM8hEFpUwpUO cLtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=O3JJ6uQwUKnR1xfApJaiE6vCDrGC25cjY5kJAhwrCp4=; b=ZY2q16hJC9/KSiUK1ilC4m69psHsGPl2W0Z6I6/BPdwF+gRXspIoqwaHS9a9PU95Kj qL7JUIg5ji2kLEE3fp8SqKzHycwYB+F02q/qC4mEZbaTNbdW+4yYyB6G0+dKVHe/yKgf nQj5/5EwkZld8Fnco1Z260u4dONJDtFvXSSwor/xvsvoFHs0WcnuO7NKfXzx3x4VJNFJ lAAf9zisZwNIIPH3QJPgYQ5MZhaPhE9NaVmWCKBY7tZjZdtDZDBAIZEZAUg8Y1rtg0qO AbxnLWvbrGgaeL+8rzWKygxmHPSnfZyaJ3kirlSS9sx3UHtr7uga2r+X+kWIYSnS8Qam 8+Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=Y6W7ku5Y; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b19-v6si18923840pls.32.2018.11.14.11.51.06; Wed, 14 Nov 2018 11:51:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=Y6W7ku5Y; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727702AbeKOFzh (ORCPT + 32 others); Thu, 15 Nov 2018 00:55:37 -0500 Received: from heliosphere.sirena.org.uk ([172.104.155.198]:48152 "EHLO heliosphere.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725756AbeKOFzg (ORCPT ); Thu, 15 Nov 2018 00:55:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sirena.org.uk; s=20170815-heliosphere; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=O3JJ6uQwUKnR1xfApJaiE6vCDrGC25cjY5kJAhwrCp4=; b=Y6W7ku5YOdV+WzkXuPO9o1nvKW j0wor+ATkTHJ6dCWw4Sxn+A1ypNuauNvYut2U1Yl8jK7IqTHJS52UE5TdpgYu9ZeVhwxChHedd1Qk YzzfjIbBS7m3zonXqNutxxi48XflkcLS0W/dR0Gfm0EqH7K8vUEwya3tjqKz+bT1JfGw=; Received: from [64.114.255.97] (helo=finisterre.ee.mobilebroadband) by heliosphere.sirena.org.uk with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gN1Bd-0004KZ-9M; Wed, 14 Nov 2018 19:50:53 +0000 Received: by finisterre.ee.mobilebroadband (Postfix, from userid 1000) id 01D92440062; Wed, 14 Nov 2018 19:50:46 +0000 (GMT) From: Mark Brown To: Shuah Khan , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Andy Lutomirski Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, x86@kernel.org, Mark Brown Subject: [PATCH RFC 1/2] selftests/x86/fsgsbase: Indirect output through a wrapper function Date: Wed, 14 Nov 2018 11:50:42 -0800 Message-Id: <20181114195043.8021-2-broonie@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181114195043.8021-1-broonie@kernel.org> References: <20181114195043.8021-1-broonie@kernel.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for a change to make this test run repeatedly which would generate huge amounts of output as is indirect all the printf() calls in the program through a wrapper and add a quiet flag which can be used to suppress the output. This is fairly quick and dirty, I'm not 100% sure what would be idiomatic here. Signed-off-by: Mark Brown --- tools/testing/selftests/x86/fsgsbase.c | 52 ++++++++++++++++---------- 1 file changed, 32 insertions(+), 20 deletions(-) -- 2.19.1 diff --git a/tools/testing/selftests/x86/fsgsbase.c b/tools/testing/selftests/x86/fsgsbase.c index f249e042b3b5..6cda6daa1f8c 100644 --- a/tools/testing/selftests/x86/fsgsbase.c +++ b/tools/testing/selftests/x86/fsgsbase.c @@ -7,6 +7,7 @@ #define _GNU_SOURCE #include #include +#include #include #include #include @@ -32,6 +33,17 @@ static volatile sig_atomic_t want_segv; static volatile unsigned long segv_addr; static int nerrs; +static bool quiet; + +static void logger(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + if (!quiet) + vprintf(fmt, args); + va_end(args); +} static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *), int flags) @@ -118,29 +130,29 @@ static void check_gs_value(unsigned long value) unsigned long base; unsigned short sel; - printf("[RUN]\tARCH_SET_GS to 0x%lx\n", value); + logger("[RUN]\tARCH_SET_GS to 0x%lx\n", value); if (syscall(SYS_arch_prctl, ARCH_SET_GS, value) != 0) err(1, "ARCH_SET_GS"); asm volatile ("mov %%gs, %0" : "=rm" (sel)); base = read_base(GS); if (base == value) { - printf("[OK]\tGSBASE was set as expected (selector 0x%hx)\n", + logger("[OK]\tGSBASE was set as expected (selector 0x%hx)\n", sel); } else { nerrs++; - printf("[FAIL]\tGSBASE was not as expected: got 0x%lx (selector 0x%hx)\n", + logger("[FAIL]\tGSBASE was not as expected: got 0x%lx (selector 0x%hx)\n", base, sel); } if (syscall(SYS_arch_prctl, ARCH_GET_GS, &base) != 0) err(1, "ARCH_GET_GS"); if (base == value) { - printf("[OK]\tARCH_GET_GS worked as expected (selector 0x%hx)\n", + logger("[OK]\tARCH_GET_GS worked as expected (selector 0x%hx)\n", sel); } else { nerrs++; - printf("[FAIL]\tARCH_GET_GS was not as expected: got 0x%lx (selector 0x%hx)\n", + logger("[FAIL]\tARCH_GET_GS was not as expected: got 0x%lx (selector 0x%hx)\n", base, sel); } } @@ -149,7 +161,7 @@ static void mov_0_gs(unsigned long initial_base, bool schedule) { unsigned long base, arch_base; - printf("[RUN]\tARCH_SET_GS to 0x%lx then mov 0 to %%gs%s\n", initial_base, schedule ? " and schedule " : ""); + logger("[RUN]\tARCH_SET_GS to 0x%lx then mov 0 to %%gs%s\n", initial_base, schedule ? " and schedule " : ""); if (syscall(SYS_arch_prctl, ARCH_SET_GS, initial_base) != 0) err(1, "ARCH_SET_GS"); @@ -161,10 +173,10 @@ static void mov_0_gs(unsigned long initial_base, bool schedule) if (syscall(SYS_arch_prctl, ARCH_GET_GS, &arch_base) != 0) err(1, "ARCH_GET_GS"); if (base == arch_base) { - printf("[OK]\tGSBASE is 0x%lx\n", base); + logger("[OK]\tGSBASE is 0x%lx\n", base); } else { nerrs++; - printf("[FAIL]\tGSBASE changed to 0x%lx but kernel reports 0x%lx\n", base, arch_base); + logger("[FAIL]\tGSBASE changed to 0x%lx but kernel reports 0x%lx\n", base, arch_base); } } @@ -195,7 +207,7 @@ static void do_remote_base() unsigned short sel; asm volatile ("mov %%gs, %0" : "=rm" (sel)); - printf("\tother thread: ARCH_SET_GS(0x%lx)%s -- sel is 0x%hx\n", + logger("\tother thread: ARCH_SET_GS(0x%lx)%s -- sel is 0x%hx\n", to_set, hard_zero ? " and clear gs" : "", sel); } @@ -228,7 +240,7 @@ void do_unexpected_base(void) .useable = 0 }; if (syscall(SYS_modify_ldt, 1, &desc, sizeof(desc)) == 0) { - printf("\tother thread: using LDT slot 0\n"); + logger("\tother thread: using LDT slot 0\n"); asm volatile ("mov %0, %%gs" : : "rm" ((unsigned short)0x7)); } else { /* No modify_ldt for us (configured out, perhaps) */ @@ -250,10 +262,10 @@ void do_unexpected_base(void) munmap(low_desc, sizeof(desc)); if (ret != 0) { - printf("[NOTE]\tcould not create a segment -- test won't do anything\n"); + logger("[NOTE]\tcould not create a segment -- test won't do anything\n"); return; } - printf("\tother thread: using GDT slot %d\n", desc.entry_number); + logger("\tother thread: using GDT slot %d\n", desc.entry_number); asm volatile ("mov %0, %%gs" : : "rm" ((unsigned short)((desc.entry_number << 3) | 0x3))); } @@ -298,10 +310,10 @@ static void set_gs_and_switch_to(unsigned long local, local = 0; } - printf("[RUN]\tARCH_SET_GS(0x%lx)%s, then schedule to 0x%lx\n", + logger("[RUN]\tARCH_SET_GS(0x%lx)%s, then schedule to 0x%lx\n", local, hard_zero ? " and clear gs" : "", remote); if (force_sel) - printf("\tBefore schedule, set selector to 0x%hx\n", force_sel); + logger("\tBefore schedule, set selector to 0x%hx\n", force_sel); if (syscall(SYS_arch_prctl, ARCH_SET_GS, local) != 0) err(1, "ARCH_SET_GS"); if (hard_zero) @@ -309,7 +321,7 @@ static void set_gs_and_switch_to(unsigned long local, if (read_base(GS) != local) { nerrs++; - printf("[FAIL]\tGSBASE wasn't set as expected\n"); + logger("[FAIL]\tGSBASE wasn't set as expected\n"); } if (force_sel) { @@ -335,11 +347,11 @@ static void set_gs_and_switch_to(unsigned long local, asm volatile ("mov %%gs, %0" : "=rm" (sel_post_sched)); base = read_base(GS); if (base == local && sel_pre_sched == sel_post_sched) { - printf("[OK]\tGS/BASE remained 0x%hx/0x%lx\n", + logger("[OK]\tGS/BASE remained 0x%hx/0x%lx\n", sel_pre_sched, local); } else { nerrs++; - printf("[FAIL]\tGS/BASE changed from 0x%hx/0x%lx to 0x%hx/0x%lx\n", + logger("[FAIL]\tGS/BASE changed from 0x%hx/0x%lx to 0x%hx/0x%lx\n", sel_pre_sched, local, sel_post_sched, base); } } @@ -348,7 +360,7 @@ static void test_unexpected_base(void) { unsigned long base; - printf("[RUN]\tARCH_SET_GS(0), clear gs, then manipulate GSBASE in a different thread\n"); + logger("[RUN]\tARCH_SET_GS(0), clear gs, then manipulate GSBASE in a different thread\n"); if (syscall(SYS_arch_prctl, ARCH_SET_GS, 0) != 0) err(1, "ARCH_SET_GS"); asm volatile ("mov %0, %%gs" : : "rm" ((unsigned short)0)); @@ -360,10 +372,10 @@ static void test_unexpected_base(void) base = read_base(GS); if (base == 0) { - printf("[OK]\tGSBASE remained 0\n"); + logger("[OK]\tGSBASE remained 0\n"); } else { nerrs++; - printf("[FAIL]\tGSBASE changed to 0x%lx\n", base); + logger("[FAIL]\tGSBASE changed to 0x%lx\n", base); } } From patchwork Wed Nov 14 19:50:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 151120 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6105577ljp; Wed, 14 Nov 2018 11:51:12 -0800 (PST) X-Google-Smtp-Source: AJdET5ejuIVgAno+4AA63emcaBU2AOd25ljqGirmCS0XUUT1/VISEcIHr3ame334Q3DRsbSS8hJT X-Received: by 2002:a63:314c:: with SMTP id x73mr3020590pgx.323.1542225072788; Wed, 14 Nov 2018 11:51:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542225072; cv=none; d=google.com; s=arc-20160816; b=0+sY8NFoqL7ybWL/Gae+f/Z2UOzhPmjoFLbS/FZZfZx5DhNR2bxNlpg7XDnijfKMg2 U0l2EwylNRUD56O5E+e/VH0o4kJ58G2nERnP7sSQZBQs7nKsQz6PUKmu8Judyh+ue6SG h/NnatnxZMrOZEmo988yatnTcu3nUgq9aMkGxgAg8hef0fReQCO8ZlhH9ploSYq46qSW U08aVc4DgZZU9qPpzRMB4FRMFhBGwVuoglqaq6st0rcWUVNRei700io7dRCUYoR07hF6 Mrh9/Ak1a0Rfn5lOvETjnP5zgymiW1IQjD31R7TrT4uxbZhKligVgjdqOQDhfXf4cYAI 7sFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SbIHJ6Qgb/UHyCHdpX/ITanH1IL6ffpfB5+IP7GGx3w=; b=fiquJ883kgXUDHSvRUeBoY/nWD4yaCF9XefsDrFIKgMzdFLZfMIT/MGx+JnMIMuvs0 NniE6HKK8xVXVGtR1JFW6I/ucj+oTxZbogQb3fYu2Fx5GS29uP1zG7+Pk5OEqlkwjQUG iQTXBTPpUX8mzLbmHYViLhYJXIK534bGCNJlPFC39wd2yPMIQLrfBg52duG0OeDM4dnC RprG9OR3SG38F94stRZAyetWH23C1KDcS2hK6TE/xwVpWoWmYgCMPXPEkF/N/30ATF8c 5366vOaY4e6bjwS80+jyz6VAKlK2bp6gTGpO8pm5Nan3rvZ2UHziDdjsjfHHYHzbvmf7 ki2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=TPVtcwuv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p5si4978908pga.352.2018.11.14.11.51.12; Wed, 14 Nov 2018 11:51:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=TPVtcwuv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728005AbeKOFzo (ORCPT + 32 others); Thu, 15 Nov 2018 00:55:44 -0500 Received: from heliosphere.sirena.org.uk ([172.104.155.198]:48156 "EHLO heliosphere.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725791AbeKOFzh (ORCPT ); Thu, 15 Nov 2018 00:55:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sirena.org.uk; s=20170815-heliosphere; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=SbIHJ6Qgb/UHyCHdpX/ITanH1IL6ffpfB5+IP7GGx3w=; b=TPVtcwuv9buopKaIpi9AnOXfyI 7pheUl2J9ylPqOXFwvb3/5VaGOdauuJJgGpFbEyRjDjIIqlMVK+J55aP+HXzqxqw3rK1O9qnjj4FT PVGekG429kZlqkjK/rTFQh4t392zzFvzkpwYVfIyECzUJdgQb0MM3hoTkviUj3Cw7pP4=; Received: from [64.114.255.97] (helo=finisterre.ee.mobilebroadband) by heliosphere.sirena.org.uk with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gN1Bd-0004Ka-7D; Wed, 14 Nov 2018 19:50:53 +0000 Received: by finisterre.ee.mobilebroadband (Postfix, from userid 1000) id 0DB5144007A; Wed, 14 Nov 2018 19:50:47 +0000 (GMT) From: Mark Brown To: Shuah Khan , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Andy Lutomirski Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, x86@kernel.org, Mark Brown Subject: [PATCH RFC 2/2] selftests/x86/fsgsbase: Default to trying to run the test repeatedly Date: Wed, 14 Nov 2018 11:50:43 -0800 Message-Id: <20181114195043.8021-3-broonie@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181114195043.8021-1-broonie@kernel.org> References: <20181114195043.8021-1-broonie@kernel.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In automated testing it has been found that on many systems the fsgsbase test fails intermittently. This was reported and discussed a while back: https://lore.kernel.org/lkml/20180126153631.ha7yc33fj5uhitjo@xps/ with the analysis concluding that this is a hardware issue affecting a subset of systems but no fix has been merged as yet. As well as the actual problem found by testing the intermittent test failure is causing issues for the people doing the automated testing due to the noise. In order to make the testing stable modify the test program to iterate through the test repeatedly, choosing 5000 iterations based on prior reports and local testing. This unfortunately greatly increases the execution time for the selftests when things succeed which isn't great, in my local tests on a range of systems it pushes the execution time up to approximately a minute when no failures are encountered. Reported-by: Dan Rue Signed-off-by: Mark Brown --- tools/testing/selftests/x86/fsgsbase.c | 27 +++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) -- 2.19.1 diff --git a/tools/testing/selftests/x86/fsgsbase.c b/tools/testing/selftests/x86/fsgsbase.c index 6cda6daa1f8c..83410749ff1f 100644 --- a/tools/testing/selftests/x86/fsgsbase.c +++ b/tools/testing/selftests/x86/fsgsbase.c @@ -379,7 +379,7 @@ static void test_unexpected_base(void) } } -int main() +int test() { pthread_t thread; @@ -437,3 +437,28 @@ int main() return nerrs == 0 ? 0 : 1; } + +int main() +{ + int tries = 5000; + int i; + + if (tries > 1) + quiet = true; + + for (i = 0; i < tries; i++) { + if (test() != 0) + break; + } + + if (quiet) { + if (nerrs) { + printf("[FAIL] %d errors detected in %d tries\n", + nerrs, i + 1); + } else { + printf("[PASS] %d runs succeeded\n", i); + } + } + + return nerrs == 0 ? 0 : 1; +}