Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3850535imu; Mon, 7 Jan 2019 10:35:30 -0800 (PST) X-Google-Smtp-Source: ALg8bN5xw9qCqjJ16/bd0kHFWYU8VXGvwm2wxW1+ioDuz8XdYKQKA+U/i7jQq5v98NNP+8i390LY X-Received: by 2002:a63:2263:: with SMTP id t35mr11799103pgm.69.1546886130215; Mon, 07 Jan 2019 10:35:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546886130; cv=none; d=google.com; s=arc-20160816; b=FxIY8OM8oeD2a1VV5TzJ5rat7wc5gYOGEjxVEM/rVsjFJ72A2PLf0vLcLG9z8i3QIM 3eReqFH++kSHUhGLPTmQNhmshnEHu3eji5syLlQNilcQzN2NEK7nkBRvMx3qk27Xh0Ny O8asFyILxsXoehoF+bKULAi2+v3ecQQHReuIG9ilrauEsUyqbsfr6WguN5FwRMef3euB D2GSzPaF60ZS4xJiqUW4oiuBYuqWN2bWUGZNSR0EXzPW0tNkLVlkrx8ORoz0X3bwzXKs fHjvzMNA0HfsxrHEo+RuflSBtVXGTcK4tT6f88K91+rumlRROgB282BmmmPjWJy5vlf4 ycyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=9g+6HwMP9gvVHgdkijBM5/BFjJjMxfixoLwKD9Du1bM=; b=ltjLeHr2MD5AP/LibEJ8WLuazZTisePbyw/2U+jqRUw47Qo/VxtV3xAzr0NYO0DusX 56GsItJODpSf4fKwM8KxTAjzCjOAgJsFWpv94ZccL3PI2VHAhIHsnmD8u8SaYwHeTlD8 /gYEXhHn1qZaCQr56Rm9nJqZ/tjQLW0En30mwj4M07bDmoRyejpHVOC/iNKvXuPGG1wy AcBhFlJlpHqNzVTiwEKwI20vPmPUtq3Uj0RDLDbWbRwNvAFHM8DYlWWXRdFFowzOJ41B 1ZhSN2k9r1Vyp7z10VT0JnqQPscfF/HibDdi8Ca2ArCXO6fi9ztB1oYxWs921w2Jzv9V G1Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HA4bDr3G; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 37si4949629pgs.447.2019.01.07.10.35.14; Mon, 07 Jan 2019 10:35:30 -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=@google.com header.s=20161025 header.b=HA4bDr3G; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727938AbfAGSFk (ORCPT + 99 others); Mon, 7 Jan 2019 13:05:40 -0500 Received: from mail-it1-f195.google.com ([209.85.166.195]:52570 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726643AbfAGSFk (ORCPT ); Mon, 7 Jan 2019 13:05:40 -0500 Received: by mail-it1-f195.google.com with SMTP id g76so2465175itg.2 for ; Mon, 07 Jan 2019 10:05:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=9g+6HwMP9gvVHgdkijBM5/BFjJjMxfixoLwKD9Du1bM=; b=HA4bDr3GnI8phJrHJeuR53fiDT9oCkR0fHg7SxuIC0qbgqbYOfgvedbGx0iMysCuPk yIAykapwJWRtU92yEb/w5kf0CzTeh6Qnha5eeZ/9mkEPXJ4KCTW9j6KuZgZWNiEPNh9d NWnQB6JlE/ewsR91/tkGpYHVZzmVstjdIYV6GYXoQQ5iuX/KJi4E1PgLsQZ6hhgtEkUY 9PyEfPsmxVmQBHrtIPtdOo29c48pLDIMFlF3wB92tL5zRXXwtpBtvvDzdsZo9Mvw0d6L dNL4ghmF0IqufmyR6rJqD4hG2830oXSwgQTslXXLNJp3xgKSRUslyyTQF7+lMEFrFpmY KUMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=9g+6HwMP9gvVHgdkijBM5/BFjJjMxfixoLwKD9Du1bM=; b=J7ucBFRKwhCb2tjug7PbybxgTzpf22/Upk6I+PlLCzG6Pbn6sh0z4Kr2jd3yJyKX/o e3PMeO0C7xCqDb9i8rWJ6/LjJ6xDr1eBTa5U9wMhWK8qzvIlnA7PhCrPCBn9d7drmH+n LE/LtX9CT25udPB6AaTysv7jkzZIp1fFcbRqFDgB/lFfOJ0H5L1R/uZVHFp+6OAXLLvZ xN3GYQD+t9oUjJtFthNeeOJbBJojHCOb3SB88Zmrk4bw3mq+jQOWoQC7bTmLmarzJ82e iqPjBDefLV31JxvtAKLDEOL356MXuoTXyaRZtXbhuED8Z/h8uR1xO2LxDIimf9B1+yZ1 R6JQ== X-Gm-Message-State: AJcUukeJs89Licm32pcVBm335RXSFZFPUTM6Ah8p4jUNf1LDUCZv/j+A h5uMsCpt+DqmyH5nEWsMznGOzWHOnMbGpRxIQEuBBg== X-Received: by 2002:a24:4a95:: with SMTP id k143mr7697660itb.77.1546884338477; Mon, 07 Jan 2019 10:05:38 -0800 (PST) MIME-Version: 1.0 References: <1545816338-1171-1-git-send-email-wei.w.wang@intel.com> <1545816338-1171-6-git-send-email-wei.w.wang@intel.com> <5C2DC132.9050103@intel.com> <5C3318A1.9090009@intel.com> In-Reply-To: <5C3318A1.9090009@intel.com> From: Jim Mattson Date: Mon, 7 Jan 2019 10:05:27 -0800 Message-ID: Subject: Re: [PATCH v4 05/10] KVM/x86: expose MSR_IA32_PERF_CAPABILITIES to the guest To: Wei Wang Cc: LKML , kvm list , Paolo Bonzini , Andi Kleen , Peter Zijlstra , Kan Liang , Ingo Molnar , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , like.xu@intel.com, Jann Horn , arei.gonglei@huawei.com 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 On Mon, Jan 7, 2019 at 1:09 AM Wei Wang wrote: > > On 01/03/2019 11:25 PM, Jim Mattson wrote: > > On Wed, Jan 2, 2019 at 11:55 PM Wei Wang wrote: > > > >> Right, thanks. Probably better to change it to below: > >> > >> msr_info->data = 0; > >> data = native_read_msr(MSR_IA32_PERF_CAPABILITIES); > >> if (vcpu->kvm->arch.lbr_in_guest) > >> msr_info->data |= (data & X86_PERF_CAP_MASK_LBR_FMT); > >> > > This still breaks backwards compatibility. Returning 0 and raising #GP > > are not the same. > > I'm not sure about raising GP# in this case. > > This PERF_CAP msr contains more things than the lbr format. > For example, a guest with lbr=false option could read it to get PEBS_FMT, > which is PERF_CAP[11:8]. We should offer those bits in this case. > > When lbr=false, the lbr feature is not usable by the guest, > so I think whatever value (0 or other value) of the LBR_FMT bits that > we give to the guest might not be important. The issue is compatibility. Prior to your change, reading this MSR from a VM would raise #GP. After your change, it won't. That means that if you have a VM migrating between hosts with kernel versions before and after this change, the results will be inconsistent. In the forward migration path, RDMSR will first raise #GP, and later will return 0. In the backward migration path, RDMSR will first return 0, and later it will raise #GP. To avoid these inconsistencies, the new MSR behavior should be explicitly enabled by an opt-in ioctl from userspace (not necessarily the same ioctl that enables LBR).