From patchwork Tue Mar 23 09:58:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157355 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C71AC433C1 for ; Tue, 23 Mar 2021 10:07:53 +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 DF20D619AB for ; Tue, 23 Mar 2021 10:07:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DF20D619AB Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.100582.191773 (Exim 4.92) (envelope-from ) id 1lOdwo-0000db-QO; Tue, 23 Mar 2021 10:07:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100582.191773; Tue, 23 Mar 2021 10:07:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdwo-0000dU-NP; Tue, 23 Mar 2021 10:07:38 +0000 Received: by outflank-mailman (input) for mailman id 100582; Tue, 23 Mar 2021 10:07:37 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdr9-0006c2-1B for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 10:01:47 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id cce34c28-814a-474a-b18c-56b37af096c9; Tue, 23 Mar 2021 10:01:37 +0000 (UTC) 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: cce34c28-814a-474a-b18c-56b37af096c9 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493697; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=elgicdoLLjyAPG6mTxXmUlhWyWbTk4KjmQet+vnO69Q=; b=DZkitnqXKuZBiIC1A9HeW2mmWTxmekPiKQcU0Ii+3ainK8Rf2ygpK0Dh bqPLZaFZpnb6i8ltZagZGa/B5yxzQ5f6QuY4B+tGbjcelmW3fZje9HoDl Ck92fAWWsbMUyArW7W/hAEnMnYyn0yA7zm4mXm8nYpOlcZvJaS29ha7Hv A=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: DK49BHw+0b9sC4ZyTccq2A1VcLd2uJ38RZw+M7GYiGZWsQJZrYU9+IQlTPLx93pQg4SHNHvmYi ZhSrtiQTEnTAaPluhln1G1WFLXrChiT9uKmInCdIsgQW2FP84COtMeVuQBE2hwPz35GlfueSfQ KHrcem9qGl83v0RKMmjKMMH8pT5RBiNY+1uWBC2j/TkeP2RALVafPd1C0x32ljqJVeet9f4GIN mZDLQz4n1rZ+G/5RWYriaBG+ubMhziy3HU4PlWoDzpHVFFuMrVYxZ0/GRh65b42DXnyIh/zh5v e34= X-SBRS: 5.2 X-MesageID: 39900444 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:oW3gKaFSjQIIjIkOpLqFbZTXdLJzesId70hD6mlYcjYQWtCEls yogfQQ3QL1jjFUY307hdWcIsC7Lk/03aVepa0cJ62rUgWjgmunK4l+8ZDvqgeNJwTXzcQY76 tpdsFFZeHYJURmjMr8/QmzG8shxt7Cy6yzmeLC1R5WLD1CQYsI1XYcNi+wFEpqSA5aQacjHJ 2H6cZd4xamc3IbbsO0b0N1I9TrjdvNiZ7gfFo6FwcqgTP+8A+AxZzbN1yj3hkYWy5S2rtKyw b4uiHw+6nLiYDc9jbyzGnWhq4m+ufJ6twGP8CUj9hQFzOEsHfSWK1Ee5mv+A84u/uu7lFCqq i9nz4FM95o433cOkGZyCGdojXI6zol53/8xVLwuxKKyqaYNVFKefZpvo5XfgDU7EAtprhHod h29lmUqoZNClf4lDn9juK4Ji1CrFa+onYpjIco/htieLYZAYUhyLA3zQd+FZcNGz/C84Y3EO ViJ9G03ocpTXqqK1/epWVh29qqQzAaGQqHWFELvoiv3yFRh20R9TpV+OUv2lM7sL4tQZhN4O rJdoxuibF1V8cTKYZwHv0IT8ebAnHEKCi8f166EBDCLuUqKnjNo5n47PEe/+exYqEFy5M0hd DoTE5YnXRaQTOvNeS+mLlwtjzdSmS0WjrgjutE4YJih7H6TL33dQWeVVEVlde6qfl3OLybZ9 +DfLZtR9PzJ2rnHohEmyfkXYNJFHUYWMoJ/vkhXVajpd/KN53KuuTXfO27HsuuLR8UHkfERl cTVjn6I8tNqmqxXGXjvRTXU3TxPmzzlKgAVZTyzqw28swgJ4dMug8ahRCS/ceQMwBPtaQwYQ 9bKLPjmaWrmHmu8Q/zniFUEysYKnwQzKTrUntMqwNPGVjza6w/t9KWfn0X+3ebOBllTYfzHB REr1p6vYK7RqbgixwKOpaCCCa3nnETrHWFQ9M3gauY//rofZs+E9IBQ6x+FQLCEjRvggZ0oG J/aAsJL3WvVQ/GuOGAttg5Fevff95zjEOAOshPs0/Ssk2auIUSXHcBZiWvVsSWmA4qYDJRij RKgugiqYvFvQzqBXo0gew+PlEJTGiMGrpJAD6IY5hulqnxdBt9SnqLgjKmmwg+E1CahHk6ty jEF2m5aPvLCl1StjRj3qHm/EhdW0+dc0hzA0oK+rFVJCDjgDJewOWLbq283y+tcVME2PgaKy yASyAVOBlSy9e+0wO1lD6OGW49/IgnOvXQAd0YAvfu80LoDLfNubANHvdS8pogCcvntfUTV/ mDPyCSNzH1BooSqnqoj0dgHBMxjnYqkfnlgkK4qEe52WMyGvrULhBNQaoBL9SV8mjjQLKp3f xC/KYIlNr1Fl+0TNiMjZzzRXpkDDj4pGatVeEmqZxOp8sJxfNONqiedQGN7W1N2RU1Edz9m0 wfSplq+bypAP4bQ+UiPwZiumcznNuBLEEXohX7L+83c1YqlWLaNbqyks31gItqJkWAoQfqUG PvixF1zrPgXyGZ06QdBL91CWNKaFIk4HAKxpLJS6TgTCGrffpE5ly0LzuUd6JcUrGMHfE1og xh69+F28+ReCyQ4nGcgRJLZoZP+X2gW8W8HUalHvNJ6cWzPRC0uZSRifTDxQvfeH+ccEQXhY pMaEwWYIBis1AZ/fIK+xn3bLf2rEIjm0ZZ+hd9mDfWq9Gb3Fs= X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="39900444" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AOKtNw58QdCQiPzStDBaWTYixloQZO3WhTzwSha0l2L+yqOqK7eLXwMClH/Sc8yoJrGlyOTL8skRLJlEswRFCVsX2cc+UkpHJNzGH7q+bMDspwMUCDrzkDLOHB1uoVdTPJxUPc3R7Z11D7bAaRJTzZ3ltCbmXsaVLWz/EF2WLOlu/YXLHYju71SF2LYfAsASq/6Tcdsj9uoEVspyX4HNxy0COdZeuKteDEuLN3XSO8oLLZzFgQniRPpnmFX4XYUX2CnlVtLHnE9YXZqhqxqA2DFmvudPO/kqroggalKwczInL7sffFEmNH4gHjyNP4ubfWTbekqm/IhhXBVLk16MkQ== 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-SenderADCheck; bh=/sAstwZ3FZzzgYovYIPvWV/JpZRMk/Un8JhdEN4a52A=; b=I+LsnmI+QZuBTFfTCX1N51EhE8BeG0Ap/QAf/GtoYaY3g8XKKGbJZNCccGcpvhe0I1GU1EsVYZfLMD5AOpCZOT6nAkcfQ2DZ/doWubd5bGKU/CuJJJgAfh9JIrMEaK5eWPNEOUEVUNGjnEhkHKMvRBlu3d3QP2qrRdJGvM8JMC1SE/bEVk634mag7Y8QcY+hc7ee//pTz26/I4jDmlpG/PVOed388hsBi81dTGJ1Zq4q9dHNE68aQojhB0FXT9wTGRcthDZg7k0iaL9O7VfAh0Qpbhv1aXzDQz+cVtDngWZjMNpI1oHd0P7lN+WxkKxqs8RbZ7e4xQK1s/b8xz+ffg== 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=/sAstwZ3FZzzgYovYIPvWV/JpZRMk/Un8JhdEN4a52A=; b=Ajs2cmCZbeBkD9V2vWhH4FMyo1DhToX0513zehcMUlAFgQrhqn3Ot5UUs/BD06FbwQ7VHH4WoRdiM3OGp9QaHhv6DVmkbcX8C0qMPOieZzdWZARkzga+TrHWd+oFKQQZrt5TM4QOsCCuLuwpLXSiMQxPMORYxcH81WZctuhaMzU= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH 19/21] libs/guest: apply a featureset into a cpu policy Date: Tue, 23 Mar 2021 10:58:47 +0100 Message-ID: <20210323095849.37858-20-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0126.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:30::18) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d14b9d14-0391-40b2-09f2-08d8ede29d6f X-MS-TrafficTypeDiagnostic: DM6PR03MB4969: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RTkijCKJ1KFTtE8o9PKnBhvssfJyfO7/cpwRLa5J8yvfBPQ8YkqZ+o/2AxWZuFoIGu3KajxME3ooQj7kAcbgEXS2hxjMl3PtghpU4ExZgYYSWTauTjdYTxF5rwwgoS16pSv9Wvu9qvU6N1ltDVNnXIbspBV5AiEfWwTrVI6tWF1xq9khhK7mtUZVXwTRiCl0ObmzxS5wnxc8pmRbO7KZuG/GhHUqsV5dmxEVNCy27rBukBNA44nDJSc3B3dcJSrG2sLr/Zv5awdKZL+Zr3mMWDF+rRXWZkTHDR6Amky2FjKZP6eSoOkAfTxFNGVBqenYxuUWFdy9QNqkAIOSY4L2OUv6Xl97EIg1+cx/PPE+qaM+nKOGM6MSmEx43TuunzBmyAFVw+a9uKGD8sZjBDCe9iw9h08RBI6AoO6eGw2kxgArm1FjWJRh8WmtVES/B8pCChEOIEmnqRAOrLgpN2naIKtJYBgmV84qJwo35a8mAnT3DQySZBqyHPsNBw+6g112DO7cwrZb3ATLF757aSm5K2ZtqV5EgVtTf4OLOmif3J+IX0s296Ie7ja4w1TFf6faEwRE5bq3FHREUKToVRSFUQSZdS3c+HByjSTNJO8GDPX5EWrird9jrasJh2ocSVUVTsSqi3EgrNh7SjzXJpRtmw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(136003)(376002)(396003)(346002)(39860400002)(54906003)(36756003)(2616005)(316002)(26005)(6486002)(956004)(16526019)(186003)(2906002)(86362001)(66556008)(6916009)(478600001)(5660300002)(8936002)(6496006)(38100700001)(83380400001)(6666004)(66476007)(8676002)(66946007)(1076003)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?lKM3+Zaf4mGKmu+QfsFN+AqsySFpqX?= =?utf-8?q?pKrapMIv4SzPZe91gK9wpHHcPWEnAqNyTv1ErSevhUYJUI+ZEwmvd5V3nF5fTCRrP?= =?utf-8?q?QRnY8Xm9FEZY3ezNHZGqoKihqjucdYSBEtnpyEmML4UCWKlY2WJ+5VpNdflp3S/MK?= =?utf-8?q?qlIXWoeeUutbSBhKx8FKOFYRHBS9agN2K2NF5g3ECnBGi2z4YQK2LMiZE2s6rN8xC?= =?utf-8?q?PuJGOFk/f8gYC1zxBBv1ntqP8TvLyWcSXM8M9V06T3v2s5DqEZVXapWcUyP7j1qdr?= =?utf-8?q?Vg9OLeOKmS5eqmJF5p/nTFhxUxJIarXIITzbs6N4Sw7kuc4XN4JGzoaYO4GyTIm9p?= =?utf-8?q?VGQj7T4d/cfRRly1BxgKW8hs9/dZMZws8Xye25bPH0WXJZvJvsN75WMlC45EN37ou?= =?utf-8?q?dxanBTJ5mRAVJR113PuQmofjZipHGo2yj8Eu7CBh3Enp8r0ydhoXZ6FuzWm2Cyere?= =?utf-8?q?CxwyfXlJ6B2AvY6M09ayTCezkmr9QoXgkrKT0bIMDW3JTgPX98UKiiulIY5hnBzw8?= =?utf-8?q?bvJzRth5J7J6a0bLU14IQnD25j1Dg4HmlXNqw2cvcxnTyScV3kn0WvzHSBnoJVqv8?= =?utf-8?q?ex1khmlRz+9+WTKedVpb5YleD1VZbbKKDOQFVMHnxuiHIG72AsfQY2fR3/S1uP6Fb?= =?utf-8?q?/8Ww6aSzqrR6YIouxDMt5WEqELM10V+tNG0ICvWg8zXBpowuJtZ4PDlsItRxznd+y?= =?utf-8?q?LiURLv+Jhxknk0zCTf+sUshTqUSr41ctdNKUN7nieBmMGp+hcKzRNuEOJg9s7pg1F?= =?utf-8?q?xDDp6Gdm1WkUrd18Eb6Uu1ZnmmK7ZsGZ1+cRrMbXOlsygWmNgAnvqnoqrumHOyHym?= =?utf-8?q?1vXh0EjCUzUZr7Ewlt422FBq5C1Mu4YedoPYvYecy/hOnJlCRv9TMQ7vdOQUNGGRO?= =?utf-8?q?AeTfNVAm22tIt06O0aBEtzCnqaL9T3f1rxfCgnlUu/qpsJUSQDK19xh6wjY2xYliG?= =?utf-8?q?DVU0UQaJPFJJyIFkOsO3mVriVkH3PElwdH9/H+CZNr+9EJCUZ8xInsQ9G8aywxCQs?= =?utf-8?q?Om1pmc05HMy5WbrkoY/TLsYh5vxJGPYWjXx71lU/OHcroLsM892RI16WXORqo4wLp?= =?utf-8?q?aH16bB+/IT2GZW8a9AaGfgPBiFCFYZ8N4D0pjNML2pZ9HwccCW/6nooxLv1sGkayv?= =?utf-8?q?nctaodBj05Fe8O93uNCXhssmmh3QAoakv+KR15qkQfl0njzBdVK4/szmnpvvd3Ilq?= =?utf-8?q?L8SHOLtxgKFDREfAVFYaGnvh4wyyqUqtjQic18ZVOlXTAiIgLZczEw4//k6vho3dM?= =?utf-8?q?JGsCKRmd+TnB6q?= X-MS-Exchange-CrossTenant-Network-Message-Id: d14b9d14-0391-40b2-09f2-08d8ede29d6f X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 10:01:23.3851 (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: yeDoZ/E7oFk2udtTDTughx7lpIwXtbR5DlwlcXptKtz3yBpdFrW39UgbLZt2mnjUStF1ySzMQNZVxnbgBenWGg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4969 X-OriginatorOrg: citrix.com Pull out the code from xc_cpuid_apply_policy that applies a featureset to a cpu policy and place it on it's own standalone function that's part of the public interface. No functional change intended. Signed-off-by: Roger Pau Monné --- tools/include/xenctrl.h | 5 ++ tools/libs/guest/xg_cpuid_x86.c | 94 ++++++++++++++++++++------------- 2 files changed, 61 insertions(+), 38 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 07b8bfc08aa..a830fac1d12 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2639,6 +2639,11 @@ int xc_cpu_policy_topology(xc_interface *xch, xc_cpu_policy_t policy, int xc_cpu_policy_apply_cpuid(xc_interface *xch, xc_cpu_policy_t policy, const struct xc_xend_cpuid *cpuid, bool hvm); +/* Apply a featureset to the policy. */ +int xc_cpu_policy_apply_featureset(xc_interface *xch, xc_cpu_policy_t policy, + const uint32_t *featureset, + unsigned int nr_features); + int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps); int xc_get_cpu_featureset(xc_interface *xch, uint32_t index, uint32_t *nr_features, uint32_t *featureset); diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c index ce4a4a1a436..96b969342fa 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -450,46 +450,14 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore, if ( featureset ) { - uint32_t disabled_features[FEATURESET_NR_ENTRIES], - feat[FEATURESET_NR_ENTRIES] = {}; - static const uint32_t deep_features[] = INIT_DEEP_FEATURES; - unsigned int i, b; - - /* - * The user supplied featureset may be shorter or longer than - * FEATURESET_NR_ENTRIES. Shorter is fine, and we will zero-extend. - * Longer is fine, so long as it only padded with zeros. - */ - unsigned int user_len = min(FEATURESET_NR_ENTRIES + 0u, nr_features); - - /* Check for truncated set bits. */ - rc = -EOPNOTSUPP; - for ( i = user_len; i < nr_features; ++i ) - if ( featureset[i] != 0 ) - goto out; - - memcpy(feat, featureset, sizeof(*featureset) * user_len); - - /* Disable deep dependencies of disabled features. */ - for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i ) - disabled_features[i] = ~feat[i] & deep_features[i]; - - for ( b = 0; b < sizeof(disabled_features) * CHAR_BIT; ++b ) + policy.cpuid = p; + rc = xc_cpu_policy_apply_featureset(xch, &policy, featureset, + nr_features); + if ( rc ) { - const uint32_t *dfs; - - if ( !test_bit(b, disabled_features) || - !(dfs = x86_cpuid_lookup_deep_deps(b)) ) - continue; - - for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i ) - { - feat[i] &= ~dfs[i]; - disabled_features[i] &= ~dfs[i]; - } + ERROR("Failed to apply featureset to policy"); + goto out; } - - cpuid_featureset_to_policy(feat, p); } else { @@ -1230,3 +1198,53 @@ int xc_cpu_policy_topology(xc_interface *xch, xc_cpu_policy_t policy, return 0; } + +int xc_cpu_policy_apply_featureset(xc_interface *xch, xc_cpu_policy_t policy, + const uint32_t *featureset, + unsigned int nr_features) +{ + uint32_t disabled_features[FEATURESET_NR_ENTRIES], + feat[FEATURESET_NR_ENTRIES] = {}; + static const uint32_t deep_features[] = INIT_DEEP_FEATURES; + unsigned int i, b; + + /* + * The user supplied featureset may be shorter or longer than + * FEATURESET_NR_ENTRIES. Shorter is fine, and we will zero-extend. + * Longer is fine, so long as it only padded with zeros. + */ + unsigned int user_len = min(FEATURESET_NR_ENTRIES + 0u, nr_features); + + /* Check for truncated set bits. */ + for ( i = user_len; i < nr_features; ++i ) + if ( featureset[i] != 0 ) + { + errno = EOPNOTSUPP; + return -1; + } + + memcpy(feat, featureset, sizeof(*featureset) * user_len); + + /* Disable deep dependencies of disabled features. */ + for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i ) + disabled_features[i] = ~feat[i] & deep_features[i]; + + for ( b = 0; b < sizeof(disabled_features) * CHAR_BIT; ++b ) + { + const uint32_t *dfs; + + if ( !test_bit(b, disabled_features) || + !(dfs = x86_cpuid_lookup_deep_deps(b)) ) + continue; + + for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i ) + { + feat[i] &= ~dfs[i]; + disabled_features[i] &= ~dfs[i]; + } + } + + cpuid_featureset_to_policy(feat, policy->cpuid); + + return 0; +}