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

Configure Feed

Select the types of activity you want to include in your feed.

arm_mpam: Probe hardware to find the supported partid/pmg values

CPUs can generate traffic with a range of PARTID and PMG values,
but each MSC may also have its own maximum size for these fields.
Before MPAM can be used, the driver needs to probe each RIS on
each MSC, to find the system-wide smallest value that can be used.
The limits from requestors (e.g. CPUs) also need taking into account.

While doing this, RIS entries that firmware didn't describe are created
under MPAM_CLASS_UNKNOWN.

This adds the low level MSC write accessors.

While we're here, implement the mpam_register_requestor() call
for the arch code to register the CPU limits. Future callers of this
will tell us about the SMMU and ITS.

Signed-off-by: James Morse <james.morse@arm.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Reviewed-by: Ben Horgan <ben.horgan@arm.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Reviewed-by: Fenghua Yu <fenghuay@nvidia.com>
Tested-by: Fenghua Yu <fenghuay@nvidia.com>
Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com>
Tested-by: Gavin Shan <gshan@redhat.com>
Tested-by: Zeng Heng <zengheng4@huawei.com>
Tested-by: Hanjun Guo <guohanjun@huawei.com>
Signed-off-by: Ben Horgan <ben.horgan@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>

authored by

James Morse and committed by
Catalin Marinas
bd221f9f 8f8d0ac1

+167 -1
+147 -1
drivers/resctrl/mpam_devices.c
··· 6 6 #include <linux/acpi.h> 7 7 #include <linux/atomic.h> 8 8 #include <linux/arm_mpam.h> 9 + #include <linux/bitfield.h> 9 10 #include <linux/cacheinfo.h> 10 11 #include <linux/cpu.h> 11 12 #include <linux/cpumask.h> ··· 42 41 43 42 static int mpam_cpuhp_state; 44 43 static DEFINE_MUTEX(mpam_cpuhp_state_lock); 44 + 45 + /* 46 + * The smallest common values for any CPU or MSC in the system. 47 + * Generating traffic outside this range will result in screaming interrupts. 48 + */ 49 + u16 mpam_partid_max; 50 + u8 mpam_pmg_max; 51 + static bool partid_max_init, partid_max_published; 52 + static DEFINE_SPINLOCK(partid_max_lock); 45 53 46 54 /* 47 55 * mpam is enabled once all devices have been probed from CPU online callbacks, ··· 152 142 } 153 143 154 144 #define mpam_read_partsel_reg(msc, reg) _mpam_read_partsel_reg(msc, MPAMF_##reg) 145 + 146 + static void __mpam_write_reg(struct mpam_msc *msc, u16 reg, u32 val) 147 + { 148 + WARN_ON_ONCE(reg + sizeof(u32) > msc->mapped_hwpage_sz); 149 + WARN_ON_ONCE(!cpumask_test_cpu(smp_processor_id(), &msc->accessibility)); 150 + 151 + writel_relaxed(val, msc->mapped_hwpage + reg); 152 + } 153 + 154 + static inline void _mpam_write_partsel_reg(struct mpam_msc *msc, u16 reg, u32 val) 155 + { 156 + lockdep_assert_held_once(&msc->part_sel_lock); 157 + __mpam_write_reg(msc, reg, val); 158 + } 159 + 160 + #define mpam_write_partsel_reg(msc, reg, val) _mpam_write_partsel_reg(msc, MPAMCFG_##reg, val) 161 + 162 + static u64 mpam_msc_read_idr(struct mpam_msc *msc) 163 + { 164 + u64 idr_high = 0, idr_low; 165 + 166 + lockdep_assert_held(&msc->part_sel_lock); 167 + 168 + idr_low = mpam_read_partsel_reg(msc, IDR); 169 + if (FIELD_GET(MPAMF_IDR_EXT, idr_low)) 170 + idr_high = mpam_read_partsel_reg(msc, IDR + 4); 171 + 172 + return (idr_high << 32) | idr_low; 173 + } 174 + 175 + static void __mpam_part_sel_raw(u32 partsel, struct mpam_msc *msc) 176 + { 177 + lockdep_assert_held(&msc->part_sel_lock); 178 + 179 + mpam_write_partsel_reg(msc, PART_SEL, partsel); 180 + } 181 + 182 + static void __mpam_part_sel(u8 ris_idx, u16 partid, struct mpam_msc *msc) 183 + { 184 + u32 partsel = FIELD_PREP(MPAMCFG_PART_SEL_RIS, ris_idx) | 185 + FIELD_PREP(MPAMCFG_PART_SEL_PARTID_SEL, partid); 186 + 187 + __mpam_part_sel_raw(partsel, msc); 188 + } 189 + 190 + int mpam_register_requestor(u16 partid_max, u8 pmg_max) 191 + { 192 + guard(spinlock)(&partid_max_lock); 193 + if (!partid_max_init) { 194 + mpam_partid_max = partid_max; 195 + mpam_pmg_max = pmg_max; 196 + partid_max_init = true; 197 + } else if (!partid_max_published) { 198 + mpam_partid_max = min(mpam_partid_max, partid_max); 199 + mpam_pmg_max = min(mpam_pmg_max, pmg_max); 200 + } else { 201 + /* New requestors can't lower the values */ 202 + if (partid_max < mpam_partid_max || pmg_max < mpam_pmg_max) 203 + return -EBUSY; 204 + } 205 + 206 + return 0; 207 + } 208 + EXPORT_SYMBOL(mpam_register_requestor); 155 209 156 210 static struct mpam_class * 157 211 mpam_class_alloc(u8 level_idx, enum mpam_class_types type) ··· 524 450 return err; 525 451 } 526 452 453 + static struct mpam_msc_ris *mpam_get_or_create_ris(struct mpam_msc *msc, 454 + u8 ris_idx) 455 + { 456 + int err; 457 + struct mpam_msc_ris *ris; 458 + 459 + lockdep_assert_held(&mpam_list_lock); 460 + 461 + if (!test_bit(ris_idx, &msc->ris_idxs)) { 462 + err = mpam_ris_create_locked(msc, ris_idx, MPAM_CLASS_UNKNOWN, 463 + 0, 0); 464 + if (err) 465 + return ERR_PTR(err); 466 + } 467 + 468 + list_for_each_entry(ris, &msc->ris, msc_list) { 469 + if (ris->ris_idx == ris_idx) 470 + return ris; 471 + } 472 + 473 + return ERR_PTR(-ENOENT); 474 + } 475 + 527 476 static int mpam_msc_hw_probe(struct mpam_msc *msc) 528 477 { 529 478 u64 idr; 479 + u16 partid_max; 480 + u8 ris_idx, pmg_max; 481 + struct mpam_msc_ris *ris; 530 482 struct device *dev = &msc->pdev->dev; 531 483 532 484 lockdep_assert_held(&msc->probe_lock); ··· 562 462 dev_err_once(dev, "MSC does not match MPAM architecture v1.x\n"); 563 463 return -EIO; 564 464 } 465 + 466 + /* Grab an IDR value to find out how many RIS there are */ 467 + mutex_lock(&msc->part_sel_lock); 468 + idr = mpam_msc_read_idr(msc); 469 + mutex_unlock(&msc->part_sel_lock); 470 + 471 + msc->ris_max = FIELD_GET(MPAMF_IDR_RIS_MAX, idr); 472 + 473 + /* Use these values so partid/pmg always starts with a valid value */ 474 + msc->partid_max = FIELD_GET(MPAMF_IDR_PARTID_MAX, idr); 475 + msc->pmg_max = FIELD_GET(MPAMF_IDR_PMG_MAX, idr); 476 + 477 + for (ris_idx = 0; ris_idx <= msc->ris_max; ris_idx++) { 478 + mutex_lock(&msc->part_sel_lock); 479 + __mpam_part_sel(ris_idx, 0, msc); 480 + idr = mpam_msc_read_idr(msc); 481 + mutex_unlock(&msc->part_sel_lock); 482 + 483 + partid_max = FIELD_GET(MPAMF_IDR_PARTID_MAX, idr); 484 + pmg_max = FIELD_GET(MPAMF_IDR_PMG_MAX, idr); 485 + msc->partid_max = min(msc->partid_max, partid_max); 486 + msc->pmg_max = min(msc->pmg_max, pmg_max); 487 + 488 + mutex_lock(&mpam_list_lock); 489 + ris = mpam_get_or_create_ris(msc, ris_idx); 490 + mutex_unlock(&mpam_list_lock); 491 + if (IS_ERR(ris)) 492 + return PTR_ERR(ris); 493 + } 494 + 495 + spin_lock(&partid_max_lock); 496 + mpam_partid_max = min(mpam_partid_max, msc->partid_max); 497 + mpam_pmg_max = min(mpam_pmg_max, msc->pmg_max); 498 + spin_unlock(&partid_max_lock); 565 499 566 500 msc->probed = true; 567 501 ··· 816 682 817 683 static void mpam_enable_once(void) 818 684 { 685 + /* 686 + * Once the cpuhp callbacks have been changed, mpam_partid_max can no 687 + * longer change. 688 + */ 689 + spin_lock(&partid_max_lock); 690 + partid_max_published = true; 691 + spin_unlock(&partid_max_lock); 692 + 819 693 mpam_register_cpuhp_callbacks(mpam_cpu_online, mpam_cpu_offline, 820 694 "mpam:online"); 821 695 822 - pr_info("MPAM enabled\n"); 696 + /* Use printk() to avoid the pr_fmt adding the function name. */ 697 + printk(KERN_INFO "MPAM enabled with %u PARTIDs and %u PMGs\n", 698 + mpam_partid_max + 1, mpam_pmg_max + 1); 823 699 } 824 700 825 701 void mpam_disable(struct work_struct *ignored) ··· 895 751 896 752 return platform_driver_register(&mpam_msc_driver); 897 753 } 754 + 755 + /* Must occur after arm64_mpam_register_cpus() from arch_initcall() */ 898 756 subsys_initcall(mpam_msc_driver_init);
+6
drivers/resctrl/mpam_internal.h
··· 49 49 */ 50 50 struct mutex probe_lock; 51 51 bool probed; 52 + u16 partid_max; 53 + u8 pmg_max; 52 54 unsigned long ris_idxs; 53 55 u32 ris_max; 54 56 ··· 139 137 /* List of all classes - protected by srcu*/ 140 138 extern struct srcu_struct mpam_srcu; 141 139 extern struct list_head mpam_classes; 140 + 141 + /* System wide partid/pmg values */ 142 + extern u16 mpam_partid_max; 143 + extern u8 mpam_pmg_max; 142 144 143 145 /* Scheduled work callback to enable mpam once all MSC have been probed */ 144 146 void mpam_enable(struct work_struct *work);
+14
include/linux/arm_mpam.h
··· 49 49 } 50 50 #endif 51 51 52 + /** 53 + * mpam_register_requestor() - Register a requestor with the MPAM driver 54 + * @partid_max: The maximum PARTID value the requestor can generate. 55 + * @pmg_max: The maximum PMG value the requestor can generate. 56 + * 57 + * Registers a requestor with the MPAM driver to ensure the chosen system-wide 58 + * minimum PARTID and PMG values will allow the requestors features to be used. 59 + * 60 + * Returns an error if the registration is too late, and a larger PARTID/PMG 61 + * value has been advertised to user-space. In this case the requestor should 62 + * not use its MPAM features. Returns 0 on success. 63 + */ 64 + int mpam_register_requestor(u16 partid_max, u8 pmg_max); 65 + 52 66 #endif /* __LINUX_ARM_MPAM_H */