From mboxrd@z Thu Jan 1 00:00:00 1970 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=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 0453EC4361B for ; Fri, 4 Dec 2020 23:57:51 +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 B79A622581 for ; Fri, 4 Dec 2020 23:57:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B79A622581 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org 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.45129.80618 (Exim 4.92) (envelope-from ) id 1klKxI-00038z-6I; Fri, 04 Dec 2020 23:57:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 45129.80618; Fri, 04 Dec 2020 23:57:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1klKxI-00038s-3H; Fri, 04 Dec 2020 23:57:40 +0000 Received: by outflank-mailman (input) for mailman id 45129; Fri, 04 Dec 2020 23:57:38 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1klKxG-00038n-T1 for xen-devel@lists.xenproject.org; Fri, 04 Dec 2020 23:57:38 +0000 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 48ed7307-cfde-4bf3-b860-1304d03df2a9; Fri, 04 Dec 2020 23:57:38 +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: 48ed7307-cfde-4bf3-b860-1304d03df2a9 Date: Fri, 4 Dec 2020 15:57:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1607126257; bh=5h37HYw38QL1InbByuCWEuuiG/Y2OGL9FZe2XfEIETo=; h=From:To:cc:Subject:In-Reply-To:References:From; b=KZ0NhyrsVXbfPNDqjW0roWv56n5aXd3VB93jD5XQbURqEi7v88xn25EroTTWkKq7h KfJQaBaRBlKtEcxsjz3FNcs8nPnPHt0eJnUdciqlg0W52XypwiDSxbgTJhNJL9N2UC 25B7fwuZV4fG5CdmzBbX+lEr92iPyZHBPlSr6uSF8lcoxTUQ4BdhlP7yHKD+oDt1W+ wrICrUMTzoROy4zshk6la5MYGmUQoPjaxY5oEnfJ63/gXRlEmVlfH2xWWtAicVeRZP QHZtgFRSkmZW5t84vUTw/DzE7kiprmnIX9BJQworvf8wYWXOX5AXws3BW5gWRLDIT3 dAorYU4rvNVoQ== From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-T480s To: Bertrand Marquis cc: xen-devel@lists.xenproject.org, Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: Re: [PATCH v2 3/7] xen/arm: create a cpuinfo structure for guest In-Reply-To: <539cc9c817a80e35a2532dba5bc01e9b2533ff56.1606742184.git.bertrand.marquis@arm.com> Message-ID: References: <539cc9c817a80e35a2532dba5bc01e9b2533ff56.1606742184.git.bertrand.marquis@arm.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII On Mon, 30 Nov 2020, Bertrand Marquis wrote: > Create a cpuinfo structure for guest and mask into it the features that > we do not support in Xen or that we do not want to publish to guests. > > Modify some values in the cpuinfo structure for guests to mask some > features which we do not want to allow to guests (like AMU) or we do not > support (like SVE). The first two sentences seem to say the same thing in two different ways. > The code is trying to group together registers modifications for the > same feature to be able in the long term to easily enable/disable a > feature depending on user parameters or add other registers modification > in the same place (like enabling/disabling HCR bits). > > Signed-off-by: Bertrand Marquis > --- > Changes in V2: rebase > --- > xen/arch/arm/cpufeature.c | 51 ++++++++++++++++++++++++++++++++ > xen/include/asm-arm/cpufeature.h | 2 ++ > 2 files changed, 53 insertions(+) > > diff --git a/xen/arch/arm/cpufeature.c b/xen/arch/arm/cpufeature.c > index 204be9b084..309941ff37 100644 > --- a/xen/arch/arm/cpufeature.c > +++ b/xen/arch/arm/cpufeature.c > @@ -24,6 +24,8 @@ > > DECLARE_BITMAP(cpu_hwcaps, ARM_NCAPS); > > +struct cpuinfo_arm __read_mostly guest_cpuinfo; > + > void update_cpu_capabilities(const struct arm_cpu_capabilities *caps, > const char *info) > { > @@ -156,6 +158,55 @@ void identify_cpu(struct cpuinfo_arm *c) > #endif > } > > +/* > + * This function is creating a cpuinfo structure with values modified to mask > + * all cpu features that should not be published to guest. > + * The created structure is then used to provide ID registers values to guests. > + */ > +static int __init create_guest_cpuinfo(void) > +{ > + /* > + * TODO: The code is currently using only the features detected on the boot > + * core. In the long term we should try to compute values containing only > + * features supported by all cores. > + */ > + identify_cpu(&guest_cpuinfo); Given that we already have boot_cpu_data and current_cpu_data, which should be already initialized at this point, we could simply: guest_cpuinfo = current_cpu_data; or guest_cpuinfo = boot_cpu_data; ? > +#ifdef CONFIG_ARM_64 > + /* Disable MPAM as xen does not support it */ > + guest_cpuinfo.pfr64.mpam = 0; > + guest_cpuinfo.pfr64.mpam_frac = 0; > + > + /* Disable SVE as Xen does not support it */ > + guest_cpuinfo.pfr64.sve = 0; > + guest_cpuinfo.zfr64.bits[0] = 0; > + > + /* Disable MTE as Xen does not support it */ > + guest_cpuinfo.pfr64.mte = 0; > +#endif > + > + /* Disable AMU */ > +#ifdef CONFIG_ARM_64 > + guest_cpuinfo.pfr64.amu = 0; > +#endif > + guest_cpuinfo.pfr32.amu = 0; > + > + /* Disable RAS as Xen does not support it */ > +#ifdef CONFIG_ARM_64 > + guest_cpuinfo.pfr64.ras = 0; > + guest_cpuinfo.pfr64.ras_frac = 0; > +#endif > + guest_cpuinfo.pfr32.ras = 0; > + guest_cpuinfo.pfr32.ras_frac = 0; > + > + return 0; > +} > +/* > + * This function needs to be run after all smp are started to have > + * cpuinfo structures for all cores. > + */ > +__initcall(create_guest_cpuinfo); > + > /* > * Local variables: > * mode: C > diff --git a/xen/include/asm-arm/cpufeature.h b/xen/include/asm-arm/cpufeature.h > index 64354c3f19..0ab6dd42a0 100644 > --- a/xen/include/asm-arm/cpufeature.h > +++ b/xen/include/asm-arm/cpufeature.h > @@ -290,6 +290,8 @@ extern void identify_cpu(struct cpuinfo_arm *); > extern struct cpuinfo_arm cpu_data[]; > #define current_cpu_data cpu_data[smp_processor_id()] > > +extern struct cpuinfo_arm guest_cpuinfo; > + > #endif /* __ASSEMBLY__ */ > > #endif > -- > 2.17.1 >