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=-12.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 1356CC433ED for ; Wed, 14 Apr 2021 13:49:11 +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 AE960611EE for ; Wed, 14 Apr 2021 13:49:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AE960611EE Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.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.110658.211228 (Exim 4.92) (envelope-from ) id 1lWftA-0005Qx-TZ; Wed, 14 Apr 2021 13:49:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 110658.211228; Wed, 14 Apr 2021 13:49:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lWftA-0005Qq-QB; Wed, 14 Apr 2021 13:49:04 +0000 Received: by outflank-mailman (input) for mailman id 110658; Wed, 14 Apr 2021 13:49:04 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lWftA-0005Qj-6l for xen-devel@lists.xenproject.org; Wed, 14 Apr 2021 13:49:04 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 37e6e066-d268-4e71-ba80-bba9dd57ddc6; Wed, 14 Apr 2021 13:49:03 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 62BD3AFD2; Wed, 14 Apr 2021 13:49:02 +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: 37e6e066-d268-4e71-ba80-bba9dd57ddc6 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1618408142; h=from:from:reply-to: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=oRPq2/vYACH6nua6suekQSNoK5M+eBcLDGoKFsrwq/4=; b=ggzKMge9FhetJABKNbrMfpDUJxjKIztlro9o0P63vN1EPku6lU6ByDgTc/7r85H1H2Cl5x 5yQjS8PX6ZrFJcEdxKuD+LGqy+dK/YbA0TEgS+u61ai7uXfNSv+qqbWGukdq61phjJF5pC lAo1U01NQuio7mSfxlrD7WptuH5t2Fg= Subject: Re: [PATCH v2 15/21] libs/guest: obtain a compatible cpu policy from two input ones To: Roger Pau Monne Cc: Andrew Cooper , Ian Jackson , Wei Liu , Anthony PERARD , xen-devel@lists.xenproject.org References: <20210413140140.73690-1-roger.pau@citrix.com> <20210413140140.73690-16-roger.pau@citrix.com> From: Jan Beulich Message-ID: <391b56d0-bb4d-8d3c-231c-e2e3ad7e2f42@suse.com> Date: Wed, 14 Apr 2021 15:49:02 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 In-Reply-To: <20210413140140.73690-16-roger.pau@citrix.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 13.04.2021 16:01, Roger Pau Monne wrote: > @@ -944,3 +945,130 @@ bool xc_cpu_policy_is_compatible(xc_interface *xch, const xc_cpu_policy_t host, > > return false; > } > + > +static uint64_t level_msr(unsigned int index, uint64_t val1, uint64_t val2) > +{ > + uint64_t val = val1 & val2;; For arbitrary MSRs this isn't going to do any good. If only very specific MSRs are assumed to make it here, I think this wants commenting on. Also, nit: stray semicolon. > + switch ( index ) > + { > + case MSR_ARCH_CAPABILITIES: > + /* > + * Set RSBA if present on any of the input values to notice the guest > + * might run on vulnerable hardware at some point. > + */ > + val |= (val1 | val2) & ARCH_CAPS_RSBA; > + break; > + } > + > + return val; > +} > + > +static bool level_leaf(xen_cpuid_leaf_t *l1, xen_cpuid_leaf_t *l2, const (twice)? > + xen_cpuid_leaf_t *out) > +{ > + *out = (xen_cpuid_leaf_t){ }; > + > + switch ( l1->leaf ) > + { > + case 0x1: > + case 0x80000001: > + out->c = l1->c & l2->c; > + out->d = l1->d & l2->d; > + return true; > + > + case 0xd: > + if ( l1->subleaf != 1 ) > + break; > + out->a = l1->a & l2->a; > + return true; Could you explain your thinking behind this (a code comment would likely help)? You effectively discard everything except subleaf 1 by returning false in that case, don't you? > + case 0x7: > + switch ( l1->subleaf ) > + { > + case 0: > + out->b = l1->b & l2->b; > + out->c = l1->c & l2->c; > + out->d = l1->d & l2->d; > + return true; > + > + case 1: > + out->a = l1->a & l2->a; > + return true; > + } > + break; Can we perhaps assume all subleaves here are going to hold flags, and hence and both sides together without regard to what subleaf we're actually dealing with (subleaf 1 remaining special as to EAX of course)? This would avoid having to remember to make yet another mechanical change when enabling a new subleaf. > + case 0x80000007: > + out->d = l1->d & l2->d; > + return true; > + > + case 0x80000008: > + out->b = l1->b & l2->b; > + return true; > + } > + > + return false; > +} Considering your LFENCE-always-serializing patch, I assume whichever ends up going in last will take care of adding handling of that leaf here? Jan