Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp806236pxb; Wed, 16 Feb 2022 05:00:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJzX6ZsfqvfTFtrOOZ6ZrQ76e/Ydbfxs5Pn4GZ24xz2IApPMh6EyjNaL0NOUMTI1jkqsF4Sd X-Received: by 2002:a17:903:40c1:b0:14d:ce7d:afc0 with SMTP id t1-20020a17090340c100b0014dce7dafc0mr2487360pld.40.1645016428446; Wed, 16 Feb 2022 05:00:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645016428; cv=none; d=google.com; s=arc-20160816; b=t/o25XfUu1b2KtAn0Gg/JsZbtpWpM3pwu2R/331vE+pPEy+p+WL7CAElb1Spisk4pV 0P7gefsyFtaCRZ00Cc4i6sxpitGgEu6MBA90umabP2k6/19CsHGWpO4Ma2lrqHYzdbbf YRwyYeM2693XZlwZ1rza8mTU7LNeHY4GYQMdxd8fM8MBgpx6cojquBqqx0Lo9nACWgjk TbCk9GN/H23Uoxd0nnhC36i4Wipml3V8an9RkGtUsWySzw04wLFxYnWSyIsyq8dnzv+2 3089pD/ieB4f4DaqUZn+GCU57iZ0SjFqevDh1Q7+mo5XDsH/7I00TgcDrzx1o9gRjN6P W5nw== 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=WP90pIk7jEBwCs42OYImo884m3Sc20R1f26ph5uJrT8=; b=fPBMQfldAJbymhnkCmSvg0tnosPvHivaj/1WZQ6JwT5ehlhYlFD6zjLOcCz/0F+kN5 sXTW47x7SunGqv0bdJBz0eT35g7v90qIVdm2m/SjkUV8XopIuuFAZoWEvOaHA3+bGEVY 2HO7YWKAHi69zBTvTugzK0J57eGnCszySTN8NP32aEuWJ2HaLdYt+KFEtx+CaBjA1u6o NX7n07f8K9b1TfTK/oy1CZhdKscPVS2ppekttoGDmuytM8/37mDXIzR1Dy0W6HuXzX4Y 7tTL0lf3RYkekdXjUfBlUFRBZKUphR+rA3bjU37yefZGhJKv727IIa8J2pqtTBInFixm G9Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="JN67/N93"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d9si18063469plr.130.2022.02.16.05.00.12; Wed, 16 Feb 2022 05:00:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="JN67/N93"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232160AbiBPLqA (ORCPT + 99 others); Wed, 16 Feb 2022 06:46:00 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:37780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232176AbiBPLp7 (ORCPT ); Wed, 16 Feb 2022 06:45:59 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 31FA5BBE15 for ; Wed, 16 Feb 2022 03:45:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645011946; 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=WP90pIk7jEBwCs42OYImo884m3Sc20R1f26ph5uJrT8=; b=JN67/N93b5tx/pBdpDZnU5JXONcgaENMKl/1nus0i6kr8CBGUpneSqchktvCIvy/frzRVK jPxNkP6EmGpGNsveT+IboK70BVPr6kujT5VJWB4XxXmgfmg4ghzAswum4TVWEQxr9gzMGQ uKfXORmX5eGtEsDARBb0CEM8ZMU04xk= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-173-0n8uunhDNJetlFEtI5iz8w-1; Wed, 16 Feb 2022 06:45:45 -0500 X-MC-Unique: 0n8uunhDNJetlFEtI5iz8w-1 Received: by mail-ed1-f70.google.com with SMTP id e10-20020a056402190a00b00410f20467abso1379363edz.14 for ; Wed, 16 Feb 2022 03:45:44 -0800 (PST) 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=WP90pIk7jEBwCs42OYImo884m3Sc20R1f26ph5uJrT8=; b=ytRMLNLyy/ewxvyQ/dPmFO9ecHd5kdxk6oxqYRLjh851ktMZfWiTe0vn1LbSxNR/qN kdpFcDb8EiUwjVvrnApP2DM9u0XlfOG5P36tmMbL1WXebiXCvnPvEjiF4ZgxCGsSSm0/ UBl7+fWliRlwstp5fw3FUHiOYHvoqjATzjYGy3qgaLAAUjSChbJZCg2fgkj/YLG3zkcH ztozu+gEe9ilBQyfRvssqP1eijYK9s01nF6R5yueZf6eEJDO/79QwknyOzYft88cdDu2 LNGAAhjIR2YosBbxEuS9Ktk4L4Kg3H4bV+gBy9Po2Gpb7WCvCKRvRQO5k54sbuV1nLGC cvfQ== X-Gm-Message-State: AOAM530LnGmWFrbzWeYxeLZq/v2wLN4NFGVmfJRadg8lM+ze5V4qSQjD GAt1iQ5vK1Jf/Tpk5w184zOgdWZ0lINNetu5LgTzUqxog1kuZhNnjFTBrTYGLxPMJtnLhE6ke65 8YJAzQySYkb1IfrGX4ptm2Pu+ X-Received: by 2002:aa7:d8d8:0:b0:3f5:9041:2450 with SMTP id k24-20020aa7d8d8000000b003f590412450mr2610140eds.322.1645011943875; Wed, 16 Feb 2022 03:45:43 -0800 (PST) X-Received: by 2002:aa7:d8d8:0:b0:3f5:9041:2450 with SMTP id k24-20020aa7d8d8000000b003f590412450mr2610107eds.322.1645011943624; Wed, 16 Feb 2022 03:45:43 -0800 (PST) Received: from ?IPV6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.googlemail.com with ESMTPSA id s1sm1467429edt.49.2022.02.16.03.45.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Feb 2022 03:45:42 -0800 (PST) Message-ID: <9b1d925c-1e6a-8a06-ada5-941adb5b349f@redhat.com> Date: Wed, 16 Feb 2022 12:45:41 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH v3 1/1] x86/kvm/fpu: Mask guest fpstate->xfeatures with guest_supported_xcr0 Content-Language: en-US To: Leonardo Bras Soares Passos Cc: David Edmondson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , "Chang S. Bae" , Yang Zhong , Andy Lutomirski , linux-kernel@vger.kernel.org, kvm@vger.kernel.org References: <20220211060742.34083-1-leobras@redhat.com> <5fd84e2f-8ebc-9a4c-64bf-8d6a2c146629@redhat.com> <6bee793c-f7fc-2ede-0405-7a5d7968b175@redhat.com> From: Paolo Bonzini In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/16/22 08:48, Leonardo Bras Soares Passos wrote: > On Mon, Feb 14, 2022 at 6:56 AM Paolo Bonzini wrote: >> On top of this patch, we can even replace vcpu->arch.guest_supported_xcr0 >> with vcpu->arch.guest_fpu.fpstate->user_xfeatures. Probably with local >> variables or wrapper functions though, so as to keep the code readable. > > You mean another patch (#2) removing guest_supported_xcr0 field from > kvm_vcpu_arch ? > (and introducing something like kvm_guest_supported_xcr() ?) Yes, introducing both kvm_guest_supported_xcr0() that just reads user_xfeatures, and kvm_guest_supported_xfd() as below. >> For example: >> >> static inline u64 kvm_guest_supported_xfd() >> { >> u64 guest_supported_xcr0 = vcpu->arch.guest_fpu.fpstate->user_xfeatures; >> >> return guest_supported_xcr0 & XFEATURE_MASK_USER_DYNAMIC; >> } > > Not sure If I get the above. > Are you suggesting also removing fpstate->xfd and use a wrapper instead? > Or is the above just an example? > (s/xfd/xcr0/ & s/XFEATURE_MASK_USER_DYNAMIC/XFEATURE_MASK_USER_SUPPORTED/ ) The above is an example of how even "indirect" uses as guest_supported_xcr0 can be changed to a function. >> Also, already in this patch fpstate_realloc should do >> >> newfps->user_xfeatures = curfps->user_xfeatures | xfeatures; >> >> only if !guest_fpu. In other words, the user_xfeatures of the guest FPU >> should be controlled exclusively by KVM_SET_CPUID2. > > Just to check, you suggest adding this on patch #2 ? > (I am failing to see how would that impact on #1) In patch 1. Since KVM_SET_CPUID2 now changes newfps->user_xfeatures, it should be the only place where it's changed, and arch_prctl() should not change it anymore. Paolo