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 37135D5CCB3 for ; Wed, 30 Oct 2024 14:46:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.828267.1243127 (Exim 4.92) (envelope-from ) id 1t69ww-0002CW-2o; Wed, 30 Oct 2024 14:45:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 828267.1243127; Wed, 30 Oct 2024 14:45:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t69wv-0002CP-WF; Wed, 30 Oct 2024 14:45:30 +0000 Received: by outflank-mailman (input) for mailman id 828267; Wed, 30 Oct 2024 14:45:28 +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 1t69wu-0002CJ-Gb for xen-devel@lists.xenproject.org; Wed, 30 Oct 2024 14:45:28 +0000 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [2a00:1450:4864:20::632]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 97734962-96cd-11ef-99a3-01e77a169b0f; Wed, 30 Oct 2024 15:45:22 +0100 (CET) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a998a5ca499so893662666b.0 for ; Wed, 30 Oct 2024 07:45:22 -0700 (PDT) Received: from [10.125.226.166] ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1dec7dacsm577392766b.9.2024.10.30.07.45.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 30 Oct 2024 07:45:21 -0700 (PDT) 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: 97734962-96cd-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo2MzIiLCJoZWxvIjoibWFpbC1lajEteDYzMi5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6Ijk3NzM0OTYyLTk2Y2QtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMwMjk5NTIyLjY4NTYyNCwic2VuZGVyIjoiYW5kcmV3LmNvb3BlckBjbG91ZC5jb20iLCJyZWNpcGllbnQiOiJ4ZW4tZGV2ZWxAbGlzdHMueGVucHJvamVjdC5vcmcifQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1730299522; x=1730904322; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=AldCFs3TcVsl18Unm2tnnWx5W3hkWuJpwwxBn9s4zoo=; b=NfyIPqXhDepn3/ObKNW7ZfyKdsjVJrY0ivMjd3PHLmZncbfHyw7r7eAELkHQFR1lFu h+fi+6uYFTjBaJUX7buKuiWvm1V3V0GwWNxeCfPNYKiAJqbcbj2OkMdsj7D4xDjyxn2a GiAz9sKTsWJr34HP4L1c6z/ysGMUClEt5vWiI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730299522; x=1730904322; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=AldCFs3TcVsl18Unm2tnnWx5W3hkWuJpwwxBn9s4zoo=; b=c0vP4X7v1CFLTKiWuwCimELjO47veSDNi3bE8DvnCsD9WreiJgBUffWrM+T/irYZWz 0SqIiLlz92/+52/Nv7wC1f13VJYOrlJPBQt9leCngyJ3JdJKmSAXFtEasF3Da0L+WPHj lO/yUylUlXDLjefq4Yae60tGuVImdBRHPykZOSFXzAubvs7xDF1VXTvCSDcoJ+DVydwZ yREa7GYGfF+ZaJblWx4At82Y02T7Udp8ZKioIxeFK2uYtr2XatmktchD/heOFDLYjo1C 0kw/YhFhJ5QSPH4IFFTLC3YtVcaQbva7rDLvc2i6AQcbxxlRi7KPPupkJ9vD09Y2jO69 BmaQ== X-Gm-Message-State: AOJu0YxRZbFvsViHmPyQhZ5E0vOcSrHnZQi74pkW/b8ZocWqmAjleCJX Kg9ljvv+v7F3C5j6/fKi7O0DEDtzmW3djG9akzrf8tlCv95KMjWri0VqiECMcGc= X-Google-Smtp-Source: AGHT+IGmYwAPYJjMSaheZqWzb7hMcrtH02W8ocl2jtahptlANWnXyL78ZnJbbro1SikfQCuf/YsWMA== X-Received: by 2002:a17:907:3e20:b0:a99:d587:6045 with SMTP id a640c23a62f3a-a9de5d977b4mr1412220266b.19.1730299522015; Wed, 30 Oct 2024 07:45:22 -0700 (PDT) Message-ID: <3effac8c-b4cf-4d96-a5f6-99def9f7ec1c@citrix.com> Date: Wed, 30 Oct 2024 14:45:19 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] x86/cpu-policy: Extend the guest max policy max leaf/subleaves To: =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= Cc: Xen-devel , Jan Beulich , Alejandro Vallejo References: <20241029175505.2698661-1-andrew.cooper3@citrix.com> Content-Language: en-GB From: Andrew Cooper Autocrypt: addr=andrew.cooper3@citrix.com; keydata= xsFNBFLhNn8BEADVhE+Hb8i0GV6mihnnr/uiQQdPF8kUoFzCOPXkf7jQ5sLYeJa0cQi6Penp VtiFYznTairnVsN5J+ujSTI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Blw/kGpdefoG4XEACD1Qf/er8EA7g23HMxYWd3FXHThrVQ HgiGdk5Yh632vjOm9L4sd/GCEACVQKjsu98e8o3ysitFlznEns5EAAXEbITrgKWXDDUWGYxd pnjj2u+GkVdsOAGk0kxczX6s+VRBhpbBI2PWnOsRJgU2n10PZ3mZD4Xu9kU2IXYmuW+e5KCA vTArRUdCrAtIa1k01sPipPPw6dfxx2e5asy21YOytzxuWFfJTGnVxZZSCyLUO83sh6OZhJkk b9rxL9wPmpN/t2IPaEKoAc0FTQZS36wAMOXkBh24PQ9gaLJvfPKpNzGD8XWR5HHF0NLIJhgg 4ZlEXQ2fVp3XrtocHqhu4UZR4koCijgB8sB7Tb0GCpwK+C4UePdFLfhKyRdSXuvY3AHJd4CP 4JzW0Bzq/WXY3XMOzUTYApGQpnUpdOmuQSfpV9MQO+/jo7r6yPbxT7CwRS5dcQPzUiuHLK9i nvjREdh84qycnx0/6dDroYhp0DFv4udxuAvt1h4wGwTPRQZerSm4xaYegEFusyhbZrI0U9tJ B8WrhBLXDiYlyJT6zOV2yZFuW47VrLsjYnHwn27hmxTC/7tvG3euCklmkn9Sl9IAKFu29RSo d5bD8kMSCYsTqtTfT6W4A3qHGvIDta3ptLYpIAOD2sY3GYq2nf3Bbzx81wZK14JdDDHUX2Rs 6+ahAA== In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 30/10/2024 11:03 am, Roger Pau Monné wrote: > On Wed, Oct 30, 2024 at 10:39:12AM +0000, Andrew Cooper wrote: >> On 30/10/2024 8:59 am, Roger Pau Monné wrote: >>> On Tue, Oct 29, 2024 at 05:55:05PM +0000, Andrew Cooper wrote: >>>> diff --git a/xen/arch/x86/cpu-policy.c b/xen/arch/x86/cpu-policy.c >>>> index b6d9fad56773..78bc9872b09a 100644 >>>> --- a/xen/arch/x86/cpu-policy.c >>>> +++ b/xen/arch/x86/cpu-policy.c >>>> @@ -391,6 +391,27 @@ static void __init calculate_host_policy(void) >>>> p->platform_info.cpuid_faulting = cpu_has_cpuid_faulting; >>>> } >>>> >>>> +/* >>>> + * Guest max policies can have any max leaf/subleaf within bounds. >>>> + * >>>> + * - Some incoming VMs have a larger-than-necessary feat max_subleaf. >>>> + * - Some VMs we'd like to synthesise leaves not present on the host. >>>> + */ >>>> +static void __init guest_common_max_leaves(struct cpu_policy *p) >>>> +{ >>>> + p->basic.max_leaf = ARRAY_SIZE(p->basic.raw) - 1; >>>> + p->feat.max_subleaf = ARRAY_SIZE(p->feat.raw) - 1; >>>> + p->extd.max_leaf = 0x80000000U + ARRAY_SIZE(p->extd.raw) - 1; >>>> +} >>>> + >>>> +/* Guest default policies inherit the host max leaf/subleaf settings. */ >>>> +static void __init guest_common_default_leaves(struct cpu_policy *p) >>>> +{ >>>> + p->basic.max_leaf = host_cpu_policy.basic.max_leaf; >>>> + p->feat.max_subleaf = host_cpu_policy.feat.max_subleaf; >>>> + p->extd.max_leaf = host_cpu_policy.extd.max_leaf; >>>> +} >>> I think this what I'm going to ask is future work. After the >>> modifications done to the host policy by max functions >>> (calculate_{hvm,pv}_max_policy()) won't the max {sub,}leaf adjustments >>> better be done taking into account the contents of the policy, rather >>> than capping to the host values? >>> >>> (note this comment is strictly for guest_common_default_leaves(), the >>> max version is fine using ARRAY_SIZE). >> I'm afraid I don't follow. >> >> calculate_{pv,hvm}_max_policy() don't modify the host policy. > Hm, I don't think I've expressed myself clearly, sorry. Let me try > again. > > calculate_{hvm,pv}_max_policy() extends the host policy by possibly > setting new features, and such extended policy is then used as the > base for the PV/HVM default policies. > > Won't the resulting policy in calculate_{hvm,pv}_def_policy() risks > having bits set past the max {sub,}leaf in the host policy, as it's > based in {hvm,pv}_def_cpu_policy that might have such bits set? Oh, right. This patch doesn't change anything WRT that. But I think you're right that we do risk getting into that case (in principle at least) because of how guest_common_*_feature_adjustment() work. Furthermore, the bug will typically get hidden because we serialise based on the max_leaf/subleaf, and will discard feature words outside of the max_leaf/subleaf bounds. I suppose we probably want a variation of x86_cpu_featureset_to_policy() which extends the max_leaf/subleaf based on non-zero values in leaves.  (This already feels like it's going to be an ugly algorithm.) ~Andrew