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.web12.7941.1602751643547586103 for ; Thu, 15 Oct 2020 01:47:23 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Eq2g274f; 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=1602751642; 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=9bcR02nzEhyMvQAEuSyeeECGnhjfZT+q0LQdyMmD7UQ=; b=Eq2g274fSi3dUHIaNjeDZEhWJBu9B7cqQi1OTVyfn7vRGwEkZ8DZ8vY5WrZwpi8iSkJXFB JGWSD6XeH3qgYUeCQG/c9LptC9kTOR9erFBWFgSzGP4CAowqnV7jLTeHayXIyNUQ9Zh7wt zpVKFubvlG4DPeHk+AkOeFdaaghptcQ= 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-456-2PY6-ShXM7WXUNcskniHjQ-1; Thu, 15 Oct 2020 04:47:20 -0400 X-MC-Unique: 2PY6-ShXM7WXUNcskniHjQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F3E24425DD; Thu, 15 Oct 2020 08:47:18 +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 B5DAA75132; Thu, 15 Oct 2020 08:47:17 +0000 (UTC) Subject: Re: [PATCH 2/9] OvmfPkg/VmgExitLib: Set the SW exit fields when performing VMGEXIT To: Tom Lendacky , devel@edk2.groups.io Cc: Brijesh Singh , Jordan Justen , Ard Biesheuvel References: From: "Laszlo Ersek" Message-ID: <34bc7f77-2b5a-2e74-e78e-ddf606b6305b@redhat.com> Date: Thu, 15 Oct 2020 10:47:16 +0200 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/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 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 >