From patchwork Fri Jan 13 01:17:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Bottomley X-Patchwork-Id: 9514473 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4074D607D2 for ; Fri, 13 Jan 2017 01:17:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AED1286F0 for ; Fri, 13 Jan 2017 01:17:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D551237A5; Fri, 13 Jan 2017 01:17:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 82FCA237A5 for ; Fri, 13 Jan 2017 01:17:40 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cRqUs-0005G5-AU; Fri, 13 Jan 2017 01:17:38 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cRqUq-0005Fz-Sz for tpmdd-devel@lists.sourceforge.net; Fri, 13 Jan 2017 01:17:36 +0000 X-ACL-Warn: Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1cRqUp-0003N5-MR for tpmdd-devel@lists.sourceforge.net; Fri, 13 Jan 2017 01:17:36 +0000 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id v0D1DdjW029291 for ; Thu, 12 Jan 2017 20:17:30 -0500 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0a-001b2d01.pphosted.com with ESMTP id 27xfyrtrwn-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 12 Jan 2017 20:17:29 -0500 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 12 Jan 2017 18:17:28 -0700 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 12 Jan 2017 18:17:27 -0700 Received: from b03cxnp07028.gho.boulder.ibm.com (b03cxnp07028.gho.boulder.ibm.com [9.17.130.15]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id D65C13E4003F; Thu, 12 Jan 2017 18:17:26 -0700 (MST) Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v0D1HQqw15008150; Thu, 12 Jan 2017 18:17:26 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 96360C6047; Thu, 12 Jan 2017 18:17:26 -0700 (MST) Received: from jarvis.ext.hansenpartnership.com (unknown [9.80.199.178]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTPS id 67FDAC603C; Thu, 12 Jan 2017 18:17:25 -0700 (MST) From: James Bottomley To: Jarkko Sakkinen , tpmdd-devel@lists.sourceforge.net Date: Thu, 12 Jan 2017 17:17:23 -0800 In-Reply-To: <20170112174612.9314-4-jarkko.sakkinen@linux.intel.com> References: <20170112174612.9314-1-jarkko.sakkinen@linux.intel.com> <20170112174612.9314-4-jarkko.sakkinen@linux.intel.com> X-Mailer: Evolution 3.16.5 Mime-Version: 1.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17011301-0020-0000-0000-00000AB8870B X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006423; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000199; SDB=6.00806863; UDB=6.00392697; IPR=6.00584194; BA=6.00005052; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00013906; XFM=3.00000011; UTC=2017-01-13 01:17:28 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17011301-0021-0000-0000-000058D3EE59 Message-Id: <1484270243.5807.31.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-01-12_16:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1701130017 X-Headers-End: 1cRqUp-0003N5-MR Cc: linux-security-module@vger.kernel.org, open list Subject: Re: [tpmdd-devel] [PATCH RFC v2 3/5] tpm: infrastructure for TPM spaces X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Virus-Scanned: ClamAV using ClamSMTP On Thu, 2017-01-12 at 19:46 +0200, Jarkko Sakkinen wrote: > @@ -189,6 +190,12 @@ struct tpm_chip *tpm_chip_alloc(struct device > *pdev, > chip->cdev.owner = THIS_MODULE; > chip->cdev.kobj.parent = &chip->dev.kobj; > > + chip->work_space.context_buf = kzalloc(PAGE_SIZE, > GFP_KERNEL); > + if (!chip->work_space.context_buf) { > + rc = -ENOMEM; > + goto out; > + } > + I think the work_buf handling can be greatly simplified by making it a pointer to the space: it's only usable between tpm2_prepare_space() and tpm2_commit_space() which are protected by the chip mutex, so there's no need for it to exist outside of these calls (i.e. it can be NULL). Doing it this way also saves the allocation and copying overhead of work_space. The patch below can be folded to effect this. James --- ------------------------------------------------------------------------------ Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE. Training and support from Colfax. Order your platform today. http://sdm.link/xeonphi diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 13cac09..770a8c0 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -131,7 +131,6 @@ static void tpm_dev_release(struct device *dev) mutex_unlock(&idr_lock); kfree(chip->log.bios_event_log); - kfree(chip->work_space.context_buf); kfree(chip); } @@ -206,12 +205,6 @@ struct tpm_chip *tpm_chip_alloc(struct device *pdev, chip->cdev.kobj.parent = &chip->dev.kobj; chip->cdevrm.kobj.parent = &chip->devrm.kobj; - chip->work_space.context_buf = kzalloc(PAGE_SIZE, GFP_KERNEL); - if (!chip->work_space.context_buf) { - rc = -ENOMEM; - goto out; - } - return chip; out: diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 8009ed4..adf7810 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -211,7 +211,7 @@ struct tpm_chip { char ppi_version[TPM_PPI_VERSION_LEN + 1]; #endif /* CONFIG_ACPI */ - struct tpm_space work_space; + struct tpm_space *work_space; u32 nr_commands; u32 *cc_attrs_tbl; }; diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c index 44e5501..285361e 100644 --- a/drivers/char/tpm/tpm2-space.c +++ b/drivers/char/tpm/tpm2-space.c @@ -27,7 +27,7 @@ enum tpm2_handle_types { static void tpm2_flush_space(struct tpm_chip *chip) { - struct tpm_space *space = &chip->work_space; + struct tpm_space *space = chip->work_space; int i; for (i = 0; i < ARRAY_SIZE(space->context_tbl); i++) @@ -45,7 +45,7 @@ struct tpm2_context { static int tpm2_load_space(struct tpm_chip *chip) { - struct tpm_space *space = &chip->work_space; + struct tpm_space *space = chip->work_space; struct tpm2_context *ctx; struct tpm_buf buf; int i; @@ -99,7 +99,7 @@ static int tpm2_load_space(struct tpm_chip *chip) static int tpm2_map_command(struct tpm_chip *chip, u32 cc, u8 *cmd, size_t len) { - struct tpm_space *space = &chip->work_space; + struct tpm_space *space = chip->work_space; unsigned int nr_handles; u32 vhandle; u32 phandle; @@ -147,9 +147,7 @@ int tpm2_prepare_space(struct tpm_chip *chip, struct tpm_space *space, if (!space) return 0; - memcpy(&chip->work_space.context_tbl, &space->context_tbl, - sizeof(space->context_tbl)); - memcpy(chip->work_space.context_buf, space->context_buf, PAGE_SIZE); + chip->work_space = space; rc = tpm2_load_space(chip); if (rc) @@ -164,7 +162,7 @@ int tpm2_prepare_space(struct tpm_chip *chip, struct tpm_space *space, static int tpm2_map_response(struct tpm_chip *chip, u32 cc, u8 *rsp, size_t len) { - struct tpm_space *space = &chip->work_space; + struct tpm_space *space = chip->work_space; u32 phandle; u32 vhandle; u32 attrs; @@ -222,7 +220,7 @@ static int tpm2_map_response(struct tpm_chip *chip, u32 cc, u8 *rsp, size_t len) static int tpm2_save_space(struct tpm_chip *chip) { - struct tpm_space *space = &chip->work_space; + struct tpm_space *space = chip->work_space; struct tpm_buf buf; int i; int j; @@ -295,9 +293,7 @@ int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space, if (rc) return rc; - memcpy(&space->context_tbl, &chip->work_space.context_tbl, - sizeof(space->context_tbl)); - memcpy(space->context_buf, chip->work_space.context_buf, PAGE_SIZE); + chip->work_space = NULL; return 0; }