Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp771840ybl; Wed, 11 Dec 2019 07:17:26 -0800 (PST) X-Google-Smtp-Source: APXvYqyTowO3xXbeJINPFVmXN5awkJ6nvrtrx7abXcFHUlt9z6EvtTvF3fvu/No1+tDcqM9XERgc X-Received: by 2002:a05:6830:1599:: with SMTP id i25mr2597107otr.205.1576077446724; Wed, 11 Dec 2019 07:17:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576077446; cv=none; d=google.com; s=arc-20160816; b=ib/5q9QbqGM08tEWOWNMZbynRSApkue44u8cqtPVoF+7h4bc+HX7XNf5Smv4Ndb97E NKerY2wLcbiiKOo9h3dY0WxcwrDqar1ypBGIADyiDyDj/At3vdhjFFWaQFVBHahIOU3o a/xl3j6LuqOcCamTYzg+cITTZA0KoTdE7Z3uUXki9T8YOaapBmXvcT/IlzAClWOio2eP xQgrwgrse5cOhHruOf21F0nJLaERxytw1AHY0LajvoD6VzioKWni77IMr/CCqBv7SFFM NmmeqtQEouTXfCVo0JUonlAOeI5rWAIDbtTw5X//1/dMgTMeZ2L8DhZOz6D0RdChrbwQ Z68A== 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=xIAgL1erk39L7lWfEnx8a6Oqx3dkw99JfoEdK+PNXsI=; b=Q6JxF0mVAQaoWZZusd/RR0EyPjmnzHb7p/9wZov9sPvTD+y71qyEheGANvFU3NDo50 20OpavEfapzL7KKRfWq/Ka+yN4cVrbGzq2wVoiWaRzYu0TFT+cFIRu2icb57Mv1lbCM4 UlW5rwBD0BVtHP8evCAIqqnRsYvoQUXI0R8L4Nzp+tySDMfSjzXrBvAZxKc14ySZ/B14 aVMBbBxDe3aCLLGDGT8Jt/cEG0AYDJvjds0xhvAMiyS83gKl+p1tVsoaNfkGAUzkjDr8 SDVPiO61MGBkAnSwJ2zLUfjvi3S+dsULz6shqDaKW7HviwCineb+BF7F77daNBQqOdVW hh6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gDuzAVKz; 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 q25si1409951otg.128.2019.12.11.07.17.14; Wed, 11 Dec 2019 07:17:26 -0800 (PST) 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=gDuzAVKz; 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 S1731797AbfLKPP2 (ORCPT + 99 others); Wed, 11 Dec 2019 10:15:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:40080 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731638AbfLKPOe (ORCPT ); Wed, 11 Dec 2019 10:14:34 -0500 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 84F9B24658; Wed, 11 Dec 2019 15:14:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077274; bh=Gw4aZjR8Io/XIQ78BX+sc+7ll0U9rP0IAVhxmX2jV3g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gDuzAVKzdBX4DpuBgkZl6jfRXvk5ygB/nwtUEpywj8vq1QgtoLN3zZ7zHmvmihKhg gfePPM5n9FthcpTLdBIJe2Xcp/1kHzJjF7eI5fPmYDSQFyB/kbtxRUNpjR3gKf0mWZ nXoki8h9W+3fTgV9gUrrGG72NfPP2vTVvgCHMnVk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jim Mattson , Paolo Bonzini Subject: [PATCH 5.3 081/105] KVM: x86: do not modify masked bits of shared MSRs Date: Wed, 11 Dec 2019 16:06:10 +0100 Message-Id: <20191211150258.164355315@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@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 From: Paolo Bonzini commit de1fca5d6e0105c9d33924e1247e2f386efc3ece upstream. "Shared MSRs" are guest MSRs that are written to the host MSRs but keep their value until the next return to userspace. They support a mask, so that some bits keep the host value, but this mask is only used to skip an unnecessary MSR write and the value written to the MSR is always the guest MSR. Fix this and, while at it, do not update smsr->values[slot].curr if for whatever reason the wrmsr fails. This should only happen due to reserved bits, so the value written to smsr->values[slot].curr will not match when the user-return notifier and the host value will always be restored. However, it is untidy and in rare cases this can actually avoid spurious WRMSRs on return to userspace. Cc: stable@vger.kernel.org Reviewed-by: Jim Mattson Tested-by: Jim Mattson Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/x86.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -300,13 +300,14 @@ int kvm_set_shared_msr(unsigned slot, u6 struct kvm_shared_msrs *smsr = per_cpu_ptr(shared_msrs, cpu); int err; - if (((value ^ smsr->values[slot].curr) & mask) == 0) + value = (value & mask) | (smsr->values[slot].host & ~mask); + if (value == smsr->values[slot].curr) return 0; - smsr->values[slot].curr = value; err = wrmsrl_safe(shared_msrs_global.msrs[slot], value); if (err) return 1; + smsr->values[slot].curr = value; if (!smsr->registered) { smsr->urn.on_user_return = kvm_on_user_return; user_return_notifier_register(&smsr->urn);