From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by mx.groups.io with SMTP id smtpd.web12.451.1614718140265823377 for ; Tue, 02 Mar 2021 12:49:00 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@ibm.com header.s=pp1 header.b=HYp8z+cQ; spf=pass (domain: linux.ibm.com, ip: 148.163.158.5, mailfrom: tobin@linux.ibm.com) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 122KhK6T167291; Tue, 2 Mar 2021 15:48:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=C5La8/+TuzCLvQ62MdlntxvZ25UHUO0ncsRIf8uaOOY=; b=HYp8z+cQiGSOlOafupW7X8ql8A0i4fPm+YpF8qWMhHGWY++ihZfh+/P/y/d1Q7z/lK9M a23PzYSWgReE1BGdjpa+EK1PYjK2kQIRswYRx4F3RPEF5ZCW+hoAr/LcSL8YK9psIwYy S4I0Zu8JtUQ5RyoUsodWWlw+/9/v23cpZCf+TFoAry98skA0DO6Hts1RQNmFrwFdqZG1 qtIk7OBPla9qdmwdOS44B+8cCwS6gjPVNngvY/wjJoiVfJ+wLT8fsQryIUym+Z0MFrsW 8ZbRYoAC7gAsbCiF1ehmJmAseP3XR0gRwo5/oB9DuIZ7rWghaKsVNVuNmJDXbdqY9+4B ow== Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0a-001b2d01.pphosted.com with ESMTP id 371vn488g2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Mar 2021 15:48:57 -0500 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 122Kkpx4028077; Tue, 2 Mar 2021 20:48:56 GMT Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17]) by ppma01dal.us.ibm.com with ESMTP id 371qmuagy4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Mar 2021 20:48:56 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 122KmsBG29098478 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 2 Mar 2021 20:48:54 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 57B5FC6057; Tue, 2 Mar 2021 20:48:54 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C3947C6055; Tue, 2 Mar 2021 20:48:53 +0000 (GMT) Received: from amdrome1.watson.ibm.com (unknown [9.2.130.16]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 2 Mar 2021 20:48:53 +0000 (GMT) From: "Tobin Feldman-Fitzthum" To: devel@edk2.groups.io Cc: Dov Murik , Tobin Feldman-Fitzthum , Tobin Feldman-Fitzthum , James Bottomley , Hubertus Franke , Brijesh Singh , Ashish Kalra , Jon Grimm , Tom Lendacky Subject: [RFC PATCH 12/14] OvmfPkg/AmdSev: Don't overwrite mailbox or pagetables Date: Tue, 2 Mar 2021 15:48:37 -0500 Message-Id: <20210302204839.82042-13-tobin@linux.ibm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210302204839.82042-1-tobin@linux.ibm.com> References: <20210302204839.82042-1-tobin@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.761 definitions=2021-03-02_08:2021-03-01,2021-03-02 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 spamscore=0 bulkscore=0 suspectscore=0 impostorscore=0 mlxlogscore=999 malwarescore=0 clxscore=1015 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103020156 Content-Transfer-Encoding: 8bit While restoring pages, the MH should avoid overwriting its pagetables or the mailbox it uses to communicate with the HV. Signed-off-by: Tobin Feldman-Fitzthum --- .../ConfidentialMigrationDxe.c | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c index 3df3b09732..f609e16f8d 100644 --- a/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c +++ b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c @@ -128,6 +128,10 @@ MigrationHandlerMain ( IN OUT VOID *Buffer ) { + UINT64 mailbox_start; + UINT64 mailbox_end; + UINT64 pagetable_start; + UINT64 pagetable_end; UINT64 params_base; MH_COMMAND_PARAMETERS *params; VOID *page_va; @@ -139,10 +143,16 @@ MigrationHandlerMain ( // // Shared pages must be offset by UNENC_VIRT_ADDR_BASE. // - params_base = PcdGet32 (PcdConfidentialMigrationMailboxBase) + UNENC_VIRT_ADDR_BASE; + mailbox_start = PcdGet32 (PcdConfidentialMigrationMailboxBase); + params_base = mailbox_start + UNENC_VIRT_ADDR_BASE; params = (VOID *)params_base; page_va = (VOID *)params_base + 0x1000; + mailbox_end = mailbox_start + 2 * EFI_PAGE_SIZE; + + pagetable_start = mMigrationHelperPageTables; + pagetable_end = pagetable_start + 11 * EFI_PAGE_SIZE; + DisableInterrupts(); params->go = 0; @@ -163,7 +173,15 @@ MigrationHandlerMain ( break; case MH_FUNC_RESTORE_PAGE: - CopyMem((VOID *)params->gpa, page_va, 4096); + // + // Don't import a page that covers the mailbox or pagetables. + // + if ((params->gpa >= mailbox_start && params->gpa < mailbox_end) || + (params->gpa >= pagetable_start && params->gpa < pagetable_end)) { + } + else { + CopyMem((VOID *)params->gpa, page_va, 4096); + } params->ret = MH_SUCCESS; break; -- 2.20.1