Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp3934037ybe; Mon, 9 Sep 2019 01:15:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqyfBQeVbUSzhBNpwFdVQe+hPpKVD13sCbKPSic9ZsWm/2u7QW6VoPpNLBwoVWxPDQ06prHE X-Received: by 2002:a50:fc18:: with SMTP id i24mr22719806edr.69.1568016901086; Mon, 09 Sep 2019 01:15:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568016901; cv=none; d=google.com; s=arc-20160816; b=v9Nx7I0tblmVNLg8S0tjOlF5H6OcH1DcxCZekjvKX7NOhwUbTc9quk8Dbapf+/LFSf mUimf9ANA6V28VhKbQ8Pht1qmwn6/Qd5BCrndwPzhrlZoRBzOqIZZh+cO9oS1dBqs8aN Aw2ti1m7vW500zqqphanjW+d9I1TzQ5z8Dh33oDlgN6WKxuQfDoSaU/5ow2zEKsT2q6a 20SwGkWoBE8h69djzaL6O8kxZhBrZuZxwznqaaK1YUGkhYsYz0wZsB1qmj8UO3SCpWFI pE1BnQd47j0iFdU24sOfv+X7dp3NfX9fl+/GUpyjRy6oJwNR8S0z1cyCrp7rGFrEmDUF 4k+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:organization:references:in-reply-to:date:cc:to:from :subject:message-id; bh=78XsTz+7NRh8SwhM6fscTMHe6QGbX6j18PD+uur0+PI=; b=Ed2EkVFlwfeGS5B0A0/OaX8IPYaiqGu2hmZenp24zOEHXKpY4HLwNKNQDIuB045N7B wLLMyuKR7d+KZUfF2ZIPmU6JJjK8FiSswCrOe/punUV8YJoEVSmdgsSv/q0pYbuvILVa xvyIwy5x9rfzaD0UyyUx5cs4V9Ysp7YGMnuOl95mv6zFrm/xcw5/1lykD8nYAQx+YJsy JKuUSXNhNxWONUHgaNODwXADL/aT2pjRfQZAkKTw/4KA51ByiKNTB/xTP1o0oax4Ul9B KbP6vpR/iQnf5Bes+8fEPXR6hz4rP5qd6UTQjwN4x6CpeOQj1NpUICC+l2uDh7FD2ttO AXrQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id s42si8185347edm.292.2019.09.09.01.14.25; Mon, 09 Sep 2019 01:15:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727754AbfIGVtQ (ORCPT + 99 others); Sat, 7 Sep 2019 17:49:16 -0400 Received: from mga05.intel.com ([192.55.52.43]:28678 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727632AbfIGVtP (ORCPT ); Sat, 7 Sep 2019 17:49:15 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Sep 2019 14:49:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,478,1559545200"; d="scan'208";a="177970505" Received: from dpotapen-mobl1.ger.corp.intel.com ([10.252.53.110]) by orsmga008.jf.intel.com with ESMTP; 07 Sep 2019 14:49:12 -0700 Message-ID: <180a3a0fd33cbac9df8adf65999c53a9ddc20bf5.camel@linux.intel.com> Subject: Re: [PATCH] tpm_crb: fix fTPM on AMD Zen+ CPUs From: Jarkko Sakkinen To: ivan.lazeev@gmail.com Cc: Peter Huewe , Jason Gunthorpe , Arnd Bergmann , Greg Kroah-Hartman , linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org Date: Sun, 08 Sep 2019 00:49:11 +0300 In-Reply-To: <20190904190332.25019-1-ivan.lazeev@gmail.com> References: <20190904190332.25019-1-ivan.lazeev@gmail.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.2-1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2019-09-04 at 22:03 +0300, ivan.lazeev@gmail.com wrote: > From: Ivan Lazeev > > Bug link: https://bugzilla.kernel.org/show_bug.cgi?id=195657 > > cmd/rsp buffers are expected to be in the same ACPI region. > For Zen+ CPUs BIOS's might report two different regions, some of > them also report region sizes inconsistent with values from TPM > registers. > > Work around the issue by storing ACPI regions declared for the > device in a list, then using it to find entry corresponding > to each buffer. Use information from the entry to map each resource > at most once and make buffer size consistent with the length of the > region. > > Signed-off-by: Ivan Lazeev Can you add the relevant pieces of /proc/iomem output to the commit message so we can see the memory configuration? I don't have the hardware available where this kind of situation occurs. > --- > > Tested on ASRock x470 ITX motherboard with Ryzen 2600X CPU. > However, I don't have any other hardware to test the changes on and no > expertise to be sure that other TPMs won't break as a result. You can still ask yourself that if the hardware describes the memory with only one region do the code flows reduce mostly to do the same as before this patch. It is not the same as testing with such hardware but it is still a good mental exercise. To summarize, I do get "not having hardware" part but completely disqualify "not having expertise" part as the expertise needed here has nothing specific to do with TPMs :-) > > drivers/char/tpm/tpm_crb.c | 137 +++++++++++++++++++++++++++---------- > 1 file changed, 101 insertions(+), 36 deletions(-) > > diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c > index e59f1f91d7f3..0bcfe52db5d6 100644 > --- a/drivers/char/tpm/tpm_crb.c > +++ b/drivers/char/tpm/tpm_crb.c > @@ -91,7 +91,6 @@ enum crb_status { > struct crb_priv { > u32 sm; > const char *hid; > - void __iomem *iobase; > struct crb_regs_head __iomem *regs_h; > struct crb_regs_tail __iomem *regs_t; > u8 __iomem *cmd; > @@ -108,6 +107,12 @@ struct tpm2_crb_smc { > u32 smc_func_id; > }; > > +struct crb_resource { > + struct resource io_res; > + void __iomem *iobase; > + struct list_head node; > +}; Please rename 'node' as 'list' for the sake of coherency with the rest of the kernel and io_res as iores for the sake of coherency with the other fields. I think it would be cleaner to do the following: 1. Start with empty resource list. 2. Everytime crb_map_res() is called it does check the existing resources and does a ACPI walk on need basis at most adding one new entry. In other words, crb_map_res() gets the list and appends one entry when necessary. Overhead of doing multiple walks is irrelevant here. The simplicity and clarity win. /Jarkko