Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3026473rwb; Mon, 15 Aug 2022 16:24:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR4BVSThYO+M6ZmBbHkqc6yTuNZ3j77NLsdye8uHI+W81JRTleiYDs9PhPagWGhnimbXbDEb X-Received: by 2002:a63:6cc4:0:b0:41a:ff04:661f with SMTP id h187-20020a636cc4000000b0041aff04661fmr15477323pgc.600.1660605874607; Mon, 15 Aug 2022 16:24:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605874; cv=none; d=google.com; s=arc-20160816; b=GuCznDBskcm1RLKhOoNC5d/mMuK4vrwajJO9bk5Z6tFG83rTJJ8Z2N8ZsZDxB29Yx/ bgAY1lz5p56NSBYV2dotRWG7GwSYtqOM3v3SDGBdgGhBJXCKrkS7SqJG4z0pyec4V6d9 Jl77YU+uf5y/RUtjleF7fM9icihjEWVF3BrV5vTjbIQmLGD6on7/pcduRkEyhs3xYr/b S3WKTfBrPVbucyugo/nDbWBCglx/wt3Z1N0xARfxnHoBtMDj6hAsWKoY4OIe1zT2Pbpm UcV6b09j/GtaoX0Kar99d3zSb4qd9VYarTVfEW7SJAKy2n18Qj/UjVrB+uFbidyHGATN HiaQ== 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=CibG6j+8fgalMpQB0uFgBjkPdKTtPZKKKBj1b1KpQGg=; b=jxXpua+FNCPtVIw6PAZlcM31GE3c1GxX8FYiMMglpMxldmWFDeuJzAzIdOkQ8h0zjN yqpkek7q/skmFW61wl4CFWy5xvtbfVIbZpRzUpue+jVWIa8Dds3tsQ1wopkiCTmiV70T dHtjMT5494Ay2AV/5G/AmWgLuZ7EUDbcX/aqfN3KbbSSzyMAZ7bDj/LaPL5weXB9bldE 7w+aP33MfNBetzku018lUIJcXoVPAJP4g9ImfC+cvn5keyU4HEDxR0AOR7K/CnIAlZsJ k9G0z4lSXgoWIwrK2KTBTWYz7cWCVGcADEL+nqU49PZra9cAOz+I/DOiDiCeNX7Atm57 dDfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eQfhVkRh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 9-20020a170902c14900b0016f1aab2253si11051881plj.93.2022.08.15.16.24.23; Mon, 15 Aug 2022 16:24:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eQfhVkRh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1344535AbiHOVzK (ORCPT + 99 others); Mon, 15 Aug 2022 17:55:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350293AbiHOVws (ORCPT ); Mon, 15 Aug 2022 17:52:48 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8447108945; Mon, 15 Aug 2022 12:33:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 18E2BB80EAC; Mon, 15 Aug 2022 19:33:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45FB5C433C1; Mon, 15 Aug 2022 19:33:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660591998; bh=wWCgrPVrYdAMVWPaZH24aEPoNQN+KLCiqhuw3uMJlzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eQfhVkRhzbwCgGZgjuUS4PJ6em0GfiInftONwVttHiWz0VJyv4j2ykfov6S3cmlwj /YPAhsK1+L/LbE7WsBsM0mQ+9R+kmjIARXHMAbS5tNQ/+d/eMumiDzEC8+pa/tW1Jd L1PYyEise/Sjqwk7EC6Xkar53x8kUDbMMytUAo5k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Woodhouse , Paolo Bonzini Subject: [PATCH 5.19 0042/1157] KVM: x86: do not report preemption if the steal time cache is stale Date: Mon, 15 Aug 2022 19:49:58 +0200 Message-Id: <20220815180441.121490727@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paolo Bonzini commit c3c28d24d910a746b02f496d190e0e8c6560224b upstream. Commit 7e2175ebd695 ("KVM: x86: Fix recording of guest steal time / preempted status", 2021-11-11) open coded the previous call to kvm_map_gfn, but in doing so it dropped the comparison between the cached guest physical address and the one in the MSR. This cause an incorrect cache hit if the guest modifies the steal time address while the memslots remain the same. This can happen with kexec, in which case the preempted bit is written at the address used by the old kernel instead of the old one. Cc: David Woodhouse Cc: stable@vger.kernel.org Fixes: 7e2175ebd695 ("KVM: x86: Fix recording of guest steal time / preempted status") Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/x86.c | 2 ++ 1 file changed, 2 insertions(+) --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4635,6 +4635,7 @@ static void kvm_steal_time_set_preempted struct kvm_steal_time __user *st; struct kvm_memslots *slots; static const u8 preempted = KVM_VCPU_PREEMPTED; + gpa_t gpa = vcpu->arch.st.msr_val & KVM_STEAL_VALID_BITS; /* * The vCPU can be marked preempted if and only if the VM-Exit was on @@ -4662,6 +4663,7 @@ static void kvm_steal_time_set_preempted slots = kvm_memslots(vcpu->kvm); if (unlikely(slots->generation != ghc->generation || + gpa != ghc->gpa || kvm_is_error_hva(ghc->hva) || !ghc->memslot)) return;