From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.120]) by mx.groups.io with SMTP id smtpd.web12.6510.1580736164216450889 for ; Mon, 03 Feb 2020 05:22:44 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TgRhgV14; spf=pass (domain: redhat.com, ip: 207.211.31.120, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580736163; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fayatYBeAYOl+P9l4g2auRyNwRm+KCgIn/XIh3kosME=; b=TgRhgV14F8WBhqe0xYyJWaQ48Xr6lkbaKeqXJ2ynW1Csogw8qrd7XTm/bat6qNtDYIiNF4 /6qWDYA65qKn/1kLxdsJhUVJF11uC8cvRnTkWGF160ssN8PbsfxoHcfj3kFYNEBFJgEHEZ QJS/1zIEpSKCwe8BLXoRRuXvZ4CeBUo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-73-EMGebOzjPwuM9r0m2R-ABg-1; Mon, 03 Feb 2020 08:22:39 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0CFBB100550E; Mon, 3 Feb 2020 13:22:38 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id D41BD10013A7; Mon, 3 Feb 2020 13:22:36 +0000 (UTC) Subject: Re: [PATCH] UefiCpuPkg RegisterCpuFeaturesLib: Use %08x to print CacheControl Index To: "Zeng, Star" , "devel@edk2.groups.io" Cc: "Dong, Eric" , "Ni, Ray" References: <20200203070631.14332-1-star.zeng@intel.com> <3bf7a886-205b-957b-6573-9fa6f04c169e@redhat.com> <0C09AFA07DD0434D9E2A0C6AEB048310405354A4@shsmsx102.ccr.corp.intel.com> From: "Laszlo Ersek" Message-ID: Date: Mon, 3 Feb 2020 14:22:35 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <0C09AFA07DD0434D9E2A0C6AEB048310405354A4@shsmsx102.ccr.corp.intel.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: EMGebOzjPwuM9r0m2R-ABg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 02/03/20 10:09, Zeng, Star wrote: >> -----Original Message----- >> From: Laszlo Ersek >> Sent: Monday, February 3, 2020 4:47 PM >> To: Zeng, Star ; devel@edk2.groups.io >> Cc: Dong, Eric ; Ni, Ray >> Subject: Re: [PATCH] UefiCpuPkg RegisterCpuFeaturesLib: Use %08x to prin= t >> CacheControl Index >> >> Hello Star, >> >> On 02/03/20 08:06, Star Zeng wrote: >>> Instead of %08lx, use %08x to print CacheControl Index as it is UINT32 >>> type. >>> >>> Cc: Eric Dong >>> Cc: Ray Ni >>> Cc: Laszlo Ersek >>> Signed-off-by: Star Zeng >>> --- >>> .../Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git >>> a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c >>> b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c >>> index 0a4fcff033a3..1a02809b0e7c 100644 >>> --- >>> a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c >>> +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize. >>> +++ c >>> @@ -465,7 +465,7 @@ DumpRegisterTableOnProcessor ( >>> case CacheControl: >>> DEBUG (( >>> DebugPrintErrorLevel, >>> - "Processor: %04d: Index %04d, CACHE: %08lx, Bit Start: %02d, >> Bit Length: %02d, Value: %016lx\r\n", >>> + "Processor: %04d: Index %04d, CACHE: %08x, Bit Start: %02d, >>> + Bit Length: %02d, Value: %016lx\r\n", >>> ProcessorNumber, >>> FeatureIndex, >>> RegisterTableEntry->Index, >>> >> >> if you are already touching this DEBUG invocation, can you please fix th= e >> rest of the issues with the format string? >> >> - ProcessorNumber is UINTN. If we know for sure it can be represented in= a >> UINT32, then it should be cast to UINT32 explicitly, and logged with "%0= 4u". >> (Otherwise, UINTN needs to be cast to UINT64, and logged with %lu or %lx= .) >> >> - Ditto for FeatureIndex. >=20 > %04u or %04d is not enough for UINT32 which needs %08x. > I thought the code is just taking assumption about their value should be = not > 9999u. It is not a real issue. I disagree. It's not about the field width / padding (4 vs. 8 characters), but the width of the data type. The parameter that's being passed is a UINTN, which is UINT64 on X64. But the format specifier (%d, %u, %x all alike) only expect a UINT32. If we pass a UINT64 (in the form of a UINTN), then we should print it with a UINT64 specifier (such as %lu or %lx). Alternatively, if we know for sure that the value of the UINT64 in question will fit in a UINT32, then we can use %u or %x for printing, but then we need to truncate (cast) the data that's being passed in, to UINT32. My point is that the data size should be a match between what's passed in and what is described with a format specifier. There is no format specifier that directly matches UINTN, so you either need to cast UINTN to UINT64 and use %lx, or cast UINTN to UINT32 and use %x. >=20 > This patch is to fix a real issue, without it, the print for ValidBitStar= t, ValidBitLength and Value will be wrong because the parameter for them ar= e shifted for Index to fetch UINT64 value. The patch is not wrong, it's just incomplete (given that we're modifying a format string that mismatches the argument list in other places too). ProcessorNumber and FeatureIndex are UINTNs, and they are being printed with %d. Those are real issues too. > I found another real issue is MMIO : %08lx should be MMIO : %016lx as the= code is on purpose to get UINT64 MMIO address. Field width / padding are useful to get right, but getting the data types to match is even more important. Thanks Laszlo > I prefer to just handle the real issue in this patch. How do you think? = =F0=9F=98=8A