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: Add helpers for managing the locking around the mon_sel registers

The MSC MON_SEL register needs to be accessed from hardirq for the overflow
interrupt, and when taking an IPI to access these registers on platforms
where MSC are not accessible from every CPU. This makes an irqsave
spinlock the obvious lock to protect these registers. On systems with SCMI
or PCC mailboxes it must be able to sleep, meaning a mutex must be used.
The SCMI or PCC platforms can't support an overflow interrupt, and
can't access the registers from hardirq context.

Clearly these two can't exist for one MSC at the same time.

Add helpers for the MON_SEL locking. For now, use a irqsave spinlock and
only support 'real' MMIO platforms.

In the future this lock will be split in two allowing SCMI/PCC platforms
to take a mutex. Because there are contexts where the SCMI/PCC platforms
can't make an access, mpam_mon_sel_lock() needs to be able to fail. Do
this now, so that all the error handling on these paths is present. This
allows the relevant paths to fail if they are needed on a platform where
this isn't possible, instead of having to make explicit checks of the
interface type.

Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.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: James Morse <james.morse@arm.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
d02beb06 bd221f9f

+43
+2
drivers/resctrl/mpam_devices.c
··· 19 19 #include <linux/platform_device.h> 20 20 #include <linux/printk.h> 21 21 #include <linux/srcu.h> 22 + #include <linux/spinlock.h> 22 23 #include <linux/types.h> 23 24 #include <linux/workqueue.h> 24 25 ··· 741 740 if (err) 742 741 return ERR_PTR(err); 743 742 743 + mpam_mon_sel_lock_init(msc); 744 744 msc->id = pdev->id; 745 745 msc->pdev = pdev; 746 746 INIT_LIST_HEAD_RCU(&msc->all_msc_list);
+41
drivers/resctrl/mpam_internal.h
··· 10 10 #include <linux/llist.h> 11 11 #include <linux/mutex.h> 12 12 #include <linux/srcu.h> 13 + #include <linux/spinlock.h> 13 14 #include <linux/types.h> 14 15 15 16 #define MPAM_MSC_MAX_NUM_RIS 16 ··· 66 65 */ 67 66 struct mutex part_sel_lock; 68 67 68 + /* 69 + * mon_sel_lock protects access to the MSC hardware registers that are 70 + * affected by MPAMCFG_MON_SEL, and the mbwu_state. 71 + * Access to mon_sel is needed from both process and interrupt contexts, 72 + * but is complicated by firmware-backed platforms that can't make any 73 + * access unless they can sleep. 74 + * Always use the mpam_mon_sel_lock() helpers. 75 + * Accesses to mon_sel need to be able to fail if they occur in the wrong 76 + * context. 77 + * If needed, take msc->probe_lock first. 78 + */ 79 + raw_spinlock_t _mon_sel_lock; 80 + unsigned long _mon_sel_flags; 81 + 69 82 void __iomem *mapped_hwpage; 70 83 size_t mapped_hwpage_sz; 71 84 72 85 struct mpam_garbage garbage; 73 86 }; 87 + 88 + /* Returning false here means accesses to mon_sel must fail and report an error. */ 89 + static inline bool __must_check mpam_mon_sel_lock(struct mpam_msc *msc) 90 + { 91 + /* Locking will require updating to support a firmware backed interface */ 92 + if (WARN_ON_ONCE(msc->iface != MPAM_IFACE_MMIO)) 93 + return false; 94 + 95 + raw_spin_lock_irqsave(&msc->_mon_sel_lock, msc->_mon_sel_flags); 96 + return true; 97 + } 98 + 99 + static inline void mpam_mon_sel_unlock(struct mpam_msc *msc) 100 + { 101 + raw_spin_unlock_irqrestore(&msc->_mon_sel_lock, msc->_mon_sel_flags); 102 + } 103 + 104 + static inline void mpam_mon_sel_lock_held(struct mpam_msc *msc) 105 + { 106 + lockdep_assert_held_once(&msc->_mon_sel_lock); 107 + } 108 + 109 + static inline void mpam_mon_sel_lock_init(struct mpam_msc *msc) 110 + { 111 + raw_spin_lock_init(&msc->_mon_sel_lock); 112 + } 74 113 75 114 struct mpam_class { 76 115 /* mpam_components in this class */