Received: by 10.223.176.5 with SMTP id f5csp662885wra; Fri, 9 Feb 2018 05:19:38 -0800 (PST) X-Google-Smtp-Source: AH8x225nDB7V29cfZGevgFcisGKkwiBzrws0lLmIkieuKkObT2Ff7dwp6qbGHtl3Wm0IN1e6r1zu X-Received: by 2002:a17:902:67:: with SMTP id 94-v6mr2552824pla.183.1518182378628; Fri, 09 Feb 2018 05:19:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518182378; cv=none; d=google.com; s=arc-20160816; b=XzdKUBi/58tykgt8pZRYb67jbqyae48daug7ak91wp53FCw9dpHgOQjq4jGw2l5lGj fqndMmCKIXxyO0jdJogxsAi1sYBVjJ6QnZ/gGTd9/vFFQlDcKPS+083emXYOR20LCU8X 5jIrz04zjkCjohhfLsX9R+7/PehoS5WWkpJzJy45HUWcfYhTnBVru8vNXes9XzqNXSPP D/z2haaQEgaFMuDw5mWMydVFnBOUk+skPz1PvzfRV/pVXgqoli1+xsjZXYnkjlXzffOd WRciea0WWaD8j/DMz9RGxAaa6Rr9sLo1AIWHkHcAbQyWyVgvSE/u/aWcikrFcs/lGp7l O/fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ZcG5I/jf9tVQsJW6iej8qIQfcSkl/kta9iKB4r2pPxo=; b=A/3aHBFVuTPGUaKxYqkmUTRx+fE5JOgu/e6KT4j9GsCV53q1t/K3uVdWzPAoFOfTTu m6UUutSu+lJPbGGtGV50cfIJ+po9KYA+az7SQLoJ7uud0ArQ6VqiU9x4900XIBmsrYq3 k71t9/WBUHpLe4c+KgEWK7pT0iIm/Ez6LFshG1K6mlqfcpKoxgrj6h8XJIid3wg7koTw rSFGBKdjW3i90rcykgCVcCAad+ijHhZ5V4JrjOquLtlDaDdjUuODaHpc+Eyx0ggNHgqD mHGI4+z/eViY+omrNQyvVCZ+/uUAiPaR0p9P7UVQtctHB+Nx2NFwqqkC4aFJoSeO1hDW qmHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b59-v6si1552047plc.302.2018.02.09.05.19.24; Fri, 09 Feb 2018 05:19:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751253AbeBINSl (ORCPT + 99 others); Fri, 9 Feb 2018 08:18:41 -0500 Received: from mga14.intel.com ([192.55.52.115]:1704 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750997AbeBINSi (ORCPT ); Fri, 9 Feb 2018 08:18:38 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Feb 2018 05:18:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,483,1511856000"; d="scan'208";a="29475600" Received: from kinstrum-mobl.ccr.corp.intel.com (HELO localhost) ([10.249.254.132]) by fmsmga001.fm.intel.com with ESMTP; 09 Feb 2018 05:18:35 -0800 From: Jarkko Sakkinen To: linux-integrity@vger.kernel.org Cc: Jarkko Sakkinen , Peter Huewe , Jason Gunthorpe , linux-kernel@vger.kernel.org (open list) Subject: [PATCH] tpm: migrate tpm2_do_selftest() to use struct tpm_buf Date: Fri, 9 Feb 2018 15:18:20 +0200 Message-Id: <20180209131820.23718-1-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.14.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As part of an ongoing effort to encapsulate TPM commands to struct tpm_buf instead of using clunky union of structs, migrated tpm2_do_selft_test() to use struct tpm_buf. Signed-off-by: Jarkko Sakkinen --- I wish this would be included as part of patch set that fixes the timing issue. drivers/char/tpm/tpm2-cmd.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c index c17e75348a99..a91a2c6f03a7 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -31,10 +31,6 @@ struct tpm2_startup_in { __be16 startup_type; } __packed; -struct tpm2_self_test_in { - u8 full_test; -} __packed; - struct tpm2_get_tpm_pt_in { __be32 cap_id; __be32 property_id; @@ -60,7 +56,6 @@ struct tpm2_get_random_out { union tpm2_cmd_params { struct tpm2_startup_in startup_in; - struct tpm2_self_test_in selftest_in; struct tpm2_get_tpm_pt_in get_tpm_pt_in; struct tpm2_get_tpm_pt_out get_tpm_pt_out; struct tpm2_get_random_in getrandom_in; @@ -823,16 +818,6 @@ unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal) } EXPORT_SYMBOL_GPL(tpm2_calc_ordinal_duration); -#define TPM2_SELF_TEST_IN_SIZE \ - (sizeof(struct tpm_input_header) + \ - sizeof(struct tpm2_self_test_in)) - -static const struct tpm_input_header tpm2_selftest_header = { - .tag = cpu_to_be16(TPM2_ST_NO_SESSIONS), - .length = cpu_to_be32(TPM2_SELF_TEST_IN_SIZE), - .ordinal = cpu_to_be32(TPM2_CC_SELF_TEST) -}; - /** * tpm2_do_selftest() - ensure that all self tests have passed * @@ -851,18 +836,21 @@ static int tpm2_do_selftest(struct tpm_chip *chip) int rc; unsigned int delay_msec = 10; long duration; - struct tpm2_cmd cmd; + struct tpm_buf buf; duration = jiffies_to_msecs( tpm2_calc_ordinal_duration(chip, TPM2_CC_SELF_TEST)); - while (1) { - cmd.header.in = tpm2_selftest_header; - cmd.params.selftest_in.full_test = 0; - - rc = tpm_transmit_cmd(chip, NULL, &cmd, TPM2_SELF_TEST_IN_SIZE, - 0, 0, "continue selftest"); + for (;;) { + rc = tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_SELF_TEST); + if (rc) + return rc; + /* Perform tests in the background. */ + tpm_buf_append_u8(&buf, 0); + rc = tpm_transmit_cmd(chip, NULL, buf.data, PAGE_SIZE, 0, 0, + "continue selftest"); + tpm_buf_destroy(&buf); if (rc != TPM2_RC_TESTING || delay_msec >= duration) break; -- 2.14.1