Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1690747ybz; Thu, 16 Apr 2020 13:46:39 -0700 (PDT) X-Google-Smtp-Source: APiQypKpSTdKSxIqCJDpMyoZTXXzVkF6MGBhz9t3mh3f+jWKv/wSIDhFIgKETT0IenImS3U9TQLo X-Received: by 2002:aa7:c40c:: with SMTP id j12mr44788edq.169.1587069999126; Thu, 16 Apr 2020 13:46:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587069999; cv=none; d=google.com; s=arc-20160816; b=YV1J2sawSwdyalI1eS8lRS/gTB8Oy6vzm8De5AmtjqzQ88g3/0y6/xOl2NhFWLfOTQ wij+YEzfmhgX/zmi1UUYDhD5oq4rq44+G7mUzJ8P3kPLijdiAMO7ZY5OX22ZA8RhzidA iCJwBeCLUemG7+qlqm8ue54hi1Mbr7X+5oCFywnxnpiVfzOw1n57uP+lrBWrRXYmraTQ RjYgp7H8Da6kKlnt27V7jW1EBD8xCwPSbS8IFdK4loymqZ3CHlnk6H+bAfXi7AK6sg44 CiGJd5t4VoQPnyNrPv+U1N2QMKZfZxn5jnfM8utuRgmL4qtf7ItAjXxHD0AvK2Eu2F0q V56w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=mC/qr0j7HUgGt77fxIftKjS5qqz0qPQen02hUmh1Dh8=; b=wfjoJfBtkq5Z8oW80sIfmKBOjhtly8o3Ronrk6aaiW0qloTQfEyHxUtxj2h8cdc8Lz M+GZEchZIwcnvzd6Go7UuTOyt9TUuMUaaM+ETXpTf8iTte+QZLMIhODkklJWI0FM38zQ dNPmQXkOrnyFBG9FLixfRvtWlqsM2oX1p0N41VazbTFlWboR74JOAVLnHK/Mx6Tdg3Bl YmLQjcT5Jjubs841CCzPLevXm7JBeTKQKbHp2G2ckEtXuwzN1QI6l8MI5zVw86BC6A3U 7Y4Gqkamb7h4l0RgRoX3Kxi+UVPLy9feHrwxFglVXZCF75DYNV4rz7vx3ktazKmDykjE E3rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=CFPLLGPX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oq22si12667320ejb.213.2020.04.16.13.46.16; Thu, 16 Apr 2020 13:46:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=CFPLLGPX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730049AbgDPSnR (ORCPT + 99 others); Thu, 16 Apr 2020 14:43:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728815AbgDPSnQ (ORCPT ); Thu, 16 Apr 2020 14:43:16 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D216AC061A0F for ; Thu, 16 Apr 2020 11:43:16 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id w7so3536021ply.0 for ; Thu, 16 Apr 2020 11:43:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=mC/qr0j7HUgGt77fxIftKjS5qqz0qPQen02hUmh1Dh8=; b=CFPLLGPX4ctg78piDhgn3JbQBZ4NUQ5XOGuQiN/7vBRQR685triRRUALfmerg6W9xb j17+dKXQTA3N2V71skyu4zTFuVB/4OZSOXSyyskfOa5GZcQt4xpXMOQ5n5GE5MlQPCkQ 1ZT3ut6wPZWf8D1dz63sAtr4+ZZSe1wtluo7mS5hgEVFNheTwFlMBnRW1WwxEpYbZ7ua XDKaJoHGbdm/AHYIKimMrLcSP6KvyLTT43OvDxyfMe60DGjgycAsTONaibnbQmuRB/82 56FsiaOolzNptFQmMpl3CS8QBl6GBmGxjoAOyseLH1OgPbkueAOjEA0utBJPCWW3wD5F nYEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=mC/qr0j7HUgGt77fxIftKjS5qqz0qPQen02hUmh1Dh8=; b=tBCGUtTCctleQ6OGKbMTywY0+UBrRyL2AYmf0l7a3rWMh/gYO6cDrOT82IB/bhAYoD +RLfSQUe3MH0Epdr/vgY5+qqYuRa7qPum26EHlQ/jz76Gptbww7vZLiBSoFJunNFxwhB NXMeNFj8zC2Uh+CO9ZsxFhQotoCXEImmHqvfIYfRVHeyGfgaGcpkGOBJrHc8V8LJEWFg a3sSKrwE018sBnpUWYXbb4g1Yg+gpa6cUBwaKR79mPFXHDfM11nibnPdTo+Q+z2xVfVy eqbKAX0MXtKEgYVFUdP8innmZwUe/Qhq5xuv7SSwYxRtXOHIdSt93IvdY+GpHHKc9IU1 bTDg== X-Gm-Message-State: AGi0PubsWdhxiZfqbMHt/88dOHq44FN8Z93lz1HtCtaC0kfVcatjpOY9 qgE594Td2RSJYh6GwQSzSjZrNAWvY4JK8g== X-Received: by 2002:a17:90a:65c8:: with SMTP id i8mr6679174pjs.156.1587062596155; Thu, 16 Apr 2020 11:43:16 -0700 (PDT) Date: Thu, 16 Apr 2020 11:42:54 -0700 Message-Id: <20200416184254.248374-1-jcargill@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.26.1.301.g55bc3eb7cb9-goog Subject: [PATCH] kvm: Handle reads of SandyBridge RAPL PMU MSRs rather than injecting #GP From: Jon Cargille To: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Venkatesh Srinivas , Jon Cargille Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Venkatesh Srinivas Linux 3.14 unconditionally reads the RAPL PMU MSRs on boot, without handling General Protection Faults on reading those MSRs. Rather than injecting a #GP, which prevents boot, handle the MSRs by returning 0 for their data. Zero was checked to be safe by code review of the RAPL PMU driver and in discussion with the original driver author (eranian@google.com). Signed-off-by: Venkatesh Srinivas Signed-off-by: Jon Cargille Reviewed-by: Jim Mattson --- arch/x86/kvm/x86.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3cc3f673785c8..4f9b7dd687e3c 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3060,6 +3060,17 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) case MSR_IA32_PERF_CTL: case MSR_AMD64_DC_CFG: case MSR_F15H_EX_CFG: + /* + * Intel Sandy Bridge CPUs must support the RAPL (running average power + * limit) MSRs. Just return 0, as we do not want to expose the host + * data here. Do not conditionalize this on CPUID, as KVM does not do + * so for existing CPU-specific MSRs. + */ + case MSR_RAPL_POWER_UNIT: + case MSR_PP0_ENERGY_STATUS: /* Power plane 0 (core) */ + case MSR_PP1_ENERGY_STATUS: /* Power plane 1 (graphics uncore) */ + case MSR_PKG_ENERGY_STATUS: /* Total package */ + case MSR_DRAM_ENERGY_STATUS: /* DRAM controller */ msr_info->data = 0; break; case MSR_F15H_PERF_CTL0 ... MSR_F15H_PERF_CTR5: -- 2.26.0.110.g2183baf09c-goog