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=-8.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 DDBDEC433E6 for ; Mon, 8 Feb 2021 19:14:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 918B764E8F for ; Mon, 8 Feb 2021 19:14:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236042AbhBHTOZ (ORCPT ); Mon, 8 Feb 2021 14:14:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22754 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235060AbhBHRzV (ORCPT ); Mon, 8 Feb 2021 12:55:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612806834; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AGNSJcTi1GoljhoR82wLbrQntb542AwjI3pFM5LOGco=; b=Kd3CcHzhFdutNPwU2HFT0btZ9mzVCQOXsny/rjL0DXzBvpY3ozjoGmRMxwtB2Q+PKrjpam UOANdZiY8GEW8Vrg1lULf1EsgA3/RlFo1SqBUfpGe9zUmSTRDXi61dhcin7Xd9VKzfEU/M zdmSVEfkv09HW/CFndGfXFHp7tTyOOk= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-583-Oguu71TKOp6N6UQxxFMdjA-1; Mon, 08 Feb 2021 12:53:53 -0500 X-MC-Unique: Oguu71TKOp6N6UQxxFMdjA-1 Received: by mail-wr1-f72.google.com with SMTP id x12so13678025wrw.21 for ; Mon, 08 Feb 2021 09:53:51 -0800 (PST) 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=AGNSJcTi1GoljhoR82wLbrQntb542AwjI3pFM5LOGco=; b=fwXy+AlCAcAq3fPyW/rSZfPN6rPkogs9dMiaCW2BFwAWAQK5IUtwHjjiS+Ly0AP7Uh qFYZz8e2wqquzvOAJfxhZQa/KwmbvQ4vbYMd5uTxt4MGNgLR8d9Kj/+MSMX2qhzgqeCa dhJVeDtcBYNhA+TS0abTcf08azwJJeUDEQ8FRSoPO3f5jxGeqdEEZFJcMENf650bqMO+ QaVir5TEFfYAWBSw4RTZsZ4N+/h9TjHkhveft54RFXYJgOlvdzN+5UT89TZUditoAEes OLxF6lug/O4DQDqX2Wtbzk7VmBj5ZC88YJ3RYjytJUY4rCtITHi84Q+pERtLCWEX7Ngs Fmvg== X-Gm-Message-State: AOAM531c/sg89ZzXVdlwpgoQIbwf7ax7Vf5EUJDFJ5759Oettt53c0Dc E3wKdweB710A9gbUj3r9RRzgO9meDoX8NsthmHxW4LrS7eG/14rEB4rtKcr0os5mLb7ZFgJumMn xhGqhRl46R+swPDruFEQf0DM2 X-Received: by 2002:a1c:6387:: with SMTP id x129mr15900601wmb.84.1612806830720; Mon, 08 Feb 2021 09:53:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJySadVeryWc/7vUh0Ff5GUx9WW+NmNKRHZ1APFrdW/36WG32BOLRjVIUusY0dEbCCjEaVe5ig== X-Received: by 2002:a1c:9dcd:: with SMTP id g196mr14066748wme.30.1612806338634; Mon, 08 Feb 2021 09:45:38 -0800 (PST) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id d16sm29664733wrr.59.2021.02.08.09.45.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 08 Feb 2021 09:45:36 -0800 (PST) To: Sean Christopherson Cc: Jing Liu , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, jing2.liu@intel.com References: <20210207154256.52850-1-jing2.liu@linux.intel.com> <20210207154256.52850-4-jing2.liu@linux.intel.com> From: Paolo Bonzini Subject: Re: [PATCH RFC 3/7] kvm: x86: XSAVE state and XFD MSRs context switch Message-ID: <77b27707-721a-5c6a-c00d-e1768da55c64@redhat.com> Date: Mon, 8 Feb 2021 18:45:35 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.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 08/02/21 18:31, Sean Christopherson wrote: > On Mon, Feb 08, 2021, Paolo Bonzini wrote: >> On 07/02/21 16:42, Jing Liu wrote: >>> In KVM, "guest_fpu" serves for any guest task working on this vcpu >>> during vmexit and vmenter. We provide a pre-allocated guest_fpu space >>> and entire "guest_fpu.state_mask" to avoid each dynamic features >>> detection on each vcpu task. Meanwhile, to ensure correctly >>> xsaves/xrstors guest state, set IA32_XFD as zero during vmexit and >>> vmenter. >> >> Most guests will not need the whole xstate feature set. So perhaps you >> could set XFD to the host value | the guest value, trap #NM if the host XFD >> is zero, and possibly reflect the exception to the guest's XFD and XFD_ERR. >> >> In addition, loading the guest XFD MSRs should use the MSR autoload feature >> (add_atomic_switch_msr). > > Why do you say that? I would strongly prefer to use the load lists only if they > are absolutely necessary. I don't think that's the case here, as I can't > imagine accessing FPU state in NMI context is allowed, at least not without a > big pile of save/restore code. I was thinking more of the added vmentry/vmexit overhead due to xfd_guest_enter xfd_guest_exit. That said, the case where we saw MSR autoload as faster involved EFER, and we decided that it was due to TLB flushes (commit f6577a5fa15d, "x86, kvm, vmx: Always use LOAD_IA32_EFER if available", 2014-11-12). Do you know if RDMSR/WRMSR is always slower than MSR autoload? Paolo