From nobody Thu Mar 28 14:15:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1562895846; cv=none; d=zoho.com; s=zohoarc; b=P1qxnQ99m6UkOsIVvRT01hcwONkQHVf2LTLUgOgsJdYbn0RBh1apkqjbmYFMxzNRMF3qqgX6pWekN/k8JwegHE7OR0+eaxqlufu5EfZYjBzelXsRo1FR8lqBQ2XHriqXvMPfLLu6H9YdzghBSDamHxCwbfewGx42cegk0fmLJ7s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562895846; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=GWueveKxzLo87Ks/iGtj1/ay7g6854ssdr1TivFspmM=; b=eivtaeiVq5Yob64jMUMpb/TcQ/vIe042ii9mr8s9gzHE+yHegUPQzz8GxHp+whjDrQda2ajU0xMiIFLtyEsymq2elGgM0s26yPDBY6wOHdx7d/h/OZBZXn7FiwcV+lSVxN2aIJSsREfvXUUtjhKrV1/DP6b+VGvd5Lhntwgatio= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562895846672410.0914587447659; Thu, 11 Jul 2019 18:44:06 -0700 (PDT) Received: from localhost ([::1]:46164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlkbO-000799-Sd for importer@patchew.org; Thu, 11 Jul 2019 21:43:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60970) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlkb6-0006Jw-4Q for qemu-devel@nongnu.org; Thu, 11 Jul 2019 21:43:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlkb4-0003Fa-U4 for qemu-devel@nongnu.org; Thu, 11 Jul 2019 21:43:40 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:19674) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hlkb4-0003Ep-JU for qemu-devel@nongnu.org; Thu, 11 Jul 2019 21:43:38 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6C1gDrJ140247 for ; Thu, 11 Jul 2019 21:43:37 -0400 Received: from e13.ny.us.ibm.com (e13.ny.us.ibm.com [129.33.205.203]) by mx0a-001b2d01.pphosted.com with ESMTP id 2tpdxt4y0r-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 Jul 2019 21:43:37 -0400 Received: from localhost by e13.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 12 Jul 2019 02:21:02 +0100 Received: from b01cxnp22034.gho.pok.ibm.com (9.57.198.24) by e13.ny.us.ibm.com (146.89.104.200) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 12 Jul 2019 02:20:30 +0100 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x6C1K1Bm36962596 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jul 2019 01:20:01 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7EE8DB206B; Fri, 12 Jul 2019 01:20:01 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6C20BB2066; Fri, 12 Jul 2019 01:20:01 +0000 (GMT) Received: from localhost (unknown [9.53.179.212]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Fri, 12 Jul 2019 01:20:01 +0000 (GMT) From: Michael Roth To: qemu-devel@nongnu.org Date: Thu, 11 Jul 2019 20:19:33 -0500 X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190712011934.29863-1-mdroth@linux.vnet.ibm.com> References: <20190712011934.29863-1-mdroth@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19071201-0064-0000-0000-000003FA8FFF X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00011412; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000286; SDB=6.01230877; UDB=6.00648363; IPR=6.01012152; MB=3.00027683; MTD=3.00000008; XFM=3.00000015; UTC=2019-07-12 01:21:00 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19071201-0065-0000-0000-00003E3A2A2E Message-Id: <20190712011934.29863-2-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-07-11_07:, , 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-1907120020 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH 1/2] docs/specs: initial spec summary for Ultravisor-related hcalls X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linuxram@us.ibm.com, qemu-ppc@nongnu.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" For now this only covers hcalls relating to TPM communication since it's the only one particularly important from a QEMU perspective atm, but others can be added here where it makes sense. The full specification for all hcalls/ucalls will eventually be made available in the public/OpenPower version of the PAPR specification. Signed-off-by: Michael Roth --- docs/specs/ppc-spapr-uv-hcalls.txt | 74 ++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 docs/specs/ppc-spapr-uv-hcalls.txt diff --git a/docs/specs/ppc-spapr-uv-hcalls.txt b/docs/specs/ppc-spapr-uv-h= calls.txt new file mode 100644 index 0000000000..0278f89190 --- /dev/null +++ b/docs/specs/ppc-spapr-uv-hcalls.txt @@ -0,0 +1,74 @@ +On PPC64 systems supporting Protected Execution Facility (PEF), system +memory can be placed in a secured region where only an "ultravisor" +running in firmware can provide to access it. pseries guests on such +systems can communicate with the ultravisor (via ultracalls) to switch to a +secure VM mode (SVM) where the guest's memory is relocated to this secured +region, making its memory inaccessible to normal processes/guests running = on +the host. + +The various ultracalls/hypercalls relating to SVM mode are currently +only documented internally, but are planned for direct inclusion into the +public OpenPOWER version of the PAPR specification (LoPAPR/LoPAR). An inte= rnal +ACR has been filed to reserve a hypercall number range specific to this +use-case to avoid any future conflicts with the internally-maintained PAPR +specification. This document summarizes some of these details as they rela= te +to QEMU. + +=3D=3D hypercalls needed by the ultravisor =3D=3D + +Switching to SVM mode involves a number of hcalls issued by the ultravisor +to the hypervisor to orchestrate the movement of guest memory to secure +memory and various other aspects SVM mode. The below documents the hcalls +relevant to QEMU. + +- H_TPM_COMM (0xef10) + + For TPM_COMM_OP_EXECUTE operation: + Send a request to a TPM and receive a response, opening a new TPM sess= ion + if one has not already been opened. + + For TPM_COMM_OP_CLOSE_SESSION operation: + Close the existing TPM session, if any. + + Arguments: + + r3 : H_TPM_COMM (0xef10) + r4 : TPM operation, one of: + TPM_COMM_OP_EXECUTE (0x1) + TPM_COMM_OP_CLOSE_SESSION (0x2) + r5 : in_buffer, guest physical address of buffer containing the request + - Caller may use the same address for both request and response + r6 : in_size, size of the in buffer, must + - Must be less than or equal to 4KB + r7 : out_buffer, guest physical address of buffer to store the response + - Caller may use the same address for both request and response + r8 : out_size, size of the out buffer + - Must be at least 4KB, as this is the maximum request/response s= ize + supported by most TPM implementations, including the TPM Resour= ce + Manager in the linux kernel. + + Return values: + + r3 : H_Success request processed successfully + H_PARAMETER invalid TPM operation + H_P2 in_buffer is invalid + H_P3 in_size is invalid + H_P4 out_buffer is invalid + H_P5 out_size is invalid + H_RESOURCE TPM is unavailable + r4 : For TPM_COMM_OP_EXECUTE, the size of the response will be stored = here + upon success. + + Use-case/notes: + + SVM filesystems are encrypted using a symmetric key. This key is then + wrapped/encrypted using the public key of a trusted system which has t= he + private key stored in the system's TPM. An Ultravisor will use this + hcall to unwrap/unseal the symmetric key using the system's TPM device + or a TPM Resource Manager associated with the device. + + The Ultravisor sets up a separate session key with the TPM in advance + during host system boot. All sensitive in and out values will be + encrypted using the session key. Though the hypervisor will see the 'i= n' + and 'out' buffers in raw form, any sensitive contents will generally be + encrypted using this session key. --=20 2.17.1 From nobody Thu Mar 28 14:15:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1562900769; cv=none; d=zoho.com; s=zohoarc; b=T1xC+MsX/1+k0jKlfVpS/0nm1fYPzQnzgO8aBNcskgTbDiFpWQNBhBfpyUgRZNzHfU5Gbf5MJZeXHuT/kG9GfftD74NS4fAktVtitBiT8pizZEsXEnvui7bFqGH4GSA3nzq1iBdahq5MBzTc0y5Ga7V20SnY2gtKB8Q6Xw8Bbc8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562900769; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=W3PKTKhpaZggFaOpSOqzN4HAqva9kd9uG35eHVd/1PA=; b=dgJZJmmlACPom8qSpVOhq8WlmoOlV6OVSrc6q7iXECpT8/JpOcxvTXii5ZNpdC1Q3JL7DZLKzq+R1uqcK9Nytff+oKSUUNnyLMN4gS+y94h69Y6pxVJvP6zOBCyTIxpIlT98dsmU7OJnXUxip7gYUak1NpCpdKpiGaWuSrkajws= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562900769455339.5346727958579; Thu, 11 Jul 2019 20:06:09 -0700 (PDT) Received: from localhost ([::1]:46380 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hllsj-00044K-Td for importer@patchew.org; Thu, 11 Jul 2019 23:05:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52918) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hllsW-0003eX-Ve for qemu-devel@nongnu.org; Thu, 11 Jul 2019 23:05:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hllsV-0000uZ-E2 for qemu-devel@nongnu.org; Thu, 11 Jul 2019 23:05:44 -0400 Received: from mail-oi1-x244.google.com ([2607:f8b0:4864:20::244]:38385) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hllsV-0000tA-4p; Thu, 11 Jul 2019 23:05:43 -0400 Received: by mail-oi1-x244.google.com with SMTP id v186so6201361oie.5; Thu, 11 Jul 2019 20:05:42 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id k18sm2725715oib.56.2019.07.11.20.05.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Jul 2019 20:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=W3PKTKhpaZggFaOpSOqzN4HAqva9kd9uG35eHVd/1PA=; b=nSUKTdqTOIw5ijqTpGmTzW5kfm/OdCsWC1xK5aHwQgj6zg6lBOtlGOVGNMbYKtPsEA KXccLH1O7DKXoPT7pjVGJVfjoJKFGv4GFKweUZ05pAf8SIqkhCqC6eiWXiVnFE4wtnzq 39ABAIgRea03JBJ+08AF9/bgVWRQIMKAE1/zvylKAEcIfGBIQDG+W/cSyIFF0SqrHu8X sP8sUq8PSMxYM8SD7CxaoxUjFfzo8wekWSH/wXcCb4fLDhiuQhFKoNQupbg/dTuGrhkS f8CzF7wi5+O/bwpJMUAJAGbfpxIA5te7dRH4cPmOMeLGU0mPhoYgTcZNKW8L/yWDshsC Fmjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=W3PKTKhpaZggFaOpSOqzN4HAqva9kd9uG35eHVd/1PA=; b=cR5rsyrr8juN0ilEJa11ykU09pxnJokFagiZs+sf14DfYYKdROrCU45s8S92gTX7wC xhO8DZ3KoFksgCOolF4yhn0nmdUwFZAOaK/qX0rMO/lXtklfgV837Fdx2cwX4nnrOXWH wWI08lF7d+epJvxDk9gQwPkjx8AR3qDw/QyYyfk55Y0uDfRJdaomam+wIr1CCebtxZsv KnNd8u2ETMZ6nH2dbrqNNp57aEoG5s1FZjla+B7K29xk3/xpqfmR9C1WrPR6MsguM3uv zvipzLuvy0Wxg76ispNaoXZFBOQ919iHJeJOFUZBmY4jX5oZTkOKlrzwJNjZ6V0xPoAW HrVw== X-Gm-Message-State: APjAAAU7EuoLODI+kVyiHgxQFDt56OYWIU9OvLy69r8d9B11C+tSWXZ2 SZTZF/nQVSc6S8yrF0Jf9dWhfSws X-Google-Smtp-Source: APXvYqy27834pDllQ5cvfBe9OgWSrb+/SeFPOoLLBWaXjwuw8d3bBs6ayQrRAKP8oWNaAJuvtDv5XA== X-Received: by 2002:aca:c695:: with SMTP id w143mr4119938oif.11.1562900740875; Thu, 11 Jul 2019 20:05:40 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Thu, 11 Jul 2019 20:19:34 -0500 Message-Id: <20190712011934.29863-3-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190712011934.29863-1-mdroth@linux.vnet.ibm.com> References: <20190712011934.29863-1-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::244 Subject: [Qemu-devel] [PATCH 2/2] spapr: initial implementation for H_TPM_COMM hcall X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linuxram@us.ibm.com, qemu-ppc@nongnu.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This implements the H_TPM_COMM hypercall, which is used by an Ultravisor to pass TPM commands directly to the host's TPM device, or a TPM Resource Manager associated with the device. This also introduces a new pseries machine option which is used to configure what TPM device to pass commands to, for example: -machine pseries,...,tpm-device-file=3D/dev/tmprm0 By default, no tpm-device-file is defined and hcalls will return H_RESOURCE. The full specification for this hypercall can be found in docs/specs/ppc-spapr-uv-hcalls.txt Signed-off-by: Michael Roth tpm_device_file) { + spapr_hcall_tpm_reset(); + } + spapr_clear_pending_events(spapr); =20 /* @@ -3340,6 +3344,21 @@ static void spapr_set_host_serial(Object *obj, const= char *value, Error **errp) spapr->host_serial =3D g_strdup(value); } =20 +static char *spapr_get_tpm_device_file(Object *obj, Error **errp) +{ + SpaprMachineState *spapr =3D SPAPR_MACHINE(obj); + + return g_strdup(spapr->tpm_device_file); +} + +static void spapr_set_tpm_device_file(Object *obj, const char *value, Erro= r **errp) +{ + SpaprMachineState *spapr =3D SPAPR_MACHINE(obj); + + g_free(spapr->tpm_device_file); + spapr->tpm_device_file =3D g_strdup(value); +} + static void spapr_instance_init(Object *obj) { SpaprMachineState *spapr =3D SPAPR_MACHINE(obj); @@ -3396,6 +3415,14 @@ static void spapr_instance_init(Object *obj) &error_abort); object_property_set_description(obj, "host-serial", "Host serial number to advertise in guest device tree", &error_abo= rt); + object_property_add_str(obj, "tpm-device-file", + spapr_get_tpm_device_file, + spapr_set_tpm_device_file, &error_abort); + object_property_set_description(obj, "tpm-device-file", + "Specifies the path to the TPM character device file to u= se" + " for TPM communication via hypercalls (usually a TPM" + " resource manager)", + &error_abort); } =20 static void spapr_machine_finalizefn(Object *obj) diff --git a/hw/ppc/spapr_hcall_tpm.c b/hw/ppc/spapr_hcall_tpm.c new file mode 100644 index 0000000000..75e2b6d594 --- /dev/null +++ b/hw/ppc/spapr_hcall_tpm.c @@ -0,0 +1,135 @@ +/* + * SPAPR TPM Hypercall + * + * Copyright IBM Corp. 2019 + * + * Authors: + * Michael Roth + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "cpu.h" +#include "hw/ppc/spapr.h" +#include "trace.h" + +#define TPM_SPAPR_BUFSIZE 4096 + +enum { + TPM_COMM_OP_EXECUTE =3D 1, + TPM_COMM_OP_CLOSE_SESSION =3D 2, +}; + +static int tpm_devfd =3D -1; + +static ssize_t tpm_execute(SpaprMachineState *spapr, target_ulong *args) +{ + uint64_t data_in =3D ppc64_phys_to_real(args[1]); + target_ulong data_in_size =3D args[2]; + uint64_t data_out =3D ppc64_phys_to_real(args[3]); + target_ulong data_out_size =3D args[4]; + uint8_t buf_in[TPM_SPAPR_BUFSIZE]; + uint8_t buf_out[TPM_SPAPR_BUFSIZE]; + ssize_t ret; + + trace_spapr_tpm_execute(data_in, data_in_size, data_out, data_out_size= ); + + if (data_in_size > TPM_SPAPR_BUFSIZE) { + error_report("invalid TPM input buffer size: " TARGET_FMT_lu "\n", + data_in_size); + return H_P3; + } + + if (data_out_size < TPM_SPAPR_BUFSIZE) { + error_report("invalid TPM output buffer size: " TARGET_FMT_lu "\n", + data_out_size); + return H_P5; + } + + if (tpm_devfd =3D=3D -1) { + tpm_devfd =3D open(spapr->tpm_device_file, O_RDWR); + if (tpm_devfd =3D=3D -1) { + error_report("failed to open TPM device %s: %d", + spapr->tpm_device_file, errno); + return H_RESOURCE; + } + } + + cpu_physical_memory_read(data_in, buf_in, data_in_size); + + do { + ret =3D write(tpm_devfd, buf_in, data_in_size); + if (ret > 0) { + data_in_size -=3D ret; + } + } while ((ret >=3D 0 && data_in_size > 0) || (ret =3D=3D -1 && errno = =3D=3D EINTR)); + + if (ret =3D=3D -1) { + error_report("failed to write to TPM device %s: %d", + spapr->tpm_device_file, errno); + return H_RESOURCE; + } + + do { + ret =3D read(tpm_devfd, buf_out, data_out_size); + } while (ret =3D=3D 0 || (ret =3D=3D -1 && errno =3D=3D EINTR)); + + if (ret =3D=3D -1) { + error_report("failed to read from TPM device %s: %d", + spapr->tpm_device_file, errno); + return H_RESOURCE; + } + + cpu_physical_memory_write(data_out, buf_out, ret); + args[0] =3D ret; + + return H_SUCCESS; +} + +static target_ulong h_tpm_comm(PowerPCCPU *cpu, + SpaprMachineState *spapr, + target_ulong opcode, + target_ulong *args) +{ + target_ulong op =3D args[0]; + + trace_spapr_h_tpm_comm(spapr->tpm_device_file ?: "null", op); + + if (!spapr->tpm_device_file) { + error_report("TPM device not specified"); + return H_RESOURCE; + } + + switch (op) { + case TPM_COMM_OP_EXECUTE: + return tpm_execute(spapr, args); + case TPM_COMM_OP_CLOSE_SESSION: + if (tpm_devfd !=3D -1) { + close(tpm_devfd); + tpm_devfd =3D -1; + } + return H_SUCCESS; + default: + return H_PARAMETER; + } +} + +void spapr_hcall_tpm_reset(void) +{ + if (tpm_devfd !=3D -1) { + close(tpm_devfd); + tpm_devfd =3D -1; + } +} + +static void hypercall_register_types(void) +{ + spapr_register_hypercall(H_TPM_COMM, h_tpm_comm); +} + +type_init(hypercall_register_types) diff --git a/hw/ppc/trace-events b/hw/ppc/trace-events index f76448f532..96dad767a1 100644 --- a/hw/ppc/trace-events +++ b/hw/ppc/trace-events @@ -25,6 +25,10 @@ spapr_update_dt(unsigned cb) "New blob %u bytes" spapr_update_dt_failed_size(unsigned cbold, unsigned cbnew, unsigned magic= ) "Old blob %u bytes, new blob %u bytes, magic 0x%x" spapr_update_dt_failed_check(unsigned cbold, unsigned cbnew, unsigned magi= c) "Old blob %u bytes, new blob %u bytes, magic 0x%x" =20 +# spapr_hcall_tpm.c +spapr_h_tpm_comm(const char *device_path, uint64_t operation) "tpm_device_= path=3D%s operation=3D0x%"PRIu64 +spapr_tpm_execute(uint64_t data_in, uint64_t data_in_sz, uint64_t data_out= , uint64_t data_out_sz) "data_in=3D0x%"PRIx64", data_in_sz=3D%"PRIu64", dat= a_out=3D0x%"PRIx64", data_out_sz=3D%"PRIu64 + # spapr_iommu.c spapr_iommu_put(uint64_t liobn, uint64_t ioba, uint64_t tce, uint64_t ret)= "liobn=3D0x%"PRIx64" ioba=3D0x%"PRIx64" tce=3D0x%"PRIx64" ret=3D%"PRId64 spapr_iommu_get(uint64_t liobn, uint64_t ioba, uint64_t ret, uint64_t tce)= "liobn=3D0x%"PRIx64" ioba=3D0x%"PRIx64" ret=3D%"PRId64" tce=3D0x%"PRIx64 diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 60553d32c4..7bd47575d7 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -198,6 +198,7 @@ struct SpaprMachineState { SpaprXive *xive; SpaprIrq *irq; qemu_irq *qirqs; + char *tpm_device_file; =20 bool cmd_line_caps[SPAPR_CAP_NUM]; SpaprCapabilities def, eff, mig; @@ -490,8 +491,9 @@ struct SpaprMachineState { #define H_INT_ESB 0x3C8 #define H_INT_SYNC 0x3CC #define H_INT_RESET 0x3D0 +#define H_TPM_COMM 0xEF10 =20 -#define MAX_HCALL_OPCODE H_INT_RESET +#define MAX_HCALL_OPCODE H_TPM_COMM =20 /* The hcalls above are standardized in PAPR and implemented by pHyp * as well. @@ -864,6 +866,9 @@ int spapr_caps_post_migration(SpaprMachineState *spapr); =20 void spapr_check_pagesize(SpaprMachineState *spapr, hwaddr pagesize, Error **errp); + +void spapr_hcall_tpm_reset(void); + /* * XIVE definitions */ --=20 2.17.1