Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp960329pxb; Fri, 13 Aug 2021 10:05:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1ZTjEz/L1AbLtH+l10pdaMjbqlnUYhLJHezDvMNHcWZDFlTRmbYS/avtmpz9lNM/hFI2c X-Received: by 2002:a05:6e02:1bc7:: with SMTP id x7mr2610598ilv.116.1628874345711; Fri, 13 Aug 2021 10:05:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628874345; cv=none; d=google.com; s=arc-20160816; b=FEUNO0PzBS7LgbBkdL7pMBg4E8macPZyHPwqZ/vPNj1u90c+ZRqAcpvrFMl92vjITx YzWvMbkxPJ5ZF64NxTXKWBAtzfTqGTqy04k2Tw+scaH/dCo2md9C4X9fvcVJuX38AWdi z5G6HkW91zondQVIl9l1qrMXsTjI+QBpcjBk7n1KeEl90Siqx0R4qiDQErIAP2LJx/mi 9MgnOqAdwj8jqrMCxO95yhGhFG/jg0jtyHyivQM2mDCMyoxQjL9oA3GLneBdC4fzDkew rdMq0DCCuqX2l/4/xdQDHroc7QXcvY4T6K2G9wmxwYJ7y2IYZC4QyuVDj5X+2v0EyUvL 77Vw== 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=M3JCH8CPfA3WgBBsG6wDfbFDcag4BDOHuXkNwmEbGYU=; b=Vsvw8OeKX+3SQaCt6od6BCo+Q4YjTuhVn/hEfBNSHgCAqSKk2Y+nhyL9OqpBm4beyK 4uTNvFpk/rynR5p3NnvHOD8qDn01vSHLkQK11h8Q7Yj2XMO8EyBNWLhgzNUYjLbh2KL8 vhutJMFAERLzNshhlbRlP5ktw/wUxsjR+u1+YAoSqN3Qon87A3t6a2XgbJIve1QsqhWy 3ZIlX5QJPrltQObLv21m9Xa5tEjVhxFalzWOhZHBrgB8Kdzv3S8FOIopBF2JRtnFmn2n 2bv6p61obAkIEd5X+KnvgfTl+7d6qCC1qPtBNewmSMrSVaGqn8sCkzx59hYJihrEUQJT spGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AvWz8NrZ; 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 v20si2443931jas.98.2021.08.13.10.05.34; Fri, 13 Aug 2021 10:05:45 -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=AvWz8NrZ; 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 S242628AbhHMPSO (ORCPT + 99 others); Fri, 13 Aug 2021 11:18:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:55900 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242698AbhHMPOg (ORCPT ); Fri, 13 Aug 2021 11:14:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 16239610CF; Fri, 13 Aug 2021 15:14:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628867649; bh=wxC2BJHbVvWK0CrPHUrgXcHsT/DCnS0d6ToQ1p6AQrY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AvWz8NrZ7sIETBZLmfaKZkLSmMj7zZobgThSygHfdmROCVpC1MQGG+oElYy827MJU O07lofY49/AvDEAJ77D5o5ASaGEnWhtRWfN4tvdaW2OvYcxG8oeX/OuWQcEPy4hjF/ 8+Z5e68i4LirC22Qzhqz5M+Z5IZpXRs6PyisL3/0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tom Lendacky , Brijesh Singh , Sean Christopherson , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.10 01/19] KVM: SVM: Fix off-by-one indexing when nullifying last used SEV VMCB Date: Fri, 13 Aug 2021 17:07:18 +0200 Message-Id: <20210813150522.671018477@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210813150522.623322501@linuxfoundation.org> References: <20210813150522.623322501@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore 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: Sean Christopherson [ Upstream commit 179c6c27bf487273652efc99acd3ba512a23c137 ] Use the raw ASID, not ASID-1, when nullifying the last used VMCB when freeing an SEV ASID. The consumer, pre_sev_run(), indexes the array by the raw ASID, thus KVM could get a false negative when checking for a different VMCB if KVM manages to reallocate the same ASID+VMCB combo for a new VM. Note, this cannot cause a functional issue _in the current code_, as pre_sev_run() also checks which pCPU last did VMRUN for the vCPU, and last_vmentry_cpu is initialized to -1 during vCPU creation, i.e. is guaranteed to mismatch on the first VMRUN. However, prior to commit 8a14fe4f0c54 ("kvm: x86: Move last_cpu into kvm_vcpu_arch as last_vmentry_cpu"), SVM tracked pCPU on its own and zero-initialized the last_cpu variable. Thus it's theoretically possible that older versions of KVM could miss a TLB flush if the first VMRUN is on pCPU0 and the ASID and VMCB exactly match those of a prior VM. Fixes: 70cd94e60c73 ("KVM: SVM: VMRUN should use associated ASID when SEV is enabled") Cc: Tom Lendacky Cc: Brijesh Singh Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/svm/sev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 01547bdbfb06..6c82ef22985d 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -124,7 +124,7 @@ static void sev_asid_free(int asid) for_each_possible_cpu(cpu) { sd = per_cpu(svm_data, cpu); - sd->sev_vmcbs[pos] = NULL; + sd->sev_vmcbs[asid] = NULL; } mutex_unlock(&sev_bitmap_lock); -- 2.30.2