Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp803267ybe; Fri, 13 Sep 2019 06:37:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqwlwTjA4mnvW5GBXxL4FADUSCuPqibJM+ucn9cNNzhoZJ280ChHj3pRIfCvj2ftk+1k0Kc+ X-Received: by 2002:a17:906:1ed1:: with SMTP id m17mr22179825ejj.82.1568381869170; Fri, 13 Sep 2019 06:37:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568381869; cv=none; d=google.com; s=arc-20160816; b=ItO7mR3BpIsEijq07wpkmQ2CyGk/P7CfcS9nKBi8RD/xUtPd+2G83LStu/MyvOM3kI bj5DTUXICZWKQH7mbJrtslFgVZ2tzGd3KtmyjuMlNgES6Vk04Wi63WzV/MmULku+l9jY nfS1AKcmObID/7JTCbosWX9mA+ZNbLXENplNU1Z+5zhSEJNdil9nlJsul+/i0xFYYhx9 8hTFy+KPfB4cHO7cFThjHw8duMEFrb9LooK1PdBLWTHAlQknR4g4PDOYKW62oTprpmuF gZq4159lnB5Cpq8bi5MDqAaiuTLIPNdBtovlvIcNoHHORvVTsiW/YIcLNXGhY/0bVtzZ VbTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=nAe0CzbPM4pjzDOLCjgTXSCGsi4dT8GNw2czm9z78LI=; b=zBk2ZU7LT16TVld476DpGGSkDrH5fqZYjtNoX+U1nEUnppLJEyk6doAqXTZr7vmMcR CV06V+y8eK8fQNdgUZgmJOJsuAR8GMIpppvoprtvtW4C8N6gAmCwQnlaZvN+YMSIzYla N+DOWhnpLn2oCy/cyFioLfHSZkx7VASpRBwPBQcot8LRqUqEOLjJFCMFWTCRWrk3unj3 Gfa499Pvkyl1vzXzjFssPVjwr8mXS5qdLViQ0HV4MuCWOJ7pevMtWvsHkleKgpApEB9g 6SC4VT5KumE7odajCIXWwfUpq1wFub67J2NIGfjli5u4jfOimjG6BuyCoXLk9V/53D8E FNpQ== 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 l23si14850264ejg.7.2019.09.13.06.37.25; Fri, 13 Sep 2019 06:37:49 -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 S2391619AbfIMNcn (ORCPT + 99 others); Fri, 13 Sep 2019 09:32:43 -0400 Received: from mga07.intel.com ([134.134.136.100]:1052 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389185AbfIMNMk (ORCPT ); Fri, 13 Sep 2019 09:12:40 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Sep 2019 06:12:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,501,1559545200"; d="scan'208";a="215371241" Received: from ddungax-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.37.38]) by fmsmga002.fm.intel.com with ESMTP; 13 Sep 2019 06:12:35 -0700 Date: Fri, 13 Sep 2019 14:12:34 +0100 From: Jarkko Sakkinen To: Seunghun Han Cc: Peter Huewe , Matthew Garrett , "open list:TPM DEVICE DRIVER" , Linux Kernel Mailing List , Vanya Lazeev Subject: Re: [PATCH v2 2/2] tpm: tpm_crb: enhance resource mapping mechanism for supporting AMD's fTPM Message-ID: <20190913131234.GA7412@linux.intel.com> References: <20190909090906.28700-1-kkamagui@gmail.com> <20190909090906.28700-3-kkamagui@gmail.com> <20190910144215.GA30780@linux.intel.com> <20190910150342.GA1920@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 11, 2019 at 12:28:18AM +0900, Seunghun Han wrote: > > Matthew pointed out that having a hook in NVS driver is better solution > > because it is nil functionality if the TPM driver is loaded. We need > > functions to: > > > > 1. Request a region from the NVS driver (when tpm_crb loads) > > 2. Release a region back to the NVS Driver (when tpm_crb unloads). > > > > My proposal would unnecessarily duplicate code and also leave a > > side-effect when TPM is not used in the first place. > > > > I see this as the overally best solution. If you can come up with a > > patch for the NVS side and changes to CRB drivers to utilize the new > > hooks, then combined with Vanya's changes we have a sustainable solution > > for AMD fTPM. > > It's a great solution. I will update this patch on your advice and > send it to you soon. > > By the way, I have a question about your advice. > If we handle the NVS region with NVS driver, calling devm_ioremap() > function is fine like crb_ioremap_resource() function in this patch? No, you should reclaim the resource that conflicts and return it back when tpm_crb is unregistered (e.g. rmmod tpm_crb). I would try something like enumerating iomem resources with walk_iomem_res_desc(). I would advice to peek at arch/x86/kernel/crash.c for an example how to use this for NVS regions (IORES_DESC_ACPI_NV_STORAGE). E.g. you could use a callback for it along the lines of: static int crb_find_iomem_res_cb(struct resource *res, void *io_res_ptr) { struct resource *io_res = io_res_ptr; if (res->start == io_res->start && res->end == io_res->end) { /* * Backup all resource data so that it can be inserted * later on with the flags it had etc. */ *io_res = *res; return 1; } return 0; } Then you could __release_region() to unallocate the source. When tpm_crb is removed you can then allocate and insert a resource with data matching it had. /Jarkko