Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3543077pxj; Mon, 24 May 2021 09:02:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/UMt+bup0T2q0tVEq0RwawuHrdl/zdwiZNtLbYhLIZRTJqi2ufXgVcNXHMeDH0pruksty X-Received: by 2002:a5d:8501:: with SMTP id q1mr16363089ion.66.1621872148666; Mon, 24 May 2021 09:02:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621872148; cv=none; d=google.com; s=arc-20160816; b=K+i2v7ATvqqYvC3fFMkX5FKR+U5o5T8+IN/POY2FuKqzyZPc0j0kOOfk7c7c1U7B84 BKt9J/JUOJgk68G4TQ26iN2nVjTTm1GgALsirsiOn5AN0GK2Ndg2riVqLDWaZsKrz+JH 0e1OXAUZxP52cK1O7Q8IYDlaWKLl3rWc69Gex3uUxF0twBwoNtkie55aa5Aso9V/gGsq DQit5NtoKvBO7wFal3BJZqtcEr+2vVzrTxrHDqJmWJ358o+U/eZRQ2g7E3D/AvqxqHI1 N/t0A4z4B7ATdKR3fIr5ntJJ7VYaKcF+0uiVnJUqbAJrzeJnBzb/RcadxNdnsCCPz/fJ 8Xbg== 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=NMpf7zawkzA44GRqheHj2G1YOzzMaK4G45OCTy4McEjPE53y/1eJAs3Pk5E81ZyT1+ Ckzt1294eBMCqS+nlVSqS3qHbSTWk2MPFPlY2vUSm1tQfh2uQ8xRLFCTb662YFXuOAtH DLeVrkgHwVlNW1pLpE2ZuAvpqwHvtr2dMAtE5hn4E+NLKU12MoXXcsYQ2DM8foFvzCyk VcBAYyS+IAOiwI8yV1mRISqReE7Xhy53beNDgmS7XSRWDMaZgHDfbbkBAG3b89qgAet8 NcY6WYgMyBxxZyo4nkTOTrkVTCquTrvdWwJ/DK69zcxW0stGzGr/wTVNUlNSvPA61BKl o1rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0nBKerwg; 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 g3si15861343jan.54.2021.05.24.09.02.11; Mon, 24 May 2021 09:02:28 -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=0nBKerwg; 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 S233038AbhEXQBw (ORCPT + 99 others); Mon, 24 May 2021 12:01:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:41136 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233634AbhEXPz3 (ORCPT ); Mon, 24 May 2021 11:55:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 634706143D; Mon, 24 May 2021 15:41:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621870909; bh=2eixtHJtGhNm7iHprTMw6XRac/mdtTXk6JyXaKcgtyk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0nBKerwg30cn84AIFdnZINKdxEzX1w2CLZYckiDJfhMoBgWBJ/+bDgznl20CBtHGD 5bVBr5pBdbVel7qI98KOs4bfi29l280TKBAJwpDN9CmIm3ooTaZJ5jBORTQKxHl5vM /w0zIC+dtht5SQS1GvPxgcnQQowEMBqMeN4Ft1WY= 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.10 056/104] x86/sev-es: Invalidate the GHCB after completing VMGEXIT Date: Mon, 24 May 2021 17:25:51 +0200 Message-Id: <20210524152334.720956848@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152332.844251980@linuxfoundation.org> References: <20210524152332.844251980@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; } }