From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web08.6405.1634198581671012220 for ; Thu, 14 Oct 2021 01:03:01 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KH8Uo0Ti; spf=pass (domain: redhat.com, ip: 170.10.133.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634198580; 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: in-reply-to:in-reply-to:references:references; bh=2zHiT21iSNc/peI2sEok6iw/KAkQR7bhwvyFAjGqP3s=; b=KH8Uo0TiNqHGn8fsISPOXXjJ+xLl0TciA39mpZ310wrlxNSIaDzi3LR0ktusk7tZzqKTAT lQefbK1T6Xnrc8CTtL79YzqdYzvCQtTPv0wFC8GQ1pY+F/L4W03AKQpM4X5+WylMG2RLgc rIQfXPYl1yazjr5++WnlRbyDAL6WZiM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-472-WwLKTfCwNDulc3O6SynQxw-1; Thu, 14 Oct 2021 04:02:52 -0400 X-MC-Unique: WwLKTfCwNDulc3O6SynQxw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0033210A8E01; Thu, 14 Oct 2021 08:02:51 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A47A460E1C; Thu, 14 Oct 2021 08:02:50 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 4876218007AC; Thu, 14 Oct 2021 10:02:48 +0200 (CEST) Date: Thu, 14 Oct 2021 10:02:48 +0200 From: "Gerd Hoffmann" To: Brijesh Singh Cc: devel@edk2.groups.io, James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Erdem Aktas , Michael Roth Subject: Re: [PATCH v9 14/32] OvmfPkg/MemEncryptSevLib: add support to validate system RAM Message-ID: <20211014080248.6mot5nujiziajjrx@sirius.home.kraxel.org> References: <20211013165713.727815-1-brijesh.singh@amd.com> <20211013165713.727815-15-brijesh.singh@amd.com> MIME-Version: 1.0 In-Reply-To: <20211013165713.727815-15-brijesh.singh@amd.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Oct 13, 2021 at 11:56:55AM -0500, Brijesh Singh wrote: > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3275 > > Many of the integrity guarantees of SEV-SNP are enforced through the > Reverse Map Table (RMP). Each RMP entry contains the GPA at which a > particular page of DRAM should be mapped. The guest can request the > hypervisor to add pages in the RMP table via the Page State Change VMGEXIT > defined in the GHCB specification section 2.5.1 and 4.1.6. Inside each RMP > entry is a Validated flag; this flag is automatically cleared to 0 by the > CPU hardware when a new RMP entry is created for a guest. Each VM page > can be either validated or invalidated, as indicated by the Validated > flag in the RMP entry. Memory access to a private page that is not > validated generates a #VC. A VM can use the PVALIDATE instruction to > validate the private page before using it. > > During the guest creation, the boot ROM memory is pre-validated by the > AMD-SEV firmware. The MemEncryptSevSnpValidateSystemRam() can be called > during the SEC and PEI phase to validate the detected system RAM. > > One of the fields in the Page State Change NAE is the RMP page size. The > page size input parameter indicates that either a 4KB or 2MB page should > be used while adding the RMP entry. During the validation, when possible, > the MemEncryptSevSnpValidateSystemRam() will use the 2MB entry. A > hypervisor backing the memory may choose to use the different page size > in the RMP entry. In those cases, the PVALIDATE instruction should return > SIZEMISMATCH. If a SIZEMISMATCH is detected, then validate all 512-pages > constituting a 2MB region. > > Upon completion, the PVALIDATE instruction sets the rFLAGS.CF to 0 if > instruction changed the RMP entry and to 1 if the instruction did not > change the RMP entry. The rFlags.CF will be 1 only when a memory region > is already validated. We should not double validate a memory > as it could lead to a security compromise. If double validation is > detected, terminate the boot. Acked-by: Gerd Hoffmann