Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'libnvdimm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm

Pull libnvdimm fixes from Dan Williams:
"1/ Two regression fixes since v4.6: one for the byte order of a sysfs
attribute (bz121161) and another for QEMU 2.6's NVDIMM _DSM (ACPI
Device Specific Method) implementation that gets tripped up by new
auto-probing behavior in the NFIT driver.

2/ A fix tagged for -stable that stops the kernel from
clobbering/ignoring changes to the configuration of a 'pfn'
instance ("struct page" driver). For example changing the
alignment from 2M to 1G may silently revert to 2M if that value is
currently stored on media.

3/ A fix from Eric for an xfstests failure in dax. It is not
currently tagged for -stable since it requires an 8-exabyte file
system to trigger, and there appear to be no user visible side
effects"

* 'libnvdimm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm:
nfit: fix format interface code byte order
dax: fix offset overflow in dax_io
acpi, nfit: fix acpi_check_dsm() vs zero functions implemented
libnvdimm, pfn, dax: fix initialization vs autodetect for mode + alignment

+60 -26
+6 -6
drivers/acpi/nfit.c
··· 928 928 { 929 929 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev); 930 930 931 - return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->code)); 931 + return sprintf(buf, "0x%04x\n", le16_to_cpu(dcr->code)); 932 932 } 933 933 static DEVICE_ATTR_RO(format); 934 934 ··· 961 961 continue; 962 962 if (nfit_dcr->dcr->code == dcr->code) 963 963 continue; 964 - rc = sprintf(buf, "%#x\n", 965 - be16_to_cpu(nfit_dcr->dcr->code)); 964 + rc = sprintf(buf, "0x%04x\n", 965 + le16_to_cpu(nfit_dcr->dcr->code)); 966 966 break; 967 967 } 968 968 if (rc != ENXIO) ··· 1131 1131 1132 1132 /* 1133 1133 * Until standardization materializes we need to consider up to 3 1134 - * different command sets. Note, that checking for function0 (bit0) 1135 - * tells us if any commands are reachable through this uuid. 1134 + * different command sets. Note, that checking for zero functions 1135 + * tells us if any commands might be reachable through this uuid. 1136 1136 */ 1137 1137 for (i = NVDIMM_FAMILY_INTEL; i <= NVDIMM_FAMILY_HPE2; i++) 1138 - if (acpi_check_dsm(adev_dimm->handle, to_nfit_uuid(i), 1, 1)) 1138 + if (acpi_check_dsm(adev_dimm->handle, to_nfit_uuid(i), 1, 0)) 1139 1139 break; 1140 1140 1141 1141 /* limit the supported commands to those that are publicly documented */
+5 -5
drivers/acpi/nfit.h
··· 53 53 }; 54 54 55 55 /* 56 - * Region format interface codes are stored as an array of bytes in the 57 - * NFIT DIMM Control Region structure 56 + * Region format interface codes are stored with the interface as the 57 + * LSB and the function as the MSB. 58 58 */ 59 - #define NFIT_FIC_BYTE cpu_to_be16(0x101) /* byte-addressable energy backed */ 60 - #define NFIT_FIC_BLK cpu_to_be16(0x201) /* block-addressable non-energy backed */ 61 - #define NFIT_FIC_BYTEN cpu_to_be16(0x301) /* byte-addressable non-energy backed */ 59 + #define NFIT_FIC_BYTE cpu_to_le16(0x101) /* byte-addressable energy backed */ 60 + #define NFIT_FIC_BLK cpu_to_le16(0x201) /* block-addressable non-energy backed */ 61 + #define NFIT_FIC_BYTEN cpu_to_le16(0x301) /* byte-addressable non-energy backed */ 62 62 63 63 enum { 64 64 NFIT_BLK_READ_FLUSH = 1,
+3 -3
drivers/acpi/utils.c
··· 680 680 u64 mask = 0; 681 681 union acpi_object *obj; 682 682 683 - if (funcs == 0) 684 - return false; 685 - 686 683 obj = acpi_evaluate_dsm(handle, uuid, rev, 0, NULL); 687 684 if (!obj) 688 685 return false; ··· 691 694 for (i = 0; i < obj->buffer.length && i < 8; i++) 692 695 mask |= (((u64)obj->buffer.pointer[i]) << (i * 8)); 693 696 ACPI_FREE(obj); 697 + 698 + if (funcs == 0) 699 + return true; 694 700 695 701 /* 696 702 * Bit 0 indicates whether there's support for any functions other than
+40 -11
drivers/nvdimm/pfn_devs.c
··· 344 344 int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig) 345 345 { 346 346 u64 checksum, offset; 347 + unsigned long align; 348 + enum nd_pfn_mode mode; 347 349 struct nd_namespace_io *nsio; 348 350 struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb; 349 351 struct nd_namespace_common *ndns = nd_pfn->ndns; ··· 388 386 return -ENXIO; 389 387 } 390 388 389 + align = le32_to_cpu(pfn_sb->align); 390 + offset = le64_to_cpu(pfn_sb->dataoff); 391 + if (align == 0) 392 + align = 1UL << ilog2(offset); 393 + mode = le32_to_cpu(pfn_sb->mode); 394 + 391 395 if (!nd_pfn->uuid) { 392 - /* from probe we allocate */ 396 + /* 397 + * When probing a namepace via nd_pfn_probe() the uuid 398 + * is NULL (see: nd_pfn_devinit()) we init settings from 399 + * pfn_sb 400 + */ 393 401 nd_pfn->uuid = kmemdup(pfn_sb->uuid, 16, GFP_KERNEL); 394 402 if (!nd_pfn->uuid) 395 403 return -ENOMEM; 404 + nd_pfn->align = align; 405 + nd_pfn->mode = mode; 396 406 } else { 397 - /* from init we validate */ 407 + /* 408 + * When probing a pfn / dax instance we validate the 409 + * live settings against the pfn_sb 410 + */ 398 411 if (memcmp(nd_pfn->uuid, pfn_sb->uuid, 16) != 0) 399 412 return -ENODEV; 413 + 414 + /* 415 + * If the uuid validates, but other settings mismatch 416 + * return EINVAL because userspace has managed to change 417 + * the configuration without specifying new 418 + * identification. 419 + */ 420 + if (nd_pfn->align != align || nd_pfn->mode != mode) { 421 + dev_err(&nd_pfn->dev, 422 + "init failed, settings mismatch\n"); 423 + dev_dbg(&nd_pfn->dev, "align: %lx:%lx mode: %d:%d\n", 424 + nd_pfn->align, align, nd_pfn->mode, 425 + mode); 426 + return -EINVAL; 427 + } 400 428 } 401 429 402 - if (nd_pfn->align == 0) 403 - nd_pfn->align = le32_to_cpu(pfn_sb->align); 404 - if (nd_pfn->align > nvdimm_namespace_capacity(ndns)) { 430 + if (align > nvdimm_namespace_capacity(ndns)) { 405 431 dev_err(&nd_pfn->dev, "alignment: %lx exceeds capacity %llx\n", 406 - nd_pfn->align, nvdimm_namespace_capacity(ndns)); 432 + align, nvdimm_namespace_capacity(ndns)); 407 433 return -EINVAL; 408 434 } 409 435 ··· 441 411 * namespace has changed since the pfn superblock was 442 412 * established. 443 413 */ 444 - offset = le64_to_cpu(pfn_sb->dataoff); 445 414 nsio = to_nd_namespace_io(&ndns->dev); 446 415 if (offset >= resource_size(&nsio->res)) { 447 416 dev_err(&nd_pfn->dev, "pfn array size exceeds capacity of %s\n", ··· 448 419 return -EBUSY; 449 420 } 450 421 451 - if ((nd_pfn->align && !IS_ALIGNED(offset, nd_pfn->align)) 422 + if ((align && !IS_ALIGNED(offset, align)) 452 423 || !IS_ALIGNED(offset, PAGE_SIZE)) { 453 - dev_err(&nd_pfn->dev, "bad offset: %#llx dax disabled\n", 454 - offset); 424 + dev_err(&nd_pfn->dev, 425 + "bad offset: %#llx dax disabled align: %#lx\n", 426 + offset, align); 455 427 return -ENXIO; 456 428 } 457 429 ··· 532 502 res->start += start_pad; 533 503 res->end -= end_trunc; 534 504 535 - nd_pfn->mode = le32_to_cpu(nd_pfn->pfn_sb->mode); 536 505 if (nd_pfn->mode == PFN_MODE_RAM) { 537 506 if (offset < SZ_8K) 538 507 return ERR_PTR(-EINVAL);
+6 -1
fs/dax.c
··· 208 208 dax.addr += first; 209 209 size = map_len - first; 210 210 } 211 - max = min(pos + size, end); 211 + /* 212 + * pos + size is one past the last offset for IO, 213 + * so pos + size can overflow loff_t at extreme offsets. 214 + * Cast to u64 to catch this and get the true minimum. 215 + */ 216 + max = min_t(u64, pos + size, end); 212 217 } 213 218 214 219 if (iov_iter_rw(iter) == WRITE) {