From patchwork Wed Aug 1 22:53:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Richter X-Patchwork-Id: 952543 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 41gwc45x4vz9s2g for ; Thu, 2 Aug 2018 13:28:04 +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 41gwc44bPyzF1s5 for ; Thu, 2 Aug 2018 13:28:04 +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.156.1; 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 (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 41gpX54NdSzF1Qn for ; Thu, 2 Aug 2018 08:54:13 +1000 (AEST) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w71Mn9iZ017266 for ; Wed, 1 Aug 2018 18:54:11 -0400 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 2kkfgf7p7e-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 01 Aug 2018 18:54:10 -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 b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) 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:07 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w71Ms6HD42401858 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 1 Aug 2018 22:54:06 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EDA8B4C040; Thu, 2 Aug 2018 01:54:17 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6C41B4C044; Thu, 2 Aug 2018 01:54:17 +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:17 +0100 (BST) From: Eric Richter To: skiboot@lists.ozlabs.org Date: Wed, 1 Aug 2018 18:53:46 -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-0000025B59A2 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18080122-0009-0000-0000-000021C1F5BD Message-Id: <20180801225349.6535-8-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=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-1806210000 definitions=main-1808010231 X-Mailman-Approved-At: Thu, 02 Aug 2018 13:26:15 +1000 Subject: [Skiboot] [RFC PATCH 07/10] keystore: add opal_set_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_set_variable runtime service operates the same way for the active bank and update queue; it updates an existing variable name's associated data with the supplied data blob if the requested name exists. If the requested name does not exist, it appends a new entry in the list. NOTE: This runtime service does not do any size checks, and is the likely candidate to do some form of size checking. Since we are holding the keys in a sparse structure in memory, this service should probably either use a routine to calculate the current total size, or a total size value should be maintained either in the list head or globally. Signed-off-by: Eric Richter --- libstb/keystore.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/libstb/keystore.c b/libstb/keystore.c index 8e19dbb6..8f825f8e 100644 --- a/libstb/keystore.c +++ b/libstb/keystore.c @@ -87,6 +87,66 @@ found: opal_call(OPAL_GET_VARIABLE, opal_get_variable, 4); +static int64_t opal_set_variable(uint64_t k_varname, uint64_t k_vardata, uint64_t varsize, uint64_t section) +{ + char *varname = (char*) k_varname; + char *vardata = (char*) k_vardata; + + struct keystore_variable *var = NULL; + + struct list_head *bank; + + CHECK_KEYSTORE_READY; + + bank = GET_BANK(section); + + list_for_each(bank, var, link) { + if (!strcmp(varname, var->name)) { + goto found; + } + } + + var = (struct keystore_variable *) malloc(sizeof(struct keystore_variable)); + if (!var) { + prlog(PR_ERR, "Failed to allocate new variable\n"); + return OPAL_NO_MEM; + } + + var->name_size = strlen(varname) + 1; + var->name = malloc(var->name_size); + var->name[var->name_size] = '\0'; // Ensure print-friendly NULL terminator + if (!var->name) { + prlog(PR_ERR, "Failed to allocate new variable's name\n"); + return OPAL_NO_MEM; + } + + memcpy(var->name, varname, var->name_size); + var->data = NULL; + + // Add to the list before moving to the shared behavior portion + list_add_tail(bank, &var->link); + +found: + // Clear old data if this is not a new variable. + if (var->data) + free(var->data); + + var->data_size = varsize; + var->data = malloc(var->data_size); + if (!var->data) { + prlog(PR_ERR, "Failed to allocate new variable's data\n"); + // TODO: we should probably clean up the linked list node if there is an error + // maybe we should try allocating data before freeing the old? + return OPAL_NO_MEM; + } + + memcpy(var->data, vardata, var->data_size); + + return OPAL_SUCCESS; +} +opal_call(OPAL_SET_VARIABLE, opal_set_variable, 4); + + int keystore_init(void) { int rc;