Received: by 10.223.185.116 with SMTP id b49csp1171991wrg; Fri, 23 Feb 2018 13:15:14 -0800 (PST) X-Google-Smtp-Source: AH8x224VmMssnOSlxeNPyb41UlzGaTO7BZHBYWjIZfLrpuZqjkwdDiutz7EovghphT5+WNOlRGhJ X-Received: by 10.99.168.8 with SMTP id o8mr2476812pgf.42.1519420514451; Fri, 23 Feb 2018 13:15:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519420514; cv=none; d=google.com; s=arc-20160816; b=ORJPbT+Jz8qWmnT6snL8iz4pd+WyBMgFdVWaEb72WWQkFh/W4I8wrC9KtOQddPEUP9 5+6FJOuh+0/7ZmigHwM+CMHpjuMyGuegB18ArlInd/hJy0oy/D8pGdXPKkXmJxHAmbU4 LxLMUDBxP15B+xdDegMHN5QWj2cq3LIjCtHfaWtmVYpFm3Qa74SbMYYso2Sj1RaMQCdI sJ1HXY9YTZmOLEHV6qbkt3ki/vradT5ftgCYaAigFJ7FHWSLQQ7WRcDeKDCU6x0WKPe6 i4VHsoYb/S609oJoRE5UaMKlbKwjMqNYJgRkE57XGHW0C/cKM/AQrJsJ3SaInvkpxOu2 /QBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=sFFUXl2T0b9Jicm1oLEAPFeh2kMx5Q0K5O1HJCqijgw=; b=ogdSt1ONstgPhiJt8RFxE+w6kUGO9xrG02llF9Jf9aq3+NRNcH+SnCfTnXkPUm4uGF 97SjcV8VuRpFC/UOah/7TcsCd6rwO/uAwDM+dEAeLpMSBsRS2lqqvp/gB8/PpkvXCkdq eZTYkqt8C+kgtRly/ECyiOHmjcc7N/OwkyR8DGbZpFdrjhjf/rBPSeJbOIhHURp0UFdU +cvQVJUCfdx9P9feDgaK8PDLaD3nONkvUUQ8jxk/mV21X/C6ufr7SiEnPptYKZ/IQf2+ Xbmy/F3gaSBmHUprqW2q5Pxd+iGeAk7IOPtOr+qgdd246wRbG9eVAL15wrM1jil5yjsp 2OQw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b63-v6si1140183plb.360.2018.02.23.13.14.59; Fri, 23 Feb 2018 13:15:14 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752196AbeBWVOV (ORCPT + 99 others); Fri, 23 Feb 2018 16:14:21 -0500 Received: from g2t1383g.austin.hpe.com ([15.233.16.89]:42048 "EHLO g2t1383g.austin.hpe.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751610AbeBWVOS (ORCPT ); Fri, 23 Feb 2018 16:14:18 -0500 Received: from g9t5008.houston.hpe.com (g9t5008.houston.hpe.com [15.241.48.72]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by g2t1383g.austin.hpe.com (Postfix) with ESMTPS id 15087CAE for ; Fri, 23 Feb 2018 21:14:18 +0000 (UTC) Received: from g9t2301.houston.hpecorp.net (g9t2301.houston.hpecorp.net [16.220.97.129]) by g9t5008.houston.hpe.com (Postfix) with ESMTP id 6FE2560; Fri, 23 Feb 2018 21:14:17 +0000 (UTC) Received: from misato.americas.hpqcorp.net (unknown [10.34.81.122]) by g9t2301.houston.hpecorp.net (Postfix) with ESMTP id 2E2714C; Fri, 23 Feb 2018 21:14:17 +0000 (UTC) From: Toshi Kani To: dan.j.williams@intel.com Cc: linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org, Toshi Kani Subject: [PATCH 2/2] libnvdimm, label: change nvdimm_num_label_slots per UEFI 2.7 Date: Fri, 23 Feb 2018 14:59:22 -0700 Message-Id: <20180223215922.25415-3-toshi.kani@hpe.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180223215922.25415-1-toshi.kani@hpe.com> References: <20180223215922.25415-1-toshi.kani@hpe.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org sizeof_namespace_index() fails when NVDIMM devices have the minimum 1024 bytes label storage area. nvdimm_num_label_slots() returns 3 slots while the area is only big enough for 2 slots. Change nvdimm_num_label_slots() to calculate a number of label slots according to UEFI 2.7 spec. Signed-off-by: Toshi Kani Cc: Dan Williams --- drivers/nvdimm/label.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index de66c02f6140..be3ccf7c5413 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -45,9 +45,27 @@ unsigned sizeof_namespace_label(struct nvdimm_drvdata *ndd) return ndd->nslabel_size; } +static size_t __sizeof_namespace_index(u32 nslot) +{ + return ALIGN(sizeof(struct nd_namespace_index) + DIV_ROUND_UP(nslot, 8), + NSINDEX_ALIGN); +} + +static int __nvdimm_num_label_slots(struct nvdimm_drvdata *ndd, + size_t index_size) +{ + return (ndd->nsarea.config_size - index_size * 2) / + sizeof_namespace_label(ndd); +} + int nvdimm_num_label_slots(struct nvdimm_drvdata *ndd) { - return ndd->nsarea.config_size / (sizeof_namespace_label(ndd) + 1); + u32 tmp_nslot, n; + + tmp_nslot = ndd->nsarea.config_size / sizeof_namespace_label(ndd); + n = __sizeof_namespace_index(tmp_nslot) / NSINDEX_ALIGN; + + return __nvdimm_num_label_slots(ndd, NSINDEX_ALIGN * n); } size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd) @@ -55,18 +73,14 @@ size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd) u32 nslot, space, size; /* - * The minimum index space is 512 bytes, with that amount of - * index we can describe ~1400 labels which is less than a byte - * of overhead per label. Round up to a byte of overhead per - * label and determine the size of the index region. Yes, this - * starts to waste space at larger config_sizes, but it's - * unlikely we'll ever see anything but 128K. + * Per UEFI 2.7, the minimum size of the Label Storage Area is large + * enough to hold 2 index blocks and 2 labels. The minimum index + * block size is 256 bytes, and the minimum label size is 256 bytes. */ nslot = nvdimm_num_label_slots(ndd); space = ndd->nsarea.config_size - nslot * sizeof_namespace_label(ndd); - size = ALIGN(sizeof(struct nd_namespace_index) + DIV_ROUND_UP(nslot, 8), - NSINDEX_ALIGN) * 2; - if (size <= space) + size = __sizeof_namespace_index(nslot) * 2; + if (size <= space && nslot >= 2) return size / 2; dev_err(ndd->dev, "label area (%d) too small to host (%d byte) labels\n",