[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] xen/printk: Avoid the use of L as a length modifier


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 24 Jul 2024 09:34:26 +0200
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Roger Pau Monné <roger.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 24 Jul 2024 07:34:37 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 23.07.2024 19:41, Andrew Cooper wrote:
> Coverity complains about it being invalid.  It turns out that it is a GCC-ism
> to treat ll and L equivalently.  C99 only permits L to mean long double.
> 
> Convert all uses of L in to alternatives, either l, ll or PRI.64 depending on
> the operand type.  This in turn removes some unnecessary casts which look to
> predate us having correct PRI* constants.

I'm certainly okay with switching to PRI.64 where appropriate. Switching to ll,
however, means longer string literals for no really good reason. We use all
sorts of GCC / GNU extensions; I don't see why we shouldn't be permitted to
also use this one. It's Coverity that wants to cope, imo.

Or, if we really meant to no longer use L, support for it should then imo also
be purged from vsnprintf().

> I'm disappointed at having to use %ll for __fix_to_virt() in apic.c and
> io_apic.c.  The expression ends up ULL because of the GB(64) in VMAP_VIRT_END,
> but can't really be changed without breaking 32bit builds of Xen.
> 
> One option might be to turn __fix_to_virt() into a proper function, but
> there's a lot of that infrastructure which should be dedup'd and not left to
> each arch to copy.

Maybe it doesn't need us going that far, as ...

> --- a/xen/arch/x86/apic.c
> +++ b/xen/arch/x86/apic.c
> @@ -938,7 +938,7 @@ void __init init_apic_mappings(void)
>          apic_phys = mp_lapic_addr;
>  
>      set_fixmap_nocache(FIX_APIC_BASE, apic_phys);
> -    apic_printk(APIC_VERBOSE, "mapped APIC to %08Lx (%08lx)\n", APIC_BASE,
> +    apic_printk(APIC_VERBOSE, "mapped APIC to %08llx (%08lx)\n", APIC_BASE,
>                  apic_phys);

... I wonder why we use __fix_to_virt() for APIC_BASE in the first place.
Using fix_to_virt() would look to be more logical, as all users cast to
a pointer anyway. Then it could simply be %p here.

> --- a/xen/arch/x86/cpu/intel.c
> +++ b/xen/arch/x86/cpu/intel.c
> @@ -441,7 +441,7 @@ static void intel_log_freq(const struct cpuinfo_x86 *c)
>              unsigned long long val = ecx;
>  
>              val *= ebx;
> -            printk("CPU%u: TSC: %u Hz * %u / %u = %Lu Hz\n",
> +            printk("CPU%u: TSC: %u Hz * %u / %u = %llu Hz\n",
>                     smp_processor_id(), ecx, ebx, eax, val / eax);
>          }

Maybe change val to be uint64_t instead? That's against what ./CODING_STYLE
calls for, but would be for a reason (to be able to use PRIu64) here.

> --- a/xen/arch/x86/cpu/mcheck/vmce.c
> +++ b/xen/arch/x86/cpu/mcheck/vmce.c
> @@ -71,7 +71,7 @@ int vmce_restore_vcpu(struct vcpu *v, const struct 
> hvm_vmce_vcpu *ctxt)
>      if ( ctxt->caps & ~guest_mcg_cap & ~MCG_CAP_COUNT & ~MCG_CTL_P )
>      {
>          printk(XENLOG_G_ERR
> -               "%s restore: unsupported MCA capabilities %#"PRIx64" for %pv 
> (supported: %#Lx)\n",
> +               "%s restore: unsupported MCA capabilities %#"PRIx64" for %pv 
> (supported: %#llx)\n",
>                  is_hvm_vcpu(v) ? "HVM" : "PV", ctxt->caps,
>                  v, guest_mcg_cap & ~MCG_CAP_COUNT);

guest_mcg_cap is unsigned long and MCG_CAP_COUNT could as well use UL instead
of ULL, couldn't it?

> --- a/xen/arch/x86/hvm/vmx/vmcs.c
> +++ b/xen/arch/x86/hvm/vmx/vmcs.c
> @@ -517,7 +517,7 @@ static int vmx_init_vmcs_config(bool bsp)
>          if ( (vmx_basic_msr_high & (VMX_BASIC_VMCS_SIZE_MASK >> 32)) >
>               PAGE_SIZE )
>          {
> -            printk("VMX: CPU%d VMCS size is too big (%Lu bytes)\n",
> +            printk("VMX: CPU%d VMCS size is too big (%llu bytes)\n",
>                     smp_processor_id(),
>                     vmx_basic_msr_high & (VMX_BASIC_VMCS_SIZE_MASK >> 32));
>              return -EINVAL;
> @@ -564,7 +564,7 @@ static int vmx_init_vmcs_config(bool bsp)
>          if ( (vmx_basic_msr_high & (VMX_BASIC_VMCS_SIZE_MASK >> 32)) !=
>               ((vmx_basic_msr & VMX_BASIC_VMCS_SIZE_MASK) >> 32) )
>          {
> -            printk("VMX: CPU%d unexpected VMCS size %Lu\n",
> +            printk("VMX: CPU%d unexpected VMCS size %llu\n",
>                     smp_processor_id(),
>                     vmx_basic_msr_high & (VMX_BASIC_VMCS_SIZE_MASK >> 32));
>              mismatch = 1;

Same here for VMX_BASIC_VMCS_SIZE_MASK. We leverage not doing 32-bit builds
anymore in exactly this way elsewhere.

> --- a/xen/arch/x86/io_apic.c
> +++ b/xen/arch/x86/io_apic.c
> @@ -2597,7 +2597,7 @@ static void __init ioapic_init_mappings(void)
>          }
>  
>          set_fixmap_nocache(idx, ioapic_phys);
> -        apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08Lx (%08lx)\n",
> +        apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08llx (%08lx)\n",
>                      __fix_to_virt(idx), ioapic_phys);

Like above, switch to using fix_to_virt() and %p?

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.