Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp780490ybe; Fri, 13 Sep 2019 06:17:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqxd3WOBzfenBW2fhJsjSVkNa2bbCAVWqRrNyRTjgyWk4iFvBa3mrLNouZMVrTwbglee34i3 X-Received: by 2002:a50:eb4c:: with SMTP id z12mr48167683edp.155.1568380645350; Fri, 13 Sep 2019 06:17:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568380645; cv=none; d=google.com; s=arc-20160816; b=BnCOVaA0ZRnPi51EmHWDpLfWHwiDZMIturodW2pnAmukOLxqaoPus6RBDh5ZkPCTGV 3zRLSO7855J8P1JvOiX6ZnQPl7Q/kxOSL4uSRSFdKei9Dx4r8HPEePPkyYfZuZ5H/62G zlsILbDKPfOXJf6gfu5hKGOKx+wBFruLeUWeLQvpe9T3UTqs1lhta49CkRR/7peXwSZa 8Fs7TqyhauP4ttwvYM7TwUQGsUf83XdopqLxi2TcHHs+C+rKVL5OeJwVqzx0JfCYRW3T UGV4s8LJNQgrW8YYf75FxBjj68YGNXMsDTXnQD/nk9sAScFyQkRwPHrHwJ1e/SXuG9rW oVPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UQyfc4b2HHhT5oCQN957MgmH9gdSJpZp+BrKBZR7GMY=; b=ZSPwNO9sWJpgBVgX4hlGF/fYXqOIGtz+Sk9XbQWhMjKN6LKG48e+d/3w7i0Uk2DjwN 7SHPCO14o/frNVasX9MP6TbUknpO/qwKracEfelkUtaiYOZlXdDwbGWf3lvcsQMvGck3 2k/WCqPlTUplSmT+gGJhZ+yPG8E/U0+xPOdtDgz6sP5wgVX6bih/6+dnUbQTBPL1zUy2 U9Edj30sN9B8Yr5ZrxGulrp2WDItSppCayjqUIdIb6+1gBuyN6O57GBYrKYFxxgA8665 jU2Auh/XdivJlA4WvL8GVm+f1gBAyaRYd7v0Rw67cxah8BhFNbcDl6x1pfSpWxK4VsA7 ZYwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jQmuBU1I; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g5si1496404ejp.350.2019.09.13.06.17.01; Fri, 13 Sep 2019 06:17:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jQmuBU1I; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389472AbfIMNOM (ORCPT + 99 others); Fri, 13 Sep 2019 09:14:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:39986 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388885AbfIMNOH (ORCPT ); Fri, 13 Sep 2019 09:14:07 -0400 Received: from localhost (unknown [104.132.45.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7AFCD20CC7; Fri, 13 Sep 2019 13:14:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568380447; bh=mUBQxfQ32UvOlvNiMiNAHQHwA17r2wn3WVj5j3Oj+fg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jQmuBU1IUoNUbVyyiWfR3LnFs6lwZT2+L0PQNiHXkSIfHzJPKy1UGIYFFDLuFSyoK 3C1dSZWPbfmYEoaYKoVpJf1QTlwBQI1kvf7JOnv1ivytQnkKda9Xm3bngVmRb5Qwnv 4N2ok4TupEgzJR8TMZ/MVfNBHi4TRmq5mY8h9veY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vitaly Kuznetsov , Paolo Bonzini , Sasha Levin Subject: [PATCH 4.19 044/190] x86/kvm/lapic: preserve gfn_to_hva_cache len on cache reinit Date: Fri, 13 Sep 2019 14:04:59 +0100 Message-Id: <20190913130603.285535110@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913130559.669563815@linuxfoundation.org> References: <20190913130559.669563815@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit a7c42bb6da6b1b54b2e7bd567636d72d87b10a79 ] vcpu->arch.pv_eoi is accessible through both HV_X64_MSR_VP_ASSIST_PAGE and MSR_KVM_PV_EOI_EN so on migration userspace may try to restore them in any order. Values match, however, kvm_lapic_enable_pv_eoi() uses different length: for Hyper-V case it's the whole struct hv_vp_assist_page, for KVM native case it is 8. In case we restore KVM-native MSR last cache will be reinitialized with len=8 so trying to access VP assist page beyond 8 bytes with kvm_read_guest_cached() will fail. Check if we re-initializing cache for the same address and preserve length in case it was greater. Signed-off-by: Vitaly Kuznetsov Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/lapic.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 5427fd0aa97e1..262e49301cae6 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -2636,14 +2636,22 @@ int kvm_hv_vapic_msr_read(struct kvm_vcpu *vcpu, u32 reg, u64 *data) int kvm_lapic_enable_pv_eoi(struct kvm_vcpu *vcpu, u64 data, unsigned long len) { u64 addr = data & ~KVM_MSR_ENABLED; + struct gfn_to_hva_cache *ghc = &vcpu->arch.pv_eoi.data; + unsigned long new_len; + if (!IS_ALIGNED(addr, 4)) return 1; vcpu->arch.pv_eoi.msr_val = data; if (!pv_eoi_enabled(vcpu)) return 0; - return kvm_gfn_to_hva_cache_init(vcpu->kvm, &vcpu->arch.pv_eoi.data, - addr, len); + + if (addr == ghc->gpa && len <= ghc->len) + new_len = ghc->len; + else + new_len = len; + + return kvm_gfn_to_hva_cache_init(vcpu->kvm, ghc, addr, new_len); } void kvm_apic_accept_events(struct kvm_vcpu *vcpu) -- 2.20.1