Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp532402ybt; Fri, 26 Jun 2020 05:36:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNC1I3ACbqyTz6xnYYjLVC8ehtr8t5iUjGzPcqXSncm4rXYb5XcgbsgsCfA7jTVbtAYyYf X-Received: by 2002:a17:906:1044:: with SMTP id j4mr2306911ejj.187.1593175016829; Fri, 26 Jun 2020 05:36:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593175016; cv=none; d=google.com; s=arc-20160816; b=HyE9l1YQOyGJWm6sgyyeiCFWJHTS1zF9cnRNEosnJX4A1nv64BWKtNl3JOSQErtHnz ckO7UOx7mexhT4nNV/E9Mpts8bmqA4H3nhReHlhapp7WJASA2xNeBRYO5ol9QQQ5E5hB 6enH1cjvs16JmUaC8q5rZNCrwUiSImpuUvsopftRNbPqakYhjUfohUdold0Mx2iIrDK8 mb9qBiRkasfNnuxX03WsQWTCCQuSGIiNTNkDKgfZGqDRmElW6wwl5FwEnSovzpHgztPN SXA2oRHaJOjbn7Di0qT3SDxQfMeCwU275XTOqb/axAe7de08G9Xs7BXUAkYvBTGruGIT MJwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:ironport-sdr :ironport-sdr; bh=c7DdFJRkPxJGHQgDpRLe13L36sA17hwfpFwpo3TXOnc=; b=o7uYKQ45riRVUJjhs7QXkMVgqc4p9Ucu5K1rCmqMy/Bd5Hj7G15PcLbwvi7FJcJTxe c2BQ4WkaFBPbmrAzn5lKilJzNCbVSHaXrmw3RIhjTuigZpsm9svt+rzBQn+Hbd7v81VH R32CYSm9DpxmCzUG2124w7ZvwY91ECT7ZBC6cZeVx5TJy/0uY94p7/z/WL5Rdrk8YuAV Qmeg+Hc/WqWJXm2bGvCe281VwPs6WSCMXcRqePXsrnM5aM4+QdM2t2SVXHn6VsMAt8aH xVAA1iozqgbn7GuTb3TEpE0SzUVijD1uJXAFIZF8RIPD14NhPRu9hu1+kUT8a+UTVHXV K2Ew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m23si11496435edq.346.2020.06.26.05.36.33; Fri, 26 Jun 2020 05:36:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727771AbgFZLui (ORCPT + 99 others); Fri, 26 Jun 2020 07:50:38 -0400 Received: from mga01.intel.com ([192.55.52.88]:25482 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725884AbgFZLuh (ORCPT ); Fri, 26 Jun 2020 07:50:37 -0400 IronPort-SDR: xpRXPq6Fb7PHp748Obmp6R7RO2wjf5iS6xFVieumfAXqZqICBq64QX5JoxI+Q02WF95GOaqM9f Ed9xNrv4Mwqg== X-IronPort-AV: E=McAfee;i="6000,8403,9663"; a="163343416" X-IronPort-AV: E=Sophos;i="5.75,283,1589266800"; d="scan'208";a="163343416" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2020 04:50:37 -0700 IronPort-SDR: bc2Fb/KBK57u0KnnIcJyQYSEdxA0vM/5LPsogxwcKccvptmP2PPg4tTu4gTNGndKcEAXWuDNeG CavqtMiUB9eQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,283,1589266800"; d="scan'208";a="276344069" Received: from cgheban-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.199]) by orsmga003.jf.intel.com with ESMTP; 26 Jun 2020 04:50:31 -0700 Date: Fri, 26 Jun 2020 14:50:30 +0300 From: Jarkko Sakkinen To: Stefan Berger Cc: linux-integrity@vger.kernel.org, James Bottomley , Peter Huewe , Jason Gunthorpe , Arnd Bergmann , Greg Kroah-Hartman , Jerry Snitselaar , Sumit Garg , Alexey Klimov , open list Subject: Re: [PATCH v2] tpm: tpm2-space: Resize session and context buffers dynamically Message-ID: <20200626115030.GC5847@linux.intel.com> References: <20200625043819.376693-1-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 25, 2020 at 05:38:03PM -0400, Stefan Berger wrote: > On 6/25/20 12:38 AM, Jarkko Sakkinen wrote: > > Re-allocate context and session buffers when needed. Scale them in page > > increments so that the reallocation is only seldomly required, and thus > > causes minimal stress to the system. Add a static maximum limit of four > > pages for buffer sizes. > > > > Cc: James Bottomley > > Suggested-by: Stefan Berger > > Signed-off-by: Jarkko Sakkinen > > --- > > Tested only for compilation. > > v2: TPM2_SPACE_DEFAULT_BUFFER_SIZE > > drivers/char/tpm/tpm2-space.c | 87 ++++++++++++++++++++++++----------- > > include/linux/tpm.h | 6 ++- > > 2 files changed, 64 insertions(+), 29 deletions(-) > > > > diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c > > index 982d341d8837..b8ece01d6afb 100644 > > --- a/drivers/char/tpm/tpm2-space.c > > +++ b/drivers/char/tpm/tpm2-space.c > > @@ -15,6 +15,9 @@ > > #include > > #include "tpm.h" > > +#define TPM2_SPACE_DEFAULT_BUFFER_SIZE PAGE_SIZE > > +#define TPM2_SPACE_MAX_BUFFER_SIZE (4 * PAGE_SIZE) > > + > > enum tpm2_handle_types { > > TPM2_HT_HMAC_SESSION = 0x02000000, > > TPM2_HT_POLICY_SESSION = 0x03000000, > > @@ -557,8 +588,10 @@ int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space, > > sizeof(space->context_tbl)); > > memcpy(&space->session_tbl, &chip->work_space.session_tbl, > > sizeof(space->session_tbl)); > > - memcpy(space->context_buf, chip->work_space.context_buf, PAGE_SIZE); > > - memcpy(space->session_buf, chip->work_space.session_buf, PAGE_SIZE); > > + memcpy(space->context_buf, chip->work_space.context_buf, > > + space->context_size); > > > You have to allocate the max size the in tpm_chip_alloc (tpm-chip.c): > > ?? chip->work_space.context_buf = kzalloc(TPM2_SPACE_MAX_BUFFER_SIZE, > GFP_KERNEL); > > > > + memcpy(space->session_buf, chip->work_space.session_buf, > > + space->session_size); > > > same for this That is not true. They should allocated as 4 kB in the dynamic scaling scheme. The idea is to use krealloc() to increase the buffer size. /Jarkko