Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4706801pxj; Wed, 12 May 2021 11:20:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzB4zXNFYvXVoq/gOaI283bcCYfAYo2+vBkArYRU6C/ZWo65sw9o20rGIplLmuIecXLdmFe X-Received: by 2002:aa7:c903:: with SMTP id b3mr45429394edt.296.1620843625313; Wed, 12 May 2021 11:20:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620843625; cv=none; d=google.com; s=arc-20160816; b=mLeIf8X7Eqe1TgVjPZUjxI0TigCsezjn8gFCqfkAzyQhIdl5NHQKm7zXbRW9+gKivn HFvO1FvsvHWGWRE3w5gmIPESpracA+5rMub3oMpiS0apRfrZbgSCuWuDci7HWIlfysXp XftEBQ7KCSZMURriPT2PFuRY88T+tg6pQ6Om1GzCEr67OZ+EBEveC0MV2TvMGyvfWGa8 YNGfCL2geCMJSJcX+Jp4fAW00JzolLYb78I03JPNsZ108arsCLAkJKXacwsid+21V6JS /Ax879gzpV4RkPWohOU4/PJFYWgT6BhUjKxlamxqozPeKFZPW44SrjsQ4pHsLeFJTIOG KCHw== 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=57yYYkx2OWke9Fqb1DGCxDXHA5jbgGP2ca2FEiLh5Ew=; b=tU1Qo1opiieCm2JVZNKRgI9EGxX8e/p3Af95aAbnYjuNtnhgoe1wLVyg+ztc3+ScWM 1rkQUgmy66lYlfFqUNeLYAG+znQSp0f3CNkF53OIVBkUo+Qbu+1tUVASB6mo/eftludF cuf+U/t9Y3sMz2cY4o/sPqdGk16mlYj9XVapVe7RmUIqupzzQrACDf7zocwEWsQsu5wf 1V0efLjNc8kc8ZYwlqiB2mhj1DTTsoeGajHeu6g0924w4NgJSZ3O62enGZjgKsdhL3vl KJr6ldMWzv8fxtbXbhGHdNPbx230X7NUvpofp4G/EfapKvFk29LsyoLog8DkdjFWws5y jJ7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="KXbKK/AZ"; 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 bg10si560406ejb.233.2021.05.12.11.20.01; Wed, 12 May 2021 11:20:25 -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="KXbKK/AZ"; 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 S1354439AbhELSRv (ORCPT + 99 others); Wed, 12 May 2021 14:17:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:43950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241753AbhELQ17 (ORCPT ); Wed, 12 May 2021 12:27:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 734A661453; Wed, 12 May 2021 15:55:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620834952; bh=mPBr2DQYz5le/EbWWWevrphQpFPvfrb6H/hKl//R41c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KXbKK/AZ5GR0fcrMNpe3epygAUicYMX50753aSHr4FWP6s3IQGdc/Aa8HHVcVXMnl lhiveXr20BUVVGL9/9l8EikXuPHirMvDtWCXrrpw1l6gw8qzelitK4Aoq21gzJeqZ1 7iQdgJtENQZ+lELsqfO3gohD9QumxpHpt4e2qucM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brijesh Singh , Tom Lendacky , Sean Christopherson , Paolo Bonzini Subject: [PATCH 5.12 114/677] KVM: SVM: Use online_vcpus, not created_vcpus, to iterate over vCPUs Date: Wed, 12 May 2021 16:42:40 +0200 Message-Id: <20210512144841.003634107@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144837.204217980@linuxfoundation.org> References: <20210512144837.204217980@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: Sean Christopherson commit c36b16d29f3af5f32fc1b2a3401bf48f71cabee1 upstream. Use the kvm_for_each_vcpu() helper to iterate over vCPUs when encrypting VMSAs for SEV, which effectively switches to use online_vcpus instead of created_vcpus. This fixes a possible null-pointer dereference as created_vcpus does not guarantee a vCPU exists, since it is updated at the very beginning of KVM_CREATE_VCPU. created_vcpus exists to allow the bulk of vCPU creation to run in parallel, while still correctly restricting the max number of max vCPUs. Fixes: ad73109ae7ec ("KVM: SVM: Provide support to launch and run an SEV-ES guest") Cc: stable@vger.kernel.org Cc: Brijesh Singh Cc: Tom Lendacky Signed-off-by: Sean Christopherson Message-Id: <20210331031936.2495277-2-seanjc@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/svm/sev.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -564,6 +564,7 @@ static int sev_launch_update_vmsa(struct { struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; struct sev_data_launch_update_vmsa *vmsa; + struct kvm_vcpu *vcpu; int i, ret; if (!sev_es_guest(kvm)) @@ -573,8 +574,8 @@ static int sev_launch_update_vmsa(struct if (!vmsa) return -ENOMEM; - for (i = 0; i < kvm->created_vcpus; i++) { - struct vcpu_svm *svm = to_svm(kvm->vcpus[i]); + kvm_for_each_vcpu(i, vcpu, kvm) { + struct vcpu_svm *svm = to_svm(vcpu); /* Perform some pre-encryption checks against the VMSA */ ret = sev_es_sync_vmsa(svm);