From patchwork Mon Mar 23 12:06:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11452773 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8B16992A for ; Mon, 23 Mar 2020 12:08:26 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6FBDF20784 for ; Mon, 23 Mar 2020 12:08:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6FBDF20784 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jGLqw-0001GS-OP; Mon, 23 Mar 2020 12:06:46 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jGLqv-0001GN-2L for xen-devel@lists.xenproject.org; Mon, 23 Mar 2020 12:06:45 +0000 X-Inumbo-ID: c2a4d521-6cfe-11ea-82c0-12813bfff9fa Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c2a4d521-6cfe-11ea-82c0-12813bfff9fa; Mon, 23 Mar 2020 12:06:43 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 5BEB8AEF7; Mon, 23 Mar 2020 12:06:42 +0000 (UTC) To: "xen-devel@lists.xenproject.org" From: Jan Beulich Message-ID: <75c077bc-ecf3-45fe-1a71-0804fe6aaaf4@suse.com> Date: Mon, 23 Mar 2020 13:06:32 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 Content-Language: en-US Subject: [Xen-devel] [PATCH] libx86/CPUID: fix (not just) leaf 7 processing X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" For one, subleaves within the respective union shouldn't live in separate sub-structures. And then x86_cpuid_policy_fill_native() should, as it did originally, iterate over all subleaves here as well as over all main leaves. Switch to using a "<= MIN()"-based approach similar to that used in x86_cpuid_copy_to_buffer(). Also follow this for the extended main leaves then. Fixes: 1bd2b750537b ("libx86: Fix 32bit stubdom build of x86_cpuid_policy_fill_native()") Fixes: 97e4ebdcd765 ("x86/CPUID: support leaf 7 subleaf 1 / AVX512_BF16") Signed-off-by: Jan Beulich Reviewed-by: Andrew Cooper --- a/xen/include/xen/lib/x86/cpuid.h +++ b/xen/include/xen/lib/x86/cpuid.h @@ -181,8 +181,7 @@ struct cpuid_policy uint32_t _7d0; struct { DECL_BITFIELD(7d0); }; }; - }; - struct { + /* Subleaf 1. */ union { uint32_t _7a1; --- a/xen/lib/x86/cpuid.c +++ b/xen/lib/x86/cpuid.c @@ -71,8 +71,8 @@ void x86_cpuid_policy_fill_native(struct unsigned int i; cpuid_leaf(0, &p->basic.raw[0]); - for ( i = 1; i < min_t(unsigned int, ARRAY_SIZE(p->basic.raw), - p->basic.max_leaf); ++i ) + for ( i = 1; i <= MIN(p->basic.max_leaf, + ARRAY_SIZE(p->basic.raw) - 1); ++i ) { switch ( i ) { @@ -116,8 +116,8 @@ void x86_cpuid_policy_fill_native(struct { cpuid_count_leaf(7, 0, &p->feat.raw[0]); - for ( i = 1; i < min_t(unsigned int, ARRAY_SIZE(p->feat.raw), - p->feat.max_subleaf); ++i ) + for ( i = 1; i <= MIN(p->feat.max_subleaf, + ARRAY_SIZE(p->feat.raw) - 1); ++i ) cpuid_count_leaf(7, i, &p->feat.raw[i]); } @@ -172,8 +172,8 @@ void x86_cpuid_policy_fill_native(struct /* Extended leaves. */ cpuid_leaf(0x80000000, &p->extd.raw[0]); - for ( i = 1; i < min_t(unsigned int, ARRAY_SIZE(p->extd.raw), - p->extd.max_leaf + 1 - 0x80000000); ++i ) + for ( i = 1; i <= MIN(p->extd.max_leaf & 0xffffU, + ARRAY_SIZE(p->extd.raw) - 1); ++i ) cpuid_leaf(0x80000000 + i, &p->extd.raw[i]); x86_cpuid_policy_recalc_synth(p);