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: Reset MSC controls from cpuhp callbacks

When a CPU comes online, it may bring a newly accessible MSC with
it. Only the default partid has its value reset by hardware, and
even then the MSC might not have been reset since its config was
previously dirtied. e.g. Kexec.

Any in-use partid must have its configuration restored, or reset.
In-use partids may be held in caches and evicted later.

MSC are also reset when CPUs are taken offline to cover cases where
firmware doesn't reset the MSC over reboot using UEFI, or kexec
where there is no firmware involvement.

If the configuration for a RIS has not been touched since it was
brought online, it does not need resetting again.

To reset, write the maximum values for all discovered controls.

CC: Rohit Mathew <Rohit.Mathew@arm.com>
Signed-off-by: James Morse <james.morse@arm.com>
Reviewed-by: Fenghua Yu <fenghuay@nvidia.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Reviewed-by: Gavin Shan <gshan@redhat.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
f188a36c c10ca83a

+112
+109
drivers/resctrl/mpam_devices.c
··· 7 7 #include <linux/atomic.h> 8 8 #include <linux/arm_mpam.h> 9 9 #include <linux/bitfield.h> 10 + #include <linux/bitmap.h> 10 11 #include <linux/cacheinfo.h> 11 12 #include <linux/cpu.h> 12 13 #include <linux/cpumask.h> ··· 753 752 return 0; 754 753 } 755 754 755 + static void mpam_reset_msc_bitmap(struct mpam_msc *msc, u16 reg, u16 wd) 756 + { 757 + u32 num_words, msb; 758 + u32 bm = ~0; 759 + int i; 760 + 761 + lockdep_assert_held(&msc->part_sel_lock); 762 + 763 + if (wd == 0) 764 + return; 765 + 766 + /* 767 + * Write all ~0 to all but the last 32bit-word, which may 768 + * have fewer bits... 769 + */ 770 + num_words = DIV_ROUND_UP(wd, 32); 771 + for (i = 0; i < num_words - 1; i++, reg += sizeof(bm)) 772 + __mpam_write_reg(msc, reg, bm); 773 + 774 + /* 775 + * ....and then the last (maybe) partial 32bit word. When wd is a 776 + * multiple of 32, msb should be 31 to write a full 32bit word. 777 + */ 778 + msb = (wd - 1) % 32; 779 + bm = GENMASK(msb, 0); 780 + __mpam_write_reg(msc, reg, bm); 781 + } 782 + 783 + static void mpam_reset_ris_partid(struct mpam_msc_ris *ris, u16 partid) 784 + { 785 + struct mpam_msc *msc = ris->vmsc->msc; 786 + struct mpam_props *rprops = &ris->props; 787 + 788 + WARN_ON_ONCE(!srcu_read_lock_held((&mpam_srcu))); 789 + 790 + mutex_lock(&msc->part_sel_lock); 791 + __mpam_part_sel(ris->ris_idx, partid, msc); 792 + 793 + if (mpam_has_feature(mpam_feat_cpor_part, rprops)) 794 + mpam_reset_msc_bitmap(msc, MPAMCFG_CPBM, rprops->cpbm_wd); 795 + 796 + if (mpam_has_feature(mpam_feat_mbw_part, rprops)) 797 + mpam_reset_msc_bitmap(msc, MPAMCFG_MBW_PBM, rprops->mbw_pbm_bits); 798 + 799 + if (mpam_has_feature(mpam_feat_mbw_min, rprops)) 800 + mpam_write_partsel_reg(msc, MBW_MIN, 0); 801 + 802 + if (mpam_has_feature(mpam_feat_mbw_max, rprops)) 803 + mpam_write_partsel_reg(msc, MBW_MAX, MPAMCFG_MBW_MAX_MAX); 804 + 805 + mutex_unlock(&msc->part_sel_lock); 806 + } 807 + 808 + static void mpam_reset_ris(struct mpam_msc_ris *ris) 809 + { 810 + u16 partid, partid_max; 811 + 812 + WARN_ON_ONCE(!srcu_read_lock_held((&mpam_srcu))); 813 + 814 + if (ris->in_reset_state) 815 + return; 816 + 817 + spin_lock(&partid_max_lock); 818 + partid_max = mpam_partid_max; 819 + spin_unlock(&partid_max_lock); 820 + for (partid = 0; partid <= partid_max; partid++) 821 + mpam_reset_ris_partid(ris, partid); 822 + } 823 + 824 + static void mpam_reset_msc(struct mpam_msc *msc, bool online) 825 + { 826 + struct mpam_msc_ris *ris; 827 + 828 + list_for_each_entry_srcu(ris, &msc->ris, msc_list, srcu_read_lock_held(&mpam_srcu)) { 829 + mpam_reset_ris(ris); 830 + 831 + /* 832 + * Set in_reset_state when coming online. The reset state 833 + * for non-zero partid may be lost while the CPUs are offline. 834 + */ 835 + ris->in_reset_state = online; 836 + } 837 + } 838 + 756 839 static int mpam_cpu_online(unsigned int cpu) 757 840 { 841 + struct mpam_msc *msc; 842 + 843 + guard(srcu)(&mpam_srcu); 844 + list_for_each_entry_srcu(msc, &mpam_all_msc, all_msc_list, 845 + srcu_read_lock_held(&mpam_srcu)) { 846 + if (!cpumask_test_cpu(cpu, &msc->accessibility)) 847 + continue; 848 + 849 + if (atomic_fetch_inc(&msc->online_refs) == 0) 850 + mpam_reset_msc(msc, true); 851 + } 852 + 758 853 return 0; 759 854 } 760 855 ··· 889 792 890 793 static int mpam_cpu_offline(unsigned int cpu) 891 794 { 795 + struct mpam_msc *msc; 796 + 797 + guard(srcu)(&mpam_srcu); 798 + list_for_each_entry_srcu(msc, &mpam_all_msc, all_msc_list, 799 + srcu_read_lock_held(&mpam_srcu)) { 800 + if (!cpumask_test_cpu(cpu, &msc->accessibility)) 801 + continue; 802 + 803 + if (atomic_dec_and_test(&msc->online_refs)) 804 + mpam_reset_msc(msc, false); 805 + } 806 + 892 807 return 0; 893 808 } 894 809
+3
drivers/resctrl/mpam_internal.h
··· 5 5 #define MPAM_INTERNAL_H 6 6 7 7 #include <linux/arm_mpam.h> 8 + #include <linux/atomic.h> 8 9 #include <linux/bitmap.h> 9 10 #include <linux/cpumask.h> 10 11 #include <linux/io.h> ··· 46 45 enum mpam_msc_iface iface; 47 46 u32 nrdy_usec; 48 47 cpumask_t accessibility; 48 + atomic_t online_refs; 49 49 50 50 /* 51 51 * probe_lock is only taken during discovery. After discovery these ··· 200 198 u8 ris_idx; 201 199 u64 idr; 202 200 struct mpam_props props; 201 + bool in_reset_state; 203 202 204 203 cpumask_t affinity; 205 204