Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5609pxj; Mon, 17 May 2021 19:19:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBRy2ahP+LErc3p2robzG9FI+ELOOqF9k0deZk4M0Tn2O7/NmdL4eIVNi7D+KLLikjhjtw X-Received: by 2002:a05:6e02:4a4:: with SMTP id e4mr2257357ils.179.1621304360558; Mon, 17 May 2021 19:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621304360; cv=none; d=google.com; s=arc-20160816; b=JVfpD8YkmI8amwXKnYkZ5on1y8YWeWYf/Yw5txLGQHM2JEgAHfhx2oHS6Cw/1YFhQf OwJQ2herXOiz0ZFgpTT+UL+92h51dns/0FSNZMz0vwFjE6TTVy/c+C1zDwx83morDITY 9gKvtYy07o0j9cQLSGEXlSsD6gR/fmT3vgrqmzmBK/3SEIDxDh0TBZYM+tKPM1uPx3h2 NyM4esOAcrwLzNOLjyAHmENK77ySgrlHXqDRoz0QeCEZUP+dMTUAgSfNmynzlqOyZIND yO91W3D+fT8smJXlImiKm2q0K+8Kw8mhKBGZJZn0swceshh57g3EoM1jPlVT0fyWDQEg UJeQ== 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=QWpmDWagYt08Hhx1IJAQt5l7bsXS8luOg+jjqqdUrAU=; b=y5jlWHb6nMckug7YWAiEvAejQja5gA11oXD3lnK68OhUosGVV/y490XZXjrmQbWf6/ IXdWeGsKOi2AzGkW6rWTP5NWXLY8OfdFkEoOXuqPOr50B1vE/KmtrsJaZ17emeKHgxg8 TlUYd2hQ3+2VVG+PZw7CqqlwKBiGd/0xHtn4ins5Jdd/eqIL7xPOrbVitVfFsrc4clsB OacOvZ7MwQVgfx1sF1UbEB6slNhSUNySKcECOuYki0Z4JKCkoCWSlHqIFECbibr/ietE US8IHjdksV/+YLt108DoeBPwMfyn4d9OvJLtKHlrZYyWfJSKF4cHpve9/mq9dJNFMCPp 9hBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KKf6Y5LJ; 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 k7si15208200iok.65.2021.05.17.19.19.07; Mon, 17 May 2021 19:19:20 -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=KKf6Y5LJ; 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 S240321AbhEQOhi (ORCPT + 99 others); Mon, 17 May 2021 10:37:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:43400 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240277AbhEQOdo (ORCPT ); Mon, 17 May 2021 10:33:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 064AF613DB; Mon, 17 May 2021 14:16:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260983; bh=19YmnsizSpk4vLMejuMPFuHXHYYERN4tMKKZofyBhic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KKf6Y5LJGqGDCe9p+ayvCn8rBHGqZ3Ij7/HPA1VowAxOSHV8IaGvElmGhXR1hlw/H UUagNChz2mzvhTUBq9GJuUb7bWIvbu1jUnCxxUxbhj5GglRInKGdqzVV6nFVnnfW33 uUoxPQp1226Yd9WcRvR+DTEQx+ZZGKZdBVdR0jnk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Borislav Petkov , Tom Lendacky , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.12 279/363] KVM: SVM: Move GHCB unmapping to fix RCU warning Date: Mon, 17 May 2021 16:02:25 +0200 Message-Id: <20210517140312.045000371@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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 [ Upstream commit ce7ea0cfdc2e9ff31d12da31c3226deddb9644f5 ] When an SEV-ES guest is running, the GHCB is unmapped as part of the vCPU run support. However, kvm_vcpu_unmap() triggers an RCU dereference warning with CONFIG_PROVE_LOCKING=y because the SRCU lock is released before invoking the vCPU run support. Move the GHCB unmapping into the prepare_guest_switch callback, which is invoked while still holding the SRCU lock, eliminating the RCU dereference warning. Fixes: 291bd20d5d88 ("KVM: SVM: Add initial support for a VMGEXIT VMEXIT") Reported-by: Borislav Petkov Signed-off-by: Tom Lendacky Message-Id: Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/svm/sev.c | 5 +---- arch/x86/kvm/svm/svm.c | 3 +++ arch/x86/kvm/svm/svm.h | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index ba56f677cc09..dbc6214d69de 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1668,7 +1668,7 @@ static int sev_es_validate_vmgexit(struct vcpu_svm *svm) return -EINVAL; } -static void pre_sev_es_run(struct vcpu_svm *svm) +void sev_es_unmap_ghcb(struct vcpu_svm *svm) { if (!svm->ghcb) return; @@ -1704,9 +1704,6 @@ void pre_sev_run(struct vcpu_svm *svm, int cpu) struct svm_cpu_data *sd = per_cpu(svm_data, cpu); int asid = sev_get_asid(svm->vcpu.kvm); - /* Perform any SEV-ES pre-run actions */ - pre_sev_es_run(svm); - /* Assign the asid allocated with this SEV guest */ svm->asid = asid; diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 276d3c728628..5364458cf60b 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1416,6 +1416,9 @@ static void svm_prepare_guest_switch(struct kvm_vcpu *vcpu) struct svm_cpu_data *sd = per_cpu(svm_data, vcpu->cpu); unsigned int i; + if (sev_es_guest(vcpu->kvm)) + sev_es_unmap_ghcb(svm); + if (svm->guest_state_loaded) return; diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 39e071fdab0c..98da0b91f273 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -571,6 +571,7 @@ void sev_es_init_vmcb(struct vcpu_svm *svm); void sev_es_create_vcpu(struct vcpu_svm *svm); void sev_vcpu_deliver_sipi_vector(struct kvm_vcpu *vcpu, u8 vector); void sev_es_prepare_guest_switch(struct vcpu_svm *svm, unsigned int cpu); +void sev_es_unmap_ghcb(struct vcpu_svm *svm); /* vmenter.S */ -- 2.30.2