From nobody Mon Nov 25 06:57:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1717068180; cv=pass; d=zohomail.com; s=zohoarc; b=H1zV2SPARs0oCsQ3jfVYhmRco32rBpr3FGSQPWISZRWQR27R7AyiOXOJGPy/EcKeDgAnusJ29KS0lvjkV29TrsrOdrDV3MGcT8D+wRtO5BbIMNuIGNRJJL6vxsyzDC6Bx17xwbC6q4tSCcldKlI3ynj6/KGWGv5RzDH2oK6WEt8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717068180; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=68tnYI6ipZ8mBahj5St8AOyJU76kc67TAbkPM3BQUuQ=; b=WU9sGa9wV7EK7RPhgtyWCZTslk/OLemHZFSvbUeJD6eah3MxJic3KyefteVr4bqSvssI9LpdVZBBIMp/IzX0xEh04dP6lsyn6UPmWBOXyUsBa6H9VUFIUFHyVbK+dpXkn3GlVJElAak8Cd12V0kU867SWnPAtiTQBfJlOsEYtVQ= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717068180242347.7932946177408; Thu, 30 May 2024 04:23:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCdmN-00060j-PS; Thu, 30 May 2024 07:17:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sCdmM-0005zX-Kr for qemu-devel@nongnu.org; Thu, 30 May 2024 07:17:06 -0400 Received: from mail-bn8nam11on20624.outbound.protection.outlook.com ([2a01:111:f403:2414::624] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sCdmJ-0001SK-ML for qemu-devel@nongnu.org; Thu, 30 May 2024 07:17:06 -0400 Received: from BN9PR03CA0670.namprd03.prod.outlook.com (2603:10b6:408:10e::15) by SN7PR12MB7856.namprd12.prod.outlook.com (2603:10b6:806:340::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.20; Thu, 30 May 2024 11:16:58 +0000 Received: from BN3PEPF0000B077.namprd04.prod.outlook.com (2603:10b6:408:10e:cafe::18) by BN9PR03CA0670.outlook.office365.com (2603:10b6:408:10e::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.19 via Frontend Transport; Thu, 30 May 2024 11:16:58 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN3PEPF0000B077.mail.protection.outlook.com (10.167.243.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Thu, 30 May 2024 11:16:58 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 30 May 2024 06:16:57 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 30 May 2024 06:16:57 -0500 Received: from pankaj-M75q.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 30 May 2024 06:16:57 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cL69pESnpYLjxXNxBHCbsRWq3DFf8ywaKzOnX/U7uFzH3Z4/Ir/vGOJcMsluIz+DaiqeL7aliJOUzcfwka24EVHUyzh0I1NUlgKvm+zDqukf9v/IwZq892Olr0twNrbA1SlWBPsN+9KQzN7VEDo2oLwBE3Gn+kZsoTOL2HE6OPu9AyEYxMCzAvwMhF04B3/xZrbto6Iq+zVhIcGp8WWlRxg5pNRd2oLdNhUTkUaqE/GinHMRugf+a8cLAd8dktP+t+uTasdxqoTPHgnm6427BupWyOqt2x+j5njPpUhO9APLJSmQ2m5uqtRkix/JPE+Zk/bVa6eHmpoSwDJtqNLhhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=68tnYI6ipZ8mBahj5St8AOyJU76kc67TAbkPM3BQUuQ=; b=UatOY1ZcFnvywQ0JeQ2kH7+bW6seFkLCtrB/tm2o9VHCtmXtkkpbaWjfJ0YNXFINdk/3UIVjwb/pFxWa+VQD6fc1GdJyI+zP7E2fEe5GXYJU0UpdNDeb8nMnWRxU8Yh5SdpaY9I+ZNYY55931Acm9Mh3+Nrca9J7DbEEBiuIDl2v3Cjgm9A1CMhiBG7/aQv0+a2fmf2StpXIjKf23g8DM8TJuVmWXgC2fMbYF+tzN9ZF7PliPrMf6burNRsvwnG5vLi386+X+GfWjBU7XGg9pgYF2hnVHf3VH9PH7K/FlsItzq/WFpzUrtJG2ausr9Rj0sgUPTGYrfpKFTLibl/oEQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nongnu.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=68tnYI6ipZ8mBahj5St8AOyJU76kc67TAbkPM3BQUuQ=; b=zcbeVi3kwznfCoNR9EwsrhijPkyKMl31yhixfRgEgeEe7qCzNY7XGHFejg5qTE1aALcnMmDDYZvxzf2JCJ9z6Yvrq2L2Lw2TW0HfOJGeVmLXSz17YBJrSUSfLTEvVl8llUAGunaq59C0H5s8bEd521PrgOvxzPRaMoqbG+eB9TA= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.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; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Pankaj Gupta To: CC: , , , , , , , , , , , Subject: [PATCH v4 21/31] i386/sev: Extract build_kernel_loader_hashes Date: Thu, 30 May 2024 06:16:33 -0500 Message-ID: <20240530111643.1091816-22-pankaj.gupta@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240530111643.1091816-1-pankaj.gupta@amd.com> References: <20240530111643.1091816-1-pankaj.gupta@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B077:EE_|SN7PR12MB7856:EE_ X-MS-Office365-Filtering-Correlation-Id: 1db6d0fa-2c05-461b-5036-08dc809a0556 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|1800799015|82310400017|376005|36860700004; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?o1/wygQbTLs6vnev5n5jBA9Lnn9Rl4F7Bj9fjG/67aTfXbgFN6pUXzIWlh6s?= =?us-ascii?Q?nrRfM8KSDpdMCGz13nmIjF3fdwp4yCuaReI4cMled9D995UERI0etwgP3XXJ?= =?us-ascii?Q?W7NcmLMQ9280j9zslqFsHXnc2opNPnF6YzVgUIIpwK0OC8biku+Iw2WnDgsG?= =?us-ascii?Q?kLDrJe+qV0GpVfTh3028vIGnRQDDwMtTvu6+DwKfK8YCB1HBIk2e/p76bhnH?= =?us-ascii?Q?YTmNaKbw5HVd3J/SMP2AsUeZkmYpfASiC1THNrsNdddh/ggueiQ+C3HEIsRF?= =?us-ascii?Q?DhKZDjpW7XtHqAbHuN6g506Vt4d+KI9SZf6sBB5s+x09dqEj9gYU2U23vvmc?= =?us-ascii?Q?6uzvaI4B5ywm1uFYbnYL7Z1vPb3Rngd+FN8Nj+cCWwDoFTUhZNFpAl/sRhhS?= =?us-ascii?Q?ugF0pkY7YqrzY75bpsVjOsGgyp9rUTH+hGct2HzenmcJWxPFb7L7yfD665vQ?= =?us-ascii?Q?qaCYzArxd9T9qk8XrHuy36cw0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?Q?YG4eQkZIMH3URuX+7B33nFb4e2ri?= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(1800799015)(82310400017)(376005)(36860700004); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2024 11:16:58.2160 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1db6d0fa-2c05-461b-5036-08dc809a0556 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B077.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7856 Received-SPF: permerror client-ip=2a01:111:f403:2414::624; envelope-from=Pankaj.Gupta@amd.com; helo=NAM11-BN8-obe.outbound.protection.outlook.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.085, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1717068181512100003 Content-Type: text/plain; charset="utf-8" From: Dov Murik Extract the building of the kernel hashes table out from sev_add_kernel_loader_hashes() to allow building it in other memory areas (for SNP support). No functional change intended. Signed-off-by: Dov Murik Signed-off-by: Michael Roth Signed-off-by: Pankaj Gupta --- target/i386/sev.c | 101 ++++++++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 43 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index 4388ffe867..831745c02a 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -1751,45 +1751,16 @@ static const QemuUUID sev_cmdline_entry_guid =3D { 0x4d, 0x36, 0xab, 0x2a) }; =20 -/* - * Add the hashes of the linux kernel/initrd/cmdline to an encrypted guest= page - * which is included in SEV's initial memory measurement. - */ -bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **err= p) +static bool build_kernel_loader_hashes(PaddedSevHashTable *padded_ht, + SevKernelLoaderContext *ctx, + Error **errp) { - uint8_t *data; - SevHashTableDescriptor *area; SevHashTable *ht; - PaddedSevHashTable *padded_ht; uint8_t cmdline_hash[HASH_SIZE]; uint8_t initrd_hash[HASH_SIZE]; uint8_t kernel_hash[HASH_SIZE]; uint8_t *hashp; size_t hash_len =3D HASH_SIZE; - hwaddr mapped_len =3D sizeof(*padded_ht); - MemTxAttrs attrs =3D { 0 }; - bool ret =3D true; - SevCommonState *sev_common =3D SEV_COMMON(MACHINE(qdev_get_machine())-= >cgs); - - /* - * Only add the kernel hashes if the sev-guest configuration explicitly - * stated kernel-hashes=3Don. - */ - if (!sev_common->kernel_hashes) { - return false; - } - - if (!pc_system_ovmf_table_find(SEV_HASH_TABLE_RV_GUID, &data, NULL)) { - error_setg(errp, "SEV: kernel specified but guest firmware " - "has no hashes table GUID"); - return false; - } - area =3D (SevHashTableDescriptor *)data; - if (!area->base || area->size < sizeof(PaddedSevHashTable)) { - error_setg(errp, "SEV: guest firmware hashes table area is invalid= " - "(base=3D0x%x size=3D0x%x)", area->base, area->si= ze); - return false; - } =20 /* * Calculate hash of kernel command-line with the terminating null byt= e. If @@ -1826,16 +1797,6 @@ bool sev_add_kernel_loader_hashes(SevKernelLoaderCon= text *ctx, Error **errp) } assert(hash_len =3D=3D HASH_SIZE); =20 - /* - * Populate the hashes table in the guest's memory at the OVMF-designa= ted - * area for the SEV hashes table - */ - padded_ht =3D address_space_map(&address_space_memory, area->base, - &mapped_len, true, attrs); - if (!padded_ht || mapped_len !=3D sizeof(*padded_ht)) { - error_setg(errp, "SEV: cannot map hashes table guest memory area"); - return false; - } ht =3D &padded_ht->ht; =20 ht->guid =3D sev_hash_table_header_guid; @@ -1856,7 +1817,61 @@ bool sev_add_kernel_loader_hashes(SevKernelLoaderCon= text *ctx, Error **errp) /* zero the excess data so the measurement can be reliably calculated = */ memset(padded_ht->padding, 0, sizeof(padded_ht->padding)); =20 - if (sev_encrypt_flash((uint8_t *)padded_ht, sizeof(*padded_ht), errp) = < 0) { + return true; +} + +/* + * Add the hashes of the linux kernel/initrd/cmdline to an encrypted guest= page + * which is included in SEV's initial memory measurement. + */ +bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **err= p) +{ + uint8_t *data; + SevHashTableDescriptor *area; + PaddedSevHashTable *padded_ht; + hwaddr mapped_len =3D sizeof(*padded_ht); + MemTxAttrs attrs =3D { 0 }; + bool ret =3D true; + SevCommonState *sev_common =3D SEV_COMMON(MACHINE(qdev_get_machine())-= >cgs); + + /* + * Only add the kernel hashes if the sev-guest configuration explicitly + * stated kernel-hashes=3Don. + */ + if (!sev_common->kernel_hashes) { + return false; + } + + if (!pc_system_ovmf_table_find(SEV_HASH_TABLE_RV_GUID, &data, NULL)) { + error_setg(errp, "SEV: kernel specified but guest firmware " + "has no hashes table GUID"); + return false; + } + + area =3D (SevHashTableDescriptor *)data; + if (!area->base || area->size < sizeof(PaddedSevHashTable)) { + error_setg(errp, "SEV: guest firmware hashes table area is invalid= " + "(base=3D0x%x size=3D0x%x)", area->base, area->si= ze); + return false; + } + + /* + * Populate the hashes table in the guest's memory at the OVMF-designa= ted + * area for the SEV hashes table + */ + padded_ht =3D address_space_map(&address_space_memory, area->base, + &mapped_len, true, attrs); + if (!padded_ht || mapped_len !=3D sizeof(*padded_ht)) { + error_setg(errp, "SEV: cannot map hashes table guest memory area"); + return false; + } + + if (build_kernel_loader_hashes(padded_ht, ctx, errp)) { + if (sev_encrypt_flash((uint8_t *)padded_ht, sizeof(*padded_ht), + errp) < 0) { + ret =3D false; + } + } else { ret =3D false; } =20 --=20 2.34.1