[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 8 Sep 2022 18:55:53 -0700
From: Sathyanarayanan Kuppuswamy
<sathyanarayanan.kuppuswamy@...ux.intel.com>
To: Wander Lairson Costa <wander@...hat.com>
Cc: Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
Shuah Khan <shuah@...nel.org>,
"H . Peter Anvin" <hpa@...or.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Kirill A . Shutemov" <kirill.shutemov@...ux.intel.com>,
Tony Luck <tony.luck@...el.com>,
Andi Kleen <ak@...ux.intel.com>,
Kai Huang <kai.huang@...el.com>,
Isaku Yamahata <isaku.yamahata@...il.com>,
marcelo.cerri@...onical.com, tim.gardner@...onical.com,
khalid.elmously@...onical.com, philip.cox@...onical.com,
linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org,
linux-doc@...r.kernel.org
Subject: Re: [PATCH v12 2/3] selftests: tdx: Test TDX attestation GetReport
support
On 9/8/22 7:16 AM, Wander Lairson Costa wrote:
> You can unconditionally define print_array_hex, and
> use `if (DEBUG)` instead of #ifdef `DEBUG here`. The compiler
> will get rid of the unused code when DEBUG is not defined
> as expected, but you get the parser to validate it
> independent of the definition of DEBUG.
To avoid #ifdef DEBUG in multiple places, we can try following
change. Let me know your comments.
--- a/tools/testing/selftests/tdx/tdx_attest_test.c
+++ b/tools/testing/selftests/tdx/tdx_attest_test.c
@@ -21,6 +21,14 @@
#define HEX_DUMP_SIZE 8
#define __packed __attribute__((packed))
+static inline int _no_printf(const char *format, ...) { return 0; }
+
+#ifdef DEBUG
+#define pr_debug(...) printf(__VA_ARGS__)
+#else
+#define pr_debug(...) _no_printf(__VA_ARGS__)
+#endif
+
/*
* Trusted Execution Environment (TEE) report (TDREPORT_STRUCT) type,
* sub type and version. More details can be found in TDX v1.0 Module
@@ -90,7 +98,6 @@ struct tdreport {
struct td_info tdinfo;
} __packed;
-#ifdef DEBUG
static void print_array_hex(const char *title, const char *prefix_str,
const void *buf, int len)
{
@@ -100,17 +107,16 @@ static void print_array_hex(const char *title, const char *prefix_str,
if (!len || !buf)
return;
- printf("\t\t%s", title);
+ pr_debug("\t\t%s", title);
for (i = 0; i < len; i++) {
if (!(i % rowsize))
- printf("\n%s%.8x:", prefix_str, i);
- printf(" %.2x", ptr[i]);
+ pr_debug("\n%s%.8x:", prefix_str, i);
+ pr_debug(" %.2x", ptr[i]);
}
- printf("\n");
+ pr_debug("\n");
}
-#endif
TEST(verify_report)
{
@@ -139,13 +145,11 @@ TEST(verify_report)
/* Get TDREPORT */
ASSERT_EQ(0, ioctl(devfd, TDX_CMD_GET_REPORT, &req));
-#ifdef DEBUG
print_array_hex("\n\t\tTDX report data\n", "",
reportdata, sizeof(reportdata));
print_array_hex("\n\t\tTDX tdreport data\n", "",
&tdreport, sizeof(tdreport));
-#endif
/* Make sure TDREPORT data includes the REPORTDATA passed */
ASSERT_EQ(0, memcmp(&tdreport.reportmac.reportdata[0],
--
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
Powered by blists - more mailing lists