From patchwork Thu Jun 7 15:25:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Franco de Carvalho X-Patchwork-Id: 926374 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 411qKR1K8Jz9s01 for ; Fri, 8 Jun 2018 01:32:11 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 411qKQ74KkzF356 for ; Fri, 8 Jun 2018 01:32:10 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=pedromfc@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com 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 411qBB6rXKzF34G for ; Fri, 8 Jun 2018 01:25:51 +1000 (AEST) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w57FOkd9076451 for ; Thu, 7 Jun 2018 11:25:50 -0400 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0a-001b2d01.pphosted.com with ESMTP id 2jf5q15epb-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 07 Jun 2018 11:25:49 -0400 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 7 Jun 2018 09:25:49 -0600 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 7 Jun 2018 09:25:45 -0600 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w57FPivL10420658 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 7 Jun 2018 08:25:44 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A637BBE05B for ; Thu, 7 Jun 2018 09:25:44 -0600 (MDT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6E183BE058 for ; Thu, 7 Jun 2018 09:25:44 -0600 (MDT) Received: from pedro.localdomain (unknown [9.18.235.95]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP for ; Thu, 7 Jun 2018 09:25:44 -0600 (MDT) Received: by pedro.localdomain (Postfix, from userid 1000) id 057C33C040C; Thu, 7 Jun 2018 12:25:42 -0300 (-03) From: Pedro Franco de Carvalho To: linuxppc-dev@lists.ozlabs.org Subject: [RFC PATCH 3/5] powerpc: Fix pmu get/set functions Date: Thu, 7 Jun 2018 12:25:32 -0300 X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180607152534.29427-1-pedromfc@linux.vnet.ibm.com> References: <20180607152534.29427-1-pedromfc@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18060715-0016-0000-0000-000008EA0A8E X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009146; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000265; SDB=6.01043546; UDB=6.00534338; IPR=6.00822637; MB=3.00021513; MTD=3.00000008; XFM=3.00000015; UTC=2018-06-07 15:25:47 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18060715-0017-0000-0000-00003F2917D6 Message-Id: <20180607152534.29427-4-pedromfc@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-06-07_06:, , 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=726 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806070173 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" The PMU regset exposed through ptrace has 5 64-bit words, which are all copied in and out. However, mmcr0 in the thread_struct is an unsigned, which causes pmu_set to clobber the next variable in the thread_struct (used_ebb), and pmu_get to return the same variable in one half of the mmcr0 slot. --- arch/powerpc/kernel/ptrace.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c index be8ca03a0bd5..69123feaef9e 100644 --- a/arch/powerpc/kernel/ptrace.c +++ b/arch/powerpc/kernel/ptrace.c @@ -1733,6 +1733,9 @@ static int pmu_get(struct task_struct *target, unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) { + int ret = 0; + unsigned long mmcr0 = target->thread.mmcr0; + /* Build tests */ BUILD_BUG_ON(TSO(siar) + sizeof(unsigned long) != TSO(sdar)); BUILD_BUG_ON(TSO(sdar) + sizeof(unsigned long) != TSO(sier)); @@ -1742,9 +1745,16 @@ static int pmu_get(struct task_struct *target, if (!cpu_has_feature(CPU_FTR_ARCH_207S)) return -ENODEV; - return user_regset_copyout(&pos, &count, &kbuf, &ubuf, - &target->thread.siar, 0, + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, + &target->thread.siar, 0, + 4 * sizeof(unsigned long)); + + if (!ret) + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, + &mmcr0, 4 * sizeof(unsigned long), 5 * sizeof(unsigned long)); + + return ret; } static int pmu_set(struct task_struct *target, @@ -1754,6 +1764,12 @@ static int pmu_set(struct task_struct *target, { int ret = 0; +#ifdef __BIG_ENDIAN + int mmcr0_offset = sizeof(unsigned); +#else + int mmcr0_offset = 0; +#endif + /* Build tests */ BUILD_BUG_ON(TSO(siar) + sizeof(unsigned long) != TSO(sdar)); BUILD_BUG_ON(TSO(sdar) + sizeof(unsigned long) != TSO(sier)); @@ -1783,9 +1799,16 @@ static int pmu_set(struct task_struct *target, 4 * sizeof(unsigned long)); if (!ret) + ret = user_regset_copyin_ignore(&pos, &count, &kbuf, + &ubuf, 4 * sizeof(unsigned long), + 4 * sizeof(unsigned long) + mmcr0_offset); + + if (!ret) ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, - &target->thread.mmcr0, 4 * sizeof(unsigned long), - 5 * sizeof(unsigned long)); + &target->thread.mmcr0, + 4 * sizeof(unsigned long) + mmcr0_offset, + 4 * sizeof(unsigned long) + mmcr0_offset + + sizeof (unsigned)); return ret; } #endif