From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0DB1C43603 for ; Thu, 19 Dec 2019 18:37:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A53DE24685 for ; Thu, 19 Dec 2019 18:37:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576780664; bh=61R/NdHf82RLsqLQhBJmvUPZm4nSs/T2wCwYyyd8fuU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=hh3naaZUgARPL5D4fXFegAHTepT7dEeTd2UIdkzl8ctWw6Hoig2BVHx0c+oSNBjex Hr6JL4LGwyyfSvpbhEWfGbPaVOEnmz0oxWCPiXandgu4WC+3j2WLBQFB7EsSM5DPXE VZm//kNZkh0InLEzHxTmXNh6nhO8dnpxNfewPO3o= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727858AbfLSShm (ORCPT ); Thu, 19 Dec 2019 13:37:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:55462 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727535AbfLSShm (ORCPT ); Thu, 19 Dec 2019 13:37:42 -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 2CD61222C2; Thu, 19 Dec 2019 18:37:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576780661; bh=61R/NdHf82RLsqLQhBJmvUPZm4nSs/T2wCwYyyd8fuU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jrXElFJJBFl4tDtUoXKqhSaMUhYwQ2T3Z6dKLM/m7JyJM4ohYPUXRubg4qey4oCrO GnZ56PhwOfLe8GC3oaiGH/Tycsir6nooOw73A24K9cBMtvGui/itLMfeh9CuH2KB/S tQd7IYTAJwdi0O1G+k7eVb7yDxxCPaZ/dGYhD3Q0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jim Mattson , Paolo Bonzini Subject: [PATCH 4.4 064/162] KVM: x86: do not modify masked bits of shared MSRs Date: Thu, 19 Dec 2019 19:32:52 +0100 Message-Id: <20191219183211.746261732@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183150.477687052@linuxfoundation.org> References: <20191219183150.477687052@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 @@ -260,13 +260,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);