Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3925408ybi; Mon, 10 Jun 2019 20:35:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqzvb0vmxmxpCs87PTeBTLboXTXwpHCKRNqS4kXF1M0++cM73r8MqPejp6QQ+aXelibv178f X-Received: by 2002:a17:902:e409:: with SMTP id ci9mr73883403plb.103.1560224121064; Mon, 10 Jun 2019 20:35:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560224121; cv=none; d=google.com; s=arc-20160816; b=ImxUNANHcGDTPA0I4W/tAw1hMskenkfurmcBPZrr9xQqJIL+AoUAqLHAreoRJQaGQ5 fVYbj/fdwyu/6yOjQ4PVHbiHkqpN2D9c8Kz993yH9064ufBMaEESQjECAl79dKiEOi+n jY0DV66lyMokC2M/hBe3S2HcoNgMk12vrRpXNkcxy62HQE5eH4OuOnFKd8JSvLGc0MKM l2V3XsnQMCH2b+N1MEzKj03IIx4ErX91Iw5IL98MethD2yZzabixa2xvH6JiUxukQjW7 bYrHNOTi3fOlC16K3abqTpvvVYKIBT2mxQhrq7t00R8nTaHe8gaqvELKBwM8P8olj+1T LMqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:subject:cc:to:from; bh=YtVS6KVNGZx6/ha+1MejT09j+tJr8U72+KfqDXHCvcA=; b=fyg2Eg4jgyHkfCe9r7HaIb3F/NoFJP3MawRfDfD1lRtmgF6Sagn1o1cUcMwMrXxMPG 3cAa5+P5sfIc2WOkVSp5O1b0nI5qmi4tMxA/G5sIItOLbZnRhL3yhazCzKjnhlTCo0eq UqAHaUlblDkhs3ZAMlFL+hs0Rq01uzcW9lZ0Ha7St5//rzOhK6ElA1DO+oQS3XoYfsoy zkZQR62EhBwNrNI7HhD4Hyt5scNQe9FZYXQTERvfoiP4TBOH74P7wPsomRqtUGDyYywy gf3HzRbVKpT0iHgN07ibQLYXvU2YSWBdbKV48GQphF2DRUJHgOkb9e7eYuPUGbMvrwI1 vx9w== ARC-Authentication-Results: i=1; mx.google.com; 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k186si5547198pgd.148.2019.06.10.20.35.05; Mon, 10 Jun 2019 20:35:21 -0700 (PDT) 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; 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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390950AbfFKDfC (ORCPT + 99 others); Mon, 10 Jun 2019 23:35:02 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:34100 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390881AbfFKDfB (ORCPT ); Mon, 10 Jun 2019 23:35:01 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5B3XXq7142566 for ; Mon, 10 Jun 2019 23:35:00 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0a-001b2d01.pphosted.com with ESMTP id 2t22av4aat-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 10 Jun 2019 23:35:00 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 11 Jun 2019 04:34:57 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 11 Jun 2019 04:34:53 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x5B3Yrnr45089018 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Jun 2019 03:34:53 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DD1A9A404D; Tue, 11 Jun 2019 03:34:52 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 56DF5A4055; Tue, 11 Jun 2019 03:34:49 +0000 (GMT) Received: from bangoria.ibmuc.com (unknown [9.102.1.214]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 11 Jun 2019 03:34:49 +0000 (GMT) From: Ravi Bangoria To: mpe@ellerman.id.au Cc: mikey@neuling.org, benh@kernel.crashing.org, paulus@samba.org, npiggin@gmail.com, christophe.leroy@c-s.fr, mahesh@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, naveen.n.rao@linux.vnet.ibm.com Subject: [PATCH RESEND] Powerpc/Watchpoint: Restore nvgprs while returning from exception Date: Tue, 11 Jun 2019 09:04:47 +0530 X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19061103-0020-0000-0000-00000348F15D X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19061103-0021-0000-0000-0000219C15D7 Message-Id: <20190611033447.28815-1-ravi.bangoria@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-06-11_01:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906110023 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Powerpc hw triggers watchpoint before executing the instruction. To make trigger-after-execute behavior, kernel emulates the instruction. If the instruction is 'load something into non-volatile register', exception handler should restore emulated register state while returning back, otherwise there will be register state corruption. Ex, Adding a watchpoint on a list can corrput the list: # cat /proc/kallsyms | grep kthread_create_list c00000000121c8b8 d kthread_create_list Add watchpoint on kthread_create_list->prev: # perf record -e mem:0xc00000000121c8c0 Run some workload such that new kthread gets invoked. Ex, I just logged out from console: list_add corruption. next->prev should be prev (c000000001214e00), \ but was c00000000121c8b8. (next=c00000000121c8b8). WARNING: CPU: 59 PID: 309 at lib/list_debug.c:25 __list_add_valid+0xb4/0xc0 CPU: 59 PID: 309 Comm: kworker/59:0 Kdump: loaded Not tainted 5.1.0-rc7+ #69 ... NIP __list_add_valid+0xb4/0xc0 LR __list_add_valid+0xb0/0xc0 Call Trace: __list_add_valid+0xb0/0xc0 (unreliable) __kthread_create_on_node+0xe0/0x260 kthread_create_on_node+0x34/0x50 create_worker+0xe8/0x260 worker_thread+0x444/0x560 kthread+0x160/0x1a0 ret_from_kernel_thread+0x5c/0x70 List corruption happened because it uses 'load into non-volatile register' instruction: Snippet from __kthread_create_on_node: c000000000136be8: addis r29,r2,-19 c000000000136bec: ld r29,31424(r29) if (!__list_add_valid(new, prev, next)) c000000000136bf0: mr r3,r30 c000000000136bf4: mr r5,r28 c000000000136bf8: mr r4,r29 c000000000136bfc: bl c00000000059a2f8 <__list_add_valid+0x8> Register state from WARN_ON(): GPR00: c00000000059a3a0 c000007ff23afb50 c000000001344e00 0000000000000075 GPR04: 0000000000000000 0000000000000000 0000001852af8bc1 0000000000000000 GPR08: 0000000000000001 0000000000000007 0000000000000006 00000000000004aa GPR12: 0000000000000000 c000007ffffeb080 c000000000137038 c000005ff62aaa00 GPR16: 0000000000000000 0000000000000000 c000007fffbe7600 c000007fffbe7370 GPR20: c000007fffbe7320 c000007fffbe7300 c000000001373a00 0000000000000000 GPR24: fffffffffffffef7 c00000000012e320 c000007ff23afcb0 c000000000cb8628 GPR28: c00000000121c8b8 c000000001214e00 c000007fef5b17e8 c000007fef5b17c0 Watchpoint hit at 0xc000000000136bec. addis r29,r2,-19 => r29 = 0xc000000001344e00 + (-19 << 16) => r29 = 0xc000000001214e00 ld r29,31424(r29) => r29 = *(0xc000000001214e00 + 31424) => r29 = *(0xc00000000121c8c0) 0xc00000000121c8c0 is where we placed a watchpoint and thus this instruction was emulated by emulate_step. But because handle_dabr_fault did not restore emulated register state, r29 still contains stale value in above register state. Fixes: 5aae8a5370802 ("powerpc, hw_breakpoints: Implement hw_breakpoints for 64-bit server processors") Signed-off-by: Ravi Bangoria Cc: stable@vger.kernel.org # 2.6.36+ Reviewed-by: Naveen N. Rao --- arch/powerpc/kernel/exceptions-64s.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S index 6b86055e5251..0e649d980ec3 100644 --- a/arch/powerpc/kernel/exceptions-64s.S +++ b/arch/powerpc/kernel/exceptions-64s.S @@ -1761,7 +1761,7 @@ handle_dabr_fault: ld r5,_DSISR(r1) addi r3,r1,STACK_FRAME_OVERHEAD bl do_break -12: b ret_from_except_lite +12: b ret_from_except #ifdef CONFIG_PPC_BOOK3S_64 -- 2.20.1