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.7 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,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 242FFC07E99 for ; Mon, 12 Jul 2021 08:33:44 +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 C8BC160FDB for ; Mon, 12 Jul 2021 08:33:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C8BC160FDB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.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.154406.285334 (Exim 4.92) (envelope-from ) id 1m2rNK-0003Rv-P9; Mon, 12 Jul 2021 08:33:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 154406.285334; Mon, 12 Jul 2021 08:33:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1m2rNK-0003Rn-II; Mon, 12 Jul 2021 08:33:14 +0000 Received: by outflank-mailman (input) for mailman id 154406; Mon, 12 Jul 2021 08:33:13 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1m2rNJ-0003Rh-1g for xen-devel@lists.xenproject.org; Mon, 12 Jul 2021 08:33:13 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1m2rNH-0001Hx-RI; Mon, 12 Jul 2021 08:33:11 +0000 Received: from [54.239.6.189] (helo=a483e7b01a66.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m2rNH-0001nh-Kq; Mon, 12 Jul 2021 08:33:11 +0000 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" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject; bh=kUuvFVs03oX1CwJf7o+7+AnKIVzAVyJW/GEjOCD5gd8=; b=L5NSpSIbPt6In0w1akNZ5ZoH1d KX1OB5vYTZJ2bUWzolZ6pTTr2RTdtQNURDLkGOj48wm7zZwRGvXQdMqxpbk5uT/OQcqxKipDXAlPh uSwghDmu7oaPI5keshWsATzh2kyabFQFQABIk9KnqRN5pTcBlD59mG8cJ4/PB8qXdKK4=; Subject: Re: [PATCH v2] xen/arm64: Remove READ/WRITE_SYSREG32 helper macros To: Michal Orzel , 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: Julien Grall Message-ID: Date: Mon, 12 Jul 2021 09:33:09 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <076a6500-2471-c834-97b9-547e3cf3e3b2@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 8bit 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, -- Julien Grall