Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp180436rwd; Wed, 24 May 2023 16:19:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ncTJuJKS9KuOe+/Y6sETDSXq6EHWVGAotUKAayXar6JwI1hM2/EgMe+PUcZsMBOO4sq5a X-Received: by 2002:a05:6a21:7891:b0:103:b0f9:7110 with SMTP id bf17-20020a056a21789100b00103b0f97110mr23723716pzc.11.1684970362476; Wed, 24 May 2023 16:19:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684970362; cv=none; d=google.com; s=arc-20160816; b=I+ABpXp4RWThyXqShxA3ZBrEL8iEAi8rxNnk5XWxIenQVFKkGJQ3U/hONfbnjYDOM2 naow1Xsgxt+1FoigLvHa/L2mDoGVeRB8X0N7qY+jvb7aJqVy9cM92nZ0zCpQbRTAr86P zcoQ8ATe2kr+ymWIV8K3KykHf+NxrNKJ8nv6+Yg5N5I2CXECxUAvv5sUaC8eA6Ey8pS8 NjFh5K13jV618s/FPrFl2eMKwr7m6INpWr9zYXbujCTYpRALYuzudJ61Pdd6FA5msheY 4KMy6wfqw954k4iO1lpJdBsxzEQ04IigKWuaMApmaNQ2/U0ZGb9LWoz/CjIZFn8FAcol ttMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=c2n57YKfPVwMrQwNDuZqoWvbyKlduQB03Z0HHDFLgso=; b=UekcLqQMGWsUoqz+5RQwV2jP2YeIFN5K2P2Hu5U3uc7cOrI7ASOOdfmQib2uKIha6X aNU1s8/1Ue8BIfMRSYPNMbwnhexv5eriFgH1HoXmwwruAAfoSTZujIyhoDLAXLccAHhg lzOwv/5hraYSPusrvz6g4pWfEipDDZkORAigW7rX7LsM1ZRScuTau0LhcMmoPCUsO5qx JP/xdj46Zont1ZUlNIuLAS9mQ25f3xUiNW7BrmPUBk7sgbPhFR5E4yedDEZFI9ChaTHg Qgt0UXxFTwWaTTONHJa8LheF4Hl++AtZqwiZ7wIja0nSBH51w3O/2fheiaQungCWAnvH rL0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EtCWe9dc; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l184-20020a6388c1000000b005343c3db9ebsi192912pgd.616.2023.05.24.16.19.06; Wed, 24 May 2023 16:19:22 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=EtCWe9dc; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237688AbjEXW5c (ORCPT + 99 others); Wed, 24 May 2023 18:57:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237435AbjEXW53 (ORCPT ); Wed, 24 May 2023 18:57:29 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82F76123 for ; Wed, 24 May 2023 15:56:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684969000; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=c2n57YKfPVwMrQwNDuZqoWvbyKlduQB03Z0HHDFLgso=; b=EtCWe9dcMx+p8PKu62uHg655/GpfF1YBFy+ylbD6PJnGvhOWdHd6QiCSYJ66JnnTQmG5SR vH3a8oMk3It6Q8ucD/BnAhk7Duq0teVhbfLkVWKhaJao4pN+ySzMmruhyDtt2lB+OQm6lM ASAbeI9zRGz50wNpUY7ktm5QdjlwReU= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-580-uGP8gFNWNLe6p8cbQ8ZdpA-1; Wed, 24 May 2023 18:56:39 -0400 X-MC-Unique: uGP8gFNWNLe6p8cbQ8ZdpA-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-3f7c87cf3ffso3414461cf.2 for ; Wed, 24 May 2023 15:56:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684968999; x=1687560999; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=c2n57YKfPVwMrQwNDuZqoWvbyKlduQB03Z0HHDFLgso=; b=TtalWEaJA4TBbvZgOSTDej+eZUQuGlqkti5BVYhZkCJ6iVhUB78hL2m96LdaVGsiuM YCMmgik589H+j8Akwk7JLnW2utTEe4vAhZ+VQ5VngYYDp+33wveS+nU3Tngl6q/gk5T/ w8HagvpiNsmd/YX72Wcgnjflbs9olR3xeLigYwi0QqkdFWZ/k8v19nd9lr76cC+6O4dP lojBlOKd8FhbgE2JLOxqrUC+J+AxTfoMAOrg3tcCezEla6Kt+Z+2znrUvnvRNRs3ZVX4 AcAIqMottfezQcEzRYH5R/cpMOiO5NBsUU6iUoF7l3KzZdDtJ8n6t6AIBUuclTGpIEUv rvFg== X-Gm-Message-State: AC+VfDyoQAdSFmQxu//Yvg0acn8ON36NsfpL+1/KyatB0meLIr8uX9C7 NKDRqftL6HkYm7uf6VbnM1kBJP0pxpoYWptSkbfzuyVD6H9nd85uLsUWkGOiUZCYk84BImhKFbU IGjKvTL7tIk/XuIJ+GfifawGX X-Received: by 2002:a05:622a:1812:b0:3f7:f9c6:d33a with SMTP id t18-20020a05622a181200b003f7f9c6d33amr656009qtc.51.1684968999144; Wed, 24 May 2023 15:56:39 -0700 (PDT) X-Received: by 2002:a05:622a:1812:b0:3f7:f9c6:d33a with SMTP id t18-20020a05622a181200b003f7f9c6d33amr655981qtc.51.1684968998843; Wed, 24 May 2023 15:56:38 -0700 (PDT) Received: from localhost (ip98-179-76-75.ph.ph.cox.net. [98.179.76.75]) by smtp.gmail.com with ESMTPSA id w1-20020ac84d01000000b003f6b58b986fsm2303178qtv.41.2023.05.24.15.56.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 15:56:38 -0700 (PDT) Date: Wed, 24 May 2023 15:56:37 -0700 From: Jerry Snitselaar To: Stefan Berger Cc: kexec@lists.infradead.org, devicetree@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, nayna@linux.ibm.com, nasastry@in.ibm.com, mpe@ellerman.id.au, Jarkko Sakkinen , Jason Gunthorpe , Rob Herring , Frank Rowand , Mimi Zohar , Nageswara R Sastry , Coiby Xu Subject: Re: [PATCH v9 2/4] tpm: of: Make of-tree specific function commonly available Message-ID: References: <20230418134409.177485-1-stefanb@linux.ibm.com> <20230418134409.177485-3-stefanb@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230418134409.177485-3-stefanb@linux.ibm.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 18, 2023 at 09:44:07AM -0400, Stefan Berger wrote: > Simplify tpm_read_log_of() by moving reusable parts of the code into > an inline function that makes it commonly available so it can be > used also for kexec support. Call the new of_tpm_get_sml_parameters() > function from the TPM Open Firmware driver. > > Signed-off-by: Stefan Berger > Cc: Jarkko Sakkinen > Cc: Jason Gunthorpe > Cc: Rob Herring > Cc: Frank Rowand > Reviewed-by: Mimi Zohar > Tested-by: Nageswara R Sastry > Tested-by: Coiby Xu > Acked-by: Jarkko Sakkinen > Reviewed-by: Jerry Snitselaar > --- > v9: > - Rebased on 6.3-rc7; call tpm_read_log_memory_region if -ENODEV returned > > v7: > - Added original comment back into inlined function > > v4: > - converted to inline function > --- > drivers/char/tpm/eventlog/of.c | 30 +++++----------------------- > include/linux/tpm.h | 36 ++++++++++++++++++++++++++++++++++ > 2 files changed, 41 insertions(+), 25 deletions(-) > > diff --git a/drivers/char/tpm/eventlog/of.c b/drivers/char/tpm/eventlog/of.c > index 930fe43d5daf..41688d9cbd3b 100644 > --- a/drivers/char/tpm/eventlog/of.c > +++ b/drivers/char/tpm/eventlog/of.c > @@ -51,11 +51,10 @@ static int tpm_read_log_memory_region(struct tpm_chip *chip) > int tpm_read_log_of(struct tpm_chip *chip) > { > struct device_node *np; > - const u32 *sizep; > - const u64 *basep; > struct tpm_bios_log *log; > u32 size; > u64 base; > + int ret; > > log = &chip->log; > if (chip->dev.parent && chip->dev.parent->of_node) > @@ -66,30 +65,11 @@ int tpm_read_log_of(struct tpm_chip *chip) > if (of_property_read_bool(np, "powered-while-suspended")) > chip->flags |= TPM_CHIP_FLAG_ALWAYS_POWERED; > > - sizep = of_get_property(np, "linux,sml-size", NULL); > - basep = of_get_property(np, "linux,sml-base", NULL); > - if (sizep == NULL && basep == NULL) > + ret = of_tpm_get_sml_parameters(np, &base, &size); > + if (ret == -ENODEV) > return tpm_read_log_memory_region(chip); > - if (sizep == NULL || basep == NULL) > - return -EIO; > - > - /* > - * For both vtpm/tpm, firmware has log addr and log size in big > - * endian format. But in case of vtpm, there is a method called > - * sml-handover which is run during kernel init even before > - * device tree is setup. This sml-handover function takes care > - * of endianness and writes to sml-base and sml-size in little > - * endian format. For this reason, vtpm doesn't need conversion > - * but physical tpm needs the conversion. > - */ > - if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0 && > - of_property_match_string(np, "compatible", "IBM,vtpm20") < 0) { > - size = be32_to_cpup((__force __be32 *)sizep); > - base = be64_to_cpup((__force __be64 *)basep); > - } else { > - size = *sizep; > - base = *basep; > - } > + if (ret < 0) > + return ret; > > if (size == 0) { > dev_warn(&chip->dev, "%s: Event log area empty\n", __func__); > diff --git a/include/linux/tpm.h b/include/linux/tpm.h > index 4dc97b9f65fb..dd9a376a1dbb 100644 > --- a/include/linux/tpm.h > +++ b/include/linux/tpm.h > @@ -461,4 +461,40 @@ static inline struct tpm_chip *tpm_default_chip(void) > return NULL; > } > #endif > + > +#ifdef CONFIG_OF > +static inline int of_tpm_get_sml_parameters(struct device_node *np, > + u64 *base, u32 *size) > +{ > + const u32 *sizep; > + const u64 *basep; > + > + 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; > + if (sizep == NULL || basep == NULL) > + return -EIO; > + > + /* > + * For both vtpm/tpm, firmware has log addr and log size in big > + * endian format. But in case of vtpm, there is a method called > + * sml-handover which is run during kernel init even before > + * device tree is setup. This sml-handover function takes care > + * of endianness and writes to sml-base and sml-size in little > + * endian format. For this reason, vtpm doesn't need conversion > + * but physical tpm needs the conversion. > + */ > + if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0 && > + of_property_match_string(np, "compatible", "IBM,vtpm20") < 0) { > + *size = be32_to_cpup((__force __be32 *)sizep); > + *base = be64_to_cpup((__force __be64 *)basep); > + } else { > + *size = *sizep; > + *base = *basep; > + } > + return 0; > +} > +#endif > + > #endif > -- > 2.38.1 >