From patchwork Tue May 28 05:47:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasant Hegde X-Patchwork-Id: 1106072 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (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 45Cjbw0h4Qz9s9T for ; Tue, 28 May 2019 15:50:04 +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 45Cjbv6fGczDqLV for ; Tue, 28 May 2019 15:50:03 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=hegdevasant@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 (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 45CjYR5VGyzDqL9 for ; Tue, 28 May 2019 15:47:55 +1000 (AEST) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x4S5lPgZ171066 for ; Tue, 28 May 2019 01:47:53 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0b-001b2d01.pphosted.com with ESMTP id 2srxxm0duj-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 28 May 2019 01:47:53 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 28 May 2019 06:47:51 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) 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, 28 May 2019 06:47:48 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x4S5llt748627712 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 28 May 2019 05:47:47 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C2E8711C079; Tue, 28 May 2019 05:47:47 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7946D11C058; Tue, 28 May 2019 05:47:46 +0000 (GMT) Received: from hegdevasant.in.ibm.com (unknown [9.109.241.95]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 28 May 2019 05:47:46 +0000 (GMT) From: Vasant Hegde To: skiboot@lists.ozlabs.org Date: Tue, 28 May 2019 11:17:27 +0530 X-Mailer: git-send-email 2.14.3 In-Reply-To: <20190528054727.16696-1-hegdevasant@linux.vnet.ibm.com> References: <20190528054727.16696-1-hegdevasant@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19052805-0020-0000-0000-0000034119D6 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19052805-0021-0000-0000-000021941367 Message-Id: <20190528054727.16696-10-hegdevasant@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-05-28_02:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 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-1905280040 Subject: [Skiboot] [PATCH v5 10/10] opal-prd: Fix prd message size issue 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: , Cc: Skiboot Stable MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" If prd messages size is insufficient then read_prd_msg() call fails with below error. And caller is not reallocating sufficient buffer. Also its hard to guess the size. sample log: ----------- Mar 28 03:31:43 zz24p1 opal-prd: FW: error reading from firmware: alloc 32 rc -1: Invalid argument Mar 28 03:31:43 zz24p1 opal-prd: FW: error reading from firmware: alloc 32 rc -1: Invalid argument Mar 28 03:31:43 zz24p1 opal-prd: FW: error reading from firmware: alloc 32 rc -1: Invalid argument .... Lets use `opal-msg-size` device tree property to allocate memory for prd message. Cc: Skiboot Stable Signed-off-by: Vasant Hegde --- Changes in v5: - Addressed Stewart's review comment -Vasant external/opal-prd/opal-prd.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/external/opal-prd/opal-prd.c b/external/opal-prd/opal-prd.c index 33ea5f5a8..d0a507c8d 100644 --- a/external/opal-prd/opal-prd.c +++ b/external/opal-prd/opal-prd.c @@ -2120,7 +2120,9 @@ static int init_control_socket(struct opal_prd_ctx *ctx) static int run_prd_daemon(struct opal_prd_ctx *ctx) { - int rc; + char *opal_msg_path; + void *buf; + int rc, len; /* log to syslog */ pr_log_daemon_init(); @@ -2130,14 +2132,31 @@ static int run_prd_daemon(struct opal_prd_ctx *ctx) ctx->fd = -1; ctx->socket = -1; - /* set up our message buffer */ - ctx->msg_alloc_len = sizeof(*ctx->msg); + /* + * Set up our message buffer. Use opal-msg-size device tree + * property to get message buffer size. + */ + rc = asprintf(&opal_msg_path, + "%s/ibm,opal/opal-msg-size", devicetree_base); + if (rc > 0) { + rc = open_and_read(opal_msg_path, &buf, &len); + if (rc == 0) { + ctx->msg_alloc_len = be32toh(*(__be32 *)buf); + free(buf); + } + + free(opal_msg_path); + } + + if (ctx->msg_alloc_len == 0) + ctx->msg_alloc_len = sizeof(*ctx->msg); + ctx->msg = malloc(ctx->msg_alloc_len); if (!ctx->msg) { pr_log(LOG_ERR, "FW: Can't allocate PRD message buffer: %m"); return -1; } - + memset(ctx->msg, 0, ctx->msg_alloc_len); list_head_init(&ctx->msgq);