From nobody Mon Nov 25 07:58:12 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1717483822; cv=none; d=zohomail.com; s=zohoarc; b=jSIf8CraqAGsbqmBvqnnWimyeZF1czm6BIhsone7Mm40QB9SW5+qkKL8aCv496tPuEA904TwxsTGFPV0BZAWbDeD5209z0nPjlMzYec7dA/PqOfK7Xn7wmPlGO/gaPCqdPRACFOVVsNzUvXM9/klf540MIF3UOwtcU3eMv+2KG4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717483822; 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=lo/3ikAn9rcrJ9CdEidY1h4ZPRHmzUcZc1MlRn3C+HM=; b=ae5e7xWMmBUIwZceT7/fDPEuE0aupUppTkbtfwUE5hEYTLTNBTD75fwLSdLf+1fq8k/b05oPXE8rSRnwEEd5sOQCa6v0Ssr9eJ+SLG+nWrnN9sIVTKcpzzOfzpPnHlLLgADKp2i0tbSknKvNG45i2Ce5kDthrjAOd6ed0gSDGN4= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717483822032534.8527833469384; Mon, 3 Jun 2024 23:50:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sENws-0007Gq-KR; Tue, 04 Jun 2024 02:47:10 -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 1sENvt-0004e7-Sa for qemu-devel@nongnu.org; Tue, 04 Jun 2024 02:46:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sENvs-0007dm-2D for qemu-devel@nongnu.org; Tue, 04 Jun 2024 02:46:09 -0400 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-351-RGbMZRfQNTmZUD1tJPQQ7Q-1; Tue, 04 Jun 2024 02:46:05 -0400 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-57a620e4a55so798621a12.0 for ; Mon, 03 Jun 2024 23:46:05 -0700 (PDT) Received: from avogadro.local ([151.81.115.112]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57a5fff9bc0sm3356392a12.97.2024.06.03.23.46.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 23:46:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717483567; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lo/3ikAn9rcrJ9CdEidY1h4ZPRHmzUcZc1MlRn3C+HM=; b=dLMKoaKBSiwjUQzN/0kmWV48r12F8ey8+afdLZFaiuyvhHzVn7nBuL8jAVW146tf8XrVQL ibSDLE6rpcOM77n9uc4Q4gYq78tdyjpIJ4FgMrHcy3SG+ebM+gjOvA5ZDo4qLJ7hN76JQM bt2bDUxF8B26WeT5KvghfWS3Fqkbt60= X-MC-Unique: RGbMZRfQNTmZUD1tJPQQ7Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717483564; x=1718088364; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lo/3ikAn9rcrJ9CdEidY1h4ZPRHmzUcZc1MlRn3C+HM=; b=LMUjKFnVlObA5rPm5iEeTdy7Btz934ICa58g31CmDchVOer3KQITb/qqyrBNLO6VpY 1QCxoD1Tjzemc2kiplQwqJGMDUtgamcygC6tVOpkUAT1my76Y1Z3lsrRV566eKLSFlbN 4h35Er7KKm6S4WDI6GbJOkemJVWAj2blLpvBMCaKU+Ti1kK+UzVhgr/wppgmgaKjYz/L tNbRJF7etdNaszWQQ6q+mWQvz93Dz5QLbS9HKCSsJrAcdV5MACXCDsHGEJQltTMu+k7O d5v8UDe+ff0BS9ZxMShp+hkjrlLRUqFepK36plesOyTWhTDB80GCgsbERIMjjNzrxxFE JW4A== X-Gm-Message-State: AOJu0YzPWngzMHUH0A8SCr2mLKvm7PzcBR0r+IAlDW4F42IHYlt6dMQT f3YCy2TXfRHtrok7Dw89aQq6hq0iJsQxMPJ64uUge57tFM+J8xa8RA5ALjCRQNluHvxpbOQabhs 08+S6gQrc/iRrXfzgpOLT1nf7Vx+Z+oDN2IsDmFBVUWB4cimpmlFxNbnsueD5uUZOurVQ+wtmg/ KWsFuVuKl5nywASYOza3geR5NtvNPD95JbceyE X-Received: by 2002:a50:d757:0:b0:57a:859e:4d81 with SMTP id 4fb4d7f45d1cf-57a859e4ef8mr142344a12.28.1717483563771; Mon, 03 Jun 2024 23:46:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGT9XGFkiJ/jwiFpmi9hgbngzdVvSNRU38C85DmBpUM1emXzWzkn8jal5zgleqUUIrpvTmjDg== X-Received: by 2002:a50:d757:0:b0:57a:859e:4d81 with SMTP id 4fb4d7f45d1cf-57a859e4ef8mr142325a12.28.1717483563383; Mon, 03 Jun 2024 23:46:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Dov Murik , Michael Roth , Pankaj Gupta Subject: [PULL 40/45] i386/sev: Extract build_kernel_loader_hashes Date: Tue, 4 Jun 2024 08:44:04 +0200 Message-ID: <20240604064409.957105-41-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240604064409.957105-1-pbonzini@redhat.com> References: <20240604064409.957105-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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 @redhat.com) X-ZM-MESSAGEID: 1717483823159100001 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 Message-ID: <20240530111643.1091816-22-pankaj.gupta@amd.com> Signed-off-by: Paolo Bonzini --- target/i386/sev.c | 102 ++++++++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 44 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index abb63062ac6..73f94067155 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -1754,45 +1754,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 @@ -1829,16 +1800,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; @@ -1859,8 +1820,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(area->base, (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(area->base, (uint8_t *)padded_ht, + sizeof(*padded_ht), errp) < 0) { + ret =3D false; + } + } else { ret =3D false; } =20 --=20 2.45.1