From patchwork Tue Jul 25 13:05:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13326429 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 5BF07C001DE for ; Tue, 25 Jul 2023 13:07:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.569672.890601 (Exim 4.92) (envelope-from ) id 1qOHkT-000534-8W; Tue, 25 Jul 2023 13:06:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 569672.890601; Tue, 25 Jul 2023 13:06:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOHkT-00052v-5C; Tue, 25 Jul 2023 13:06:45 +0000 Received: by outflank-mailman (input) for mailman id 569672; Tue, 25 Jul 2023 13:06:44 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOHkR-0004BN-Ry for xen-devel@lists.xenproject.org; Tue, 25 Jul 2023 13:06:43 +0000 Received: from esa1.hc3370-68.iphmx.com (esa1.hc3370-68.iphmx.com [216.71.145.142]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fabb7852-2aeb-11ee-8613-37d641c3527e; Tue, 25 Jul 2023 15:05:52 +0200 (CEST) Received: from mail-co1nam11lp2175.outbound.protection.outlook.com (HELO NAM11-CO1-obe.outbound.protection.outlook.com) ([104.47.56.175]) by ob1.hc3370-68.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Jul 2023 09:06:39 -0400 Received: from SJ0PR03MB6423.namprd03.prod.outlook.com (2603:10b6:a03:38d::21) by SA1PR03MB6516.namprd03.prod.outlook.com (2603:10b6:806:1c7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33; Tue, 25 Jul 2023 13:06:36 +0000 Received: from SJ0PR03MB6423.namprd03.prod.outlook.com ([fe80::2e0e:5665:96a7:5767]) by SJ0PR03MB6423.namprd03.prod.outlook.com ([fe80::2e0e:5665:96a7:5767%3]) with mapi id 15.20.6609.031; Tue, 25 Jul 2023 13:06:36 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: fabb7852-2aeb-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1690290401; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=3YW2uWrH0cDvz/qKgkm2RdMtfdnR+LKEqygNTbfvJjA=; b=dQBSZwaLQj5QMfayv8gWbneKNrWBspYvRwlWncrCsMjexZFTuHl/T+Dg nNsQJipwFM5rZkZ7ciHzUGjtgOz/U5SAafRdRnznzrdn4I5M98uykXgkC 5/TTNcRiF7QNFOWQ+5gjAN+Rxw/JO4Huom+nrsCJYN8TRubEc4WDIWhMX A=; X-IronPort-RemoteIP: 104.47.56.175 X-IronPort-MID: 117795529 X-IronPort-Reputation: None X-IronPort-Listener: OutboundMail X-IronPort-SenderGroup: RELAY_O365 X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:l7pT2anBQev/1El6WeMxiSro5gylJ0RdPkR7XQ2eYbSJt1+Wr1Gzt xIWDGyEaf7Ya2Km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iviFw== X-IronPort-AV: E=Sophos;i="6.01,230,1684814400"; d="scan'208";a="117795529" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LCtSwQLq1Gls2hTnfurr/Xz9Nz3Ia09KzLde1qICbHmLAWQAsZFGdCl6vmCS+jiCwcyjNIfYF/rjoqKboBHU/bUKpGeu3kvRetgYsY2GQGY4+HK8gi07G7rU5+ZQjxBcK3nlCXrFI5lTeJ0EOuIu7QU/s9VcBlIGmp8WIcHj23gJ8QxeJX8ha4wIy7m7E6LSaMMfwM1rxAW8/3+4vYJSn4V7yt7mpd4YPyhsmqunW/C8iHobu/xMNiMohP2Z56ozdBXhqeeULvz6tb1J+8MA2Hg3sR3O809JNsTe7c7PEkoxSWONyEkH1WypVhl7l9pGx2RadCSMMvukN1zJUb67jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0VuaruMFBkjm32zvsZJXEPKcdb4HJwG3XWzAhS0qQtk=; b=egSXSQeMHCwIeJN2dpvvH62kIUQ1tlFbUSBL8g48Sji+HJbUnlQfK6b668NfY6Uhfc8kol5fIzOBTKVxwBja6AXg/o6pqznI0I4y/LrHXJDyMXo3Hg1Nk3Oy3czFIsYIaOGCxPy0YQK/rPuP5zIKdP4oUvhrgZ7YwNUkTAWLD9joXnT99jcpk/3V/DTI4Uy+jHeGhp+Fv7xT3awil1lsiOOPOYdLvL3yqOpGoDR6uGdBczv1zOj0ke+AJO9vWU1/wA9oeIscJrSMzsbiGF++N3+M4YOE2FOKVKk1pxCPn2Nzg2iMeKnrQZ0wcgSqEQOcErIQv9gRaKa7Qbd3+DPyMQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0VuaruMFBkjm32zvsZJXEPKcdb4HJwG3XWzAhS0qQtk=; b=D7JVqtUg2/4SIQauCDh2Bv90795Fq6HQJSezaVChS7maYb14ZxdPyN0/mSzfQ8hxsSpz+9FngzrD3NgSIqw3Dw1AS3+crFzMh2HNkvHVOi3/pUkkWUtPCcgvcd1KRm5WSpsUW2RDWnxL9/vlEugG3mh8UIF47WxrReNB24CjQt8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v4 4/6] libxl: split logic to parse user provided CPUID features Date: Tue, 25 Jul 2023 15:05:56 +0200 Message-ID: <20230725130558.58094-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725130558.58094-1-roger.pau@citrix.com> References: <20230725130558.58094-1-roger.pau@citrix.com> X-ClientProxiedBy: LO2P265CA0494.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:13a::19) To SJ0PR03MB6423.namprd03.prod.outlook.com (2603:10b6:a03:38d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR03MB6423:EE_|SA1PR03MB6516:EE_ X-MS-Office365-Filtering-Correlation-Id: b3b60524-1da8-45ff-2fab-08db8d0ffa3e X-LD-Processed: 335836de-42ef-43a2-b145-348c2ee9ca5b,ExtAddr,ExtFwd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NNw0DSUyAqQaAVVCQd2pMffUYw5wdLUDH7Uj0y4oQo9G7THSjfsJzdsf49TFEKDqh9QHTfiidU36G8krmeEXEYi/7J2h8Wo/xiS4rd2av+PNp+rzvGc1+H4C1XK2F4j8bxRZWLx+cKpd1qiqPVrwU4oB4dqkkJRL4TgCGA5/Ojof0PXQuyF/tFwOJpocT1Ux5zByccbvLaxYSDoTS4yUiG8Sla54TNB3/iTS+xR9sbVOmkW4thMtFBcS00ZDVSIHPOYgB64l5KRuQsHVIOvur/lfZJMgr5rCkqpUEyiMgKPXsTIRAQ2BBP6gPMBTBCyzMsIT/mGzhi8LxvJpVSuqgSwXWn28e6bSLVRV3grUZbGRScYCIweE1k3WdpjceeUGBATxAP+V2YtFFCY+kE12Ja1SN0D2AIBxxhg01f5ff0yT7jNwpTXzt7MHoR+4Gl1HTDCJHxcFRxq2lW2RBWuSHwrIMtxHqYjvdP+5TZWoOo+AbFnQ+rMV8dcX0Aj23SjT1b+uuIjAYU8Brw/x/3DpQZrEhNBbn11Fte19iQyATB2vumH23vAnjwAi1G77OPCd X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR03MB6423.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(376002)(366004)(136003)(346002)(396003)(39860400002)(451199021)(6486002)(6666004)(82960400001)(478600001)(83380400001)(8936002)(1076003)(26005)(6512007)(6506007)(66946007)(38100700002)(66556008)(54906003)(6916009)(4326008)(66476007)(186003)(2616005)(5660300002)(8676002)(2906002)(316002)(41300700001)(86362001)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?bWJgHgycBeiwNFNQENWMSNIAMrHI?= =?utf-8?q?2jem09N5WJ/WoHjKQwDeEfd9NFFm3+BF49I+us7czijpd+kuOo1K7sHwyfeLNZ1Xa?= =?utf-8?q?SnueFGSyOIJzf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L+6lOcqyXZew/tGVuQAodQKwHj5H6RZbfMSfKcJoBaQitXS3E2wGTc1FhdVSnnrX+C8ukt1ykz/AoebNZ8AatZPlvP2iIJCSTFTOjld736BoDyNWQto0NrZ0o41p6KFSvT0oTuFyz60s5oFMwGR8E5Rr2+1E45Znt8GK8lumCUBVptjjRWOPbX9qs1/Fc+ilzz1gptKhcBj1afsPyLpq/T9Lc+byEY/6OFltb8IuGTyvosZlc1MdnBRe64Y4c9EsaKL29OPw9oa95ZfFN2d/YZqqQLhoeVn/6N+f0lsZOtyjirxaUZeuIqmVd0QmyQO/Mouia2eZi0iyo9GpJ2EoFh+RmRLx0fznwbXugtdpp26hOd8tjSNipGtLi9djQecX275p92IRQ/zLgET1Iexkj4PziD9cfa9WoSINw7A++QCEmH1EE3bOXUHAM6EMDZkeJf/jd/B+KAlE3fWv6m6IxUgqr2QrpeIKW8Oa56Q1E1k0IEMT2Nruty+mDwx4Abkgo321u1VmjvVA/o6Izg1ziQIpa+AapzCb25OwZye+LcC X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: b3b60524-1da8-45ff-2fab-08db8d0ffa3e X-MS-Exchange-CrossTenant-AuthSource: SJ0PR03MB6423.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2023 13:06:36.6710 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3XYaVcH2aXV3HgNi1QraV9fTnZT6qnMFZP3HuUMVrL9brfqM84iy5NybVjjcKfzo9gmkGsrrAi5zpmY5iLUUqw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR03MB6516 Move the CPUID value parsers out of libxl_cpuid_parse_config() into a newly created cpuid_add() local helper. This is in preparation for also adding MSR feature parsing support. No functional change intended. Signed-off-by: Roger Pau Monné Reviewed-by: Anthony PERARD --- Changes since v3: - Fix UB and use strtoul. --- tools/libs/light/libxl_cpuid.c | 120 +++++++++++++++++---------------- 1 file changed, 63 insertions(+), 57 deletions(-) diff --git a/tools/libs/light/libxl_cpuid.c b/tools/libs/light/libxl_cpuid.c index dd97699bbde7..f04b192c0e44 100644 --- a/tools/libs/light/libxl_cpuid.c +++ b/tools/libs/light/libxl_cpuid.c @@ -96,6 +96,66 @@ static struct xc_xend_cpuid *cpuid_find_match(libxl_cpuid_policy_list *pl, return *list + i; } +static int cpuid_add(libxl_cpuid_policy_list *policy, + const struct cpuid_flags *flag, const char *val) +{ + struct xc_xend_cpuid *entry = cpuid_find_match(policy, flag->leaf, + flag->subleaf); + unsigned long num; + char flags[33], *resstr, *endptr; + unsigned int i; + + resstr = entry->policy[flag->reg - 1]; + num = strtoul(val, &endptr, 0); + flags[flag->length] = 0; + if (endptr != val) { + /* if this was a valid number, write the binary form into the string */ + for (i = 0; i < flag->length; i++) { + flags[flag->length - 1 - i] = "01"[(num >> i) & 1]; + } + } else { + switch(val[0]) { + case 'x': case 'k': case 's': + memset(flags, val[0], flag->length); + break; + default: + return 3; + } + } + + if (resstr == NULL) { + resstr = strdup("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + } + + /* the family and model entry is potentially split up across + * two fields in Fn0000_0001_EAX, so handle them here separately. + */ + if (!strcmp(flag->name, "family")) { + if (num < 16) { + memcpy(resstr + (32 - 4) - flag->bit, flags + 4, 4); + memcpy(resstr + (32 - 8) - 20, "00000000", 8); + } else { + num -= 15; + memcpy(resstr + (32 - 4) - flag->bit, "1111", 4); + for (i = 0; i < 7; i++) { + flags[7 - i] = "01"[num & 1]; + num >>= 1; + } + memcpy(resstr + (32 - 8) - 20, flags, 8); + } + } else if (!strcmp(flag->name, "model")) { + memcpy(resstr + (32 - 4) - 16, flags, 4); + memcpy(resstr + (32 - 4) - flag->bit, flags + 4, 4); + } else { + memcpy(resstr + (32 - flag->length) - flag->bit, flags, + flag->length); + } + entry->policy[flag->reg - 1] = resstr; + + return 0; + +} + /* parse a single key=value pair and translate it into the libxc * used interface using 32-characters strings for each register. * Will overwrite earlier entries and thus can be called multiple @@ -340,12 +400,8 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *policy, const char* str) {NULL, 0, NA, CPUID_REG_INV, 0, 0} }; #undef NA - char *sep, *val, *endptr; - int i; + const char *sep, *val; const struct cpuid_flags *flag; - struct xc_xend_cpuid *entry; - unsigned long num; - char flags[33], *resstr; sep = strchr(str, '='); if (sep == NULL) { @@ -355,60 +411,10 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *policy, const char* str) } for (flag = cpuid_flags; flag->name != NULL; flag++) { if(!strncmp(str, flag->name, sep - str) && flag->name[sep - str] == 0) - break; - } - if (flag->name == NULL) { - return 2; - } - entry = cpuid_find_match(policy, flag->leaf, flag->subleaf); - resstr = entry->policy[flag->reg - 1]; - num = strtoull(val, &endptr, 0); - flags[flag->length] = 0; - if (endptr != val) { - /* if this was a valid number, write the binary form into the string */ - for (i = 0; i < flag->length; i++) { - flags[flag->length - 1 - i] = "01"[!!(num & (1 << i))]; - } - } else { - switch(val[0]) { - case 'x': case 'k': case 's': - memset(flags, val[0], flag->length); - break; - default: - return 3; - } - } - - if (resstr == NULL) { - resstr = strdup("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + return cpuid_add(policy, flag, val); } - /* the family and model entry is potentially split up across - * two fields in Fn0000_0001_EAX, so handle them here separately. - */ - if (!strncmp(str, "family", sep - str)) { - if (num < 16) { - memcpy(resstr + (32 - 4) - flag->bit, flags + 4, 4); - memcpy(resstr + (32 - 8) - 20, "00000000", 8); - } else { - num -= 15; - memcpy(resstr + (32 - 4) - flag->bit, "1111", 4); - for (i = 0; i < 7; i++) { - flags[7 - i] = "01"[num & 1]; - num >>= 1; - } - memcpy(resstr + (32 - 8) - 20, flags, 8); - } - } else if (!strncmp(str, "model", sep - str)) { - memcpy(resstr + (32 - 4) - 16, flags, 4); - memcpy(resstr + (32 - 4) - flag->bit, flags + 4, 4); - } else { - memcpy(resstr + (32 - flag->length) - flag->bit, flags, - flag->length); - } - entry->policy[flag->reg - 1] = resstr; - - return 0; + return 2; } /* parse a single list item from the legacy Python xend syntax, where