From patchwork Tue Feb 20 00:22:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 875345 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zlhN43Qy8z9ryl for ; Tue, 20 Feb 2018 11:30:12 +1100 (AEDT) Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3zlhN42Yq5zF0gZ for ; Tue, 20 Feb 2018 11:30:12 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=softfail (mailfrom) smtp.mailfrom=gmail.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=cyrilbur@gmail.com; receiver=) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3zlhCs334GzDrbP for ; Tue, 20 Feb 2018 11:23:05 +1100 (AEDT) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w1K0JZoD048551 for ; Mon, 19 Feb 2018 19:23:03 -0500 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 2g85nmp5d0-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 19 Feb 2018 19:23:02 -0500 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 20 Feb 2018 00:23:01 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 20 Feb 2018 00:22:58 -0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w1K0MvYN52953182; Tue, 20 Feb 2018 00:22:57 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2E75042047; Tue, 20 Feb 2018 00:15:36 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D2F7E4203F; Tue, 20 Feb 2018 00:15:35 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 20 Feb 2018 00:15:35 +0000 (GMT) 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 D0F36A026B; Tue, 20 Feb 2018 11:22:55 +1100 (AEDT) From: Cyril Bur To: mikey@neuling.org, benh@kernel.crashing.org, linuxppc-dev@lists.ozlabs.org Subject: [RFC PATCH 03/12] selftests/powerpc: Add tm-signal-drop-transaction TM test Date: Tue, 20 Feb 2018 11:22:32 +1100 X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180220002241.29648-1-cyrilbur@gmail.com> References: <20180220002241.29648-1-cyrilbur@gmail.com> X-TM-AS-GCONF: 00 x-cbid: 18022000-0040-0000-0000-000004145B01 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18022000-0041-0000-0000-0000261765DD Message-Id: <20180220002241.29648-4-cyrilbur@gmail.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-02-19_10:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1034 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1802200002 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This test uses a signal to 'discard' a transaction. That is, it will take a signal of a thread in a suspended transaction and just remove the suspended MSR bit. Because this will send the userspace thread back to the tebgin + 4 address, we should also set CR0 to be nice. Signed-off-by: Cyril Bur --- tools/testing/selftests/powerpc/tm/Makefile | 1 + .../powerpc/tm/tm-signal-drop-transaction.c | 74 ++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 tools/testing/selftests/powerpc/tm/tm-signal-drop-transaction.c diff --git a/tools/testing/selftests/powerpc/tm/Makefile b/tools/testing/selftests/powerpc/tm/Makefile index a23453943ad2..7a1e53297588 100644 --- a/tools/testing/selftests/powerpc/tm/Makefile +++ b/tools/testing/selftests/powerpc/tm/Makefile @@ -4,6 +4,7 @@ SIGNAL_CONTEXT_CHK_TESTS := tm-signal-context-chk-gpr tm-signal-context-chk-fpu TEST_GEN_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack \ tm-vmxcopy tm-fork tm-tar tm-tmspr tm-vmx-unavail tm-unavailable tm-trap \ + tm-signal-drop-transaction \ $(SIGNAL_CONTEXT_CHK_TESTS) include ../../lib.mk diff --git a/tools/testing/selftests/powerpc/tm/tm-signal-drop-transaction.c b/tools/testing/selftests/powerpc/tm/tm-signal-drop-transaction.c new file mode 100644 index 000000000000..a8397f7e7faa --- /dev/null +++ b/tools/testing/selftests/powerpc/tm/tm-signal-drop-transaction.c @@ -0,0 +1,74 @@ +/* + * Copyright 2018, Cyril Bur, IBM Corp. + * Licensed under GPLv2. + * + * This test uses a signal handler to make a thread go from + * transactional state to nothing state. In practice userspace, why + * would userspace ever do this? In theory, they can. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" +#include "tm.h" + +static bool passed; + +static void signal_usr1(int signum, siginfo_t *info, void *uc) +{ + ucontext_t *ucp = uc; + struct pt_regs *regs = ucp->uc_mcontext.regs; + + passed = true; + + /* I really hope I got that right, we wan't to clear both the MSR_TS bits */ + regs->msr &= ~(3ULL << 33); + /* Set CR0 to 0b0010 */ + regs->ccr &= ~(0xDULL << 28); +} + +int test_drop(void) +{ + struct sigaction act; + + 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); + } + + + asm __volatile__( + "tbegin.;" + "beq 1f; " + "tsuspend.;" + "1: ;" + : : : "memory", "cr0"); + + if (!passed && !tcheck_transactional()) { + fprintf(stderr, "Not in suspended state: 0x%1x\n", tcheck()); + exit(1); + } + + kill(getpid(), SIGUSR1); + + /* If we reach here, we've passed. Otherwise we've probably crashed + * the kernel */ + + return 0; +} + +int main(int argc, char *argv[]) +{ + return test_harness(test_drop, "tm_signal_drop_transaction"); +}