From patchwork Mon Nov 28 02:44:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gray X-Patchwork-Id: 26460 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5399088wrr; Sun, 27 Nov 2022 18:46:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf5ui81Gn59d626TaodmP6Zx57e9UVDkkD1gdtJA+QN7lX4B7C/CsUvP0EkJauWaRORhuixX X-Received: by 2002:a05:6402:520a:b0:459:4c7b:e852 with SMTP id s10-20020a056402520a00b004594c7be852mr33294990edd.347.1669603614526; Sun, 27 Nov 2022 18:46:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669603614; cv=none; d=google.com; s=arc-20160816; b=S/1LKFeB66+iI7PRuTLNGxUOIMPYye7AjcZTq3dyh0+h/fuOVdOBUhDIv9IIyzH9Ue 2pX/m4Oa7mElH45C3TEVzrvAJCZFNZDbDJBWNp3HfChqfEsRZPK003EtDsref6wXU3Xy ClVduNThDJFMrQuT0N0MH9EOYUM77gIjwDavBM3MsWVS/m4NlsE+brj2fkIylF063BIU s15jZEzF10uAJfQWhdBeNZF46SdMFE6gl1OOO//XQvrSJV0+2pxEfsimcQ9mnlxkdW3x os74CwVfTdM/yoU6G0ejDE9s/g5MZcPze4UMLUg8FwqK+xQ6vDmMI68WV9EmlQUjyHBU BfNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+fBKAg+WmulB7ZeaiELLpnzDxsjF37sIrJC+a6vCqA4=; b=NU8ylgKJQ5XPFWKiyDeUd8eTNffIM6fg/zncc3JLTU1RQgH46JB9J2BLA06ssc9uLl +UUqwkMzXLq3jyQZeIXdwOiEPfevBPHwrn4+VKTO1JhaDDZdH0vRvF8kwYdPluO6YQxS j8fxNghzerLDILnGK7NMTY33PQaC3dBhtazzD1felXpHdYWJ48+PG6Gtrfq6hoDSDcFc S2KDG0Hvdr7a1m42eNh/Hkdt5OHn6dgVZqr9GCJzUCAMZurS43PK4vaWCsC0DnZShSdO fZjfA8VkOmPg9rI41ImDGhRkZI8sd9aK2B6/x86bR/V6Lt8mIm1Jgz4S1SRS0q2F/9iz XPBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=qCrMro86; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qm5-20020a170907674500b007836ec6999dsi8329642ejc.904.2022.11.27.18.46.31; Sun, 27 Nov 2022 18:46:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=qCrMro86; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229752AbiK1CqF (ORCPT + 99 others); Sun, 27 Nov 2022 21:46:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229575AbiK1CqB (ORCPT ); Sun, 27 Nov 2022 21:46:01 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 529F3A18D; Sun, 27 Nov 2022 18:46:00 -0800 (PST) Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AS2H5VZ025654; Mon, 28 Nov 2022 02:45:47 GMT 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=+fBKAg+WmulB7ZeaiELLpnzDxsjF37sIrJC+a6vCqA4=; b=qCrMro86LDonVTzBgi+IP5ysiGoc5eNmFRCVer65h7BOE1+ax0ywmSkmpnsBxcKQUPnT 2wzQcTGGY2jffVauS1ehIm+rSAC8K6wnanpyb7Jay7gT99smp1jTUFv8Ax3b3KXaDAoN B00IASnJuH1gFcw6tNc6M2jbYPElNxI5C8qZcBrbm/bakCHuOCM3cEbnf8jpC1RyskI6 2LgC+A8uFBA5RRLU1pV+0BVMS7aR5j+YSEJ+myhMVNDOPt2sM1E+9QW63HFsFoY3Kxi4 uQYFCQxHAGpoBA4BPOm9Qq/jBHHH/mK/sZKSFNfY4E/6YVqS62tVvkVJrzNJsGIA7tdp Dg== Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3m3vnnumyw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Nov 2022 02:45:47 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2AS2ZJ03014933; Mon, 28 Nov 2022 02:45:45 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma05fra.de.ibm.com with ESMTP id 3m3ae99b6j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Nov 2022 02:45:45 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2AS2jhDs38994236 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Nov 2022 02:45:43 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2A3D7A405C; Mon, 28 Nov 2022 02:45:43 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C8749A405B; Mon, 28 Nov 2022 02:45:42 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 28 Nov 2022 02:45:42 +0000 (GMT) Received: from li-0d7fa1cc-2c9d-11b2-a85c-aed20764436d.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 4AEE360366; Mon, 28 Nov 2022 13:45:39 +1100 (AEDT) From: Benjamin Gray To: linuxppc-dev@lists.ozlabs.org Cc: ajd@linux.ibm.com, ruscur@russell.cc, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, cmr@bluescreens.de, Benjamin Gray Subject: [RFC PATCH 03/13] powerpc/dexcr: Handle hashchk exception Date: Mon, 28 Nov 2022 13:44:48 +1100 Message-Id: <20221128024458.46121-4-bgray@linux.ibm.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221128024458.46121-1-bgray@linux.ibm.com> References: <20221128024458.46121-1-bgray@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: O04wau0dzEy9mLrEdUENrMRoTmQipoec X-Proofpoint-GUID: O04wau0dzEy9mLrEdUENrMRoTmQipoec X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-28_02,2022-11-25_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 bulkscore=0 spamscore=0 phishscore=0 suspectscore=0 adultscore=0 lowpriorityscore=0 mlxscore=0 impostorscore=0 clxscore=1011 mlxlogscore=737 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211280018 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750706279450457442?= X-GMAIL-MSGID: =?utf-8?q?1750706279450457442?= Recognise and pass the appropriate signal to the user program when a hashchk instruction triggers. This is independent of allowing configuration of DEXCR[NPHIE], as a hypervisor can enforce this aspect regardless of the kernel. Signed-off-by: Benjamin Gray --- arch/powerpc/include/asm/ppc-opcode.h | 1 + arch/powerpc/include/asm/processor.h | 6 ++++++ arch/powerpc/kernel/dexcr.c | 22 ++++++++++++++++++++++ arch/powerpc/kernel/traps.c | 6 ++++++ 4 files changed, 35 insertions(+) diff --git a/arch/powerpc/include/asm/ppc-opcode.h b/arch/powerpc/include/asm/ppc-opcode.h index 21e33e46f4b8..89b316466ed1 100644 --- a/arch/powerpc/include/asm/ppc-opcode.h +++ b/arch/powerpc/include/asm/ppc-opcode.h @@ -215,6 +215,7 @@ #define OP_31_XOP_STFSX 663 #define OP_31_XOP_STFSUX 695 #define OP_31_XOP_STFDX 727 +#define OP_31_XOP_HASHCHK 754 #define OP_31_XOP_STFDUX 759 #define OP_31_XOP_LHBRX 790 #define OP_31_XOP_LFIWAX 855 diff --git a/arch/powerpc/include/asm/processor.h b/arch/powerpc/include/asm/processor.h index 0a8a793b8b8b..c17ec1e44c86 100644 --- a/arch/powerpc/include/asm/processor.h +++ b/arch/powerpc/include/asm/processor.h @@ -448,10 +448,16 @@ void *exit_vmx_ops(void *dest); #ifdef CONFIG_PPC_BOOK3S_64 +bool is_hashchk_trap(struct pt_regs const *regs); unsigned long get_thread_dexcr(struct thread_struct const *t); #else +static inline bool is_hashchk_trap(struct pt_regs const *regs) +{ + return false; +} + static inline unsigned long get_thread_dexcr(struct thread_struct const *t) { return 0; diff --git a/arch/powerpc/kernel/dexcr.c b/arch/powerpc/kernel/dexcr.c index 32a0a69ff638..11515e67afac 100644 --- a/arch/powerpc/kernel/dexcr.c +++ b/arch/powerpc/kernel/dexcr.c @@ -3,6 +3,9 @@ #include #include +#include +#include +#include #include #include @@ -19,6 +22,25 @@ static int __init dexcr_init(void) } early_initcall(dexcr_init); +bool is_hashchk_trap(struct pt_regs const *regs) +{ + ppc_inst_t insn; + + if (!cpu_has_feature(CPU_FTR_DEXCR_NPHIE)) + return false; + + if (get_user_instr(insn, (void __user *)regs->nip)) { + WARN_ON(1); + return false; + } + + if (ppc_inst_primary_opcode(insn) == 31 && + get_xop(ppc_inst_val(insn)) == OP_31_XOP_HASHCHK) + return true; + + return false; +} + unsigned long get_thread_dexcr(struct thread_struct const *t) { return DEFAULT_DEXCR; diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c index 9bdd79aa51cf..b83f5b382f24 100644 --- a/arch/powerpc/kernel/traps.c +++ b/arch/powerpc/kernel/traps.c @@ -1516,6 +1516,12 @@ static void do_program_check(struct pt_regs *regs) return; } } + + if (user_mode(regs) && is_hashchk_trap(regs)) { + _exception(SIGILL, regs, ILL_ILLOPN, regs->nip); + return; + } + _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip); return; }