Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1958685rwn; Fri, 9 Sep 2022 06:41:39 -0700 (PDT) X-Google-Smtp-Source: AA6agR53H+LWwsTTFKTMNUO40t1+8DqA1eHvCvcIP3r+PfLgTZT/bKkgP4qQmoPoiSV+lEVO8nxb X-Received: by 2002:a17:902:7d83:b0:170:9353:f299 with SMTP id a3-20020a1709027d8300b001709353f299mr13762452plm.41.1662730898747; Fri, 09 Sep 2022 06:41:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662730898; cv=none; d=google.com; s=arc-20160816; b=qJ9wKIzQeKzkRHcPgv8RoQISq8IHIovaorS939V/QtcDgZr/IveSkv8h7BENX/bVVH 3iUKUwjdwDzYIoOWxiPGGaqRxcAii4+ulyvRJiR6zDPcBChcoPnVWo9AX8axJhg2wU3X Kh+pAzTBAuMhKkdqLjfJ+dhSQgeE8uWVJjhODZkZk2GYrX1jk53QEOu1vAfBsuVPbaSZ oR+/HR9f/S16Q7NegPlizdN7VjzM5KH8ZsNc3NlwbRuGcttacRKvXu4VZ6Ysi44pLaWG N40xH+SqftB9b/PsFA61D96/ygdGNlFv4iBHoCuNdVseat6KbZwtEc7gl1YBAZWw1qFv TlIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=r+j5NRBRWTe4dwiHyAiQIy4Dst2HaG54q1byj2vgh9A=; b=iA7VlE+DDET+9bfXnmTtThgXrbBrG09Ia+nJGIsKZvhg/93tsUo+uf4aPQ/jv2lc1b 4fw36cdr/6+WZ075dxY55I8A6lNapGRUQTT6oBQAJUoHhjx5X3FZuuMfuAeBppsTaU0j ehx8MvTr36Yg7NFp15ldLKG7bZbWD4vn40DrwOpOEMndLmqsuwFyAryhXKRfzNHcY146 2qb9IU5RH8PZn52ONbixbpbJrR5B9Oto+pjCl5S25N82RD8uzoRDaMcm3ioeUTpfCcMh /eF49vUqaCTB7DEEHX8lgq0XT3hxdLfZq/fT9gysY6q8wyP2ePlY0g9P/OX3bANrhBGH 9w8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cRagtOr7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c19-20020a6566d3000000b0043855015f38si605660pgw.165.2022.09.09.06.41.25; Fri, 09 Sep 2022 06:41:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cRagtOr7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231202AbiIINgV (ORCPT + 99 others); Fri, 9 Sep 2022 09:36:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229598AbiIINgS (ORCPT ); Fri, 9 Sep 2022 09:36:18 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6FC9129C6D for ; Fri, 9 Sep 2022 06:36:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662730574; 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: in-reply-to:in-reply-to:references:references; bh=r+j5NRBRWTe4dwiHyAiQIy4Dst2HaG54q1byj2vgh9A=; b=cRagtOr7fsMrTdHyBAlsC9Zd3n0yeBcLIfkYYHUSTzgQckqFNOnXUavFvOn4FBgRCpk6f6 QmcfG5Yf1BEsXRlO+mcEqR3We/68lfn+oa9exTVgB591Bul9b01x74dTb5BrkT+1sX4xII 5gzGXzDa5FuTieWIQ9N1o4saneV3c6A= Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-160-sMbz1FYkOvWtcv2MYdgS_A-1; Fri, 09 Sep 2022 09:36:13 -0400 X-MC-Unique: sMbz1FYkOvWtcv2MYdgS_A-1 Received: by mail-pf1-f198.google.com with SMTP id f16-20020aa782d0000000b0053e242136bfso1114845pfn.0 for ; Fri, 09 Sep 2022 06:36:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=r+j5NRBRWTe4dwiHyAiQIy4Dst2HaG54q1byj2vgh9A=; b=5n6eaf+cuTXnGltLkZwIsDx+kY5XdR1VayUYG2X4wY/OqI7k+oUN0zfVk0H1C9dqGm 5diOCUVoSHG3JF7oSEHo70UNoDYJS3MgxKkOVp/hGRSWabcD2uXglUk+j8ykdBgTSRLL lArGYvHS81PEx8rxKzIfhLdX8FVbyU09XukExj5wzuE3zNDWATYzJwJ6SitXccaNIKt6 3qkdiRcIb0+aUdI0T5bhngH/aLceyh5tXhSjGHJIl66frFhUuJCG63zHFlkQj4stPxKK nhRHt4t4ps66EnvvV2sTNgawaMPh4eIjK45lm9RGlGEuXlSTQEy9BXjaesgGs3dHafZi SI2w== X-Gm-Message-State: ACgBeo3F7RBEJT3UQPXruh60CHokXwL7d/tmhzPBrT/zsdzPUSJexk9x L6WC81SeJa7EBNyEjAdQ9rnOefk40ZGib2I294bcUhrdt7sxV+AyPPrq5yf9G26qIKTc2q8vt5M hDi5dV8+0dWpquadHX1JcA4boTWjIns3buAb2b8w0 X-Received: by 2002:a63:f74c:0:b0:42b:77c2:ce7c with SMTP id f12-20020a63f74c000000b0042b77c2ce7cmr12592092pgk.473.1662730571985; Fri, 09 Sep 2022 06:36:11 -0700 (PDT) X-Received: by 2002:a63:f74c:0:b0:42b:77c2:ce7c with SMTP id f12-20020a63f74c000000b0042b77c2ce7cmr12592074pgk.473.1662730571756; Fri, 09 Sep 2022 06:36:11 -0700 (PDT) MIME-Version: 1.0 References: <20220908002723.923241-1-sathyanarayanan.kuppuswamy@linux.intel.com> <20220908002723.923241-3-sathyanarayanan.kuppuswamy@linux.intel.com> <23a76ce3-d568-3c73-eecc-fa499aeecfcd@linux.intel.com> In-Reply-To: <23a76ce3-d568-3c73-eecc-fa499aeecfcd@linux.intel.com> From: Wander Lairson Costa Date: Fri, 9 Sep 2022 10:36:00 -0300 Message-ID: Subject: Re: [PATCH v12 2/3] selftests: tdx: Test TDX attestation GetReport support To: Sathyanarayanan Kuppuswamy Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Shuah Khan , "H . Peter Anvin" , Greg Kroah-Hartman , "Kirill A . Shutemov" , Tony Luck , Andi Kleen , Kai Huang , Isaku Yamahata , marcelo.cerri@canonical.com, tim.gardner@canonical.com, khalid.elmously@canonical.com, philip.cox@canonical.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 8, 2022 at 8:45 PM Sathyanarayanan Kuppuswamy wrote: > > > > On 9/8/22 7:16 AM, Wander Lairson Costa wrote: > >> +#ifdef DEBUG > >> +static void print_array_hex(const char *title, const char *prefix_str, > >> + const void *buf, int len) > >> +{ > >> + const __u8 *ptr = buf; > >> + int i, rowsize = HEX_DUMP_SIZE; > >> + > >> + if (!len || !buf) > >> + return; > >> + > >> + printf("\t\t%s", title); > >> + > >> + for (i = 0; i < len; i++) { > >> + if (!(i % rowsize)) > >> + printf("\n%s%.8x:", prefix_str, i); > >> + printf(" %.2x", ptr[i]); > >> + } > >> + > >> + printf("\n"); > >> +} > >> +#endif > >> + > >> +TEST(verify_report) > >> +{ > >> + __u8 reportdata[TDX_REPORTDATA_LEN]; > >> + struct tdreport tdreport; > >> + struct tdx_report_req req; > >> + int devfd, i; > >> + > >> + devfd = open(TDX_GUEST_DEVNAME, O_RDWR | O_SYNC); > >> + > >> + ASSERT_LT(0, devfd); > >> + > >> + /* Generate sample report data */ > >> + for (i = 0; i < TDX_REPORTDATA_LEN; i++) > >> + reportdata[i] = i; > >> + > >> + /* Initialize IOCTL request */ > >> + req.subtype = 0; > >> + req.reportdata = (__u64)reportdata; > >> + req.rpd_len = TDX_REPORTDATA_LEN; > >> + req.tdreport = (__u64)&tdreport; > >> + req.tdr_len = sizeof(tdreport); > >> + > >> + /* 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 > > 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. > > Currently, DEBUG is a macro, so we cannot use if (DEBUG) directly. > You are suggesting to change DEBUG to a variable? Any reason to > make this change? I think both changes are functionally similar. > So I am wondering why to make this change? > My thought is always to define DEBUG. If in debug mode it is defined to 1; otherwise to 0. Then, you can use `if (DEBUG)` instead of `#ifdef DEBUG`. But the former will always check the syntax of the debug code, independent of the value of DEBUG, and the compiler will generate the same code. The GNU coding standard [1] explains that better than I do. [1] https://www.gnu.org/prep/standards/standards.html#Conditional-Compilation > > > > -- > Sathyanarayanan Kuppuswamy > Linux Kernel Developer >