From nobody Wed Jul 9 23:34:53 2025 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1677492884; cv=none; d=zohomail.com; s=zohoarc; b=jkAqTeaDiUmUNYsxBkhKUg/vaRWi+isZrMoeJEhN+01+r4SdH7eC1i/Uwa5ObSzYMygV4uQJEtlejDniEje97DKrw6uo6ek/2IsqBml3FHvEsdbOC8GX7Cba374D0YQQVtpsWqjQH8+9zwJKeWObRZFZSEcW0wNdssukkhCWsXQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677492884; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9/9ZO/RR+v2UnWUWmj7R34j/p8x5ynjq0gGM6XKdYvU=; b=MtcHMpdWfh9dMwn5+ZpfTjOJiCKPOs43e75hC6mljkVy16zD4mFA5ql62DdL5eT1Bzm0t1pN0AcZ4euycD0y9h/qp75HkXSJagX9GD6wDFrRU7m06Fa4JR+xSUl55TwyGUm6s64CIDbPinPeGtO6lB2M8N7whg2VtabqqGFi7Ds= 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+importer2=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 1677492884532711.4185493467136; Mon, 27 Feb 2023 02:14:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pWaW4-0005Cy-Ng; Mon, 27 Feb 2023 05:13:58 -0500 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 1pWaW1-0005Cd-8m for qemu-devel@nongnu.org; Mon, 27 Feb 2023 05:13:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pWaVz-00011i-Q8 for qemu-devel@nongnu.org; Mon, 27 Feb 2023 05:13:53 -0500 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.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-561-lP6KgyowNMKuBAqb8-XWjw-1; Mon, 27 Feb 2023 05:13:47 -0500 Received: by mail-ed1-f70.google.com with SMTP id r6-20020aa7c146000000b004acd97105ffso7789568edp.19 for ; Mon, 27 Feb 2023 02:13:47 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id r3-20020a50aac3000000b004acc6cbc451sm2941573edc.36.2023.02.27.02.13.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:13:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677492831; 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=9/9ZO/RR+v2UnWUWmj7R34j/p8x5ynjq0gGM6XKdYvU=; b=eBlWCmaMyMOZdMUcFOMa7tfODUuisoVKYnQUcIuRZ4O7H7oyhY0AhDcliaSrS7acOikxyi 0qVZ7DBbLYGncgTesfGJpaCOOWARNu8UH4nOxn+UJtRlczkwZKx7tgsSPhDOwTaCc5kUK7 P14T6gv7QcAtlYIAJlWYrRsi33+dvRg= X-MC-Unique: lP6KgyowNMKuBAqb8-XWjw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9/9ZO/RR+v2UnWUWmj7R34j/p8x5ynjq0gGM6XKdYvU=; b=qohSEU8UllXeimq390nSAoGuNMUpasw5OoDleYSCqJZ8tRQ7dHJaA3ykCc3m0Gblh1 iOZSVTpVGsAohdkCO3eIoO0H0XvGGyrWqNkwfmGmPsC6iGF+yyYdscM780qfQkDySARO ZOcbI29LLQP8MQTMX1e0nvryaJMMzkeKVadEG4j+le3KK8SKleG10Kt/qREFFDHvikTI oyI3o+jHHgkgaFTaNp/c/NV9TNfJR37UT8AOe1UEQiF8k5cP9vAOweaY+n/KwVxtk4gr HATgZcC9n8T2iN686zyJI5UfkjnxA5OQjjzzc5F5QG2st/LkaYKF2LLr3ppBWZJKJIX1 w15Q== X-Gm-Message-State: AO0yUKWBhgb/55mJVJiiWhfm3zwnYSmZ4/KpYg56E5+yOEGR4LH1PBfg Z9ua1dxFRnN/R7EM/4sIr+PYhFGmeN4HQXRquMHOzmmkRoc4UqDdP43/EKnfQIZtQxon01wkhfH GAYQJhPsoIJx21cFacHmB2jxgMGQbUhmKCPG3mS0u0BMNLx1zJTF9E++vV7ehMBS73cNAGcIr X-Received: by 2002:a05:6402:401:b0:4ab:4011:ff3d with SMTP id q1-20020a056402040100b004ab4011ff3dmr23866308edv.0.1677492825839; Mon, 27 Feb 2023 02:13:45 -0800 (PST) X-Google-Smtp-Source: AK7set99uuIgTlt6hf8aJS68QGkThyOU4YUxquU/mBrPfgViONehj3Ug7qyLefYdl7bdKB0qDB8yBg== X-Received: by 2002:a05:6402:401:b0:4ab:4011:ff3d with SMTP id q1-20020a056402040100b004ab4011ff3dmr23866287edv.0.1677492825573; Mon, 27 Feb 2023 02:13:45 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: lei4.wang@intel.com, robert.hu@linux.intel.com, xiaoyao.li@intel.com, chenyi.qiang@intel.com Subject: [PATCH v4 3/4] target/i386: KVM: allow fast string operations if host supports them Date: Mon, 27 Feb 2023 11:13:30 +0100 Message-Id: <20230227101332.636203-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230227101332.636203-1-pbonzini@redhat.com> References: <20230227101332.636203-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.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_H2=-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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677492884927100001 Content-Type: text/plain; charset="utf-8" These are just a flag that documents the performance characteristic of an instruction; it needs no hypervisor support. So include them even if KVM does not show them. In particular, FZRM/FSRS/FSRC have only been added very recently, but they are available on Sapphire Rapids processors. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson Reviewed-by: Xiaoyao Li --- target/i386/kvm/kvm.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 587030199192..fe66a4953d41 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -352,7 +352,7 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint= 32_t function, { struct kvm_cpuid2 *cpuid; uint32_t ret =3D 0; - uint32_t cpuid_1_edx; + uint32_t cpuid_1_edx, unused; uint64_t bitmask; =20 cpuid =3D get_supported_cpuid(s); @@ -399,10 +399,20 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, ui= nt32_t function, } else if (function =3D=3D 6 && reg =3D=3D R_EAX) { ret |=3D CPUID_6_EAX_ARAT; /* safe to allow because of emulated AP= IC */ } else if (function =3D=3D 7 && index =3D=3D 0 && reg =3D=3D R_EBX) { + /* Not new instructions, just an optimization. */ + uint32_t ebx; + host_cpuid(1, 0, &unused, &ebx, &unused, &unused); + ret |=3D ebx & CPUID_7_0_EBX_ERMS; + if (host_tsx_broken()) { ret &=3D ~(CPUID_7_0_EBX_RTM | CPUID_7_0_EBX_HLE); } } else if (function =3D=3D 7 && index =3D=3D 0 && reg =3D=3D R_EDX) { + /* Not new instructions, just an optimization. */ + uint32_t edx; + host_cpuid(1, 0, &unused, &unused, &unused, &edx); + ret |=3D edx & CPUID_7_0_EDX_FSRM; + /* * Linux v4.17-v4.20 incorrectly return ARCH_CAPABILITIES on SVM h= osts. * We can detect the bug by checking if MSR_IA32_ARCH_CAPABILITIES= is @@ -411,6 +421,11 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uin= t32_t function, if (!has_msr_arch_capabs) { ret &=3D ~CPUID_7_0_EDX_ARCH_CAPABILITIES; } + } else if (function =3D=3D 7 && index =3D=3D 1 && reg =3D=3D R_EAX) { + /* Not new instructions, just an optimization. */ + uint32_t eax; + host_cpuid(1, 0, &eax, &unused, &unused, &unused); + ret |=3D eax & (CPUID_7_1_EAX_FZRM | CPUID_7_1_EAX_FSRS | CPUID_7_= 1_EAX_FSRC); } else if (function =3D=3D 0xd && index =3D=3D 0 && (reg =3D=3D R_EAX || reg =3D=3D R_EDX)) { /* --=20 2.39.1