Skip to content

Commit b75dba7

Browse files
committed
Merge tag 'libnvdimm-fixes-5.11-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm
Pull libnvdimm fixes from Dan Williams: "A fix for a crash scenario that has been present since the initial merge, a minor regression in sysfs attribute visibility, and a fix for some flexible array warnings. The bulk of this pull is an update to the libnvdimm unit test infrastructure to test non-ACPI platforms. Given there is zero regression risk for test updates, and the tests enable validation of bits headed towards the next merge window, I saw no reason to hold the new tests back. Santosh originally submitted this before the v5.11 window opened. Summary: - Fix a crash when sysfs accesses race 'dimm' driver probe/remove. - Fix a regression in 'resource' attribute visibility necessary for mapping badblocks and other physical address interrogations. - Fix some flexible array warnings - Expand the unit test infrastructure for non-ACPI platforms" * tag 'libnvdimm-fixes-5.11-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm: libnvdimm/dimm: Avoid race between probe and available_slots_show() ndtest: Add papr health related flags ndtest: Add nvdimm control functions ndtest: Add regions and mappings to the test buses ndtest: Add dimm attributes ndtest: Add dimms to the two buses ndtest: Add compatability string to treat it as PAPR family testing/nvdimm: Add test module for non-nfit platforms libnvdimm/namespace: Fix visibility of namespace resource attribute libnvdimm/pmem: Remove unused header ACPI: NFIT: Fix flexible_array.cocci warnings
2 parents ff92acb + 7018c89 commit b75dba7

File tree

8 files changed

+1293
-58
lines changed

8 files changed

+1293
-58
lines changed

drivers/acpi/nfit/core.c

Lines changed: 28 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,49 +2269,33 @@ static const struct attribute_group *acpi_nfit_region_attribute_groups[] = {
22692269

22702270
/* enough info to uniquely specify an interleave set */
22712271
struct nfit_set_info {
2272-
struct nfit_set_info_map {
2273-
u64 region_offset;
2274-
u32 serial_number;
2275-
u32 pad;
2276-
} mapping[0];
2272+
u64 region_offset;
2273+
u32 serial_number;
2274+
u32 pad;
22772275
};
22782276

22792277
struct nfit_set_info2 {
2280-
struct nfit_set_info_map2 {
2281-
u64 region_offset;
2282-
u32 serial_number;
2283-
u16 vendor_id;
2284-
u16 manufacturing_date;
2285-
u8 manufacturing_location;
2286-
u8 reserved[31];
2287-
} mapping[0];
2278+
u64 region_offset;
2279+
u32 serial_number;
2280+
u16 vendor_id;
2281+
u16 manufacturing_date;
2282+
u8 manufacturing_location;
2283+
u8 reserved[31];
22882284
};
22892285

2290-
static size_t sizeof_nfit_set_info(int num_mappings)
2291-
{
2292-
return sizeof(struct nfit_set_info)
2293-
+ num_mappings * sizeof(struct nfit_set_info_map);
2294-
}
2295-
2296-
static size_t sizeof_nfit_set_info2(int num_mappings)
2297-
{
2298-
return sizeof(struct nfit_set_info2)
2299-
+ num_mappings * sizeof(struct nfit_set_info_map2);
2300-
}
2301-
23022286
static int cmp_map_compat(const void *m0, const void *m1)
23032287
{
2304-
const struct nfit_set_info_map *map0 = m0;
2305-
const struct nfit_set_info_map *map1 = m1;
2288+
const struct nfit_set_info *map0 = m0;
2289+
const struct nfit_set_info *map1 = m1;
23062290

23072291
return memcmp(&map0->region_offset, &map1->region_offset,
23082292
sizeof(u64));
23092293
}
23102294

23112295
static int cmp_map(const void *m0, const void *m1)
23122296
{
2313-
const struct nfit_set_info_map *map0 = m0;
2314-
const struct nfit_set_info_map *map1 = m1;
2297+
const struct nfit_set_info *map0 = m0;
2298+
const struct nfit_set_info *map1 = m1;
23152299

23162300
if (map0->region_offset < map1->region_offset)
23172301
return -1;
@@ -2322,8 +2306,8 @@ static int cmp_map(const void *m0, const void *m1)
23222306

23232307
static int cmp_map2(const void *m0, const void *m1)
23242308
{
2325-
const struct nfit_set_info_map2 *map0 = m0;
2326-
const struct nfit_set_info_map2 *map1 = m1;
2309+
const struct nfit_set_info2 *map0 = m0;
2310+
const struct nfit_set_info2 *map1 = m1;
23272311

23282312
if (map0->region_offset < map1->region_offset)
23292313
return -1;
@@ -2361,22 +2345,22 @@ static int acpi_nfit_init_interleave_set(struct acpi_nfit_desc *acpi_desc,
23612345
return -ENOMEM;
23622346
import_guid(&nd_set->type_guid, spa->range_guid);
23632347

2364-
info = devm_kzalloc(dev, sizeof_nfit_set_info(nr), GFP_KERNEL);
2348+
info = devm_kcalloc(dev, nr, sizeof(*info), GFP_KERNEL);
23652349
if (!info)
23662350
return -ENOMEM;
23672351

2368-
info2 = devm_kzalloc(dev, sizeof_nfit_set_info2(nr), GFP_KERNEL);
2352+
info2 = devm_kcalloc(dev, nr, sizeof(*info2), GFP_KERNEL);
23692353
if (!info2)
23702354
return -ENOMEM;
23712355

23722356
for (i = 0; i < nr; i++) {
23732357
struct nd_mapping_desc *mapping = &ndr_desc->mapping[i];
2374-
struct nfit_set_info_map *map = &info->mapping[i];
2375-
struct nfit_set_info_map2 *map2 = &info2->mapping[i];
23762358
struct nvdimm *nvdimm = mapping->nvdimm;
23772359
struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
2378-
struct acpi_nfit_memory_map *memdev = memdev_from_spa(acpi_desc,
2379-
spa->range_index, i);
2360+
struct nfit_set_info *map = &info[i];
2361+
struct nfit_set_info2 *map2 = &info2[i];
2362+
struct acpi_nfit_memory_map *memdev =
2363+
memdev_from_spa(acpi_desc, spa->range_index, i);
23802364
struct acpi_nfit_control_region *dcr = nfit_mem->dcr;
23812365

23822366
if (!memdev || !nfit_mem->dcr) {
@@ -2395,23 +2379,20 @@ static int acpi_nfit_init_interleave_set(struct acpi_nfit_desc *acpi_desc,
23952379
}
23962380

23972381
/* v1.1 namespaces */
2398-
sort(&info->mapping[0], nr, sizeof(struct nfit_set_info_map),
2399-
cmp_map, NULL);
2400-
nd_set->cookie1 = nd_fletcher64(info, sizeof_nfit_set_info(nr), 0);
2382+
sort(info, nr, sizeof(*info), cmp_map, NULL);
2383+
nd_set->cookie1 = nd_fletcher64(info, sizeof(*info) * nr, 0);
24012384

24022385
/* v1.2 namespaces */
2403-
sort(&info2->mapping[0], nr, sizeof(struct nfit_set_info_map2),
2404-
cmp_map2, NULL);
2405-
nd_set->cookie2 = nd_fletcher64(info2, sizeof_nfit_set_info2(nr), 0);
2386+
sort(info2, nr, sizeof(*info2), cmp_map2, NULL);
2387+
nd_set->cookie2 = nd_fletcher64(info2, sizeof(*info2) * nr, 0);
24062388

24072389
/* support v1.1 namespaces created with the wrong sort order */
2408-
sort(&info->mapping[0], nr, sizeof(struct nfit_set_info_map),
2409-
cmp_map_compat, NULL);
2410-
nd_set->altcookie = nd_fletcher64(info, sizeof_nfit_set_info(nr), 0);
2390+
sort(info, nr, sizeof(*info), cmp_map_compat, NULL);
2391+
nd_set->altcookie = nd_fletcher64(info, sizeof(*info) * nr, 0);
24112392

24122393
/* record the result of the sort for the mapping position */
24132394
for (i = 0; i < nr; i++) {
2414-
struct nfit_set_info_map2 *map2 = &info2->mapping[i];
2395+
struct nfit_set_info2 *map2 = &info2[i];
24152396
int j;
24162397

24172398
for (j = 0; j < nr; j++) {

drivers/nvdimm/dimm_devs.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,16 +335,16 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,
335335
}
336336
static DEVICE_ATTR_RO(state);
337337

338-
static ssize_t available_slots_show(struct device *dev,
339-
struct device_attribute *attr, char *buf)
338+
static ssize_t __available_slots_show(struct nvdimm_drvdata *ndd, char *buf)
340339
{
341-
struct nvdimm_drvdata *ndd = dev_get_drvdata(dev);
340+
struct device *dev;
342341
ssize_t rc;
343342
u32 nfree;
344343

345344
if (!ndd)
346345
return -ENXIO;
347346

347+
dev = ndd->dev;
348348
nvdimm_bus_lock(dev);
349349
nfree = nd_label_nfree(ndd);
350350
if (nfree - 1 > nfree) {
@@ -356,6 +356,18 @@ static ssize_t available_slots_show(struct device *dev,
356356
nvdimm_bus_unlock(dev);
357357
return rc;
358358
}
359+
360+
static ssize_t available_slots_show(struct device *dev,
361+
struct device_attribute *attr, char *buf)
362+
{
363+
ssize_t rc;
364+
365+
nd_device_lock(dev);
366+
rc = __available_slots_show(dev_get_drvdata(dev), buf);
367+
nd_device_unlock(dev);
368+
369+
return rc;
370+
}
359371
static DEVICE_ATTR_RO(available_slots);
360372

361373
__weak ssize_t security_show(struct device *dev,

drivers/nvdimm/namespace_devs.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,11 +1635,11 @@ static umode_t namespace_visible(struct kobject *kobj,
16351635
return a->mode;
16361636
}
16371637

1638-
if (a == &dev_attr_nstype.attr || a == &dev_attr_size.attr
1639-
|| a == &dev_attr_holder.attr
1640-
|| a == &dev_attr_holder_class.attr
1641-
|| a == &dev_attr_force_raw.attr
1642-
|| a == &dev_attr_mode.attr)
1638+
/* base is_namespace_io() attributes */
1639+
if (a == &dev_attr_nstype.attr || a == &dev_attr_size.attr ||
1640+
a == &dev_attr_holder.attr || a == &dev_attr_holder_class.attr ||
1641+
a == &dev_attr_force_raw.attr || a == &dev_attr_mode.attr ||
1642+
a == &dev_attr_resource.attr)
16431643
return a->mode;
16441644

16451645
return 0;

drivers/nvdimm/pmem.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <linux/uio.h>
2424
#include <linux/dax.h>
2525
#include <linux/nd.h>
26-
#include <linux/backing-dev.h>
2726
#include <linux/mm.h>
2827
#include <asm/cacheflush.h>
2928
#include "pmem.h"

tools/testing/nvdimm/config_check.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ void check(void)
1212
BUILD_BUG_ON(!IS_MODULE(CONFIG_ND_BTT));
1313
BUILD_BUG_ON(!IS_MODULE(CONFIG_ND_PFN));
1414
BUILD_BUG_ON(!IS_MODULE(CONFIG_ND_BLK));
15-
BUILD_BUG_ON(!IS_MODULE(CONFIG_ACPI_NFIT));
15+
if (IS_ENABLED(CONFIG_ACPI_NFIT))
16+
BUILD_BUG_ON(!IS_MODULE(CONFIG_ACPI_NFIT));
1617
BUILD_BUG_ON(!IS_MODULE(CONFIG_DEV_DAX));
1718
BUILD_BUG_ON(!IS_MODULE(CONFIG_DEV_DAX_PMEM));
1819
}

tools/testing/nvdimm/test/Kbuild

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@ ccflags-y += -I$(srctree)/drivers/acpi/nfit/
55
obj-m += nfit_test.o
66
obj-m += nfit_test_iomap.o
77

8-
nfit_test-y := nfit.o
8+
ifeq ($(CONFIG_ACPI_NFIT),m)
9+
nfit_test-y := nfit.o
10+
else
11+
nfit_test-y := ndtest.o
12+
endif
913
nfit_test_iomap-y := iomap.o

0 commit comments

Comments
 (0)