From patchwork Wed Aug 1 23:40:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Richter X-Patchwork-Id: 952482 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.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41gqc81db1z9s4s for ; Thu, 2 Aug 2018 09:42:48 +1000 (AEST) 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 41gqc80GhtzF1dK for ; Thu, 2 Aug 2018 09:42:48 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com 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.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=erichte@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 (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 41gqZ73FYCzF1dK for ; Thu, 2 Aug 2018 09:41:03 +1000 (AEST) Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w71NdIAj075225 for ; Wed, 1 Aug 2018 19:41:01 -0400 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 2kkmm0ca67-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 01 Aug 2018 19:41:01 -0400 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 2 Aug 2018 00:40:59 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 2 Aug 2018 00:40:57 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w71NettD34210016 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 1 Aug 2018 23:40:55 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 08BCFA4040; Thu, 2 Aug 2018 02:41:06 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7E396A4057; Thu, 2 Aug 2018 02:41:05 +0100 (BST) Received: from boston-1.rtp.stglabs.ibm.com (unknown [9.27.30.60]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 2 Aug 2018 02:41:05 +0100 (BST) From: Eric Richter To: skiboot@lists.ozlabs.org Date: Wed, 1 Aug 2018 19:40:38 -0400 X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180801234042.6740-1-erichte@linux.ibm.com> References: <20180801234042.6740-1-erichte@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18080123-0012-0000-0000-000002927033 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18080123-0013-0000-0000-000020C47A20 Message-Id: <20180801234042.6740-7-erichte@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-08-01_08:, , 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-1806210000 definitions=main-1808010240 Subject: [Skiboot] [RFC PATCH RESEND 06/10] keystore: add opal_get_variable runtime service X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Claudio Carvalho MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" The opal_get_variable runtime service retrieves a variable's data from the keystore list if the requested name (as a NULL-terminated string) exists in the requested section (enum for ACTIVE_BANK vs UPDATE_QUEUE). The kernel may query the size of a variable by calling this service by passing a NULL buffer parameter, and the by-reference varsize parameter will be set to the variable's data size if found. This will also occur if the varsize parameter is smaller than the requested data's size, to prevent overflows. NOTE: Included in this patch is a hacky macro to switch on the section enum, which is a behavior common to each of these runtime services. It should probably be changed to a static or inline function in the future. Signed-off-by: Eric Richter --- libstb/keystore.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/libstb/keystore.c b/libstb/keystore.c index 7d6027ef..8e19dbb6 100644 --- a/libstb/keystore.c +++ b/libstb/keystore.c @@ -34,6 +34,57 @@ static bool keystore_ready = false; /* has the keystore been loaded? */ // TODO: OPAL_UNSUPPORTED? #define CHECK_KEYSTORE_READY if(!keystore_ready) {prlog(PR_ERR, "Ignoring call, keystore not ready\n"); return OPAL_RESOURCE; } +// Translate the enum into a bank list pointer +#define GET_BANK(a) ((a&ACTIVE_BANK)?&active_bank_list:(((a&UPDATE_QUEUE)?&update_queue_list:NULL))) + + +static int64_t opal_get_variable(uint64_t k_buffer, uint64_t k_varsize, uint64_t k_varname, uint64_t section) +{ + // Outputs + char *buffer = (char*) k_buffer; + uint64_t *varsize = (uint64_t*) k_varsize; + // Inputs + char *varname = (char*) k_varname; + struct list_head *bank; + + struct keystore_variable *var = NULL; + + CHECK_KEYSTORE_READY; + + if (!varsize) { + prlog(PR_INFO, "Variable size parameter is NULL\n"); + return OPAL_PARAMETER; + } + + bank = GET_BANK(section); + if (!bank) { + prlog(PR_INFO, "Invalid section '%lld'\n", section); + return OPAL_PARAMETER; + } + + list_for_each(bank, var, link) { + if (!strcmp(varname, var->name)) { + goto found; + } + } + + prlog(PR_DEBUG, "No matching variable found for name '%s' in bank %lld\n", varname, section); + return OPAL_EMPTY; + +found: + // Check if this is a size query, or buffer is too small + if ((NULL == buffer) || (*varsize < var->data_size)) { + prlog(PR_DEBUG, "NULL/insufficient size check, returning varsize = %llu\n", var->data_size); + *varsize = var->data_size; + return OPAL_PARTIAL; + } + + memcpy(buffer, var->data, var->data_size); + *varsize = var->data_size; + + return OPAL_SUCCESS; +} +opal_call(OPAL_GET_VARIABLE, opal_get_variable, 4); int keystore_init(void)