From patchwork Thu Feb 28 03:26:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stewart Smith X-Patchwork-Id: 1049250 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 448ydn2nXpz9s2R for ; Thu, 28 Feb 2019 14:26:53 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 448ydn1DVNzDqL5 for ; Thu, 28 Feb 2019 14:26:53 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=stewart@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.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 448ydg4683zDqKT for ; Thu, 28 Feb 2019 14:26:47 +1100 (AEDT) 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 x1S3PO35035508 for ; Wed, 27 Feb 2019 22:26:29 -0500 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0a-001b2d01.pphosted.com with ESMTP id 2qx6getk4d-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 27 Feb 2019 22:26:29 -0500 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 28 Feb 2019 03:26:27 -0000 Received: from b01cxnp23032.gho.pok.ibm.com (9.57.198.27) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 28 Feb 2019 03:26:26 -0000 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x1S3QPbj24445162 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 28 Feb 2019 03:26:25 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 786A7B206A for ; Thu, 28 Feb 2019 03:26:25 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 38EC2B205F for ; Thu, 28 Feb 2019 03:26:25 +0000 (GMT) Received: from birb.localdomain (unknown [9.185.142.38]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP for ; Thu, 28 Feb 2019 03:26:25 +0000 (GMT) Received: by birb.localdomain (Postfix, from userid 1000) id 74CCB4EC65C; Thu, 28 Feb 2019 14:26:21 +1100 (AEDT) From: Stewart Smith To: skiboot@lists.ozlabs.org Date: Thu, 28 Feb 2019 14:26:20 +1100 X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 19022803-0040-0000-0000-000004C92B01 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010677; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000281; SDB=6.01167392; UDB=6.00606765; IPR=6.00948005; MB=3.00025772; MTD=3.00000008; XFM=3.00000015; UTC=2019-02-28 03:26:27 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19022803-0041-0000-0000-000008D43320 Message-Id: <20190228032620.16610-1-stewart@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-02-28_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-1902280020 Subject: [Skiboot] [PATCH] Don't use variable length arrays in exception code X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" OMG Kees Cook was right, the code is *smaller*. We save like a dozen instructions in the exception path! Signed-off-by: Stewart Smith --- core/exceptions.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/core/exceptions.c b/core/exceptions.c index e15848ad34af..4e5c0819e14e 100644 --- a/core/exceptions.c +++ b/core/exceptions.c @@ -39,14 +39,15 @@ static void dump_regs(struct stack_frame *stack) i, stack->gpr[i], i + 16, stack->gpr[i + 16]); } +#define EXCEPTION_MAX_STR 320 + void exception_entry(struct stack_frame *stack) { bool fatal = false; bool hv; uint64_t nip; uint64_t msr; - const size_t max = 320; - char buf[max]; + char buf[EXCEPTION_MAX_STR]; size_t l; switch (stack->type) { @@ -81,23 +82,23 @@ void exception_entry(struct stack_frame *stack) l = 0; if (stack->type == 0x100) { if (fatal) { - l += snprintf(buf + l, max - l, + l += snprintf(buf + l, EXCEPTION_MAX_STR - l, "Fatal System Reset at "REG" ", nip); } else { - l += snprintf(buf + l, max - l, + l += snprintf(buf + l, EXCEPTION_MAX_STR - l, "System Reset at "REG" ", nip); } } else if (stack->type == 0x200) { fatal = true; - l += snprintf(buf + l, max - l, + l += snprintf(buf + l, EXCEPTION_MAX_STR - l, "Fatal MCE at "REG" ", nip); } else { fatal = true; - l += snprintf(buf + l, max - l, + l += snprintf(buf + l, EXCEPTION_MAX_STR - l, "Fatal Exception 0x%llx at "REG" ", stack->type, nip); } - l += snprintf_symbol(buf + l, max - l, nip); - l += snprintf(buf + l, max - l, " MSR "REG, msr); + l += snprintf_symbol(buf + l, EXCEPTION_MAX_STR - l, nip); + l += snprintf(buf + l, EXCEPTION_MAX_STR - l, " MSR "REG, msr); prerror("%s\n", buf); dump_regs(stack); @@ -115,13 +116,12 @@ void exception_entry(struct stack_frame *stack) void exception_entry_pm_sreset(void) { - const size_t max = 320; - char buf[max]; + char buf[EXCEPTION_MAX_STR]; size_t l; prerror("***********************************************\n"); l = 0; - l += snprintf(buf + l, max - l, + l += snprintf(buf + l, EXCEPTION_MAX_STR - l, "System Reset in sleep"); prerror("%s\n", buf); backtrace(); @@ -129,13 +129,12 @@ void exception_entry_pm_sreset(void) void __noreturn exception_entry_pm_mce(void) { - const size_t max = 320; - char buf[max]; + char buf[EXCEPTION_MAX_STR]; size_t l; prerror("***********************************************\n"); l = 0; - l += snprintf(buf + l, max - l, + l += snprintf(buf + l, EXCEPTION_MAX_STR - l, "Fatal MCE in sleep"); prerror("%s\n", buf); prerror("SRR0 : "REG" SRR1 : "REG"\n",