Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3405323pxb; Wed, 13 Oct 2021 05:28:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkctxe1GYj3urs6ydEQCmGoS9KgqaqdjavPYtpSoimA6bnw0mmtEedHZdpna146aXHAlB2 X-Received: by 2002:a17:90a:1f05:: with SMTP id u5mr13170539pja.193.1634128127302; Wed, 13 Oct 2021 05:28:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634128127; cv=none; d=google.com; s=arc-20160816; b=qiO5R2Go3vK824CsEFk8YBIr6uyyZ/uURKwfQnQ+sWmzrHh89/0Lcaf9/wmJYtg6gH kCCixy+kNOwU7lfQMoElffMQQh6EkqpBp3vjq0NEb1vDFTvSIXi7JYrjsw/0k0hHjNyc gyf2EYkI7L2S9CGGBZXxigK1uSu0gz3OIwnbjD4En6JsHQ9BFNH5V0+zvsh2jUOFeWwl CUiazgRLK0nKgtjuQhrfsxIlafjwCUmJu6wgpAE65QalrlMQCYGPDrxpTZ0225rRrDmk kVIIqmepuAu6uLPVAeF24sJePKrTpiUrzMZVxGTyxc6SoSYKqGU+stGYFl6WlZw60NHu Nq5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=2Dqo/N7vzZrZZut/dmL8suAY/OFRSZSIXFt0zXfL1xY=; b=tDV2qsU58LtMUwKMPV+Bva3SBCce+oG1Q9NldTXj/eNs7jMPpMNZQFlENNXrHuvATh yUf19ezRT5PjwbIMe7MNFyZpINoPVAtpyg9BVgzkwpwQYWhU3/w/pXnfP+hYxKWkSlFW 7jAs2o9NhFmfude5AfRBrfsBMIg38VIDzAsQa275WLl/qCf14aKjyypUGVjDl1sK1xP4 P7UDX848pJjhMZ/wsaa+2N2BoEfV/6qN9oD3SvEFuf1eieedwvB/zbkmvqp2BcWfo+/8 rd/SHM988nXD3iX+w6ID4kRtFI+KB1ZMunRJVD2n16OmW0qYQ1P7FhEqhgLK8UIxOusT rOSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KV+txcrz; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q9si26481997plh.151.2021.10.13.05.28.35; Wed, 13 Oct 2021 05:28:47 -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=@redhat.com header.s=mimecast20190719 header.b=KV+txcrz; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232445AbhJMM2a (ORCPT + 99 others); Wed, 13 Oct 2021 08:28:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22980 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229535AbhJMM23 (ORCPT ); Wed, 13 Oct 2021 08:28:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634127985; 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=2Dqo/N7vzZrZZut/dmL8suAY/OFRSZSIXFt0zXfL1xY=; b=KV+txcrzdVb2ij6aUO59Texkdwv1RTnKXpo1vWEZcSV4nzie3inWsI2b+gqn/a+AHcTyBb weBKxLlsVwUGFE4ZjkoOmd/WpR8byb3gq7DdUuseNL5y8vOIGBHhD2CSFOL4nHmloW/bBv eH4o3R+HDcbZjeo2C5WTI370hGVk6a8= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-489-RO9uSLSbPguHl95aWPi8cA-1; Wed, 13 Oct 2021 08:26:24 -0400 X-MC-Unique: RO9uSLSbPguHl95aWPi8cA-1 Received: by mail-ed1-f72.google.com with SMTP id d3-20020a056402516300b003db863a248eso2038715ede.16 for ; Wed, 13 Oct 2021 05:26:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=2Dqo/N7vzZrZZut/dmL8suAY/OFRSZSIXFt0zXfL1xY=; b=eivHcVGSsoH/xBJFzzSyTD7UCsK2QznZdZS19X1pI+jN/P5UbANs0idzpcz/iQb4qs wtRsDi1n8n38Qno5HAEl4rXaaPQBDRIvFQPHbreMgvG7+VsLwbzRh8nw8cJPCRv/xRFI jCdIMW/mrO8RKHgmJa9jU0tJwjkygWcJUL4AoiWTHxIl+Xl38GNOc70PqPWT6huc1/1o 1MlPzI3ggSCy95fvma/t0h1oD2x/BIHpfuFUhrfHuRO+pf+/+37Y9DBRTo6np5UmUd3Z 0Efw9tdDrOwAP6TIQ2jlDxyb1fKrdvUzSkfCsj5BJjsCwgzhCwjqQQwzKip6khKeAcKI TLCg== X-Gm-Message-State: AOAM532zGERa1kI45mlds+MssSyiCW2EVTuMUSlbqjXD1Yk6Reuiq0w4 O77WI0l/CZ2SFTN94C3hIgvQd7212UZK15uDrHUCyltm9OpitLo7x4aHPlvbAbqzOMy1ygOcvJI wpyExZ+pmPTFS5j6ERuT5NwxB X-Received: by 2002:a17:906:c7c1:: with SMTP id dc1mr41624360ejb.6.1634127983444; Wed, 13 Oct 2021 05:26:23 -0700 (PDT) X-Received: by 2002:a17:906:c7c1:: with SMTP id dc1mr41624338ejb.6.1634127983236; Wed, 13 Oct 2021 05:26:23 -0700 (PDT) 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 z8sm6683870ejd.94.2021.10.13.05.26.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Oct 2021 05:26:21 -0700 (PDT) Message-ID: Date: Wed, 13 Oct 2021 14:26:20 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: [patch 13/31] x86/fpu: Move KVMs FPU swapping to FPU core Content-Language: en-US To: Andy Lutomirski , "Liu, Jing2" , Thomas Gleixner , Linux Kernel Mailing List Cc: the arch/x86 maintainers , "Bae, Chang Seok" , Dave Hansen , Arjan van de Ven , kvm list , "Nakajima, Jun" , Jing Liu , Sean Christopherson References: <20211011215813.558681373@linutronix.de> <20211011223611.069324121@linutronix.de> <8a5762ab-18d5-56f8-78a6-c722a2f387c5@redhat.com> <0962c143-2ff9-f157-d258-d16659818e80@redhat.com> From: Paolo Bonzini In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13/10/21 12:14, Andy Lutomirski wrote: >> I think it's simpler to always wait for #NM, it will only happen >> once per vCPU. In other words, even if the guest clears XFD before >> it generates #NM, the guest_fpu's XFD remains nonzero and an #NM >> vmexit is possible. After #NM the guest_fpu's XFD is zero; then >> passthrough can happen and the #NM vmexit trap can be disabled. > > This will stop being at all optimal when Intel inevitably adds > another feature that uses XFD. In the potentially infinite window in > which the guest manages XFD and #NM on behalf of its userspace and > when the guest allocates the other hypothetical feature, all the #NMs > will have to be trapped by KVM. The reason is that it's quite common to simply let the guest see all CPUID bits that KVM knows about. But it's not unlikely that most guests will not ever use any XFD feature, and therefore will not ever see an #NM. I wouldn't have any problem with allocating _all_ of the dynamic state space on the first #NM. Thinking more about it, #NM only has to be trapped if XCR0 enables a dynamic feature. In other words, the guest value of XFD can be limited to (host_XFD|guest_XFD) & guest_XCR0. This avoids that KVM unnecessarily traps for old guests that use CR0.TS. Paolo > Is it really worthwhile for KVM to use XFD at all instead of > preallocating the state and being done with it? KVM would still have > to avoid data loss if the guest sets XFD with non-init state, but #NM > could always pass through. >