From patchwork Wed Jun 29 06:34:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 641851 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rfY684BQbz9t0X for ; Wed, 29 Jun 2016 16:43:28 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3rfY683PnJzDqxW for ; Wed, 29 Jun 2016 16:43:28 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from ozlabs.org (ozlabs.org [103.22.144.67]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3rfY3442T6zDqts for ; Wed, 29 Jun 2016 16:40:48 +1000 (AEST) Received: by ozlabs.org (Postfix) id 3rfY343dlCz9t0j; Wed, 29 Jun 2016 16:40:48 +1000 (AEST) Delivered-To: linuxppc-dev@ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rfY340xp9z9t0X for ; Wed, 29 Jun 2016 16:40:47 +1000 (AEST) Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u5T6d52F100468 for ; Wed, 29 Jun 2016 02:40:46 -0400 Received: from e23smtp03.au.ibm.com (e23smtp03.au.ibm.com [202.81.31.145]) by mx0a-001b2d01.pphosted.com with ESMTP id 23usua0p1x-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 29 Jun 2016 02:40:46 -0400 Received: from localhost by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 29 Jun 2016 16:40:42 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp03.au.ibm.com (202.81.31.209) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 29 Jun 2016 16:40:41 +1000 X-IBM-Helo: d23dlp01.au.ibm.com X-IBM-MailFrom: cyrilbur@gmail.com X-IBM-RcptTo: linuxppc-dev@ozlabs.org Received: from d23relay06.au.ibm.com (d23relay06.au.ibm.com [9.185.63.219]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 688462CE8056 for ; Wed, 29 Jun 2016 16:40:40 +1000 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay06.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u5T6eepx8126742 for ; Wed, 29 Jun 2016 16:40:40 +1000 Received: from d23av04.au.ibm.com (localhost [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u5T6eeTX022507 for ; Wed, 29 Jun 2016 16:40:40 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u5T6edpk022494; Wed, 29 Jun 2016 16:40:39 +1000 Received: from camb691.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher DHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 55D85A01EE; Wed, 29 Jun 2016 16:40:39 +1000 (AEST) From: Cyril Bur To: linuxppc-dev@ozlabs.org Subject: [RFC 1/3] selftests/powerpc: Add test to check TM ucontext creation Date: Wed, 29 Jun 2016 16:34:34 +1000 X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160629063436.10003-1-cyrilbur@gmail.com> References: <20160629063436.10003-1-cyrilbur@gmail.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16062906-0008-0000-0000-0000009EDD24 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16062906-0009-0000-0000-0000078F0957 Message-Id: <20160629063436.10003-2-cyrilbur@gmail.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-06-29_02:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_spam_definite policy=outbound score=100 spamscore=100 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1606290062 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mikey@neuling.org, anton@samba.org MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Signed-off-by: Cyril Bur --- .../selftests/powerpc/tm/tm-signal-context-chk.c | 102 +++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 tools/testing/selftests/powerpc/tm/tm-signal-context-chk.c diff --git a/tools/testing/selftests/powerpc/tm/tm-signal-context-chk.c b/tools/testing/selftests/powerpc/tm/tm-signal-context-chk.c new file mode 100644 index 0000000..4c906cf --- /dev/null +++ b/tools/testing/selftests/powerpc/tm/tm-signal-context-chk.c @@ -0,0 +1,102 @@ +/* + * Copyright 2016, Cyril Bur, IBM Corp. + * Licensed under GPLv2. + * + * Test the kernel's signal frame code. + * + * The kernel sets up two sets of ucontexts if the signal was to be delivered + * while the thread was in a transaction. Expected behaviour is that the + * currently executing code is in the first and the checkpointed state (the + * state that will be rolled back to) is in the uc_link ucontext. + * + * The reason for this is that code which is not TM aware and installs a signal + * handler will expect to see/modify its currently running state in the uc, + * this code may have dynamicially linked against code which is TM aware and is + * doing HTM under the hood. + */ + +#include +#include +#include +#include + +#include "utils.h" +#include "tm.h" + +#define TBEGIN ".long 0x7C00051D ;" +#define TSUSPEND ".long 0x7C0005DD ;" +#define TRESUME ".long 0x7C2005DD ;" +#define MAX_ATTEMPT 100 + +static double fps[] = { 1, 2, 3, 4, 5, 6, 7, 8, + -1, -2, -3, -4, -5, -6, -7, -8 }; + +extern long tm_signal_self(pid_t pid, double *fps); + +static int signaled; +static int fail; + +static void signal_usr1(int signum, siginfo_t *info, void *uc) +{ + int i; + ucontext_t *ucp = uc; + ucontext_t *tm_ucp = ucp->uc_link; + + signaled = 1; + + /* Always be 64bit, don't really care about 32bit */ + for (i = 0; i < 8 && !fail; i++) { + fail = (ucp->uc_mcontext.gp_regs[i + 14] != i); + fail |= (tm_ucp->uc_mcontext.gp_regs[i + 14] != 0xFF - i); + } + if (fail) { + printf("Failed on %d gpr %lu or %lu\n", i - 1, ucp->uc_mcontext.gp_regs[i + 13], tm_ucp->uc_mcontext.gp_regs[i + 13]); + return; + } + for (i = 0; i < 8 && !fail; i++) { + fail = (ucp->uc_mcontext.fp_regs[i + 14] != fps[i]); + fail |= (tm_ucp->uc_mcontext.fp_regs[i + 14] != fps[i + 8]); + } + if (fail) { + printf("Failed on %d FP %g or %g\n", i - 1, ucp->uc_mcontext.fp_regs[i + 13], tm_ucp->uc_mcontext.fp_regs[i + 13]); + } +} + +static int tm_signal_context_chk() +{ + struct sigaction act; + int i; + long rc; + pid_t pid = getpid(); + + SKIP_IF(!have_htm()); + + act.sa_sigaction = signal_usr1; + sigemptyset(&act.sa_mask); + act.sa_flags = SA_SIGINFO; + if (sigaction(SIGUSR1, &act, NULL) < 0) { + perror("sigaction sigusr1"); + exit(1); + } + + i = 0; + while (!signaled && i < MAX_ATTEMPT) { + rc = tm_signal_self(pid, fps); + if (!rc) { + fprintf(stderr, "Transaction was not doomed...\n"); + FAIL_IF(!rc); + } + i++; + } + + if (i == MAX_ATTEMPT) { + fprintf(stderr, "Tried to signal %d times and didn't work, failing!\n", MAX_ATTEMPT); + fail = 1; + } + return fail; +} + +int main(void) +{ + return test_harness(tm_signal_context_chk, "tm_signal_context_chk"); +}