From nobody Wed Nov 27 14:28:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1698276604; cv=none; d=zohomail.com; s=zohoarc; b=DLFL/iE5SNx8AHXvHqjFKBb3/bUPRjRA6YC5qn/6p7jl7OWfOAdPk7vHruZk84S/qbGZWdmZL6eNnVPRlCcccX9mAFTRstZ2LBjMnDba+YDqc+ZYWSQLhdoMm35AWObtiE48quSrN6Kb68HQdwBRtm0XUlTqmsJRFw7S+8ogapA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698276604; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=GdZ68mbYRCX/mChbYRdJIewnmOXbTjCnA/qf/1jADtk=; b=esugJ9GhcK74G1HPOqP4NWpJ06AjWUczn6SFW9zhNqpRUuiXJ3UA3p/o+S5k8thGikVBcuo3NxqJn/zeS3raT8GZG1L+HzQlSUtQriYEp0jgAxFwYc1P1+76GFuY43Ho7R1kW1KKTIrW6G1Ns6hNT/JSHT/KClQzS5AmLESpxCA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1698276604610190.39917802457478; Wed, 25 Oct 2023 16:30:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvnIA-0001oL-Ou; Wed, 25 Oct 2023 19:28:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvnI8-0001iO-Ta for qemu-devel@nongnu.org; Wed, 25 Oct 2023 19:28:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvnI7-0005Ih-9M for qemu-devel@nongnu.org; Wed, 25 Oct 2023 19:28:00 -0400 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-464-vlC_mJgeNOyz50hIEEwIrw-1; Wed, 25 Oct 2023 19:27:56 -0400 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-66d38d57f49so5169256d6.0 for ; Wed, 25 Oct 2023 16:27:56 -0700 (PDT) Received: from [172.19.0.201] ([192.80.84.35]) by smtp.gmail.com with ESMTPSA id s8-20020ad44388000000b0066d11743b3esm4744823qvr.34.2023.10.25.16.27.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 16:27:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698276478; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GdZ68mbYRCX/mChbYRdJIewnmOXbTjCnA/qf/1jADtk=; b=JLwpLCErs1GRHK0OBPa59pOsLamLYYOF8W1KxTRTfnFDW3WmBrdNvlffmQoF+RFsNIMllh VgvENgVestn+AG2vLsxbCdGy2VFETvp0z2iqzgmiA0VzHXxOjadAW9adpct7ulZNL1jQM4 KhKWCmefAy50emwD3t9BVXDxM/Y+C4s= X-MC-Unique: vlC_mJgeNOyz50hIEEwIrw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698276476; x=1698881276; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GdZ68mbYRCX/mChbYRdJIewnmOXbTjCnA/qf/1jADtk=; b=c9g77qjMef5GGUXnH+hZ6hb2wCKA141w3UJi9Gvr9OjP7xHnUXJbVxD8IYDyXKj7y0 2P1oxtTChbNKv/xE7YRL4rLVzQlj2s+NWh584PIkrwO8GbxlOcL8fWEqeH2+bLLFaFZL YX1SFATLICK28vOFkNtyicaOjGW0fDr16fNO8cSDWoERAQqHHaSFPocJ9xgtHnjkTwnn oXdhcQi9D6ukS60dI+LwbKgL5QexDuu6yaZMr+dZ/UPDcvfpl6koy/sF39Bt+BZJ7gT0 7EYsah9MZ5tThwPpbkB12tO2Z2GsxFj4CWKsmcmtFCKaeCqLPFqjFdbDOINQnzf8p21l JA8g== X-Gm-Message-State: AOJu0YzNc/GmbfK+otYKlv4JzeD0vhNCsOjfRmyRdQNuH90L1LdCC5sZ Nid1VOa/bVVL1hBKUprAnct68D1BwQ67ngqcQhfXCLKMULcfI/7s8aO8NkOBUTWOV1dXZh4X8yd 638HxbMWheph43mKI1ZB+g79hlsAQHx7Q+BLNOHReWL4rKrD0nYGRWUa0V58ZDJdc/6AmyB8h8e k= X-Received: by 2002:a0c:f041:0:b0:66d:9c7e:469a with SMTP id b1-20020a0cf041000000b0066d9c7e469amr13407936qvl.10.1698276475774; Wed, 25 Oct 2023 16:27:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjHqtdsdVgpJxAsunYtPv8w7if0AD0261nKzHr/ToTuLI12DB/jUsb3Lbj7T6tj2v+xCIJ9A== X-Received: by 2002:a0c:f041:0:b0:66d:9c7e:469a with SMTP id b1-20020a0cf041000000b0066d9c7e469amr13407924qvl.10.1698276475392; Wed, 25 Oct 2023 16:27:55 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 19/24] kvm: i386: require KVM_CAP_XSAVE Date: Thu, 26 Oct 2023 01:27:12 +0200 Message-ID: <20231025232718.89428-20-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231025232718.89428-1-pbonzini@redhat.com> References: <20231025232718.89428-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1698276605631100001 Content-Type: text/plain; charset="utf-8" This was introduced in KVM in Linux 2.6.36, and could already be used at the time to save/restore FPU data even on older processor. We can require it unconditionally and stop using KVM_GET/SET_FPU. Signed-off-by: Paolo Bonzini --- target/i386/kvm/kvm.c | 70 ++----------------------------------------- 1 file changed, 2 insertions(+), 68 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index b8fb74d7f17..513a90f6307 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -94,6 +94,7 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = =3D { KVM_CAP_INFO(SIGNAL_MSI), KVM_CAP_INFO(IRQ_ROUTING), KVM_CAP_INFO(DEBUGREGS), + KVM_CAP_INFO(XSAVE), KVM_CAP_LAST_INFO }; =20 @@ -137,7 +138,6 @@ static uint32_t has_architectural_pmu_version; static uint32_t num_architectural_pmu_gp_counters; static uint32_t num_architectural_pmu_fixed_counters; =20 -static int has_xsave; static int has_xsave2; static int has_xcrs; static int has_pit_state2; @@ -1714,10 +1714,8 @@ static void kvm_init_xsave(CPUX86State *env) { if (has_xsave2) { env->xsave_buf_len =3D QEMU_ALIGN_UP(has_xsave2, 4096); - } else if (has_xsave) { - env->xsave_buf_len =3D sizeof(struct kvm_xsave); } else { - return; + env->xsave_buf_len =3D sizeof(struct kvm_xsave); } =20 env->xsave_buf =3D qemu_memalign(4096, env->xsave_buf_len); @@ -2592,7 +2590,6 @@ int kvm_arch_init(MachineState *ms, KVMState *s) return ret; } =20 - has_xsave =3D kvm_check_extension(s, KVM_CAP_XSAVE); has_xcrs =3D kvm_check_extension(s, KVM_CAP_XCRS); has_pit_state2 =3D kvm_check_extension(s, KVM_CAP_PIT_STATE2); has_sregs2 =3D kvm_check_extension(s, KVM_CAP_SREGS2) > 0; @@ -2877,40 +2874,11 @@ static int kvm_getput_regs(X86CPU *cpu, int set) return ret; } =20 -static int kvm_put_fpu(X86CPU *cpu) -{ - CPUX86State *env =3D &cpu->env; - struct kvm_fpu fpu; - int i; - - memset(&fpu, 0, sizeof fpu); - fpu.fsw =3D env->fpus & ~(7 << 11); - fpu.fsw |=3D (env->fpstt & 7) << 11; - fpu.fcw =3D env->fpuc; - fpu.last_opcode =3D env->fpop; - fpu.last_ip =3D env->fpip; - fpu.last_dp =3D env->fpdp; - for (i =3D 0; i < 8; ++i) { - fpu.ftwx |=3D (!env->fptags[i]) << i; - } - memcpy(fpu.fpr, env->fpregs, sizeof env->fpregs); - for (i =3D 0; i < CPU_NB_REGS; i++) { - stq_p(&fpu.xmm[i][0], env->xmm_regs[i].ZMM_Q(0)); - stq_p(&fpu.xmm[i][8], env->xmm_regs[i].ZMM_Q(1)); - } - fpu.mxcsr =3D env->mxcsr; - - return kvm_vcpu_ioctl(CPU(cpu), KVM_SET_FPU, &fpu); -} - static int kvm_put_xsave(X86CPU *cpu) { CPUX86State *env =3D &cpu->env; void *xsave =3D env->xsave_buf; =20 - if (!has_xsave) { - return kvm_put_fpu(cpu); - } x86_cpu_xsave_all_areas(cpu, xsave, env->xsave_buf_len); =20 return kvm_vcpu_ioctl(CPU(cpu), KVM_SET_XSAVE, xsave); @@ -3655,46 +3623,12 @@ static int kvm_put_msrs(X86CPU *cpu, int level) } =20 =20 -static int kvm_get_fpu(X86CPU *cpu) -{ - CPUX86State *env =3D &cpu->env; - struct kvm_fpu fpu; - int i, ret; - - ret =3D kvm_vcpu_ioctl(CPU(cpu), KVM_GET_FPU, &fpu); - if (ret < 0) { - return ret; - } - - env->fpstt =3D (fpu.fsw >> 11) & 7; - env->fpus =3D fpu.fsw; - env->fpuc =3D fpu.fcw; - env->fpop =3D fpu.last_opcode; - env->fpip =3D fpu.last_ip; - env->fpdp =3D fpu.last_dp; - for (i =3D 0; i < 8; ++i) { - env->fptags[i] =3D !((fpu.ftwx >> i) & 1); - } - memcpy(env->fpregs, fpu.fpr, sizeof env->fpregs); - for (i =3D 0; i < CPU_NB_REGS; i++) { - env->xmm_regs[i].ZMM_Q(0) =3D ldq_p(&fpu.xmm[i][0]); - env->xmm_regs[i].ZMM_Q(1) =3D ldq_p(&fpu.xmm[i][8]); - } - env->mxcsr =3D fpu.mxcsr; - - return 0; -} - static int kvm_get_xsave(X86CPU *cpu) { CPUX86State *env =3D &cpu->env; void *xsave =3D env->xsave_buf; int type, ret; =20 - if (!has_xsave) { - return kvm_get_fpu(cpu); - } - type =3D has_xsave2 ? KVM_GET_XSAVE2 : KVM_GET_XSAVE; ret =3D kvm_vcpu_ioctl(CPU(cpu), type, xsave); if (ret < 0) { --=20 2.41.0