Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp626614img; Fri, 22 Mar 2019 05:26:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqyV4BJmvBSYfGtFduXOu4h/gIv6VBzr6Ypynsl5NZjt0ijj8FQOX07RY1yV5Hoij0O2jBZz X-Received: by 2002:a65:4bce:: with SMTP id p14mr8820703pgr.68.1553257571668; Fri, 22 Mar 2019 05:26:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553257571; cv=none; d=google.com; s=arc-20160816; b=cSC45aB0vmmvTyLAArc9F0Q3sAfpjAJ4yfnoCqI3JESjBvCRNNJiowFfsHRzfacplT 9civMYCbWS+bJz5mlxoOZ42/3EO/wndOlqF/ptm7r0hPgGe2Rdje9NwMpO918yn6Xs+M ZKIhF7AXiOaPvdm4QVLVYkx8RcO+Cmwoy7hrcbepyynGV+xQiScMch0tb7kMb7TZFrLI rG0NgPjRBBZu24wZq+RAcUxOPfo+AntYP4Gu8+PYiX1Zh5MtH3NBjWg+7Mj85rDne+/S ps0yssonDNpBpEl/Av1Iuodtm6ZpUp0vJaPaJ7FRESsM1ZxoTD4KdqP2krs60KVYzVdd 5/zQ== 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=sYBomPzixVqupp3Mt8xviv0nAxxdRzQuY5+jro1etgk=; b=Ax3kMIzEOwk2QzK0MdyfD/obTaoKzanGd24wDwQl1r+1CUiF8jpuStZ65tIAqApANe z18FEYMIwOkdJs6ALyh58SfEu9NVH7bK+hEaa2IYdK2sRFF+42wPNYsSdhtV7oXZbVR1 ZRiA9nIktKVqQ7IUovMN7jRbrT4jC+7UuLdUGEnYdlRp4JQwhJCnr5UBAigeeeVoiJUy aAk0M/WbV2PqpqHkkCJJDpz3sxF84T7ARTOP241HEg6H4rHtoZtkfsTwvjAcB/lqu2ag ORD3NxySzSwflJOnFJUXGqCHI8cevZ4FoLjXoLB2I/fHojeZNw8j3+pa2pBId1/Zh8wv XFXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FnzqCSBZ; 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 l6si6470576pgq.305.2019.03.22.05.25.56; Fri, 22 Mar 2019 05:26:11 -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=FnzqCSBZ; 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 S2391239AbfCVMYM (ORCPT + 99 others); Fri, 22 Mar 2019 08:24:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:35908 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391230AbfCVMYK (ORCPT ); Fri, 22 Mar 2019 08:24:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 0B0A82054F; Fri, 22 Mar 2019 12:24:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553257449; bh=JnBa0KFoos04YoxuAQnpbarscZQ1xAWCQXwKnH/UkDU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FnzqCSBZrkjZF9oTTIv4cZ8eHnHoIaTwE6LfP34CqyGH3wQ9dYqHpq++EmxVoORD8 h3bxvu+vHqxE/oDJSYsti2yrq8G+QoJbAU5hdZnr7BubM/GrkO3Qmss+Z0m+jMxgyz WP5SjLGHmfRrPLGRdDqysU6upbRXsKTALmMG0LZo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Paolo Bonzini Subject: [PATCH 5.0 228/238] KVM: x86/mmu: Do not cache MMIO accesses while memslots are in flux Date: Fri, 22 Mar 2019 12:17:27 +0100 Message-Id: <20190322111311.812740218@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111258.383569278@linuxfoundation.org> References: <20190322111258.383569278@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sean Christopherson commit ddfd1730fd829743e41213e32ccc8b4aa6dc8325 upstream. When installing new memslots, KVM sets bit 0 of the generation number to indicate that an update is in-progress. Until the update is complete, there are no guarantees as to whether a vCPU will see the old or the new memslots. Explicity prevent caching MMIO accesses so as to avoid using an access cached from the old memslots after the new memslots have been installed. Note that it is unclear whether or not disabling caching during the update window is strictly necessary as there is no definitive documentation as to what ordering guarantees KVM provides with respect to updating memslots. That being said, the MMIO spte code does not allow reusing sptes created while an update is in-progress, and the associated documentation explicitly states: We do not want to use an MMIO sptes created with an odd generation number, ... If KVM is unlucky and creates an MMIO spte while the low bit is 1, the next access to the spte will always be a cache miss. At the very least, disabling the per-vCPU MMIO cache during updates will make its behavior consistent with the MMIO spte behavior and documentation. Fixes: 56f17dd3fbc4 ("kvm: x86: fix stale mmio cache bug") Cc: Signed-off-by: Sean Christopherson Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/x86.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -181,6 +181,11 @@ static inline bool emul_is_noncanonical_ static inline void vcpu_cache_mmio_info(struct kvm_vcpu *vcpu, gva_t gva, gfn_t gfn, unsigned access) { + u64 gen = kvm_memslots(vcpu->kvm)->generation; + + if (unlikely(gen & 1)) + return; + /* * If this is a shadow nested page table, the "GVA" is * actually a nGPA. @@ -188,7 +193,7 @@ static inline void vcpu_cache_mmio_info( vcpu->arch.mmio_gva = mmu_is_nested(vcpu) ? 0 : gva & PAGE_MASK; vcpu->arch.access = access; vcpu->arch.mmio_gfn = gfn; - vcpu->arch.mmio_gen = kvm_memslots(vcpu->kvm)->generation; + vcpu->arch.mmio_gen = gen; } static inline bool vcpu_match_mmio_gen(struct kvm_vcpu *vcpu)