From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web10.7978.1602751853206789415 for ; Thu, 15 Oct 2020 01:50:53 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=imtkxmey; spf=pass (domain: redhat.com, ip: 63.128.21.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602751852; 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=CdTqBfklJWI7VowY5jRUGrTGMIAxm1qsDs5QZGUwdnc=; b=imtkxmeyKwRCmrm5c2XNGKWEttFyu+OT5YTt+cYZARUHzPd0lv8KIsnKpXlScWCJyqpyUs 5f1/fIArDwz3qLAzMIsscDkwUTk0xH2gqliaRuyc9I/stvcGk1bIi+1jsUL3Z8hCyAkh0i 7/zdJHUHwE4J8Hvn/q1ArmGf3iikks4= 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-52-3_bjgvrxP0W3Ep9hBqIjkg-1; Thu, 15 Oct 2020 04:50:49 -0400 X-MC-Unique: 3_bjgvrxP0W3Ep9hBqIjkg-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 6A2101054F91; Thu, 15 Oct 2020 08:50:48 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-119.ams2.redhat.com [10.36.113.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C7D560C0F; Thu, 15 Oct 2020 08:50:47 +0000 (UTC) Subject: Re: [PATCH 2/9] OvmfPkg/VmgExitLib: Set the SW exit fields when performing VMGEXIT From: "Laszlo Ersek" To: Tom Lendacky , devel@edk2.groups.io Cc: Brijesh Singh , Jordan Justen , Ard Biesheuvel References: <34bc7f77-2b5a-2e74-e78e-ddf606b6305b@redhat.com> Message-ID: <71b855ac-8381-4767-798c-2fafd2b9bd56@redhat.com> Date: Thu, 15 Oct 2020 10:50:46 +0200 MIME-Version: 1.0 In-Reply-To: <34bc7f77-2b5a-2e74-e78e-ddf606b6305b@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 10/15/20 10:47, Laszlo Ersek wrote: > On 10/10/20 18:07, Tom Lendacky wrote: >> From: Tom Lendacky >> >> All fields that are set in the GHCB should have their associated bit in >> the GHCB ValidBitmap field set. Add support to set the bits for the >> software exit information fields when performing a VMGEXIT (SwExitCode, >> SwExitInfo1, SwExitInfo2). >> >> Fixes: 61bacc0fa16f ("OvmfPkg/VmgExitLib: Implement library support for VmgExitLib in OVMF") >> Cc: Jordan Justen >> Cc: Laszlo Ersek >> Cc: Ard Biesheuvel >> Cc: Tom Lendacky >> Cc: Brijesh Singh >> Signed-off-by: Tom Lendacky >> --- >> OvmfPkg/Library/VmgExitLib/VmgExitLib.c | 30 ++++++++++++++++++++ >> 1 file changed, 30 insertions(+) >> >> diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitLib.c b/OvmfPkg/Library/VmgExitLib/VmgExitLib.c >> index 53040cc6f649..6cf649c6101b 100644 >> --- a/OvmfPkg/Library/VmgExitLib/VmgExitLib.c >> +++ b/OvmfPkg/Library/VmgExitLib/VmgExitLib.c >> @@ -78,6 +78,32 @@ VmgExitErrorCheck ( >> return Status; >> } >> >> +/** >> + Marks a field at the specified offset as valid in the GHCB. >> + >> + The ValidBitmap area represents the areas of the GHCB that have been marked >> + valid. Set the area of the GHCB at the specified offset as valid. >> + >> + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communication Block >> + @param[in] Offset Offset in the GHCB to mark valid >> + >> +**/ >> +STATIC >> +VOID >> +GhcbSetOffsetValid ( >> + IN OUT GHCB *Ghcb, >> + IN GHCB_QWORD_OFFSET Offset >> + ) >> +{ >> + UINT32 OffsetIndex; >> + UINT32 OffsetBit; >> + >> + OffsetIndex = Offset / 8; >> + OffsetBit = Offset & 0x07; > > (1) I suggest improving the consistency of operators -- please either > use division and remainder ("Offset / 8" and "Offset % 8"), or bit shift > and masking ("Offset >> 3" and "Offset & 0x7") > > With that: > > Acked-by: Laszlo Ersek ... I realize I didn't make the same comment for GhcbIsRegValid(), so I'm taking back the above -- consistency with GhcbIsRegValid() is more important. No change needed here. Acked-by: Laszlo Ersek Thanks, Laszlo > > Thanks > Laszlo > >> + >> + Ghcb->SaveArea.ValidBitmap[OffsetIndex] |= (1 << OffsetBit); >> +} >> + >> /** >> Perform VMGEXIT. >> >> @@ -110,6 +136,10 @@ VmgExit ( >> Ghcb->SaveArea.SwExitInfo1 = ExitInfo1; >> Ghcb->SaveArea.SwExitInfo2 = ExitInfo2; >> >> + GhcbSetOffsetValid (Ghcb, GhcbSwExitCode); >> + GhcbSetOffsetValid (Ghcb, GhcbSwExitInfo1); >> + GhcbSetOffsetValid (Ghcb, GhcbSwExitInfo2); >> + >> // >> // Guest memory is used for the guest-hypervisor communication, so fence >> // the invocation of the VMGEXIT instruction to ensure GHCB accesses are >> >