Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4351661pxb; Tue, 5 Oct 2021 00:52:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQ7ubOnknQJhJnSurb7qov4OTft/ukheaOEbqaNuEMhDjfvR5b9UNxk7/d55j+FrZQr3vK X-Received: by 2002:a50:e009:: with SMTP id e9mr23939606edl.254.1633420363157; Tue, 05 Oct 2021 00:52:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633420363; cv=none; d=google.com; s=arc-20160816; b=bwfDUlR/XFunazI8G6xZj3E1X1DBsmxmN+774np8bytzJO78wL+N2Th7z0F44w5oHh lHBgmWR2SLKIiOdKVwYzvfZITQqs1S1ORM9TGcTm8BtRa0O2eGoPpxFfbFmg/jiE+0sH fWmM0bMKd1guE5D9GKHarDTwICxV2sdOvUsFF2zc2HsvIHjiBZg/vKIkq2qKYVSUBxMs Jve0UT7Csgjck6fEaKd9RtbRa9SM7oVyAqYrZeg5QkW0Y0Ai/+cxcrkvC3paNntfkN03 SdZHmK7u5wTDh+z1l2oECxq6tYgMQ4B9P+z7seYap6WVLabd++AD8B3jlLcD9f7LhcqI /2TQ== 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=n6yrW50I8Ib+vVPSj2LLrvKy9ZTsmrO7LXIDVvpPep0=; b=iWstvm+eX9usKL3ceM97U3TqS9/2maFM41XhajVH9TmNPjPxx1KFhCbX/NfvFeegdw trbl+TCWbvVOkZcihjOqaWFR/bco5OYcEfgqgg1sOh4E+QqXSoPJ/OQRmgpx3yYH89lr x0lT2kMu0+6Za+7fMayogrM0YonGdeot8DInzkKSuGScZGI1cHTEbGXNoYkD/1jMxBPy 6qGsBrIvwzkUCgbIxu5FajEvZjY0MjLbTxzKkVmwxDY1VwW2ggFH/gi+ybyLPOtDxgNv pUZV6graD0ULiIFCjhUcC7IGP1KMrI1phCdCx2mN8dAqNcYRKRZC5XI5vUjlAgK39oeR 5KkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BVippRmC; 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 q19si24563883edv.394.2021.10.05.00.52.17; Tue, 05 Oct 2021 00:52:43 -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=BVippRmC; 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 S232108AbhJEHwf (ORCPT + 99 others); Tue, 5 Oct 2021 03:52:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24797 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232871AbhJEHwa (ORCPT ); Tue, 5 Oct 2021 03:52:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633420240; 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=n6yrW50I8Ib+vVPSj2LLrvKy9ZTsmrO7LXIDVvpPep0=; b=BVippRmCzYoOS9HCrYQTaTEsSoE14fCY9SDrVCiJMBBdATzCpu7mz4kugZFPMOvlMEb1cH vJkdo3yMsrdoyOHTl3kVD0NCAFM6lHuQTI2RBqiS/x7UWuift6WiYZ8eTMKERFf/d1CcqV Y5/OItjJbuyFaMZNO8kFtk+sH0Rcez0= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-525-xuqjbifHOgS67EsJcT0kjA-1; Tue, 05 Oct 2021 03:50:39 -0400 X-MC-Unique: xuqjbifHOgS67EsJcT0kjA-1 Received: by mail-lf1-f69.google.com with SMTP id z29-20020a195e5d000000b003fd437f0e07so845766lfi.20 for ; Tue, 05 Oct 2021 00:50:39 -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=n6yrW50I8Ib+vVPSj2LLrvKy9ZTsmrO7LXIDVvpPep0=; b=50OJGFO+NDhzkjqdjk+5BQlt98qoVBBUlBrnetDAdY2tPI2SaEVAMYlVlJfd1WFCmz PhxsFF55P9p0Kzp7vhEZmV55T+EFT28IWcymnn9iwDgueEHKhcCtKzlZg6tvl/3Pclc6 6fLkahxApsWSUxt4+1MsdPMxI3caWCix9h5EYDF0map9+6TpOZiLbcdufpAEmAQ/hX/m VviCR4MlCKYYwC3GlPl5cXV3+IuZqME4/N2yK8hVBXEuSXOnUfn8cGjl+t/AwAKGXA7x mDTYl19JljLcvUAMSwNgMVqbkLtwytNe6J450K7zc2uLDOE4G16NZObHpi1wfEs+bS5/ QBsg== X-Gm-Message-State: AOAM531qcC4YY8RFTHriiaFXBkqKRaN1vfIaUPnDCmwhkX8PwknbkqT8 ZJDgycb+6up4fju6E8wfFf6iLqHCeBg48sr6NXTfQSAUCNFI4Wvn32tkd3d1bB0mJoR6QWCS9O0 ggtBCh4cjMGuzZ3TpXbP/kmoD X-Received: by 2002:a05:651c:211a:: with SMTP id a26mr20833091ljq.148.1633420237647; Tue, 05 Oct 2021 00:50:37 -0700 (PDT) X-Received: by 2002:a17:907:62a2:: with SMTP id nd34mr1617731ejc.356.1633420226861; Tue, 05 Oct 2021 00:50:26 -0700 (PDT) Received: from [192.168.10.118] ([93.56.162.200]) by smtp.gmail.com with ESMTPSA id b2sm8399684edv.73.2021.10.05.00.50.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Oct 2021 00:50:26 -0700 (PDT) Message-ID: Date: Tue, 5 Oct 2021 09:50:24 +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 v10 10/28] x86/fpu/xstate: Update the XSTATE save function to support dynamic states Content-Language: en-US To: Thomas Gleixner , "Chang S. Bae" , bp@suse.de, luto@kernel.org, mingo@kernel.org, x86@kernel.org Cc: len.brown@intel.com, lenb@kernel.org, dave.hansen@intel.com, thiago.macieira@intel.com, jing2.liu@intel.com, ravi.v.shankar@intel.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org References: <87pmsnglkr.ffs@tglx> From: Paolo Bonzini In-Reply-To: <87pmsnglkr.ffs@tglx> 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 02/10/21 23:31, Thomas Gleixner wrote: > You have two options: > > 1) Always allocate the large buffer size which is required to > accomodate all possible features. > > Trivial, but waste of memory. > > 2) Make the allocation dynamic which seems to be trivial to do in > kvm_load_guest_fpu() at least for vcpu->user_fpu. > > The vcpu->guest_fpu handling can probably be postponed to the > point where AMX is actually exposed to guests, but it's probably > not the worst idea to think about the implications now. > > Paolo, any opinions? Unless we're missing something, dynamic allocation should not be hard to do for both guest_fpu and user_fpu; either near the call sites of kvm_save_current_fpu, or in the function itself. Basically adding something like struct kvm_fpu { struct fpu *state; unsigned size; } user_fpu, guest_fpu; to struct kvm_vcpu. Since the size can vary, it can be done simply with kzalloc instead of the x86_fpu_cache that KVM has now. The only small complication is that kvm_save_current_fpu is called within fpregs_lock; the allocation has to be outside so that you can use GFP_KERNEL even on RT kernels. If the code looks better with fpregs_lock moved within kvm_save_current_fpu, go ahead and do it like that. Paolo