From owner-svn-src-all@freebsd.org Tue Nov 12 16:24:37 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id CA7131B220C; Tue, 12 Nov 2019 16:24:37 +0000 (UTC) (envelope-from scottph@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47CCkY4rmQz3GXS; Tue, 12 Nov 2019 16:24:37 +0000 (UTC) (envelope-from scottph@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8AC3A260B; Tue, 12 Nov 2019 16:24:37 +0000 (UTC) (envelope-from scottph@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xACGOb7U027785; Tue, 12 Nov 2019 16:24:37 GMT (envelope-from scottph@FreeBSD.org) Received: (from scottph@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xACGObd5027784; Tue, 12 Nov 2019 16:24:37 GMT (envelope-from scottph@FreeBSD.org) Message-Id: <201911121624.xACGObd5027784@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: scottph set sender to scottph@FreeBSD.org using -f From: D Scott Phillips Date: Tue, 12 Nov 2019 16:24:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r354648 - head/sys/dev/nvdimm X-SVN-Group: head X-SVN-Commit-Author: scottph X-SVN-Commit-Paths: head/sys/dev/nvdimm X-SVN-Commit-Revision: 354648 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Nov 2019 16:24:37 -0000 Author: scottph Date: Tue Nov 12 16:24:37 2019 New Revision: 354648 URL: https://svnweb.freebsd.org/changeset/base/354648 Log: nvdimm(4): Fix various problems when the using the second label index block struct nvdimm_label_index is dynamically sized, with the `free` bitfield expanding to hold `slot_cnt` entries. Fix a few places where we were treating the struct as though it had a fixed sized. Reviewed by: cem Approved by: scottl (mentor) MFC after: 1 week Sponsored by: Intel Corporation Differential Revision: https://reviews.freebsd.org/D22253 Modified: head/sys/dev/nvdimm/nvdimm.c Modified: head/sys/dev/nvdimm/nvdimm.c ============================================================================== --- head/sys/dev/nvdimm/nvdimm.c Tue Nov 12 15:56:27 2019 (r354647) +++ head/sys/dev/nvdimm/nvdimm.c Tue Nov 12 16:24:37 2019 (r354648) @@ -183,7 +183,7 @@ label_index_is_valid(struct nvdimm_label_index *index, { uint64_t checksum; - index = (struct nvdimm_label_index *)((uint8_t *)index + offset); + index = (struct nvdimm_label_index *)((uint8_t *)index + size * offset); if (strcmp(index->signature, NVDIMM_INDEX_BLOCK_SIGNATURE) != 0) return false; checksum = index->checksum; @@ -242,7 +242,7 @@ read_label(struct nvdimm_dev *nv, int num) static int read_labels(struct nvdimm_dev *nv) { - struct nvdimm_label_index *indices; + struct nvdimm_label_index *indices, *index1; size_t bitfield_size, index_size, num_labels; int error, n; bool index_0_valid, index_1_valid; @@ -258,6 +258,7 @@ read_labels(struct nvdimm_dev *nv) sizeof(struct nvdimm_label); bitfield_size = roundup2(num_labels, 8) / 8; indices = malloc(2 * index_size, M_NVDIMM, M_WAITOK); + index1 = (void *)((uint8_t *)indices + index_size); error = read_label_area(nv, (void *)indices, 0, 2 * index_size); if (error != 0) { free(indices, M_NVDIMM); @@ -271,18 +272,29 @@ read_labels(struct nvdimm_dev *nv) free(indices, M_NVDIMM); return (ENXIO); } - if (index_0_valid && index_1_valid && - (indices[1].seq > indices[0].seq || - (indices[1].seq == 1 && indices[0].seq == 3))) - index_0_valid = false; + if (index_0_valid && index_1_valid) { + if (((int)indices->seq - (int)index1->seq + 3) % 3 == 1) { + /* index 0 was more recently updated */ + index_1_valid = false; + } else { + /* + * either index 1 was more recently updated, + * or the sequence numbers are equal, in which + * case the specification says the block with + * the higher offset is to be treated as valid + */ + index_0_valid = false; + } + } nv->label_index = malloc(index_size, M_NVDIMM, M_WAITOK); - bcopy(indices + (index_0_valid ? 0 : 1), nv->label_index, index_size); + bcopy(index_0_valid ? indices : index1, nv->label_index, index_size); free(indices, M_NVDIMM); - for (bit_ffc_at((bitstr_t *)nv->label_index->free, 0, num_labels, &n); - n >= 0; - bit_ffc_at((bitstr_t *)nv->label_index->free, n + 1, num_labels, - &n)) { + bit_ffc_at((bitstr_t *)nv->label_index->free, 0, + nv->label_index->slot_cnt, &n); + while (n >= 0) { read_label(nv, n); + bit_ffc_at((bitstr_t *)nv->label_index->free, n + 1, + nv->label_index->slot_cnt, &n); } return (0); }