Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp399533pxv; Wed, 14 Jul 2021 06:38:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlxfYyyczqMJIt4usjKM81IoQuWdlF3lQY+QTmzH7MwSblBfQsvZAqvB+ZvBLuU8d+wglM X-Received: by 2002:aa7:c89a:: with SMTP id p26mr13557546eds.373.1626269884898; Wed, 14 Jul 2021 06:38:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626269884; cv=none; d=google.com; s=arc-20160816; b=sRGS+p1kZGULMnpFZ/SqFLlaPZDnajrPYdULM/17JT5Ld5PD2I6R6A8VOqZXwHZfLR HCBgQPw/L0iB7mFQDGpluhZDv0d7NDrwD61X+EviMm57GpgmuDMNE9lrxD7f50UaPSus 4eikptFDuhHeQBic2Y+cOHEtRSKdQgI0OGINxzTzClHB35uLgSYepL9vmD7QUKii85QE aDJl9Vm6Z7fxmxhigMiZD7Z7ES5k+rJr0Bx0cO9VRehZfibWKjW3gr9xNJ9+VIdDC6NH ytODZeYe2I2enABHSNvsN+rTe2TtDnjWOi/Ax0fi+bUlp3/u1OtLAhUw9XFuGkn7yweP KuWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:cc:to:dkim-signature; bh=zXeJ5upciacjDJ+R0O8tajIDexHBhtbchVhzFOMwTgk=; b=OZnfsIc0xMd0hvLMUa92YMcd7mdp/SRPzf+pMYOJmd0qRuvKpxtetLtvyVxj43to3+ CRps6GdDr2n2dHcaiYifocJYDZbuGL3I1jZ+bKYoZxZusHNWPN59xdrnWvzdWX7B/6tz d8/IVj3R/plT8Vbfd+5eVuIfC6kDdma0efDWTKDEmxs2LjWV8d1mDw+j2tvVCi47Gt2M jxwTnaiJPx4IQ8glgmGVQsRUcli60UNMM6eKh3V+1BoVVda8mk1GiWn3Y+w4ETaSUhND p3fEabU5sc0ueyjHhvyfj4vLtJn0lKeH6BGCVO2j3WgKCBK3Zygu3W8hBMkPTuwrS0yL 2tpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VBBHOC5r; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qa32si2716502ejc.359.2021.07.14.06.37.39; Wed, 14 Jul 2021 06:38:04 -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=@gmail.com header.s=20161025 header.b=VBBHOC5r; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232058AbhGNNgr (ORCPT + 99 others); Wed, 14 Jul 2021 09:36:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231485AbhGNNgq (ORCPT ); Wed, 14 Jul 2021 09:36:46 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CFA0C06175F; Wed, 14 Jul 2021 06:33:54 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id u14so2399764pga.11; Wed, 14 Jul 2021 06:33:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:cc:references:from:subject:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=zXeJ5upciacjDJ+R0O8tajIDexHBhtbchVhzFOMwTgk=; b=VBBHOC5rZLUn9BjaxpBV2az1ka/YY2mtcfGvyhJkoWBW4C6p08XBCwkPGMaLOrQd8U 2q8ao+bF3Gr6NVqQZA3UCC/9mO3P8y6MIsGux0lDxbIPYWQF/xIuL/CdrhTrBdqQL5fE joZsunPXTNt7nws1LOfgVvgkoJlKYhzSSlPUtDZGUl9OAC8XHydtEtk9EOn4ycrFmzFX cuSqod6mHioeTh6zfKHZ0afNXiZChdCVJuwbSFLX+KmMRFnhgntvzgfKHtWqsRyYKAcX YwxY13BrVRrMhMv24CKR9ZuFzbaGDADvwKIn5dFYuDNMBH/snOjLubpl0Sblln8SCjJP i5EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=zXeJ5upciacjDJ+R0O8tajIDexHBhtbchVhzFOMwTgk=; b=PScIR/Ibbg4YQ7umEVrMv4JVARXeQKluvjW7eK+lJIisVF/BUvQJ0c22NWFtHXwbKK dyMssIs0AZe+94juWJ5FLXfsu6vVXE4kzvpkc/VNM3sTTtNYTRPJb7FC0rXi2av4liig QHar6BXINeIwA5AaB0WZuzJN3TUi3D8tAWXzp+iTMvjxtU2A8rrGbnjnOF+zaxYVxF76 Kj2JROVWLWfjonobzCV2EYxZiq+OO0/nR2aVfjnZDr4L/Q2DuP5f5VAH6pLacZ2BNFay e+EYpt/+bJ8zW4PrWTZhYAcxXoZauzAJKtbMullntU3MUd57yznsaaFYlxoaS5jOoUQI mJ+g== X-Gm-Message-State: AOAM533saLuHMqFgWgRTF1+5JsNnIi4BZlCajwT6CSHex1veUEfSMZ2c XLYOLW2xGIIdLPt77u9j+Ng= X-Received: by 2002:a65:5648:: with SMTP id m8mr9812707pgs.93.1626269633846; Wed, 14 Jul 2021 06:33:53 -0700 (PDT) Received: from Likes-MacBook-Pro.local ([103.7.29.32]) by smtp.gmail.com with ESMTPSA id i8sm2796525pfo.154.2021.07.14.06.33.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Jul 2021 06:33:53 -0700 (PDT) To: Jim Mattson Cc: Yang Weijiang , pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, wei.w.wang@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "kan.liang@linux.intel.com" References: <1625825111-6604-1-git-send-email-weijiang.yang@intel.com> <1625825111-6604-7-git-send-email-weijiang.yang@intel.com> <20210712095305.GE12162@intel.com> <12a3e8e4-3183-9917-c9d5-59ab257b8fd3@gmail.com> From: Like Xu Subject: Re: [PATCH v5 06/13] KVM: x86/vmx: Save/Restore host MSR_ARCH_LBR_CTL state Message-ID: Date: Wed, 14 Jul 2021 21:33:44 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14/7/2021 1:00 am, Jim Mattson wrote: > On Tue, Jul 13, 2021 at 2:49 AM Like Xu wrote: >> >> On 13/7/2021 1:45 am, Jim Mattson wrote: >>> On Mon, Jul 12, 2021 at 10:20 AM Jim Mattson wrote: >>>> >>>> On Mon, Jul 12, 2021 at 3:19 AM Like Xu wrote: >>>>> >>>>> On 12/7/2021 5:53 pm, Yang Weijiang wrote: >>>>>> On Fri, Jul 09, 2021 at 04:41:30PM -0700, Jim Mattson wrote: >>>>>>> On Fri, Jul 9, 2021 at 3:54 PM Jim Mattson wrote: >>>>>>>> >>>>>>>> On Fri, Jul 9, 2021 at 2:51 AM Yang Weijiang wrote: >>>>>>>>> >>>>>>>>> If host is using MSR_ARCH_LBR_CTL then save it before vm-entry >>>>>>>>> and reload it after vm-exit. >>>>>>>> >>>>>>>> I don't see anything being done here "before VM-entry" or "after >>>>>>>> VM-exit." This code seems to be invoked on vcpu_load and vcpu_put. >>>>>>>> >>>>>>>> In any case, I don't see why this one MSR is special. It seems that if >>>>>>>> the host is using the architectural LBR MSRs, then *all* of the host >>>>>>>> architectural LBR MSRs have to be saved on vcpu_load and restored on >>>>>>>> vcpu_put. Shouldn't kvm_load_guest_fpu() and kvm_put_guest_fpu() do >>>>>>>> that via the calls to kvm_save_current_fpu(vcpu->arch.user_fpu) and >>>>>>>> restore_fpregs_from_fpstate(&vcpu->arch.user_fpu->state)? >>>>>>> >>>>>>> It does seem like there is something special about IA32_LBR_DEPTH, though... >>>>>>> >>>>>>> Section 7.3.1 of the IntelĀ® Architecture Instruction Set Extensions >>>>>>> and Future Features Programming Reference >>>>>>> says, "IA32_LBR_DEPTH is saved by XSAVES, but it is not written by >>>>>>> XRSTORS in any circumstance." It seems like that would require some >>>>>>> special handling if the host depth and the guest depth do not match. >>>>>> In our vPMU design, guest depth is alway kept the same as that of host, >>>>>> so this won't be a problem. But I'll double check the code again, thanks! >>>>> >>>>> KVM only exposes the host's depth value to the user space >>>>> so the guest can only use the same depth as the host. >>>> >>>> The allowed depth supplied by KVM_GET_SUPPORTED_CPUID isn't enforced, >>>> though, is it? >> >> Like other hardware dependent features, the functionality will not >> promise to work properly if the guest uses the unsupported CPUID. > > It's fine if it doesn't work in the guest, but can't a guest with the > wrong depth prevent the host LBRs from being reloaded when switching > back to the host state? It's definitely not okay for an ill-configured > guest to break host functionality. If the ownership of LBR changes, there must be two (or more) LBR events for perf event scheduling switch for current task, and the perf subsystem callback will save the previous LBR state and restore the state of the next LBR event considering different depths. > >>> >>> Also, doesn't this end up being a major constraint on future >>> platforms? Every host that this vCPU will ever run on will have to use >>> the same LBR depth as the host on which it was started. >>> >> >> As a first step, we made the guest LBR feature only available for the >> "migratable=off" user space, which is why we intentionally did not add >> MSR_ARCH_LBR_* stuff to msrs_to_save_all[] in earlier versions. > > We have no such concept in our user space. Features that are not > migratable should clearly be identified as such by an appropriate KVM > API. At present, I don't believe there is such an API. I couldn't agree with you more on this point. We do have a code gap to make Arch LBR migratable for any KVM user. > >> But hopefully, we may make it at least migratable for Arch LBR. >> >> I'm personally curious about the cost of using XSAVES to swicth >> guest lbr msrs during vmx transaction, and if the cost is unacceptable, >> we may ask the perf host to adjust different depths for threads. >> >> >