From patchwork Tue Mar 8 20:59:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 8537731 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 03B0E9F46A for ; Tue, 8 Mar 2016 20:59:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 01F59201FE for ; Tue, 8 Mar 2016 20:59:49 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ECD8B201E4 for ; Tue, 8 Mar 2016 20:59:47 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 462BD1A1E2B; Tue, 8 Mar 2016 13:00:01 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mail-oi0-x236.google.com (mail-oi0-x236.google.com [IPv6:2607:f8b0:4003:c06::236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 314CA1A1E2B for ; Tue, 8 Mar 2016 12:59:59 -0800 (PST) Received: by mail-oi0-x236.google.com with SMTP id m82so20288759oif.1 for ; Tue, 08 Mar 2016 12:59:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=0ZkjlDKXj8Rw1xeOF2rsh4foQW/xut5bfkHGYPPZB2Y=; b=u54Iv5k6wJgaZKQtX4q6es3PlacQasYKzlyxRVqmoVx1om3uzncb5NRMhd73vKs5s2 7kZ47bdf4cidTocPV29/NV5sdU//PumIcRt+TMv54Roru8fNK6zGZNRQ/ZJtVN2iOHls mKO9V0gCzJ5igyA4xY0axBTSK93INSsM1SVhQ7yjqcODCidvj5MQ20JCH6y2QFAuxsHp 4txYDD25XifERR0I94yR60Jqw7NvLzaMookm0n5GkVqzth5cF4/V6I4CtBQmvUbkDbCa D6O8ruPF4/YDeC0f7+e102VrjYoOcloH41pzrbJJ2uA98CVsxZfHnShrTsome7F98uPS Y24w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=0ZkjlDKXj8Rw1xeOF2rsh4foQW/xut5bfkHGYPPZB2Y=; b=XKESkkRKToifBTBJ5UJ4n/2KWu9MqrEe6XKCaawADtlIP5bgjnWYobZl6vQYCrw8AK Cpm9/7yiKhQbGNQ8gSF/0k1pOqCVXU0TsXguVN9L3SNsBq93IBx+BOBG2/P+YDbstHk2 r4c2rXVN25t9/RSM3r2mZoso1/af7hqDQCrvZuV0krGWRp/yjw5Q9WF5LVQK4wHTdJdy u+7cFpe4Q9zBgxsSVwJ0apYZPSVNx8Dmv80qit/tIkpQz8PfmXGdwCL7jGkqpK4mWOn7 U+pKTEvmg/XdHfwI70q880gQxeb9nz6ijtdAdhITBoWEPFCAHCdQik7Gzju6NXrQGham RK6Q== X-Gm-Message-State: AD7BkJL9A7pvBoSlCy5iLtomRSUMqNMtUIle2tCVv49X3uJGZ6rsyBtgkmoPb1PJBd5xPWbOofKmfZ0ppLoCmtsm MIME-Version: 1.0 X-Received: by 10.202.186.193 with SMTP id k184mr18178363oif.66.1457470784746; Tue, 08 Mar 2016 12:59:44 -0800 (PST) Received: by 10.157.15.145 with HTTP; Tue, 8 Mar 2016 12:59:44 -0800 (PST) In-Reply-To: References: <1457460530-17959-1-git-send-email-toshi.kani@hpe.com> Date: Tue, 8 Mar 2016 12:59:44 -0800 Message-ID: Subject: Re: [PATCH v2-UPDATE2 3/4] resource: Add device-managed insert/remove_resource() From: Dan Williams To: Linus Torvalds Cc: "linux-nvdimm@lists.01.org" , "Rafael J. Wysocki" , Linux Kernel Mailing List , Linux ACPI , Andrew Morton , Borislav Petkov , Ingo Molnar X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Tue, Mar 8, 2016 at 12:05 PM, Linus Torvalds wrote: > On Tue, Mar 8, 2016 at 10:08 AM, Toshi Kani wrote: >> >> Add device-managed implementaions of insert_resource() and >> remove_resouce() functions. > > Can we get an example of the users and show how much this would actually help? > > insert_resource() is fairly unusual to begin with, and it should > basically *never* be used by a driver at all (it's more of a bus > thing). > > The patch doesn't look _wrong_, but it does look potentially largely > pointless. Adding new interfaces to do things that aren't common > enough to worry about is counter-productive, imho. Here's the usage patch from Toshi [1] (copied below). It is indeed a resource injected by nfit / nvdimm bus implementation. We just happen to support nfit and libnvdimm as modules. The goal of these patches is to use the ACPI NFIT data to create a "Persistent Memory" rather than "reserved" resource. This is for platform-firmware implementations that use E820-Type2 rather than E820-Type7 to describe pmem. [1]: https://patchwork.kernel.org/patch/8485691/ 8<-- From: Toshi Kani ACPI 6.0 defines persistent memory (PMEM) ranges in multiple firmware interfaces, e820, EFI, and ACPI NFIT table. This EFI change, however, leads to hit a bug in the grub bootloader, which treats EFI_PERSISTENT_MEMORY type as regular memory and corrupts stored user data [1]. Therefore, BIOS may set generic reserved type in e820 and EFI to cover PMEM ranges. The kernel can initialize PMEM ranges from ACPI NFIT table alone. This scheme causes a problem in the iomem table, though. On x86, for instance, e820_reserve_resources() initializes top-level entries (iomem_resource.child) from the e820 table at early boot-time. This creates "reserved" entry for a PMEM range, which does not allow region_intersects() to check with PMEM type. Change acpi_nfit_register_region() to call acpi_nfit_insert_resource(), which calls devm_insert_resource() to insert a PMEM entry from NFIT when the iomem table does not have a PMEM entry already. That is, when a PMEM range is marked as reserved type in e820, it inserts "Persistent Memory" entry, which results as follows. + "Persistent Memory" + "reserved" This allows the EINJ driver, which calls region_intersects() to check PMEM ranges, to work continuously even if BIOS sets reserved type (or sets nothing) to PMEM ranges in e820 and EFI. [1]: https://lists.gnu.org/archive/html/grub-devel/2015-11/msg00209.html Signed-off-by: Toshi Kani Cc: Rafael J. Wysocki Cc: Dan Williams Cc: Ingo Molnar Cc: Borislav Petkov Cc: Andrew Morton --- drivers/acpi/nfit.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) { @@ -1781,6 +1805,12 @@ static int acpi_nfit_register_region(struct acpi_nfit_desc *acpi_desc, nvdimm_bus = acpi_desc->nvdimm_bus; if (nfit_spa_type(spa) == NFIT_SPA_PM) { + rc = acpi_nfit_insert_resource(acpi_desc, ndr_desc); + if (rc) + dev_warn(acpi_desc->dev, + "failed to insert pmem resource to iomem: %d\n", + rc); + rc = acpi_nfit_find_poison(acpi_desc, ndr_desc); if (rc) { dev_err(acpi_desc->dev, diff --git a/drivers/acpi/nfit.c b/drivers/acpi/nfit.c index fb53db1..d97b53f 100644 --- a/drivers/acpi/nfit.c +++ b/drivers/acpi/nfit.c @@ -1571,6 +1571,30 @@ static int ars_status_process_records(struct nvdimm_bus *nvdimm_bus, return 0; } +static int acpi_nfit_insert_resource(struct acpi_nfit_desc *acpi_desc, + struct nd_region_desc *ndr_desc) +{ + struct resource *res, *nd_res = ndr_desc->res; + size_t size = nd_res->end - nd_res->start + 1; + + /* No operation if the region is already registered as PMEM */ + if (region_intersects(nd_res->start, size, IORESOURCE_MEM, + IORES_DESC_PERSISTENT_MEMORY) == REGION_INTERSECTS) + return 0; + + res = devm_kzalloc(acpi_desc->dev, sizeof(*res), GFP_KERNEL); + if (!res) + return -ENOMEM; + + res->name = "Persistent Memory"; + res->start = nd_res->start; + res->end = nd_res->end; + res->flags = IORESOURCE_MEM; + res->desc = IORES_DESC_PERSISTENT_MEMORY; + + return devm_insert_resource(acpi_desc->dev, &iomem_resource, res); +} + static int acpi_nfit_find_poison(struct acpi_nfit_desc *acpi_desc, struct nd_region_desc *ndr_desc)