From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B329C282CB for ; Wed, 6 Feb 2019 02:05:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D8C782184E for ; Wed, 6 Feb 2019 02:05:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Mak7vq9r" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729341AbfBFCFJ (ORCPT ); Tue, 5 Feb 2019 21:05:09 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:46866 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728971AbfBFCFJ (ORCPT ); Tue, 5 Feb 2019 21:05:09 -0500 Received: by mail-pf1-f194.google.com with SMTP id c73so2372666pfe.13 for ; Tue, 05 Feb 2019 18:05:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=sGwebpXfFsFNd6qsbHXKxejUurww6V6o8z/0zXWslu8=; b=Mak7vq9rV8Vada01IRHf38o5SzPEdVTNmJWTQhVYlMTxmnlNVV5KiQ0nphgeckdq8O uHK1/hWqAloEf+xn0EeGX6qHxkjl7XVWvBa5G8pApqgouqcon6Xgbt6sz8c10oO0cj0i MlTWNEoNvXMW/Q3YlwxbAUs1+ja96pR2+C4t6pjAJTYxXFrBCo6T7l+HiSb7c+zdANZ9 sQOXN65VaxzFIe4U7/L23N9I1Rtba9/5wMub//Wz+u/k7CoUMYcQp5i247iB5Oydb7Qs LP+fDy7tT2RDQSm66AsSvOg3Fw3iPz/VJGaAdqQP0pewFCSjQuz7L5lpPE/Jum7wZNU3 FjjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=sGwebpXfFsFNd6qsbHXKxejUurww6V6o8z/0zXWslu8=; b=cVjELk9uPwkXLojIDKl8CvXKQbF6CgZYxjJRbpT2Jzo6QNIDm+G7gRWQjldDtgybdN rAn66Txm2N9ivO8UY0U7dy+xukFLXCDmpw929i5NONpMDWRaE89u1EkrC0oR1OtKxy9a 88V5LgVz0GF+RBaygu2E0WNbnj9FQVv7ulHdj4SEHH+onRMUj/gQ5BVCuNh0lLp4N2Oc nAXE9MZyJP1zNdeYFDIw4z9QzyFKBmPlGjfMtLb8SZI7Le0dMGPtpv6EJxJgzwaChaj1 vxseJ7dXeGg6OWjQ7heyp/DPYZKtoJCOEeBKzMXvIuIDrGnZllVlWq2eJmWUsXfE3lXl B9mg== X-Gm-Message-State: AHQUAuYGHj8magZhcclQJKmDlJMg1d7M/n1e/y+50lm4+sD34ivqPG3R UkOVjzOfFkQ7jaJNcblzYntogzVh X-Google-Smtp-Source: AHgI3IaNUAPiy4wyjlhp68pg81sTHyHK/lsmy2cDHv1KDd7ZjBTMMUGOuP87fBFyYZGlH6M1lLxh0g== X-Received: by 2002:a63:140c:: with SMTP id u12mr1592682pgl.24.1549418708419; Tue, 05 Feb 2019 18:05:08 -0800 (PST) Received: from wafer.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id i72sm6261297pfe.181.2019.02.05.18.05.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Feb 2019 18:05:07 -0800 (PST) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Cc: Oliver O'Halloran , stable@vger.kernel.org, Dan Williams Subject: [PATCH] libnvdimm: Fix altmap reservation size calculation Date: Wed, 6 Feb 2019 13:04:53 +1100 Message-Id: <20190206020453.25534-1-oohall@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Libnvdimm reserves the first 8K of pfn and devicedax namespaces to store a superblock describing the namespace. This 8K reservation is contained within the altmap area which the kernel uses for the vmemmap backing for the pages within the namespace. The altmap allows for some pages at the start of the altmap area to be reserved and that mechanism is used to protect the superblock from being re-used as vmemmap backing. The number of PFNs to reserve is calculated using: PHYS_PFN(SZ_8K) Which is implemented as: #define PHYS_PFN(x) ((unsigned long)((x) >> PAGE_SHIFT)) So on systems where PAGE_SIZE is greater than 8K the reservation size is truncated to zero and the superblock area is re-used as vmemmap backing. As a result all the namespace information stored in the superblock (i.e. if it's a PFN or DAX namespace) is lost and the namespace needs to be re-created to get access to the contents. This patch fixes this by using PFN_UP() rather than PHYS_PFN() to ensure that at least one page is reserved. On systems with a 4K pages size this patch should have no effect. Cc: stable@vger.kernel.org Cc: Dan Williams Fixes: ac515c084be9 ("libnvdimm, pmem, pfn: move pfn setup to the core") Signed-off-by: Oliver O'Halloran --- --- drivers/nvdimm/pfn_devs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c index 6f22272e8d80..9b9be83da0e7 100644 --- a/drivers/nvdimm/pfn_devs.c +++ b/drivers/nvdimm/pfn_devs.c @@ -593,7 +593,7 @@ static unsigned long init_altmap_base(resource_size_t base) static unsigned long init_altmap_reserve(resource_size_t base) { - unsigned long reserve = PHYS_PFN(SZ_8K); + unsigned long reserve = PFN_UP(SZ_8K); unsigned long base_pfn = PHYS_PFN(base); reserve += base_pfn - PFN_SECTION_ALIGN_DOWN(base_pfn); -- 2.20.1