Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp110218ybt; Thu, 25 Jun 2020 16:41:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuIef6cSMPLgCI++5Y2yEqKj5j0iLH5yfCsKtb4F0GpJVAaH/LDJz0pmJZby4PVVx+oeyW X-Received: by 2002:a17:906:66d0:: with SMTP id k16mr190339ejp.293.1593128513368; Thu, 25 Jun 2020 16:41:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593128513; cv=none; d=google.com; s=arc-20160816; b=i3/cT+/niXSZzRrzGz6r2wLUUkKpDRkf3vAv+1/3c2zboL6gZX0pr8vYiqbTRktRsb HM+uFgwVIvR1eazpxAtiIds+VvM6yRQogwxFIvUvAxVQy8gcGXDnqhVJCj8fnfXf7o3J jdWyZKrU5zqjFb03IOjLXKVUtu6i1QkpfgUD8bbbR71Vnj6cxTt9taf1V6JhTyl9LDkN I6zO1fJC64D4uoXyj0qtLf6aVVRFuf5Wz1UaabeNOwc8ZZKLBbhCb2PcdCb/S+skVhxn JtBal5TMb9JpSWhHR4/uus8aoJbKDbUwaBD7G7XOs44AqNfnQT6gfdQgzylzo9wDNRb9 oPng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=qAEzxX2G+TDJtIpcxA5UPQQcSbJgN/wNpPIvftRpZlw=; b=exl1ZrjI/TPWzPY3iCiKcJiw77MGWD3oc2KmuhFi1Jg6PeD4XR5GtmS9Iys8Wkwdu9 Yy49CxV97jDu404HAJ3GAg4yV38xODbivk4PTHFMvPBIAr69SPodWfdDiijvMOdAjG1M tMAgK8pWacUJYcXEF8M+jqWOgs9vHoTJcfWSsyI+a/onPv4ZN31jH2u7KB38vjzFOkLR vrPK1EALhb9iyRvxW2VzQ+0t38OzSfl2JWnedIviPGxKIkrznkeNrlewtvDObkSdQ+tZ ZEoAgRMmYKivDylD2wRYKw4LUd4SLaaEsykzhdMw/vnWwn2OE4bNN/JICEWGG/saJrFb /sog== 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id la26si8145550ejb.587.2020.06.25.16.41.30; Thu, 25 Jun 2020 16:41:53 -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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407284AbgFYViO (ORCPT + 99 others); Thu, 25 Jun 2020 17:38:14 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:27576 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2403961AbgFYViM (ORCPT ); Thu, 25 Jun 2020 17:38:12 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05PLY8Tr176894; Thu, 25 Jun 2020 17:38:06 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 31w3a395a4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Jun 2020 17:38:06 -0400 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 05PLYEGt177555; Thu, 25 Jun 2020 17:38:05 -0400 Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0b-001b2d01.pphosted.com with ESMTP id 31w3a3959p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Jun 2020 17:38:05 -0400 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 05PLPi7O005601; Thu, 25 Jun 2020 21:38:04 GMT Received: from b01cxnp23032.gho.pok.ibm.com (b01cxnp23032.gho.pok.ibm.com [9.57.198.27]) by ppma02dal.us.ibm.com with ESMTP id 31uurtb0bp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Jun 2020 21:38:04 +0000 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 05PLc3lR41222630 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Jun 2020 21:38:03 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8124E112067; Thu, 25 Jun 2020 21:38:03 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 57362112063; Thu, 25 Jun 2020 21:38:03 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 25 Jun 2020 21:38:03 +0000 (GMT) Subject: Re: [PATCH v2] tpm: tpm2-space: Resize session and context buffers dynamically To: Jarkko Sakkinen , linux-integrity@vger.kernel.org Cc: James Bottomley , Peter Huewe , Jason Gunthorpe , Arnd Bergmann , Greg Kroah-Hartman , Jerry Snitselaar , Sumit Garg , Alexey Klimov , open list References: <20200625043819.376693-1-jarkko.sakkinen@linux.intel.com> From: Stefan Berger Message-ID: Date: Thu, 25 Jun 2020 17:38:03 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200625043819.376693-1-jarkko.sakkinen@linux.intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-06-25_16:2020-06-25,2020-06-25 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 clxscore=1015 adultscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 spamscore=0 impostorscore=0 malwarescore=0 phishscore=0 cotscore=-2147483648 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006250124 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > return 0; > out: > diff --git a/include/linux/tpm.h b/include/linux/tpm.h > index 03e9b184411b..9ea39e8f7162 100644 > --- a/include/linux/tpm.h > +++ b/include/linux/tpm.h > @@ -92,10 +92,12 @@ enum tpm_duration { > #define TPM_PPI_VERSION_LEN 3 > > struct tpm_space { > + u8 *context_buf; > + u8 *session_buf; > + u32 context_size; > + u32 session_size; > u32 context_tbl[3]; > - u8 *context_buf; > u32 session_tbl[3]; > - u8 *session_buf; > }; > > struct tpm_bios_log {