From patchwork Tue Oct 24 17:13:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 829971 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 ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yM0Mp60g3z9t3Z for ; Wed, 25 Oct 2017 04:17:58 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yM0Mp4PF0zDqmc for ; Wed, 25 Oct 2017 04:17:58 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=debian.org (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=leitao@debian.org; 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 3yM0Gs4bJyzDqhg for ; Wed, 25 Oct 2017 04:13:40 +1100 (AEDT) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9OHDM7a060095 for ; Tue, 24 Oct 2017 13:13:36 -0400 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0b-001b2d01.pphosted.com with ESMTP id 2dt8a2exv7-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 24 Oct 2017 13:13:34 -0400 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 24 Oct 2017 11:13:30 -0600 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 24 Oct 2017 11:13:28 -0600 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v9OHDSP93932442; Tue, 24 Oct 2017 10:13:28 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5D549C603E; Tue, 24 Oct 2017 11:13:28 -0600 (MDT) Received: from debra.br.ibm.com (unknown [9.18.239.102]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 16403C603C; Tue, 24 Oct 2017 11:13:26 -0600 (MDT) From: Breno Leitao To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH] powerpc/tm: Set ckpt_regs.msr before using it. Date: Tue, 24 Oct 2017 15:13:05 -0200 X-Mailer: git-send-email 1.9.3 X-TM-AS-GCONF: 00 x-cbid: 17102417-0016-0000-0000-000007B3DA8E X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007947; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00935855; UDB=6.00471540; IPR=6.00716122; BA=6.00005658; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017690; XFM=3.00000015; UTC=2017-10-24 17:13:30 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17102417-0017-0000-0000-00003BFC198C Message-Id: <1508865185-11492-1-git-send-email-leitao@debian.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-24_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710240235 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Breno Leitao , Breno Leitao , Michael Neuling , Cyril Bur , Gustavo Romero Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Breno Leitao On commit commit f48e91e87e67 ("powerpc/tm: Fix FP and VMX register corruption"), we check ckpt_regs.msr to see if a feature (as VEC, VSX and FP) is disabled (thus the hot registers might be bogus during the reclaim), and then copy the previously saved thread registers, with the non-bogus values, into the checkpoint area for a later trecheckpoint. This mechanism is used to recheckpoints the proper register values when a transaction started using the bogus registers, and these values were sent to the memory checkpoint area. I see a problem on this code that ckpt_regs.msr is not properly set when using it, as for example, when there is a vsx_unavailable_tm() in a code like the following, the ckpt_regs.msg[FP] is 0; 1: sleep_until_{fp,vec,vsx} = 0 2: fadd 3: tbegin. 4: beq 5: xxmrghd 6: tend. In this case, line 5 will raise an vsx_unavailable_tm() exception, and the ckpt_regs.msr[FP] will be zero before memcpy() block, executing the memcpy even with the the FP registers hot. That is not correct because we executed a float point instruction on line 2, and MSR[FP] was set to 1. Fortunately this does not cause a big problem as I can see, other than this extra memcpy() because treclaim() will later overwrite this wrong copied value, since it relies on the correct MSR value, which was updated by giveup_all->check_if_tm_restore_required. There might be a problem when laziness is being turned on, but I was not able to reproduce it. The solution I am proposing is updating ckpt_regs.msr before using it. Signed-off-by: Breno Leitao Signed-off-by: Gustavo Romero CC: Cyril Bur CC: Michael Neuling Signed-off-by: Cyril Bur --- arch/powerpc/kernel/process.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index c051dc2b42ad..773e9c5594e7 100644 --- a/arch/powerpc/kernel/process.c +++ b/arch/powerpc/kernel/process.c @@ -860,6 +860,9 @@ static void tm_reclaim_thread(struct thread_struct *thr, if (!MSR_TM_SUSPENDED(mfmsr())) return; + /* Give up all the registers and set ckpt_regs.msr */ + giveup_all(container_of(thr, struct task_struct, thread)); + /* * If we are in a transaction and FP is off then we can't have * used FP inside that transaction. Hence the checkpointed @@ -879,8 +882,6 @@ static void tm_reclaim_thread(struct thread_struct *thr, memcpy(&thr->ckvr_state, &thr->vr_state, sizeof(struct thread_vr_state)); - giveup_all(container_of(thr, struct task_struct, thread)); - tm_reclaim(thr, thr->ckpt_regs.msr, cause); }