From patchwork Wed Feb 6 02:04:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 10798745 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D72A13B5 for ; Wed, 6 Feb 2019 02:05:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E27D29C31 for ; Wed, 6 Feb 2019 02:05:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 31D9229B8D; Wed, 6 Feb 2019 02:05:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 2379729805 for ; Wed, 6 Feb 2019 02:05:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A72B3211CA2C4; Tue, 5 Feb 2019 18:05:10 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::444; helo=mail-pf1-x444.google.com; envelope-from=oohall@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) (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 29D3E211CA2BF for ; Tue, 5 Feb 2019 18:05:08 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id b85so2396105pfc.3 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=G/v8peHa7Y3CH0AajmRokcJHkceagJ4nuzFAorevWswpcW28KqagdARpU0wZmY9Mj3 Fs4a38ERBMR65rrYoXZWJ13x6ClcbA1apJRHQVuq+Og3y33bMcWXnU+zGZndypjSRCLK dTDVsnH4QrciysmRZ7I0NaA8YZbDj5XHKjBqMzHosStxT2xuBRby4bdwHrtCR3fk1A5V 2kKBOzpDAOv1QdjZXoLUzsk+3NuraNK8lIJk96oah56sjmlHR2nYpnGnc1Am4VH3gG9h 7+SiQ5DVlB6Ec3dxxRO4TfgGHUlHj+LuIMH3qm3ffbcCTbGrePTOSYxDEWhLysPyrdgf 7ZNw== X-Gm-Message-State: AHQUAuZlzknBPhfKDvq1k6x4HANZ7elq8n6uy7Emc/rf6PF5pq0nA9W8 mRnifKYQDd8VNbOsbCxAdOFC+Qzg 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 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 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: stable@vger.kernel.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Vishal Verma --- --- 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);