From patchwork Wed May 19 10:47:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Naveen N. Rao" X-Patchwork-Id: 1480835 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=LTVi58QD; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FlV3C6ll0z9sX1 for ; Wed, 19 May 2021 20:48:39 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4FlV3C6C7Rz302m for ; Wed, 19 May 2021 20:48:39 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=LTVi58QD; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=naveen.n.rao@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=LTVi58QD; dkim-atps=neutral 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 4FlV2J0dmfz2yXx for ; Wed, 19 May 2021 20:47:51 +1000 (AEST) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14JAYma5100300; Wed, 19 May 2021 06:47:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=mMnj1RQOM8E4H/EZznLOa7KieYPntgSbpmiVlC2yupE=; b=LTVi58QD2gwSgN86ZF+lHsgiMO3rgG/lMJQHrBOpD0dw6g66h/wiwyrlPjTXulm51Ht5 jHyEZsNNr3vPx4/v9unEzZaIR7FXA1gMKSZBe9rz36quIWTIvYS0MjmXLWFi/TlvBsb4 nt+CyKlKVoGlX5nIjh5p0vPTD8G3AT5AWXpqXseyu/OCd9K+0bNZiZYI0ZwSrndXiiFX tHKnuQo11I8muRtuHS6rMIITNxQQPwW8vJCH2Gy+V2qH2yHFUogtXIXNbKK3c3aYzAHV dTZZSNhukSvGNgsv1UIq5YwyyIpcBpJGfc0Ppd1Fs6lf92wBSZ7t7tkultOC4PcaYkKA SA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 38n0c09md3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 May 2021 06:47:42 -0400 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 14JAYpZN100863; Wed, 19 May 2021 06:47:42 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 38n0c09mcn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 May 2021 06:47:42 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 14JATT1H030378; Wed, 19 May 2021 10:47:40 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma03fra.de.ibm.com with ESMTP id 38j5x894dp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 May 2021 10:47:40 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 14JAlAvu28639558 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 May 2021 10:47:10 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0BF0EA4051; Wed, 19 May 2021 10:47:38 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 06B65A404D; Wed, 19 May 2021 10:47:36 +0000 (GMT) Received: from naverao1-tp.in.ibm.com (unknown [9.85.72.228]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 19 May 2021 10:47:35 +0000 (GMT) From: "Naveen N. Rao" To: Michael Ellerman , Christophe Leroy , Jordan Niethe Subject: [PATCH 1/5] powerpc/kprobes: Fix validation of prefixed instructions across page boundary Date: Wed, 19 May 2021 16:17:17 +0530 Message-Id: <0df9a032a05576a2fa8e97d1b769af2ff0eafbd6.1621416666.git.naveen.n.rao@linux.vnet.ibm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: MgoHm0ts3erciDYio2PRu6IsVX1LXyQH X-Proofpoint-ORIG-GUID: EGKMBMudMYuBBdv-_o6gD5n1DVG90Rr9 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-05-19_04:2021-05-19, 2021-05-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxscore=0 spamscore=0 lowpriorityscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105190072 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" When checking if the probed instruction is the suffix of a prefixed instruction, we access the instruction at the previous word. If the probed instruction is the very first word of a module, we can end up trying to access an invalid page. Fix this by skipping the check for all instructions at the beginning of a page. Prefixed instructions cannot cross a 64-byte boundary and as such, preventing probing on such instructions is not worthwhile. Cc: stable@vger.kernel.org # v5.8+ Fixes: b4657f7650babc ("powerpc/kprobes: Don't allow breakpoints on suffixes") Reported-by: Christophe Leroy Signed-off-by: Naveen N. Rao --- arch/powerpc/kernel/kprobes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c index 01ab2163659e4b..f611d9eb3562d7 100644 --- a/arch/powerpc/kernel/kprobes.c +++ b/arch/powerpc/kernel/kprobes.c @@ -108,7 +108,6 @@ int arch_prepare_kprobe(struct kprobe *p) int ret = 0; struct kprobe *prev; struct ppc_inst insn = ppc_inst_read((struct ppc_inst *)p->addr); - struct ppc_inst prefix = ppc_inst_read((struct ppc_inst *)(p->addr - 1)); if ((unsigned long)p->addr & 0x03) { printk("Attempt to register kprobe at an unaligned address\n"); @@ -116,7 +115,8 @@ int arch_prepare_kprobe(struct kprobe *p) } else if (IS_MTMSRD(insn) || IS_RFID(insn) || IS_RFI(insn)) { printk("Cannot register a kprobe on rfi/rfid or mtmsr[d]\n"); ret = -EINVAL; - } else if (ppc_inst_prefixed(prefix)) { + } else if ((unsigned long)p->addr & ~PAGE_MASK && + ppc_inst_prefixed(ppc_inst_read((struct ppc_inst *)(p->addr - 1)))) { printk("Cannot register a kprobe on the second word of prefixed instruction\n"); ret = -EINVAL; } From patchwork Wed May 19 10:47:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Naveen N. Rao" X-Patchwork-Id: 1480837 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=MLf5fYbx; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FlV3j3r95z9sCD for ; Wed, 19 May 2021 20:49:05 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4FlV3j33g5z30Ff for ; Wed, 19 May 2021 20:49:05 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=MLf5fYbx; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=naveen.n.rao@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=MLf5fYbx; dkim-atps=neutral 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 4FlV2M3WkKz2ykP for ; Wed, 19 May 2021 20:47:55 +1000 (AEST) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14JAYU9t071254; Wed, 19 May 2021 06:47:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=y7uRnA5sG9SvFvG0LjuRWsHyJ6rc9MrIh26qgCK4/wY=; b=MLf5fYbxSEftV7spOQWP/9SItObO6pZPRKLv9ilVp0dDtsyGo5YW3MTbow6Rute0Eu8a Zehguow6rLdW2HZu4j6i2ro39McI04SH9dXwZAF4Q+zYZTn96C9bbbjrQk0bzI75JkZb Vg7VL8TqEFf7+tUYi/1QxSoBB2twy9pNW/Sf2eyFqcUwTCWVcg+iMjhiD/YY7VmyVUb+ ZDDey7LhnlqA9TaK/JC6EQcakdiXY5sk6TzfOGqkxYPCVrP4i/uGIoeKrbjZ2RZgwfNl uII1Qn3uKAlnyyJDz2R0jIdf2TPbz14IFEqSTF/PDCTn+lb7lsgT5ii4prbHMUHLtf64 Ww== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 38n0aghpx2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 May 2021 06:47:45 -0400 Received: from m0098414.ppops.net (m0098414.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 14JAYhBK072181; Wed, 19 May 2021 06:47:44 -0400 Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com with ESMTP id 38n0aghpwa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 May 2021 06:47:44 -0400 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 14JAlhmt010537; Wed, 19 May 2021 10:47:43 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma06ams.nl.ibm.com with ESMTP id 38j5jgt1rn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 May 2021 10:47:42 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 14JAleRx29425964 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 May 2021 10:47:40 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4E954A4051; Wed, 19 May 2021 10:47:40 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 72154A404D; Wed, 19 May 2021 10:47:38 +0000 (GMT) Received: from naverao1-tp.in.ibm.com (unknown [9.85.72.228]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 19 May 2021 10:47:38 +0000 (GMT) From: "Naveen N. Rao" To: Michael Ellerman , Christophe Leroy , Jordan Niethe Subject: [PATCH 2/5] powerpc/kprobes: Roll IS_RFI() macro into IS_RFID() Date: Wed, 19 May 2021 16:17:18 +0530 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: sDWJSOcnqDXeU9KHDexFl1FQMeYLAulB X-Proofpoint-ORIG-GUID: R2VCkzAvxm08GL8bFmcwDJRCmxp84TDN X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-05-19_04:2021-05-19, 2021-05-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 bulkscore=0 spamscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 phishscore=0 mlxlogscore=873 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105190072 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" In kprobes and xmon, we should exclude both 32-bit and 64-bit variants of mtmsr and rfi instructions from being stepped. Have IS_RFID() also detect a rfi instruction similar to IS_MTMSRD(). Signed-off-by: Naveen N. Rao --- arch/powerpc/include/asm/sstep.h | 7 +++---- arch/powerpc/kernel/kprobes.c | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/include/asm/sstep.h b/arch/powerpc/include/asm/sstep.h index 972ed0df154d60..1df867c2e054e5 100644 --- a/arch/powerpc/include/asm/sstep.h +++ b/arch/powerpc/include/asm/sstep.h @@ -13,12 +13,11 @@ struct pt_regs; * we don't allow putting a breakpoint on an mtmsrd instruction. * Similarly we don't allow breakpoints on rfid instructions. * These macros tell us if an instruction is a mtmsrd or rfid. - * Note that IS_MTMSRD returns true for both an mtmsr (32-bit) - * and an mtmsrd (64-bit). + * Note that these return true for both mtmsr/rfi (32-bit) + * and mtmsrd/rfid (64-bit). */ #define IS_MTMSRD(instr) ((ppc_inst_val(instr) & 0xfc0007be) == 0x7c000124) -#define IS_RFID(instr) ((ppc_inst_val(instr) & 0xfc0007fe) == 0x4c000024) -#define IS_RFI(instr) ((ppc_inst_val(instr) & 0xfc0007fe) == 0x4c000064) +#define IS_RFID(instr) ((ppc_inst_val(instr) & 0xfc0007be) == 0x4c000024) enum instruction_type { COMPUTE, /* arith/logical/CR op, etc. */ diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c index f611d9eb3562d7..b7b20875d34d91 100644 --- a/arch/powerpc/kernel/kprobes.c +++ b/arch/powerpc/kernel/kprobes.c @@ -112,8 +112,8 @@ int arch_prepare_kprobe(struct kprobe *p) if ((unsigned long)p->addr & 0x03) { printk("Attempt to register kprobe at an unaligned address\n"); ret = -EINVAL; - } else if (IS_MTMSRD(insn) || IS_RFID(insn) || IS_RFI(insn)) { - printk("Cannot register a kprobe on rfi/rfid or mtmsr[d]\n"); + } else if (IS_MTMSRD(insn) || IS_RFID(insn)) { + printk("Cannot register a kprobe on mtmsr[d]/rfi[d]\n"); ret = -EINVAL; } else if ((unsigned long)p->addr & ~PAGE_MASK && ppc_inst_prefixed(ppc_inst_read((struct ppc_inst *)(p->addr - 1)))) { From patchwork Wed May 19 10:47:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Naveen N. Rao" X-Patchwork-Id: 1480838 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Y5OmaGEI; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FlV4965rMz9sCD for ; Wed, 19 May 2021 20:49:29 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4FlV495KkWz3c6p for ; Wed, 19 May 2021 20:49:29 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Y5OmaGEI; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=naveen.n.rao@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Y5OmaGEI; dkim-atps=neutral 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 lists.ozlabs.org (Postfix) with ESMTPS id 4FlV2N0Vhmz2yxF for ; Wed, 19 May 2021 20:47:55 +1000 (AEST) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14JAXftv068459; Wed, 19 May 2021 06:47:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=HI1xUJik1hHlw8w5Q4QEE4Nfy9BYztB9ZHbmpRXmDvs=; b=Y5OmaGEIlfN4AFDlf1R7fA+XIOB6O/kr7sypn0zVystweO2o4vwxM+syqdhIM8f9a4Xa 9OwYvstlMuiAMk8mqsfHskUB0ca4zUIu8FN4bm7LAIqkJWdxO6WKCx02z6N0c6HMW3Dv tVUMdqZnBm1WlIvJJtOvTEK6UPNB0ov1s6wlfYiS6RLQqtbwsUaYhbIQlN7vlzrisjZN BH0pYA9I/CjsQ6ojfospaAT5oExSioXvkXpowNkTKQloZ/BmuOG0YlDMsYNuMXBbdFAs /sWWOLlYi5vQKGmqGdfRBBzJ2VNy1GiMyame0B8hFGtC43XUqRFRJWrZx3pFrq/S8Nwt fg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 38n0wdgj4n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 May 2021 06:47:47 -0400 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 14JAXua5070374; Wed, 19 May 2021 06:47:47 -0400 Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 38n0wdgj40-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 May 2021 06:47:46 -0400 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 14JAS6pp003771; Wed, 19 May 2021 10:47:44 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma03ams.nl.ibm.com with ESMTP id 38j5x7t1wy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 May 2021 10:47:44 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 14JAlgZb61604124 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 May 2021 10:47:42 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 88F88A404D; Wed, 19 May 2021 10:47:42 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E0E57A405B; Wed, 19 May 2021 10:47:40 +0000 (GMT) Received: from naverao1-tp.in.ibm.com (unknown [9.85.72.228]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 19 May 2021 10:47:40 +0000 (GMT) From: "Naveen N. Rao" To: Michael Ellerman , Christophe Leroy , Jordan Niethe Subject: [PATCH 3/5] powerpc/kprobes: Check instruction validity during kprobe registration Date: Wed, 19 May 2021 16:17:19 +0530 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: VNBVjxBiF89WbrQr-xt5RO7vx6JqncMI X-Proofpoint-GUID: 38QGrJpPKqbWB4HEF2InaBSe7u61zfps X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-05-19_04:2021-05-19, 2021-05-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 phishscore=0 suspectscore=0 mlxscore=0 malwarescore=0 clxscore=1015 mlxlogscore=999 spamscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105190072 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" In trap-based (classic) kprobes, we try to emulate the probed instruction so as to avoid having to single step it. We use a flag to determine if the probed instruction was successfully emulated, so that we can speed up subsequent probe hits. However, emulate_step() doesn't differentiate between unknown instructions and an emulation attempt that failed. As such, the current heuristic is not of much use. Instead, use analyse_instr() during kprobe registration to determine if the probed instruction can be decoded by our instruction emulation infrastructure. For unknown instructions, we can then directly single-step while for other instructions, we can attempt to emulate and fall back to single stepping if that fails. Signed-off-by: Naveen N. Rao --- arch/powerpc/kernel/kprobes.c | 62 +++++++++-------------------------- 1 file changed, 16 insertions(+), 46 deletions(-) diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c index b7b20875d34d91..bbef9e918ecb39 100644 --- a/arch/powerpc/kernel/kprobes.c +++ b/arch/powerpc/kernel/kprobes.c @@ -107,6 +107,8 @@ int arch_prepare_kprobe(struct kprobe *p) { int ret = 0; struct kprobe *prev; + struct pt_regs regs; + struct instruction_op op; struct ppc_inst insn = ppc_inst_read((struct ppc_inst *)p->addr); if ((unsigned long)p->addr & 0x03) { @@ -140,9 +142,18 @@ int arch_prepare_kprobe(struct kprobe *p) if (!ret) { patch_instruction((struct ppc_inst *)p->ainsn.insn, insn); p->opcode = ppc_inst_val(insn); + + /* Check if this is an instruction we recognise */ + p->ainsn.boostable = 0; + memset(®s, 0, sizeof(struct pt_regs)); + regs.nip = (unsigned long)p->addr; + regs.msr = MSR_KERNEL; + ret = analyse_instr(&op, ®s, insn); + if (ret == 1 || (ret == 0 && GETTYPE(op.type) != UNKNOWN)) + p->ainsn.boostable = 1; + ret = 0; } - p->ainsn.boostable = 0; return ret; } NOKPROBE_SYMBOL(arch_prepare_kprobe); @@ -225,47 +236,6 @@ void arch_prepare_kretprobe(struct kretprobe_instance *ri, struct pt_regs *regs) } NOKPROBE_SYMBOL(arch_prepare_kretprobe); -static int try_to_emulate(struct kprobe *p, struct pt_regs *regs) -{ - int ret; - struct ppc_inst insn = ppc_inst_read((struct ppc_inst *)p->ainsn.insn); - - /* regs->nip is also adjusted if emulate_step returns 1 */ - ret = emulate_step(regs, insn); - if (ret > 0) { - /* - * Once this instruction has been boosted - * successfully, set the boostable flag - */ - if (unlikely(p->ainsn.boostable == 0)) - p->ainsn.boostable = 1; - } else if (ret < 0) { - /* - * We don't allow kprobes on mtmsr(d)/rfi(d), etc. - * So, we should never get here... but, its still - * good to catch them, just in case... - */ - printk("Can't step on instruction %s\n", ppc_inst_as_str(insn)); - BUG(); - } else { - /* - * If we haven't previously emulated this instruction, then it - * can't be boosted. Note it down so we don't try to do so again. - * - * If, however, we had emulated this instruction in the past, - * then this is just an error with the current run (for - * instance, exceptions due to a load/store). We return 0 so - * that this is now single-stepped, but continue to try - * emulating it in subsequent probe hits. - */ - if (unlikely(p->ainsn.boostable != 1)) - p->ainsn.boostable = -1; - } - - return ret; -} -NOKPROBE_SYMBOL(try_to_emulate); - int kprobe_handler(struct pt_regs *regs) { struct kprobe *p; @@ -334,8 +304,8 @@ int kprobe_handler(struct pt_regs *regs) set_current_kprobe(p, regs, kcb); kprobes_inc_nmissed_count(p); kcb->kprobe_status = KPROBE_REENTER; - if (p->ainsn.boostable >= 0) { - ret = try_to_emulate(p, regs); + if (p->ainsn.boostable) { + ret = emulate_step(regs, ppc_inst_read((struct ppc_inst *)p->ainsn.insn)); if (ret > 0) { restore_previous_kprobe(kcb); @@ -356,8 +326,8 @@ int kprobe_handler(struct pt_regs *regs) return 1; } - if (p->ainsn.boostable >= 0) { - ret = try_to_emulate(p, regs); + if (p->ainsn.boostable) { + ret = emulate_step(regs, ppc_inst_read((struct ppc_inst *)p->ainsn.insn)); if (ret > 0) { if (p->post_handler) From patchwork Wed May 19 10:47:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Naveen N. Rao" X-Patchwork-Id: 1480839 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=fgOeaCdy; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FlV4m6KmGz9sCD for ; Wed, 19 May 2021 20:50:00 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4FlV4m5wyDz302D for ; Wed, 19 May 2021 20:50:00 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=fgOeaCdy; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=naveen.n.rao@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=fgOeaCdy; dkim-atps=neutral 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 4FlV2P58f1z3021 for ; Wed, 19 May 2021 20:47:57 +1000 (AEST) Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14JAXMbg060942; Wed, 19 May 2021 06:47:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=pck/0HzqIqFKP2DtlKubg3MXM1ejDFgg5K/mi4qw9bA=; b=fgOeaCdyp8tDl5Ud+4Musn9aK/MK5BvC/kMZIclH2YV0OZCJ0S16w1b9pvIhSFweQrK5 YsZemIQ+Z/84HgYEIWNx+wThemli8RKAAh54WKEnI4Lq20yvqCZ48r/Surr2NURAZ85h K/Aquw/4T4YxyvZm1Y8DrSgwj2J1bscnOu4w63IhqAdnW7i27CuuPm8IANbIudElTbvT K1/2k8g5iTV1j4QXnC5pxIQFSHFCur6E+VIK/MhgdPwFLHn6aTQ9yG6zIpYNXn3SR8lP FC54i2QqIx0LXGHlafoFFiZf8IdtdcejRjolEFpEJxPKln8qlpvFBYzqpMgRYFjQtfRP /A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 38n0s18q8v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 May 2021 06:47:49 -0400 Received: from m0098413.ppops.net (m0098413.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 14JAYsND068883; Wed, 19 May 2021 06:47:49 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 38n0s18q86-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 May 2021 06:47:49 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 14JATFBo030323; Wed, 19 May 2021 10:47:47 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma03fra.de.ibm.com with ESMTP id 38j5x894dr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 May 2021 10:47:47 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 14JAlHHG37487014 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 May 2021 10:47:17 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E097DA404D; Wed, 19 May 2021 10:47:44 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E71CFA4051; Wed, 19 May 2021 10:47:42 +0000 (GMT) Received: from naverao1-tp.in.ibm.com (unknown [9.85.72.228]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 19 May 2021 10:47:42 +0000 (GMT) From: "Naveen N. Rao" To: Michael Ellerman , Christophe Leroy , Jordan Niethe Subject: [PATCH 4/5] powerpc/kprobes: Refactor arch_prepare_kprobe() Date: Wed, 19 May 2021 16:17:20 +0530 Message-Id: <6a532d967b1263d463c2413fd647a173453bdc15.1621416666.git.naveen.n.rao@linux.vnet.ibm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Lu0yLH8uIzRltWn5CDb05hRpgZx_Wqpc X-Proofpoint-GUID: jUMgmy0dr2oTRcZhIz-SDgs-a7LI3AEJ X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-05-19_04:2021-05-19, 2021-05-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 mlxlogscore=984 mlxscore=0 bulkscore=0 adultscore=0 suspectscore=0 impostorscore=0 clxscore=1015 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105190072 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Clean up the function to look sane: - return immediately on error, rather than pointlessly setting the return value - pr_info() instead of printk() - check return value of patch_instruction() - and to top it all of: a reverse christmas tree! Signed-off-by: Naveen N. Rao --- arch/powerpc/kernel/kprobes.c | 64 +++++++++++++++++------------------ 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c index bbef9e918ecb39..7195162362941f 100644 --- a/arch/powerpc/kernel/kprobes.c +++ b/arch/powerpc/kernel/kprobes.c @@ -105,56 +105,54 @@ kprobe_opcode_t *kprobe_lookup_name(const char *name, unsigned int offset) int arch_prepare_kprobe(struct kprobe *p) { - int ret = 0; + struct ppc_inst insn = ppc_inst_read((struct ppc_inst *)p->addr); + struct instruction_op op; struct kprobe *prev; struct pt_regs regs; - struct instruction_op op; - struct ppc_inst insn = ppc_inst_read((struct ppc_inst *)p->addr); + int ret = 0; if ((unsigned long)p->addr & 0x03) { - printk("Attempt to register kprobe at an unaligned address\n"); - ret = -EINVAL; + pr_info("Attempt to register kprobe at an unaligned address\n"); + return -EINVAL; } else if (IS_MTMSRD(insn) || IS_RFID(insn)) { - printk("Cannot register a kprobe on mtmsr[d]/rfi[d]\n"); - ret = -EINVAL; + pr_info("Cannot register a kprobe on mtmsr[d]/rfi[d]\n"); + return -EINVAL; } else if ((unsigned long)p->addr & ~PAGE_MASK && ppc_inst_prefixed(ppc_inst_read((struct ppc_inst *)(p->addr - 1)))) { - printk("Cannot register a kprobe on the second word of prefixed instruction\n"); - ret = -EINVAL; + pr_info("Cannot register a kprobe on the second word of prefixed instruction\n"); + return -EINVAL; } + + /* Check if the previous instruction is a prefix instruction with an active kprobe */ preempt_disable(); prev = get_kprobe(p->addr - 1); preempt_enable_no_resched(); - if (prev && - ppc_inst_prefixed(ppc_inst_read((struct ppc_inst *)prev->ainsn.insn))) { - printk("Cannot register a kprobe on the second word of prefixed instruction\n"); - ret = -EINVAL; + if (prev && ppc_inst_prefixed(ppc_inst_read((struct ppc_inst *)prev->ainsn.insn))) { + pr_info("Cannot register a kprobe on the second word of prefixed instruction\n"); + return -EINVAL; } /* insn must be on a special executable page on ppc64. This is * not explicitly required on ppc32 (right now), but it doesn't hurt */ - if (!ret) { - p->ainsn.insn = get_insn_slot(); - if (!p->ainsn.insn) - ret = -ENOMEM; - } + p->ainsn.insn = get_insn_slot(); + if (!p->ainsn.insn) + return -ENOMEM; - if (!ret) { - patch_instruction((struct ppc_inst *)p->ainsn.insn, insn); - p->opcode = ppc_inst_val(insn); - - /* Check if this is an instruction we recognise */ - p->ainsn.boostable = 0; - memset(®s, 0, sizeof(struct pt_regs)); - regs.nip = (unsigned long)p->addr; - regs.msr = MSR_KERNEL; - ret = analyse_instr(&op, ®s, insn); - if (ret == 1 || (ret == 0 && GETTYPE(op.type) != UNKNOWN)) - p->ainsn.boostable = 1; - ret = 0; - } + if (patch_instruction((struct ppc_inst *)p->ainsn.insn, insn)) + return -EFAULT; - return ret; + p->opcode = ppc_inst_val(insn); + + /* Check if this is an instruction we recognise */ + p->ainsn.boostable = 0; + memset(®s, 0, sizeof(struct pt_regs)); + regs.nip = (unsigned long)p->addr; + regs.msr = MSR_KERNEL; + ret = analyse_instr(&op, ®s, insn); + if (ret == 1 || (ret == 0 && GETTYPE(op.type) != UNKNOWN)) + p->ainsn.boostable = 1; + + return 0; } NOKPROBE_SYMBOL(arch_prepare_kprobe); From patchwork Wed May 19 10:47:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Naveen N. Rao" X-Patchwork-Id: 1480840 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=mfBeOBwr; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FlV5K2jLlz9sXM for ; Wed, 19 May 2021 20:50:29 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4FlV5K1nbWz3cGd for ; Wed, 19 May 2021 20:50:29 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=mfBeOBwr; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=naveen.n.rao@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=mfBeOBwr; dkim-atps=neutral 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 lists.ozlabs.org (Postfix) with ESMTPS id 4FlV2Y6HxKz3068 for ; Wed, 19 May 2021 20:48:05 +1000 (AEST) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14JAhYFv038721; Wed, 19 May 2021 06:47:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=n72zeEhlfmLyVDF+mvHpIAVNMFr/sI9GKBbqisuuxNI=; b=mfBeOBwrNcGTZTFpby5xTHhBm87NSH1vf0wYtKVTlKzT0TZnPwRCsvtRdrmv8TrGuEt4 W3FQDmHIP80KQNXvvU2dRNyytBwH5bIl2Ldu3GfPLXzbsUdAvYEAJdvV9vMN9FQhy2mW cyeJgv6CPrXmP/AhbLrggzaw4nbmxpe08MAOR2IldiCroOXlwpa1k1MAYP578o7xPCz+ 1GIbAEtHFx1Wkev2GdpMN8hQEV7iy5cyCBaIfExS9vrR7GkxNPdlfvaxKRP61Uw3k84Z jdsIUFDbQj8j0vqsx+OuJTPb8RBdW4vme2ZUSJqVwZg8NYmRD3Og9ajhsJIiwJIYpbrF 7A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 38n0sp8rrc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 May 2021 06:47:52 -0400 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 14JAhoKd039324; Wed, 19 May 2021 06:47:52 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 38n0sp8rqb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 May 2021 06:47:52 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 14JASPQ6029796; Wed, 19 May 2021 10:47:49 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma03fra.de.ibm.com with ESMTP id 38j5x894dt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 May 2021 10:47:49 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 14JAllwg16712066 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 May 2021 10:47:47 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 431BAA404D; Wed, 19 May 2021 10:47:47 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 50FB1A4040; Wed, 19 May 2021 10:47:45 +0000 (GMT) Received: from naverao1-tp.in.ibm.com (unknown [9.85.72.228]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 19 May 2021 10:47:45 +0000 (GMT) From: "Naveen N. Rao" To: Michael Ellerman , Christophe Leroy , Jordan Niethe Subject: [PATCH 5/5] powerpc/kprobes: Warn if instruction patching failed Date: Wed, 19 May 2021 16:17:21 +0530 Message-Id: <18d7b1309f938c08ce07738100932b551bdd3a52.1621416666.git.naveen.n.rao@linux.vnet.ibm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: yHbHOP_Zy5g3pIrVmUfY3Lr-ZrL743qe X-Proofpoint-ORIG-GUID: M5xa1Sf0YOzOuzmlWtf6aOTBRv2PHa0W X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-05-19_04:2021-05-19, 2021-05-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 impostorscore=0 bulkscore=0 adultscore=0 spamscore=0 clxscore=1015 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105190072 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" When arming and disarming probes, we currently assume that instruction patching can never fail, and don't have a mechanism to surface errors. Add a warning in case instruction patching ever fails. Signed-off-by: Naveen N. Rao --- arch/powerpc/kernel/kprobes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c index 7195162362941f..e0190e75a221eb 100644 --- a/arch/powerpc/kernel/kprobes.c +++ b/arch/powerpc/kernel/kprobes.c @@ -158,13 +158,13 @@ NOKPROBE_SYMBOL(arch_prepare_kprobe); void arch_arm_kprobe(struct kprobe *p) { - patch_instruction((struct ppc_inst *)p->addr, ppc_inst(BREAKPOINT_INSTRUCTION)); + WARN_ON_ONCE(patch_instruction((struct ppc_inst *)p->addr, ppc_inst(BREAKPOINT_INSTRUCTION))); } NOKPROBE_SYMBOL(arch_arm_kprobe); void arch_disarm_kprobe(struct kprobe *p) { - patch_instruction((struct ppc_inst *)p->addr, ppc_inst(p->opcode)); + WARN_ON_ONCE(patch_instruction((struct ppc_inst *)p->addr, ppc_inst(p->opcode))); } NOKPROBE_SYMBOL(arch_disarm_kprobe);