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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, 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 93735C07E99 for ; Mon, 12 Jul 2021 08:47:15 +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 5920A60FEF for ; Mon, 12 Jul 2021 08:47:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5920A60FEF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.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.154420.285355 (Exim 4.92) (envelope-from ) id 1m2rai-0005dc-4t; Mon, 12 Jul 2021 08:47:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 154420.285355; Mon, 12 Jul 2021 08:47: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 1m2rai-0005dV-1T; Mon, 12 Jul 2021 08:47:04 +0000 Received: by outflank-mailman (input) for mailman id 154420; Mon, 12 Jul 2021 08:47:02 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1m2rag-0005dN-Ih for xen-devel@lists.xenproject.org; Mon, 12 Jul 2021 08:47:02 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id b94ae67a-e2ed-11eb-86d8-12813bfff9fa; Mon, 12 Jul 2021 08:47:00 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 81A321FB; Mon, 12 Jul 2021 01:47:00 -0700 (PDT) Received: from [10.57.1.228] (unknown [10.57.1.228]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8E4643F694; Mon, 12 Jul 2021 01:46:59 -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: b94ae67a-e2ed-11eb-86d8-12813bfff9fa Subject: Re: [PATCH v2] xen/arm64: Remove READ/WRITE_SYSREG32 helper macros To: Julien Grall , xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Volodymyr Babchuk , bertrand.marquis@arm.com References: <20210709124035.5520-1-michal.orzel@arm.com> <24141b99-a4a2-80f2-1cca-4f86ebc90d94@xen.org> <076a6500-2471-c834-97b9-547e3cf3e3b2@arm.com> From: Michal Orzel Message-ID: Date: Mon, 12 Jul 2021 10:46:50 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit On 12.07.2021 10:33, Julien Grall wrote: > > > On 12/07/2021 07:26, Michal Orzel wrote: >> Hi Julien, > > Hi Michal, > >> On 09.07.2021 17:21, Julien Grall wrote: >>> Hi Michal, >>> >>> On 09/07/2021 13:40, Michal Orzel wrote: >>>> AArch64 system registers are 64bit whereas AArch32 ones >>>> are 32bit or 64bit. MSR/MRS are expecting 64bit values thus >>>> we should get rid of helpers READ/WRITE_SYSREG32 >>>> in favour of using READ/WRITE_SYSREG. >>>> >>>> The last place in code making use of READ/WRITE_SYSREG32 >>>> on arm64 is in TVM_REG macro defining functions vreg_emulate_. >>>> Implement a macro WRITE_SYSREG_SZ which expands as follows: >>>> -on arm64: WRITE_SYSREG >>>> -on arm32: WRITE_SYSREG{32/64} >>>> >>>> As there are no other places in the code using these helpers >>>> on arm64 - remove them. >>>> >>>> Signed-off-by: Michal Orzel >>>> --- >>>> Changes since v1: >>>> -implement WRITE_SYSREG_SZ instead of duplicating the TVM_REG >>>> --- >>>>    xen/arch/arm/vcpreg.c               | 12 +++++++++++- >>>>    xen/include/asm-arm/arm64/sysregs.h |  4 ---- >>>>    2 files changed, 11 insertions(+), 5 deletions(-) >>>> >>>> diff --git a/xen/arch/arm/vcpreg.c b/xen/arch/arm/vcpreg.c >>>> index f0cdcc8a54..10c4846954 100644 >>>> --- a/xen/arch/arm/vcpreg.c >>>> +++ b/xen/arch/arm/vcpreg.c >>>> @@ -47,6 +47,16 @@ >>>>     * >>>>     */ >>>>    +#ifdef CONFIG_ARM_64 >>>> +#define WRITE_SYSREG_SZ(sz, val, sysreg)     WRITE_SYSREG(val, sysreg) >>> >>> I think you want to cast to (uint##sz##_t) to avoid any surprise. I think... >>> >> But the val will always be of type uint##sz##_t because it is passed from ... >>>> +#else >>>> +/* >>>> + * WRITE_SYSREG{32/64} on arm32 is defined as variadic macro which imposes >>>> + * on the below macro to be defined like that as well. >>>> + */ >>>> +#define WRITE_SYSREG_SZ(sz, val, sysreg...)  WRITE_SYSREG##sz(val, sysreg) >>>> +#endif >>>> + >>>>    /* The name is passed from the upper macro to workaround macro expansion. */ >>>>    #define TVM_REG(sz, func, reg...)                                           \ >>>>    static bool func(struct cpu_user_regs *regs, uint##sz##_t *r, bool read)    \ >>>> @@ -55,7 +65,7 @@ static bool func(struct cpu_user_regs *regs, uint##sz##_t *r, bool read)    \ >> ... here(*r argument). >> So I do not think that such casting makes sense e.g >> uint##sz##_t foo; >> WRITE_SYSREG((uint##sz##_t)foo, bar); > > I agree that this doesn't make sense for the *current* use. However, when writing code, we need to think how one could use it in the future... > > When I read the name, I would expect that if I call it with sz == 32, then bottom 32-bit value to be written and the top 32-bit zeroed. But this is not the case... > > You are relying on the developper and reviewer to notice that only 32-bit value should be passed when sz == 32. > > I am not particularly keen on relying on this when a simple cast could prevent any future misuse. Alternatively, I would be happy to consider checking the type of the value at build time. > > Cheers, > Ok, you are right that it does not cost much to add it, so let's stick with: #ifdef CONFIG_ARM_64 #define WRITE_SYSREG_SZ(sz, val, sysreg) WRITE_SYSREG((uint##sz##_t)val, sysreg) #else I will push v3 with this change. Cheers, Michal