Message ID | 20230103162010.381214-1-eajames@linux.ibm.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4703585wrt; Tue, 3 Jan 2023 08:22:35 -0800 (PST) X-Google-Smtp-Source: AMrXdXvU4WfPDD2h4nbpFIB/kRtktmTTYy0oq6/3qMWvzwxb6DpVgjvnQhAEu7vE/c31MsMOdna2 X-Received: by 2002:a17:90a:d58a:b0:219:7d75:de7b with SMTP id v10-20020a17090ad58a00b002197d75de7bmr46530061pju.35.1672762954684; Tue, 03 Jan 2023 08:22:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672762954; cv=none; d=google.com; s=arc-20160816; b=aUkMU5apPyVr3p9jcQcJ3FgbKpRKETzpB2H+RgDiCNDWRTAurWX19P5SYrunZO7Efb 9TLrMaN6eOVHRmyce5I8DQ/9fAzAn3+/Cuw3jYtOWWd+olkRZNs6Z9Qj8/j0wrESMz/y Azx22xAimPdHuhTBzdByjJZkdYve/0CbT9O1hoFQDSxNd55blP4PwwordEnIkaGd2gbf raWqrhrJfIBTExpDbErzNs4/+mW2isVWh2fSM6BBPt5D1OPoqJK/Htv3H8b2M5hcanPX 9k4rv4qiwD+MsrUjxny0nCEw/wOMMFeQ9FHQ2KRNk48is5SEq8hQQGWD/p5MRTQZhB35 y7IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=kcMCFZqix5oHLmpcalz5usfADuqOgIyWiV1vo6pPxJ0=; b=L2PdkH7y+++tE4WFUEQ62nsTTpM18PY2eNCL3JXGkQ0x8SJLfcz30cbGI9OSsXlJ5q TmsFp5YT53T/HF7Zwa9vwqpdVOOHKWp0pmhvJkMrhhYngNQUGdmpDyTyZW3Uv7ThADH0 jDfrSN7OOlctxkr48x3NHif1PIsLJ86kF2b3KJHla0l1vyqkqZ9nQF+XRxnI7ZTRlsj/ FBlVvbqxpVWV0d/nyFAFGpSbOB0GfsbQd36DM5l1vnbVUiAJsFujKJdRD8TEq1OrTh3Q 16NPaBwquddm5NBRvb0+2qj8O4HWMgRhhnXSnxY6CUtGO5vIjfNBJ8KVZTb/QxueWlOq Yc2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=NsP2cCXb; 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=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g7-20020a17090a4b0700b00212ce534ef7si30808285pjh.22.2023.01.03.08.22.21; Tue, 03 Jan 2023 08:22:34 -0800 (PST) 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=@ibm.com header.s=pp1 header.b=NsP2cCXb; 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=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238012AbjACQU4 (ORCPT <rfc822;tmhikaru@gmail.com> + 99 others); Tue, 3 Jan 2023 11:20:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238085AbjACQUa (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 3 Jan 2023 11:20:30 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D3A4F58C; Tue, 3 Jan 2023 08:20:29 -0800 (PST) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 303F0vMJ031306; Tue, 3 Jan 2023 16:20:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=kcMCFZqix5oHLmpcalz5usfADuqOgIyWiV1vo6pPxJ0=; b=NsP2cCXbqaP7ex3x0GuQV+ypk72gd5kT5VPFEh5AXit91h/rbZzwekW1kriKOokKZw2K sN+/TP62roaMDiUZAIlomnkV7Djzn4YRwHpZ1MWJBFpCrnH35y8sR5OGS+Fg3ihGvTAY OYptB/XQg7stx7Mrqgm+ln5Mi9wyZAFjd2oO/e8fqjWR/ePqP/O/fp4l4H9BsPI6yv84 JmVgBDTe7k/ZLeZbPWqSE9nxnEfATn13f13iNUlLDVi/qsmvAjpu7yOIwLC6O3+UgYD5 a9ciy6f6sxPQoOKIoxs4KQ8SlSigXwsPBG0m1Y6BRdqVoZG6fqpstcGWF/7nBVXRvedD 3g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3mvh8phrdv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 03 Jan 2023 16:20:18 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 303GGhHt017826; Tue, 3 Jan 2023 16:20:17 GMT Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3mvh8phrdh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 03 Jan 2023 16:20:17 +0000 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 303EwpeI026039; Tue, 3 Jan 2023 16:20:17 GMT Received: from smtprelay04.wdc07v.mail.ibm.com ([9.208.129.114]) by ppma04dal.us.ibm.com (PPS) with ESMTPS id 3mtcq7fc10-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 03 Jan 2023 16:20:17 +0000 Received: from smtpav05.dal12v.mail.ibm.com (smtpav05.dal12v.mail.ibm.com [10.241.53.104]) by smtprelay04.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 303GKFhH19923700 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 3 Jan 2023 16:20:15 GMT Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 40F2658065; Tue, 3 Jan 2023 16:20:15 +0000 (GMT) Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6694258067; Tue, 3 Jan 2023 16:20:14 +0000 (GMT) Received: from slate16.aus.stglabs.ibm.com (unknown [9.65.211.96]) by smtpav05.dal12v.mail.ibm.com (Postfix) with ESMTP; Tue, 3 Jan 2023 16:20:14 +0000 (GMT) From: Eddie James <eajames@linux.ibm.com> To: linux-integrity@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jgg@ziepe.ca, jarkko@kernel.org, peterhuewe@gmx.de, joel@jms.id.au, Eddie James <eajames@linux.ibm.com> Subject: [PATCH] tpm: Add reserved memory event log Date: Tue, 3 Jan 2023 10:20:10 -0600 Message-Id: <20230103162010.381214-1-eajames@linux.ibm.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: vWnW_1v0opqqCYQIcVr5CjIxHBaAnkzQ X-Proofpoint-ORIG-GUID: tHy89K9MSouH0iz10GQNBcqvGl3G93Vo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-03_05,2023-01-03_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 suspectscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 bulkscore=0 impostorscore=0 clxscore=1011 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301030136 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754019087592085178?= X-GMAIL-MSGID: =?utf-8?q?1754019087592085178?= |
Series |
tpm: Add reserved memory event log
|
|
Commit Message
Eddie James
Jan. 3, 2023, 4:20 p.m. UTC
Some platforms may desire to pass the event log up to linux in the
form of a reserved memory region. Add support for this in the TPM
core to find the reserved memory region and map it.
Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
drivers/char/tpm/eventlog/of.c | 38 +++++++++++++++++++++++++++++++++-
drivers/char/tpm/tpm-chip.c | 3 ++-
include/linux/tpm.h | 1 +
3 files changed, 40 insertions(+), 2 deletions(-)
Comments
Hi Eddie, I love your patch! Perhaps something to improve: [auto build test WARNING on char-misc/char-misc-testing] [also build test WARNING on char-misc/char-misc-next char-misc/char-misc-linus linus/master v6.2-rc2 next-20221226] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Eddie-James/tpm-Add-reserved-memory-event-log/20230104-002229 patch link: https://lore.kernel.org/r/20230103162010.381214-1-eajames%40linux.ibm.com patch subject: [PATCH] tpm: Add reserved memory event log config: arm-buildonly-randconfig-r005-20230101 compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 7a8cb6cd4e3ff8aaadebff2b9d3ee9e2a326d444) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # install arm cross compiling tool for clang build # apt-get install binutils-arm-linux-gnueabi # https://github.com/intel-lab-lkp/linux/commit/6aebeea318ade8b695dc36f4c5a2ad166ae4f1a7 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Eddie-James/tpm-Add-reserved-memory-event-log/20230104-002229 git checkout 6aebeea318ade8b695dc36f4c5a2ad166ae4f1a7 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash drivers/char/tpm/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): In file included from drivers/char/tpm/tpm-chip.c:24: include/linux/tpm_eventlog.h:167:6: warning: variable 'mapping_size' set but not used [-Wunused-but-set-variable] int mapping_size; ^ >> drivers/char/tpm/tpm-chip.c:327:22: warning: cast from 'void (*)(const void *)' to 'void (*)(void *)' converts to incompatible function type [-Wcast-function-type-strict] chip->log.release = (void(*)(void *))kfree; ^~~~~~~~~~~~~~~~~~~~~~ 2 warnings generated. vim +327 drivers/char/tpm/tpm-chip.c 302 303 /** 304 * tpm_chip_alloc() - allocate a new struct tpm_chip instance 305 * @pdev: device to which the chip is associated 306 * At this point pdev mst be initialized, but does not have to 307 * be registered 308 * @ops: struct tpm_class_ops instance 309 * 310 * Allocates a new struct tpm_chip instance and assigns a free 311 * device number for it. Must be paired with put_device(&chip->dev). 312 */ 313 struct tpm_chip *tpm_chip_alloc(struct device *pdev, 314 const struct tpm_class_ops *ops) 315 { 316 struct tpm_chip *chip; 317 int rc; 318 319 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 320 if (chip == NULL) 321 return ERR_PTR(-ENOMEM); 322 323 mutex_init(&chip->tpm_mutex); 324 init_rwsem(&chip->ops_sem); 325 326 chip->ops = ops; > 327 chip->log.release = (void(*)(void *))kfree; 328 329 mutex_lock(&idr_lock); 330 rc = idr_alloc(&dev_nums_idr, NULL, 0, TPM_NUM_DEVICES, GFP_KERNEL); 331 mutex_unlock(&idr_lock); 332 if (rc < 0) { 333 dev_err(pdev, "No available tpm device numbers\n"); 334 kfree(chip); 335 return ERR_PTR(rc); 336 } 337 chip->dev_num = rc; 338 339 device_initialize(&chip->dev); 340 341 chip->dev.class = tpm_class; 342 chip->dev.class->shutdown_pre = tpm_class_shutdown; 343 chip->dev.release = tpm_dev_release; 344 chip->dev.parent = pdev; 345 chip->dev.groups = chip->groups; 346 347 if (chip->dev_num == 0) 348 chip->dev.devt = MKDEV(MISC_MAJOR, TPM_MINOR); 349 else 350 chip->dev.devt = MKDEV(MAJOR(tpm_devt), chip->dev_num); 351 352 rc = dev_set_name(&chip->dev, "tpm%d", chip->dev_num); 353 if (rc) 354 goto out; 355 356 if (!pdev) 357 chip->flags |= TPM_CHIP_FLAG_VIRTUAL; 358 359 cdev_init(&chip->cdev, &tpm_fops); 360 chip->cdev.owner = THIS_MODULE; 361 362 rc = tpm2_init_space(&chip->work_space, TPM2_SPACE_BUFFER_SIZE); 363 if (rc) { 364 rc = -ENOMEM; 365 goto out; 366 } 367 368 chip->locality = -1; 369 return chip; 370 371 out: 372 put_device(&chip->dev); 373 return ERR_PTR(rc); 374 } 375 EXPORT_SYMBOL_GPL(tpm_chip_alloc); 376
On Tue, Jan 03, 2023 at 10:20:10AM -0600, Eddie James wrote: > Some platforms may desire to pass the event log up to linux in the > form of a reserved memory region. Add support for this in the TPM > core to find the reserved memory region and map it. > > Signed-off-by: Eddie James <eajames@linux.ibm.com> Which platforms? I do not see information of + void (*release)(void *ptr); in the commit message. The description of the implemenation approach is missing. > --- > drivers/char/tpm/eventlog/of.c | 38 +++++++++++++++++++++++++++++++++- > drivers/char/tpm/tpm-chip.c | 3 ++- > include/linux/tpm.h | 1 + > 3 files changed, 40 insertions(+), 2 deletions(-) > > diff --git a/drivers/char/tpm/eventlog/of.c b/drivers/char/tpm/eventlog/of.c > index a9ce66d09a75..0455d7f61c10 100644 > --- a/drivers/char/tpm/eventlog/of.c > +++ b/drivers/char/tpm/eventlog/of.c > @@ -11,12 +11,48 @@ > */ > > #include <linux/slab.h> > +#include <linux/io.h> > +#include <linux/ioport.h> > #include <linux/of.h> > +#include <linux/of_address.h> > +#include <linux/of_reserved_mem.h> > #include <linux/tpm_eventlog.h> > > #include "../tpm.h" > #include "common.h" > > +static int tpm_read_log_memory_region(struct tpm_chip *chip) > +{ > + struct device_node *node; > + struct resource res; > + int rc; > + > + node = of_parse_phandle(chip->dev.parent->of_node, "memory-region", 0); > + if (!node) { > + dev_info(&chip->dev, "no phandle\n"); > + return -ENODEV; > + } > + > + rc = of_address_to_resource(node, 0, &res); > + of_node_put(node); > + if (rc) { > + dev_info(&chip->dev, "no mem\n"); > + return rc; > + } > + > + chip->log.bios_event_log = memremap(res.start, resource_size(&res), MEMREMAP_WB); > + if (!chip->log.bios_event_log) { > + dev_info(&chip->dev, "err memremap\n"); > + return -ENOMEM; > + } > + > + chip->log.release = memunmap; > + chip->log.bios_event_log_end = chip->log.bios_event_log + resource_size(&res); > + > + return chip->flags & TPM_CHIP_FLAG_TPM2 ? EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 : > + EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2; > +} We do not want to support TPM 1.2 for new features. > + > int tpm_read_log_of(struct tpm_chip *chip) > { > struct device_node *np; > @@ -38,7 +74,7 @@ int tpm_read_log_of(struct tpm_chip *chip) > sizep = of_get_property(np, "linux,sml-size", NULL); > basep = of_get_property(np, "linux,sml-base", NULL); > if (sizep == NULL && basep == NULL) > - return -ENODEV; > + return tpm_read_log_memory_region(chip); > if (sizep == NULL || basep == NULL) > return -EIO; > > diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c > index 741d8f3e8fb3..09ea8145d7c6 100644 > --- a/drivers/char/tpm/tpm-chip.c > +++ b/drivers/char/tpm/tpm-chip.c > @@ -267,7 +267,7 @@ static void tpm_dev_release(struct device *dev) > idr_remove(&dev_nums_idr, chip->dev_num); > mutex_unlock(&idr_lock); > > - kfree(chip->log.bios_event_log); > + chip->log.release(chip->log.bios_event_log); > kfree(chip->work_space.context_buf); > kfree(chip->work_space.session_buf); > kfree(chip->allocated_banks); > @@ -324,6 +324,7 @@ struct tpm_chip *tpm_chip_alloc(struct device *pdev, > init_rwsem(&chip->ops_sem); > > chip->ops = ops; > + chip->log.release = (void(*)(void *))kfree; Why do you need this cast? > > mutex_lock(&idr_lock); > rc = idr_alloc(&dev_nums_idr, NULL, 0, TPM_NUM_DEVICES, GFP_KERNEL); > diff --git a/include/linux/tpm.h b/include/linux/tpm.h > index dfeb25a0362d..f1c0b0eb20a5 100644 > --- a/include/linux/tpm.h > +++ b/include/linux/tpm.h > @@ -109,6 +109,7 @@ struct tpm_space { > struct tpm_bios_log { > void *bios_event_log; > void *bios_event_log_end; > + void (*release)(void *ptr); > }; > > struct tpm_chip_seqops { > -- > 2.31.1 > BR, Jarkko
On 1/16/23 00:53, Jarkko Sakkinen wrote: > On Tue, Jan 03, 2023 at 10:20:10AM -0600, Eddie James wrote: >> Some platforms may desire to pass the event log up to linux in the >> form of a reserved memory region. Add support for this in the TPM >> core to find the reserved memory region and map it. >> >> Signed-off-by: Eddie James <eajames@linux.ibm.com> > Which platforms? > > I do not see information of > > + void (*release)(void *ptr); > > in the commit message. The description of the implemenation approach is > missing. Hi, please see v2 which is a two patch series. I have changed the implementation to avoid this release pointer. https://patchwork.kernel.org/project/linux-integrity/list/?series=711832 Thanks, Eddie > > >> --- >> drivers/char/tpm/eventlog/of.c | 38 +++++++++++++++++++++++++++++++++- >> drivers/char/tpm/tpm-chip.c | 3 ++- >> include/linux/tpm.h | 1 + >> 3 files changed, 40 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/char/tpm/eventlog/of.c b/drivers/char/tpm/eventlog/of.c >> index a9ce66d09a75..0455d7f61c10 100644 >> --- a/drivers/char/tpm/eventlog/of.c >> +++ b/drivers/char/tpm/eventlog/of.c >> @@ -11,12 +11,48 @@ >> */ >> >> #include <linux/slab.h> >> +#include <linux/io.h> >> +#include <linux/ioport.h> >> #include <linux/of.h> >> +#include <linux/of_address.h> >> +#include <linux/of_reserved_mem.h> >> #include <linux/tpm_eventlog.h> >> >> #include "../tpm.h" >> #include "common.h" >> >> +static int tpm_read_log_memory_region(struct tpm_chip *chip) >> +{ >> + struct device_node *node; >> + struct resource res; >> + int rc; >> + >> + node = of_parse_phandle(chip->dev.parent->of_node, "memory-region", 0); >> + if (!node) { >> + dev_info(&chip->dev, "no phandle\n"); >> + return -ENODEV; >> + } >> + >> + rc = of_address_to_resource(node, 0, &res); >> + of_node_put(node); >> + if (rc) { >> + dev_info(&chip->dev, "no mem\n"); >> + return rc; >> + } >> + >> + chip->log.bios_event_log = memremap(res.start, resource_size(&res), MEMREMAP_WB); >> + if (!chip->log.bios_event_log) { >> + dev_info(&chip->dev, "err memremap\n"); >> + return -ENOMEM; >> + } >> + >> + chip->log.release = memunmap; >> + chip->log.bios_event_log_end = chip->log.bios_event_log + resource_size(&res); >> + >> + return chip->flags & TPM_CHIP_FLAG_TPM2 ? EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 : >> + EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2; >> +} > We do not want to support TPM 1.2 for new features. > >> + >> int tpm_read_log_of(struct tpm_chip *chip) >> { >> struct device_node *np; >> @@ -38,7 +74,7 @@ int tpm_read_log_of(struct tpm_chip *chip) >> sizep = of_get_property(np, "linux,sml-size", NULL); >> basep = of_get_property(np, "linux,sml-base", NULL); >> if (sizep == NULL && basep == NULL) >> - return -ENODEV; >> + return tpm_read_log_memory_region(chip); >> if (sizep == NULL || basep == NULL) >> return -EIO; >> >> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c >> index 741d8f3e8fb3..09ea8145d7c6 100644 >> --- a/drivers/char/tpm/tpm-chip.c >> +++ b/drivers/char/tpm/tpm-chip.c >> @@ -267,7 +267,7 @@ static void tpm_dev_release(struct device *dev) >> idr_remove(&dev_nums_idr, chip->dev_num); >> mutex_unlock(&idr_lock); >> >> - kfree(chip->log.bios_event_log); >> + chip->log.release(chip->log.bios_event_log); >> kfree(chip->work_space.context_buf); >> kfree(chip->work_space.session_buf); >> kfree(chip->allocated_banks); >> @@ -324,6 +324,7 @@ struct tpm_chip *tpm_chip_alloc(struct device *pdev, >> init_rwsem(&chip->ops_sem); >> >> chip->ops = ops; >> + chip->log.release = (void(*)(void *))kfree; > Why do you need this cast? > >> >> mutex_lock(&idr_lock); >> rc = idr_alloc(&dev_nums_idr, NULL, 0, TPM_NUM_DEVICES, GFP_KERNEL); >> diff --git a/include/linux/tpm.h b/include/linux/tpm.h >> index dfeb25a0362d..f1c0b0eb20a5 100644 >> --- a/include/linux/tpm.h >> +++ b/include/linux/tpm.h >> @@ -109,6 +109,7 @@ struct tpm_space { >> struct tpm_bios_log { >> void *bios_event_log; >> void *bios_event_log_end; >> + void (*release)(void *ptr); >> }; >> >> struct tpm_chip_seqops { >> -- >> 2.31.1 >> > BR, Jarkko
diff --git a/drivers/char/tpm/eventlog/of.c b/drivers/char/tpm/eventlog/of.c index a9ce66d09a75..0455d7f61c10 100644 --- a/drivers/char/tpm/eventlog/of.c +++ b/drivers/char/tpm/eventlog/of.c @@ -11,12 +11,48 @@ */ #include <linux/slab.h> +#include <linux/io.h> +#include <linux/ioport.h> #include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_reserved_mem.h> #include <linux/tpm_eventlog.h> #include "../tpm.h" #include "common.h" +static int tpm_read_log_memory_region(struct tpm_chip *chip) +{ + struct device_node *node; + struct resource res; + int rc; + + node = of_parse_phandle(chip->dev.parent->of_node, "memory-region", 0); + if (!node) { + dev_info(&chip->dev, "no phandle\n"); + return -ENODEV; + } + + rc = of_address_to_resource(node, 0, &res); + of_node_put(node); + if (rc) { + dev_info(&chip->dev, "no mem\n"); + return rc; + } + + chip->log.bios_event_log = memremap(res.start, resource_size(&res), MEMREMAP_WB); + if (!chip->log.bios_event_log) { + dev_info(&chip->dev, "err memremap\n"); + return -ENOMEM; + } + + chip->log.release = memunmap; + chip->log.bios_event_log_end = chip->log.bios_event_log + resource_size(&res); + + return chip->flags & TPM_CHIP_FLAG_TPM2 ? EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 : + EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2; +} + int tpm_read_log_of(struct tpm_chip *chip) { struct device_node *np; @@ -38,7 +74,7 @@ int tpm_read_log_of(struct tpm_chip *chip) sizep = of_get_property(np, "linux,sml-size", NULL); basep = of_get_property(np, "linux,sml-base", NULL); if (sizep == NULL && basep == NULL) - return -ENODEV; + return tpm_read_log_memory_region(chip); if (sizep == NULL || basep == NULL) return -EIO; diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 741d8f3e8fb3..09ea8145d7c6 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -267,7 +267,7 @@ static void tpm_dev_release(struct device *dev) idr_remove(&dev_nums_idr, chip->dev_num); mutex_unlock(&idr_lock); - kfree(chip->log.bios_event_log); + chip->log.release(chip->log.bios_event_log); kfree(chip->work_space.context_buf); kfree(chip->work_space.session_buf); kfree(chip->allocated_banks); @@ -324,6 +324,7 @@ struct tpm_chip *tpm_chip_alloc(struct device *pdev, init_rwsem(&chip->ops_sem); chip->ops = ops; + chip->log.release = (void(*)(void *))kfree; mutex_lock(&idr_lock); rc = idr_alloc(&dev_nums_idr, NULL, 0, TPM_NUM_DEVICES, GFP_KERNEL); diff --git a/include/linux/tpm.h b/include/linux/tpm.h index dfeb25a0362d..f1c0b0eb20a5 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -109,6 +109,7 @@ struct tpm_space { struct tpm_bios_log { void *bios_event_log; void *bios_event_log_end; + void (*release)(void *ptr); }; struct tpm_chip_seqops {