Skip to content

Commit 1fe3385

Browse files
committed
s390/pai: export number of sysfs attribute files
jira LE-4018 Rebuild_History Non-Buildable kernel-5.14.0-570.37.1.el9_6 commit-author Thomas Richter <tmricht@linux.ibm.com> commit d414f4e The number of sysfs files to be exported by the PAI device drivers depends on the hardware version level. Use the value returned by the hardware as the maximum number of counters to be exported in the sysfs attribute tree. Without the fix, older machine generation export counter names based on paiXXXX_ctrnames static array info, which can be inaccurate, as this array could also contain newer counter names in the future. This ensures proper pai counter sysfs attributes for both newer generation and older generation processors. Signed-off-by: Thomas Richter <tmricht@linux.ibm.com> Acked-by: Sumanth Korikkar <sumanthk@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com> (cherry picked from commit d414f4e) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 38098ed commit 1fe3385

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

arch/s390/kernel/perf_pai_crypto.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,12 @@ static int __init attr_event_init_one(struct attribute **attrs, int num)
634634
{
635635
struct perf_pmu_events_attr *pa;
636636

637+
/* Index larger than array_size, no counter name available */
638+
if (num >= ARRAY_SIZE(paicrypt_ctrnames)) {
639+
attrs[num] = NULL;
640+
return 0;
641+
}
642+
637643
pa = kzalloc(sizeof(*pa), GFP_KERNEL);
638644
if (!pa)
639645
return -ENOMEM;
@@ -654,11 +660,10 @@ static int __init attr_event_init(void)
654660
struct attribute **attrs;
655661
int ret, i;
656662

657-
attrs = kmalloc_array(ARRAY_SIZE(paicrypt_ctrnames) + 1, sizeof(*attrs),
658-
GFP_KERNEL);
663+
attrs = kmalloc_array(paicrypt_cnt + 2, sizeof(*attrs), GFP_KERNEL);
659664
if (!attrs)
660665
return -ENOMEM;
661-
for (i = 0; i < ARRAY_SIZE(paicrypt_ctrnames); i++) {
666+
for (i = 0; i <= paicrypt_cnt; i++) {
662667
ret = attr_event_init_one(attrs, i);
663668
if (ret) {
664669
attr_event_free(attrs, i);

arch/s390/kernel/perf_pai_ext.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,12 @@ static int __init attr_event_init_one(struct attribute **attrs, int num)
588588
{
589589
struct perf_pmu_events_attr *pa;
590590

591+
/* Index larger than array_size, no counter name available */
592+
if (num >= ARRAY_SIZE(paiext_ctrnames)) {
593+
attrs[num] = NULL;
594+
return 0;
595+
}
596+
591597
pa = kzalloc(sizeof(*pa), GFP_KERNEL);
592598
if (!pa)
593599
return -ENOMEM;
@@ -608,11 +614,10 @@ static int __init attr_event_init(void)
608614
struct attribute **attrs;
609615
int ret, i;
610616

611-
attrs = kmalloc_array(ARRAY_SIZE(paiext_ctrnames) + 1, sizeof(*attrs),
612-
GFP_KERNEL);
617+
attrs = kmalloc_array(paiext_cnt + 2, sizeof(*attrs), GFP_KERNEL);
613618
if (!attrs)
614619
return -ENOMEM;
615-
for (i = 0; i < ARRAY_SIZE(paiext_ctrnames); i++) {
620+
for (i = 0; i <= paiext_cnt; i++) {
616621
ret = attr_event_init_one(attrs, i);
617622
if (ret) {
618623
attr_event_free(attrs, i);

0 commit comments

Comments
 (0)