From nobody Fri Dec 19 06:31:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+79524+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+79524+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linux.ibm.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1629321683667513.6240818765083; Wed, 18 Aug 2021 14:21:23 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id bqU2YY1788612xsmUcsGqVHL; Wed, 18 Aug 2021 14:21:23 -0700 X-Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by mx.groups.io with SMTP id smtpd.web10.61420.1629321682316478233 for ; Wed, 18 Aug 2021 14:21:22 -0700 X-Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17IL3Ngt156667; Wed, 18 Aug 2021 17:21:17 -0400 X-Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3agcvsj97g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Aug 2021 17:21:17 -0400 X-Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 17IL3VAT157371; Wed, 18 Aug 2021 17:21:17 -0400 X-Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0a-001b2d01.pphosted.com with ESMTP id 3agcvsj96p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Aug 2021 17:21:17 -0400 X-Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 17ILI7hY021080; Wed, 18 Aug 2021 21:21:15 GMT X-Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17]) by ppma05wdc.us.ibm.com with ESMTP id 3ae5fdw9fy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Aug 2021 21:21:15 +0000 X-Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 17ILLEsI51380620 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 Aug 2021 21:21:14 GMT X-Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4A854BE04F; Wed, 18 Aug 2021 21:21:14 +0000 (GMT) X-Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 351ECBE053; Wed, 18 Aug 2021 21:21:13 +0000 (GMT) X-Received: from amdrome1.watson.ibm.com (unknown [9.2.130.16]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 18 Aug 2021 21:21:13 +0000 (GMT) From: "Tobin Feldman-Fitzthum" To: tobin@ibm.com, dovmurik@linux.vnet.ibm.com, jejb@linux.ibm.com, frankeh@us.ibm.com, pbonzini@redhat.com, ashish.kalra@amd.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, dgilbert@redhat.com, srutherford@google.com, devel@edk2.groups.io, ard.biesheuvel@arm.com, jiewen.yao@intel.com Subject: [edk2-devel] [RFC PATCH 7/9] OvmfPkg/AmdSev: Don't overwrite MH stack Date: Wed, 18 Aug 2021 17:20:46 -0400 Message-Id: <20210818212048.162626-8-tobin@linux.ibm.com> In-Reply-To: <20210818212048.162626-1-tobin@linux.ibm.com> References: <20210818212048.162626-1-tobin@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: PpAhBoufF4cbi7FDEdp3sJFfzpKWnFG3 X-Proofpoint-GUID: 73K_IK9aGSpoQpAlu9iARgrwc2WgpiBx Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,tobin@linux.ibm.com X-Gm-Message-State: xBSycpDfhJDkLoLFggSNY7dZx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1629321683; bh=GWHS+0Rti8vzOBQFoaH2Z3ABn04ywy6xsQqpLU3VkJU=; h=Date:From:Reply-To:Subject:To; b=ZkePBOmD7XNIqDujbdMd9njVi21bNxvsxrkQBPE7x7tiJIUqh7gTW2AWGTEbLQ7ZdTb WQcEHs1O0JaZjQnlEqdKYrO1uM9L2w2bUx63v1JkKmEPIjxStmIu+Bxc7w7ad+9FHPBw6 b2QJmOWxoF3mJPRQTKPSKHX0j6llQylPZ2E= X-ZohoMail-DKIM: fail (Computed bodyhash is different from the expected one) X-ZM-MESSAGEID: 1629321684423100017 Content-Type: text/plain; charset="utf-8" The Migration Handler uses its own stack and should avoid overwriting the stack when importing pages. Signed-off-by: Tobin Feldman-Fitzthum --- .../ConfidentialMigrationDxe.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.= c b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c index ee1466eb00..2de35a7bb1 100644 --- a/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c +++ b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c @@ -45,6 +45,8 @@ typedef volatile struct { =20 STATIC PAGE_TABLE_POOL *mPageTablePool =3D NULL; PHYSICAL_ADDRESS mMigrationHandlerPageTables =3D 0; +PHYSICAL_ADDRESS mMigrationHandlerStackBase =3D 0; +UINT32 mMigrationHandlerStackSize =3D 4; =20 /** Allocates and fills in custom page tables for Migration Handler. @@ -112,6 +114,8 @@ MigrationHandlerMain () UINT64 MailboxEnd; UINT64 PagetableStart; UINT64 PagetableEnd; + UINT64 StackStart; + UINT64 StackEnd; MH_COMMAND_PARAMETERS *Params; VOID *PageVa; =20 @@ -126,6 +130,9 @@ MigrationHandlerMain () PagetableStart =3D mMigrationHandlerPageTables; PagetableEnd =3D PagetableStart + 11 * EFI_PAGE_SIZE; =20 + StackStart =3D mMigrationHandlerStackBase; + StackEnd =3D StackStart + mMigrationHandlerStackSize; + DisableInterrupts (); Params->Go =3D 0; =20 @@ -147,10 +154,11 @@ MigrationHandlerMain () =20 case MH_FUNC_RESTORE_PAGE: // - // Don't import a page that covers the mailbox or pagetables. + // Don't import a page that covers the mailbox, pagetables, or stack. // if (!((Params->Gpa >=3D MailboxStart && Params->Gpa < MailboxEnd) || - (Params->Gpa >=3D PagetableStart && Params->Gpa < PagetableEnd))= ) { + (Params->Gpa >=3D PagetableStart && Params->Gpa < PagetableEnd) = || + (Params->Gpa >=3D StackStart && Params->Gpa < StackEnd))) { =20 CopyMem ((VOID *)Params->Gpa, PageVa, 4096); } @@ -190,6 +198,11 @@ SetupMigrationHandler ( return 0; } =20 + // + // Setup stack and pagetables for Migration Handler + // + mMigrationHandlerStackBase =3D (UINTN)AllocateAlignedRuntimePages (mMigr= ationHandlerStackSize, PAGE_TABLE_POOL_ALIGNMENT); + PrepareMigrationHandlerPageTables (); =20 // --=20 2.20.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#79524): https://edk2.groups.io/g/devel/message/79524 Mute This Topic: https://groups.io/mt/84982987/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-