From patchwork Wed Aug 1 22:53:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Richter X-Patchwork-Id: 952542 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 41gwbn3TBHz9s2g for ; Thu, 2 Aug 2018 13:27:49 +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 41gwbn2D9RzF1pH for ; Thu, 2 Aug 2018 13:27:49 +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 41gpX41l2ZzF1Qn for ; Thu, 2 Aug 2018 08:54:12 +1000 (AEST) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w71Mn8pH134161 for ; Wed, 1 Aug 2018 18:54:09 -0400 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 2kknjxgvhn-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 01 Aug 2018 18:54:09 -0400 Received: from localhost by e06smtp02.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 1 Aug 2018 23:54:08 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp02.uk.ibm.com (192.168.101.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 1 Aug 2018 23:54:06 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w71Ms48239321688 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 1 Aug 2018 22:54:04 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3C8334C044; Thu, 2 Aug 2018 01:54:16 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AFA8C4C040; Thu, 2 Aug 2018 01:54:15 +0100 (BST) Received: from boston-1.rtp.stglabs.ibm.com (unknown [9.27.30.60]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 2 Aug 2018 01:54:15 +0100 (BST) From: Eric Richter To: skiboot@lists.ozlabs.org Date: Wed, 1 Aug 2018 18:53:45 -0400 X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180801225349.6535-1-erichte@linux.ibm.com> References: <20180801225349.6535-1-erichte@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18080122-0008-0000-0000-0000025B59A1 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18080122-0009-0000-0000-000021C1F5BC Message-Id: <20180801225349.6535-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-1808010231 X-Mailman-Approved-At: Thu, 02 Aug 2018 13:26:15 +1000 Subject: [Skiboot] [RFC PATCH 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)