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=-4.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 176A5C07E95 for ; Tue, 13 Jul 2021 09:49:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 01F1B61158 for ; Tue, 13 Jul 2021 09:49:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235297AbhGMJwY (ORCPT ); Tue, 13 Jul 2021 05:52:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235231AbhGMJwN (ORCPT ); Tue, 13 Jul 2021 05:52:13 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA45AC0613DD; Tue, 13 Jul 2021 02:49:22 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id o201so14001358pfd.1; Tue, 13 Jul 2021 02:49:22 -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=IWSTYmC+Gac/5Ldupb1nMyka7wi/+11TTLpxgLg5GHM=; b=pt7ylunuAhUhBsF4LTcq9NewSXEZ81QBmP/CZyUDcn4u8txh6flQ+f/T11LwekBIN0 Hbq49Y5irTZ/GD/NRoB/RlOGq8kvUKS+vOzabsDvLnaJh7EZfZLlDdlt3j09ehm9VtKk /L4QboZucO8ACimWE9NISPsIe3jLzSQg3Z2JPlM0xpc9sQspDRsqNPTJUzdCydBnQuMc BHY/KEtygzQ9GLVZ5XVc4POkkjw5xfXgf4oTjTZiZDHwyYxe5xdI94OVIY+vaVdaT49t SNaiFYPX+fgrUwcUosFxYa3QLyfl6gTaVPi5fQ+44tfARmLH1wQklbkGedfquNz8VWcB VXYw== 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=IWSTYmC+Gac/5Ldupb1nMyka7wi/+11TTLpxgLg5GHM=; b=q3YBWX5nyHe2XxLczFosyORec270uH9Kyom7kpdxizMlrk5klWjs09aV9LwJt86q6L Pd28LnnPbxz57pOBOrZZ1sMMi6oefBcsCg38NIqc0Bua6KTpLMOBbdR/kjR2/0hZyP5u m3P+yXq2P39nNHTtB+qwYheZ4/KxDfYUaPr27eKN8icSaYwzy86Wnin1zO7A5eTWq7es iQd6fYiaM9gNpY19WdrP/HBfovUW1q52R++UD2+qkMDT/zgMy9y3rt/u8RJmy0TFBRRK TPxYwmEH/Bhlb848pjX6yBqV8lEhcQnDaFK5vDdBn/gGVrUGRmqxDZafqDi6VoxJmssG E6JA== X-Gm-Message-State: AOAM533fbIix7jty4TdP5LDHn0G7phieIJjWbuI3UZtO0LR8hBUAkmN/ f7Ulsv3PhUOk5uA8GFMMH3I= X-Google-Smtp-Source: ABdhPJztHe9NoZYxGJJbjJfelTtp19bEeBQfBUe49b64bl0QScpBHBU1MvKg4Rq9EZqmgIfazZ6NNw== X-Received: by 2002:aa7:97bd:0:b029:32c:56cc:8fa9 with SMTP id d29-20020aa797bd0000b029032c56cc8fa9mr3810333pfq.65.1626169762386; Tue, 13 Jul 2021 02:49:22 -0700 (PDT) Received: from Likes-MacBook-Pro.local ([103.7.29.32]) by smtp.gmail.com with ESMTPSA id j22sm20334415pgb.62.2021.07.13.02.49.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 13 Jul 2021 02:49:21 -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> From: Like Xu Subject: Re: [PATCH v5 06/13] KVM: x86/vmx: Save/Restore host MSR_ARCH_LBR_CTL state Message-ID: <12a3e8e4-3183-9917-c9d5-59ab257b8fd3@gmail.com> Date: Tue, 13 Jul 2021 17:49:05 +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 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. > > 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. 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.