Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3546487pxj; Mon, 24 May 2021 09:05:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzL9bYMpUk8SlWZMAdL+jdXKrugW/F+E7TokaNGgf2CoWTs29qPzjjuwhWeY99SGx4IG1Oh X-Received: by 2002:adf:f50f:: with SMTP id q15mr22105534wro.279.1621872355808; Mon, 24 May 2021 09:05:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621872355; cv=none; d=google.com; s=arc-20160816; b=OwWeWWaIZhOk+OGA0Z34aXpeKdX8uo7Yjdcdi8FpqFu8vVE0qngDF+x+KGlNRPxSmX VbR3kq5ZEDXVhkvZ/sHFjIDtzJQ4Vgh3gZVlYZpNFTDWtIXrJ5ZHMIm20XAaGM9mBY2p jb/cuyTrzABQYYP56xa/sHqH66LsRBO4ExRYDpNtdZaX7CCX40uNKZcoRoTRcuhPHaBh GuBV1/X6KuY+H33q40n6Zynti6BjNdg009g0NYxEFC/lEt3ihtb01w9ZKvQe4l5hwCJz wYG3TYwiyUv6iUWa8oTaJ0upumBvnD3i/z/ZBYcVYO8ohZ3VlANnTDGFEHG4FKmmBCNK LPxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NM1882O94Y0oyFzfprOhnxqTTFrRnLDstnQj+dgUXBs=; b=F8fhV3wGzoU7M4ENwcm3xbTsrgTDfHPBhKAHEWYEW07wqsukbtW4flB3z/vlcpSnii 1hbw5WszigpVmVZauY5PoiYc7Kdmr/wyj9PuaNvQ/gONyWEds5MBVCPM3COaoHTv0oKE Wkecy6umJ3y4LYwLdj2d2lkTLoV4IZYXH/Sqnrr3V7bvrq4rh87xz2epY3KtvMHh82pQ Dsxuw6feuQjUjradXK2D/XsTxqL5YnSo60Fr2vflq76mES5qntr/aEmwKmB+OaH919aD QO0xjYEJTwZU6LDaU3fbpEA2KXQJfRtLKpEI71ZaX3QGo5D8byPgOvHOXSva54+WfugN fWCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VaR+9q9I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jw3si7806067ejc.279.2021.05.24.09.05.27; Mon, 24 May 2021 09:05:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VaR+9q9I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237676AbhEXQFd (ORCPT + 99 others); Mon, 24 May 2021 12:05:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:40506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235729AbhEXP7J (ORCPT ); Mon, 24 May 2021 11:59:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A723C6195D; Mon, 24 May 2021 15:44:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621871092; bh=2eixtHJtGhNm7iHprTMw6XRac/mdtTXk6JyXaKcgtyk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VaR+9q9Ip1/2NJe+ZAxMCLWorTsIN2zaAX3b3zKiNCW9K3d3KWKqpVuqSIVQnjSRJ Z6Fq2OybZZ2JecnCoyKcDougiVNyWSqymR+t8nhGbxLrl6E3UVEekPbjAqD/YE5S6N R5LvIQ+PLO/l/sw1YXhLOHDl9+ywCnBH89WTAd+s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tom Lendacky , Borislav Petkov Subject: [PATCH 5.12 070/127] x86/sev-es: Invalidate the GHCB after completing VMGEXIT Date: Mon, 24 May 2021 17:26:27 +0200 Message-Id: <20210524152337.219129168@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152334.857620285@linuxfoundation.org> References: <20210524152334.857620285@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tom Lendacky commit a50c5bebc99c525e7fbc059988c6a5ab8680cb76 upstream. Since the VMGEXIT instruction can be issued from userspace, invalidate the GHCB after performing VMGEXIT processing in the kernel. Invalidation is only required after userspace is available, so call vc_ghcb_invalidate() from sev_es_put_ghcb(). Update vc_ghcb_invalidate() to additionally clear the GHCB exit code so that it is always presented as 0 when VMGEXIT has been issued by anything else besides the kernel. Fixes: 0786138c78e79 ("x86/sev-es: Add a Runtime #VC Exception Handler") Signed-off-by: Tom Lendacky Signed-off-by: Borislav Petkov Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/5a8130462e4f0057ee1184509cd056eedd78742b.1621273353.git.thomas.lendacky@amd.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/sev-es-shared.c | 1 + arch/x86/kernel/sev-es.c | 5 +++++ 2 files changed, 6 insertions(+) --- a/arch/x86/kernel/sev-es-shared.c +++ b/arch/x86/kernel/sev-es-shared.c @@ -63,6 +63,7 @@ static bool sev_es_negotiate_protocol(vo static __always_inline void vc_ghcb_invalidate(struct ghcb *ghcb) { + ghcb->save.sw_exit_code = 0; memset(ghcb->save.valid_bitmap, 0, sizeof(ghcb->save.valid_bitmap)); } --- a/arch/x86/kernel/sev-es.c +++ b/arch/x86/kernel/sev-es.c @@ -430,6 +430,11 @@ static __always_inline void sev_es_put_g data->backup_ghcb_active = false; state->ghcb = NULL; } else { + /* + * Invalidate the GHCB so a VMGEXIT instruction issued + * from userspace won't appear to be valid. + */ + vc_ghcb_invalidate(ghcb); data->ghcb_active = false; } }