All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ayan Kumar Halder <ayankuma@amd.com>
To: Julien Grall <julien@xen.org>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Ayan Kumar Halder <ayan.kumar.halder@amd.com>
Cc: xen-devel@lists.xenproject.org, stefano.stabellini@amd.com,
	Volodymyr_Babchuk@epam.com, bertrand.marquis@arm.com
Subject: Re: [XEN v2 05/11] xen/arm: Use paddr_t instead of u64 for address/size
Date: Tue, 7 Feb 2023 10:59:11 +0000	[thread overview]
Message-ID: <a741c812-0161-e6a2-8057-7e22d36ea5d9@amd.com> (raw)
In-Reply-To: <4f98390c-1cf3-99f3-5131-a42a7ed4387a@xen.org>

Hi Julien,

On 07/02/2023 09:03, Julien Grall wrote:
>
>
> On 06/02/2023 19:21, Ayan Kumar Halder wrote:
>> Hi Stefano,
>>
>> On 19/01/2023 23:24, Stefano Stabellini wrote:
>>> On Tue, 17 Jan 2023, Ayan Kumar Halder wrote:
>>>> One should now be able to use 'paddr_t' to represent address and size.
>>>> Consequently, one should use 'PRIpaddr' as a format specifier for 
>>>> paddr_t.
>>>>
>>>> Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
>>>> ---
>>>>
>>>> Changes from -
>>>>
>>>> v1 - 1. Rebased the patch.
>>>>
>>>>   xen/arch/arm/domain_build.c        |  9 +++++----
>>>>   xen/arch/arm/gic-v3.c              |  2 +-
>>>>   xen/arch/arm/platforms/exynos5.c   | 26 +++++++++++++-------------
>>>>   xen/drivers/char/exynos4210-uart.c |  2 +-
>>>>   xen/drivers/char/ns16550.c         |  8 ++++----
>>>>   xen/drivers/char/omap-uart.c       |  2 +-
>>>>   xen/drivers/char/pl011.c           |  4 ++--
>>>>   xen/drivers/char/scif-uart.c       |  2 +-
>>>>   xen/drivers/passthrough/arm/smmu.c |  6 +++---
>>>>   9 files changed, 31 insertions(+), 30 deletions(-)
>>>>
>>>> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
>>>> index 72b9afbb4c..cf8ae37a14 100644
>>>> --- a/xen/arch/arm/domain_build.c
>>>> +++ b/xen/arch/arm/domain_build.c
>>>> @@ -1666,7 +1666,7 @@ static int __init find_memory_holes(const 
>>>> struct kernel_info *kinfo,
>>>>       dt_for_each_device_node( dt_host, np )
>>>>       {
>>>>           unsigned int naddr;
>>>> -        u64 addr, size;
>>>> +        paddr_t addr, size;
>>>>           naddr = dt_number_of_address(np);
>>>> @@ -2445,7 +2445,7 @@ static int __init handle_device(struct domain 
>>>> *d, struct dt_device_node *dev,
>>>>       unsigned int naddr;
>>>>       unsigned int i;
>>>>       int res;
>>>> -    u64 addr, size;
>>>> +    paddr_t addr, size;
>>>>       bool own_device = !dt_device_for_passthrough(dev);
>>>>       /*
>>>>        * We want to avoid mapping the MMIO in dom0 for the 
>>>> following cases:
>>>> @@ -2941,9 +2941,10 @@ static int __init 
>>>> handle_passthrough_prop(struct kernel_info *kinfo,
>>>>           if ( res )
>>>>           {
>>>>               printk(XENLOG_ERR "Unable to permit to dom%d access to"
>>>> -                   " 0x%"PRIx64" - 0x%"PRIx64"\n",
>>>> +                   " 0x%"PRIpaddr" - 0x%"PRIpaddr"\n",
>>>>                      kinfo->d->domain_id,
>>>> -                   mstart & PAGE_MASK, PAGE_ALIGN(mstart + size) - 
>>>> 1);
>>>> +                   (paddr_t) (mstart & PAGE_MASK),
>>>> +                   (paddr_t) (PAGE_ALIGN(mstart + size) - 1));
>>> Why do you need the casts here? mstart is already defined as paddr_t
>>
>> Actually, this is because the PAGE_MASK is defined as 'long'. See 
>> xen/include/xen/page-size.h :-
>>
>> #define PAGE_SIZE           (_AC(1,L) << PAGE_SHIFT)
>> #define PAGE_MASK           (~(PAGE_SIZE-1))
>>
>> So, the resultant type inferred is 'long unsigned int'. Thus, we need 
>> to add an explicit cast.
>
> Hmmm... I am a bit confused with this statement. If the resultant type 
> inferred is actually 'long unsigned int', then why was the current 
> specifier worked before ('long unsigned int' is 32-bit on Arm32)?

Before this change, mstart was of type paddr_t (ie u64 ie unsigned long 
long on Arm_32). When 'unsigned long long' was operated with 'long' (ie 
PAGE_SIZE), then the resultant type is 'unsigned long long'. The rule 
from 'C Standard 2011' 
(https://web.cs.dal.ca/~vlado/pl/C_Standard_2011-n1570.pdf) , page 53 
(Section 6.3.1.8 Usual arithmetic conversions) is :-

"Otherwise, if the operand that has unsigned integer type has rank 
greater or equal to the rank of the type of the other operand, then the 
operand with signed integer type is converted to the type of the operand 
with unsigned integer type."

And from 6.3.1.1

"The rank of long long int shall be greater than the rank of long int, 
which shall be greater than the rank of int, which shall be greater than 
the rank of short int, which shall be greater than the rank of signed char.

The rank of any unsigned integer type shall equal the rank of the 
corresponding signed integer type, if any."

And using 'PRIx64' to print 'unsigned long long' will not require any cast.

Now with the change,
mstart is of paddr_t (ie 'unsigned int'). 'unsigned int' operated with 
'long', then  the result is 'unsigned long int'. As the rank of 
'unsigned long int' > 'int', thus it cannot be printed using PRIx32 
(integer format specifier) without an explicit cast.

Please let me know if this makes sense.

-Ayan
>
> Cheers,
>


  reply	other threads:[~2023-02-07 10:59 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-17 17:43 [XEN v2 00/11] Add support for 32 bit physical address Ayan Kumar Halder
2023-01-17 17:43 ` [XEN v2 01/11] xen/ns16550: Remove unneeded truncation check in the DT init code Ayan Kumar Halder
2023-01-17 17:43 ` [XEN v2 02/11] xen/arm: Use the correct format specifier Ayan Kumar Halder
2023-01-19 22:54   ` Stefano Stabellini
2023-01-20  9:32     ` Julien Grall
2023-01-20 11:09       ` Ayan Kumar Halder
2023-01-20 14:40       ` Michal Orzel
2023-01-20 15:09         ` Julien Grall
2023-01-20 16:03           ` Michal Orzel
2023-01-20 17:49             ` Julien Grall
2023-01-20 18:08               ` Ayan Kumar Halder
2023-01-20 23:01                 ` Stefano Stabellini
2023-01-21 10:24                   ` Michal Orzel
2023-01-17 17:43 ` [XEN v2 03/11] xen/arm: domain_build: Replace use of paddr_t in find_domU_holes() Ayan Kumar Halder
2023-01-19 23:02   ` Stefano Stabellini
2023-01-20  9:48     ` Julien Grall
2023-01-20  9:52       ` Julien Grall
2023-01-17 17:43 ` [XEN v2 04/11] xen/arm: Typecast the DT values into paddr_t Ayan Kumar Halder
2023-01-19 23:20   ` Stefano Stabellini
2023-01-19 23:34     ` Stefano Stabellini
2023-01-20 10:16       ` Julien Grall
2023-01-31 10:51         ` Ayan Kumar Halder
2023-01-31 15:57           ` Julien Grall
2023-01-17 17:43 ` [XEN v2 05/11] xen/arm: Use paddr_t instead of u64 for address/size Ayan Kumar Halder
2023-01-18  8:40   ` Jan Beulich
2023-01-18 11:15     ` Ayan Kumar Halder
2023-01-18 13:14       ` Jan Beulich
2023-01-18 13:34         ` George Dunlap
2023-01-18 13:58           ` Jan Beulich
2023-01-18 14:45             ` George Dunlap
2023-01-19 23:24   ` Stefano Stabellini
2023-02-06 19:21     ` Ayan Kumar Halder
2023-02-07  9:03       ` Julien Grall
2023-02-07 10:59         ` Ayan Kumar Halder [this message]
2023-02-07 12:18           ` Julien Grall
2023-01-20 10:34   ` Julien Grall
2023-01-17 17:43 ` [XEN v2 06/11] xen/arm: Introduce a wrapper for dt_device_get_address() to handle paddr_t Ayan Kumar Halder
2023-01-19 23:35   ` Stefano Stabellini
2023-01-17 17:43 ` [XEN v2 07/11] xen/arm: smmu: Use writeq_relaxed_non_atomic() for writing to SMMU_CBn_TTBR0 Ayan Kumar Halder
2023-01-19 23:40   ` Stefano Stabellini
2023-01-17 17:43 ` [XEN v2 08/11] xen/arm: guest_walk: LPAE specific bits should be enclosed within "ifndef CONFIG_ARM_PA_32" Ayan Kumar Halder
2023-01-19 23:43   ` Stefano Stabellini
2023-01-20 10:39     ` Julien Grall
2023-01-17 17:43 ` [XEN v2 09/11] xen/arm: Introduce ARM_PA_32 to support 32 bit physical address Ayan Kumar Halder
2023-01-18  8:50   ` Jan Beulich
2023-01-18 11:57     ` Ayan Kumar Halder
2023-01-18 13:19       ` Jan Beulich
2023-01-19 23:48         ` Stefano Stabellini
2023-01-18  9:18   ` Julien Grall
2023-01-30 22:00   ` Julien Grall
2023-01-17 17:43 ` [XEN v2 10/11] xen/arm: Restrict zeroeth_table_offset for ARM_64 Ayan Kumar Halder
2023-01-20  0:19   ` Stefano Stabellini
2023-01-20 10:53     ` Julien Grall
2023-01-20 16:53       ` Stefano Stabellini
2023-01-17 17:43 ` [XEN v2 11/11] xen/arm: p2m: Enable support for 32bit IPA Ayan Kumar Halder
2023-01-20  0:05   ` Stefano Stabellini
2023-01-20 11:06   ` Julien Grall
2023-02-07 15:34     ` Ayan Kumar Halder
2023-02-09 11:45       ` Julien Grall
2023-02-10 15:39         ` Ayan Kumar Halder
2023-02-10 16:19           ` Julien Grall
2023-02-10 17:51             ` Ayan Kumar Halder
2023-02-10 17:58               ` Julien Grall
2023-01-18 10:12 ` [XEN v2 00/11] Add support for 32 bit physical address Michal Orzel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a741c812-0161-e6a2-8057-7e22d36ea5d9@amd.com \
    --to=ayankuma@amd.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=ayan.kumar.halder@amd.com \
    --cc=bertrand.marquis@arm.com \
    --cc=julien@xen.org \
    --cc=sstabellini@kernel.org \
    --cc=stefano.stabellini@amd.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.