mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 18:41:58 +09:00
firmware: arm_scmi: Harden perf domain info access
[ Upstream commit3da8211235] Harden internal accesses to domain info in the SCMI perf protocol. Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Link: https://lore.kernel.org/r/20230717161246.1761777-2-cristian.marussi@arm.com Signed-off-by: Sudeep Holla <sudeep.holla@arm.com> Stable-dep-of:c3638b851b("firmware: arm_scmi: Fixup perf power-cost/microwatt support") Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
3a21635aed
commit
a135c88138
@@ -139,7 +139,7 @@ struct perf_dom_info {
|
|||||||
|
|
||||||
struct scmi_perf_info {
|
struct scmi_perf_info {
|
||||||
u32 version;
|
u32 version;
|
||||||
int num_domains;
|
u16 num_domains;
|
||||||
enum scmi_power_scale power_scale;
|
enum scmi_power_scale power_scale;
|
||||||
u64 stats_addr;
|
u64 stats_addr;
|
||||||
u32 stats_size;
|
u32 stats_size;
|
||||||
@@ -356,11 +356,26 @@ static int scmi_perf_mb_limits_set(const struct scmi_protocol_handle *ph,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct perf_dom_info *
|
||||||
|
scmi_perf_domain_lookup(const struct scmi_protocol_handle *ph, u32 domain)
|
||||||
|
{
|
||||||
|
struct scmi_perf_info *pi = ph->get_priv(ph);
|
||||||
|
|
||||||
|
if (domain >= pi->num_domains)
|
||||||
|
return ERR_PTR(-EINVAL);
|
||||||
|
|
||||||
|
return pi->dom_info + domain;
|
||||||
|
}
|
||||||
|
|
||||||
static int scmi_perf_limits_set(const struct scmi_protocol_handle *ph,
|
static int scmi_perf_limits_set(const struct scmi_protocol_handle *ph,
|
||||||
u32 domain, u32 max_perf, u32 min_perf)
|
u32 domain, u32 max_perf, u32 min_perf)
|
||||||
{
|
{
|
||||||
struct scmi_perf_info *pi = ph->get_priv(ph);
|
struct scmi_perf_info *pi = ph->get_priv(ph);
|
||||||
struct perf_dom_info *dom = pi->dom_info + domain;
|
struct perf_dom_info *dom;
|
||||||
|
|
||||||
|
dom = scmi_perf_domain_lookup(ph, domain);
|
||||||
|
if (IS_ERR(dom))
|
||||||
|
return PTR_ERR(dom);
|
||||||
|
|
||||||
if (PROTOCOL_REV_MAJOR(pi->version) >= 0x3 && !max_perf && !min_perf)
|
if (PROTOCOL_REV_MAJOR(pi->version) >= 0x3 && !max_perf && !min_perf)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@@ -408,8 +423,11 @@ static int scmi_perf_mb_limits_get(const struct scmi_protocol_handle *ph,
|
|||||||
static int scmi_perf_limits_get(const struct scmi_protocol_handle *ph,
|
static int scmi_perf_limits_get(const struct scmi_protocol_handle *ph,
|
||||||
u32 domain, u32 *max_perf, u32 *min_perf)
|
u32 domain, u32 *max_perf, u32 *min_perf)
|
||||||
{
|
{
|
||||||
struct scmi_perf_info *pi = ph->get_priv(ph);
|
struct perf_dom_info *dom;
|
||||||
struct perf_dom_info *dom = pi->dom_info + domain;
|
|
||||||
|
dom = scmi_perf_domain_lookup(ph, domain);
|
||||||
|
if (IS_ERR(dom))
|
||||||
|
return PTR_ERR(dom);
|
||||||
|
|
||||||
if (dom->fc_info && dom->fc_info[PERF_FC_LIMIT].get_addr) {
|
if (dom->fc_info && dom->fc_info[PERF_FC_LIMIT].get_addr) {
|
||||||
struct scmi_fc_info *fci = &dom->fc_info[PERF_FC_LIMIT];
|
struct scmi_fc_info *fci = &dom->fc_info[PERF_FC_LIMIT];
|
||||||
@@ -449,8 +467,11 @@ static int scmi_perf_mb_level_set(const struct scmi_protocol_handle *ph,
|
|||||||
static int scmi_perf_level_set(const struct scmi_protocol_handle *ph,
|
static int scmi_perf_level_set(const struct scmi_protocol_handle *ph,
|
||||||
u32 domain, u32 level, bool poll)
|
u32 domain, u32 level, bool poll)
|
||||||
{
|
{
|
||||||
struct scmi_perf_info *pi = ph->get_priv(ph);
|
struct perf_dom_info *dom;
|
||||||
struct perf_dom_info *dom = pi->dom_info + domain;
|
|
||||||
|
dom = scmi_perf_domain_lookup(ph, domain);
|
||||||
|
if (IS_ERR(dom))
|
||||||
|
return PTR_ERR(dom);
|
||||||
|
|
||||||
if (dom->fc_info && dom->fc_info[PERF_FC_LEVEL].set_addr) {
|
if (dom->fc_info && dom->fc_info[PERF_FC_LEVEL].set_addr) {
|
||||||
struct scmi_fc_info *fci = &dom->fc_info[PERF_FC_LEVEL];
|
struct scmi_fc_info *fci = &dom->fc_info[PERF_FC_LEVEL];
|
||||||
@@ -490,8 +511,11 @@ static int scmi_perf_mb_level_get(const struct scmi_protocol_handle *ph,
|
|||||||
static int scmi_perf_level_get(const struct scmi_protocol_handle *ph,
|
static int scmi_perf_level_get(const struct scmi_protocol_handle *ph,
|
||||||
u32 domain, u32 *level, bool poll)
|
u32 domain, u32 *level, bool poll)
|
||||||
{
|
{
|
||||||
struct scmi_perf_info *pi = ph->get_priv(ph);
|
struct perf_dom_info *dom;
|
||||||
struct perf_dom_info *dom = pi->dom_info + domain;
|
|
||||||
|
dom = scmi_perf_domain_lookup(ph, domain);
|
||||||
|
if (IS_ERR(dom))
|
||||||
|
return PTR_ERR(dom);
|
||||||
|
|
||||||
if (dom->fc_info && dom->fc_info[PERF_FC_LEVEL].get_addr) {
|
if (dom->fc_info && dom->fc_info[PERF_FC_LEVEL].get_addr) {
|
||||||
*level = ioread32(dom->fc_info[PERF_FC_LEVEL].get_addr);
|
*level = ioread32(dom->fc_info[PERF_FC_LEVEL].get_addr);
|
||||||
@@ -574,13 +598,14 @@ static int scmi_dvfs_device_opps_add(const struct scmi_protocol_handle *ph,
|
|||||||
unsigned long freq;
|
unsigned long freq;
|
||||||
struct scmi_opp *opp;
|
struct scmi_opp *opp;
|
||||||
struct perf_dom_info *dom;
|
struct perf_dom_info *dom;
|
||||||
struct scmi_perf_info *pi = ph->get_priv(ph);
|
|
||||||
|
|
||||||
domain = scmi_dev_domain_id(dev);
|
domain = scmi_dev_domain_id(dev);
|
||||||
if (domain < 0)
|
if (domain < 0)
|
||||||
return domain;
|
return -EINVAL;
|
||||||
|
|
||||||
dom = pi->dom_info + domain;
|
dom = scmi_perf_domain_lookup(ph, domain);
|
||||||
|
if (IS_ERR(dom))
|
||||||
|
return PTR_ERR(dom);
|
||||||
|
|
||||||
for (opp = dom->opp, idx = 0; idx < dom->opp_count; idx++, opp++) {
|
for (opp = dom->opp, idx = 0; idx < dom->opp_count; idx++, opp++) {
|
||||||
freq = opp->perf * dom->mult_factor;
|
freq = opp->perf * dom->mult_factor;
|
||||||
@@ -603,14 +628,17 @@ static int
|
|||||||
scmi_dvfs_transition_latency_get(const struct scmi_protocol_handle *ph,
|
scmi_dvfs_transition_latency_get(const struct scmi_protocol_handle *ph,
|
||||||
struct device *dev)
|
struct device *dev)
|
||||||
{
|
{
|
||||||
|
int domain;
|
||||||
struct perf_dom_info *dom;
|
struct perf_dom_info *dom;
|
||||||
struct scmi_perf_info *pi = ph->get_priv(ph);
|
|
||||||
int domain = scmi_dev_domain_id(dev);
|
|
||||||
|
|
||||||
|
domain = scmi_dev_domain_id(dev);
|
||||||
if (domain < 0)
|
if (domain < 0)
|
||||||
return domain;
|
return -EINVAL;
|
||||||
|
|
||||||
|
dom = scmi_perf_domain_lookup(ph, domain);
|
||||||
|
if (IS_ERR(dom))
|
||||||
|
return PTR_ERR(dom);
|
||||||
|
|
||||||
dom = pi->dom_info + domain;
|
|
||||||
/* uS to nS */
|
/* uS to nS */
|
||||||
return dom->opp[dom->opp_count - 1].trans_latency_us * 1000;
|
return dom->opp[dom->opp_count - 1].trans_latency_us * 1000;
|
||||||
}
|
}
|
||||||
@@ -618,8 +646,11 @@ scmi_dvfs_transition_latency_get(const struct scmi_protocol_handle *ph,
|
|||||||
static int scmi_dvfs_freq_set(const struct scmi_protocol_handle *ph, u32 domain,
|
static int scmi_dvfs_freq_set(const struct scmi_protocol_handle *ph, u32 domain,
|
||||||
unsigned long freq, bool poll)
|
unsigned long freq, bool poll)
|
||||||
{
|
{
|
||||||
struct scmi_perf_info *pi = ph->get_priv(ph);
|
struct perf_dom_info *dom;
|
||||||
struct perf_dom_info *dom = pi->dom_info + domain;
|
|
||||||
|
dom = scmi_perf_domain_lookup(ph, domain);
|
||||||
|
if (IS_ERR(dom))
|
||||||
|
return PTR_ERR(dom);
|
||||||
|
|
||||||
return scmi_perf_level_set(ph, domain, freq / dom->mult_factor, poll);
|
return scmi_perf_level_set(ph, domain, freq / dom->mult_factor, poll);
|
||||||
}
|
}
|
||||||
@@ -630,11 +661,14 @@ static int scmi_dvfs_freq_get(const struct scmi_protocol_handle *ph, u32 domain,
|
|||||||
int ret;
|
int ret;
|
||||||
u32 level;
|
u32 level;
|
||||||
struct scmi_perf_info *pi = ph->get_priv(ph);
|
struct scmi_perf_info *pi = ph->get_priv(ph);
|
||||||
struct perf_dom_info *dom = pi->dom_info + domain;
|
|
||||||
|
|
||||||
ret = scmi_perf_level_get(ph, domain, &level, poll);
|
ret = scmi_perf_level_get(ph, domain, &level, poll);
|
||||||
if (!ret)
|
if (!ret) {
|
||||||
|
struct perf_dom_info *dom = pi->dom_info + domain;
|
||||||
|
|
||||||
|
/* Note domain is validated implicitly by scmi_perf_level_get */
|
||||||
*freq = level * dom->mult_factor;
|
*freq = level * dom->mult_factor;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -643,15 +677,14 @@ static int scmi_dvfs_est_power_get(const struct scmi_protocol_handle *ph,
|
|||||||
u32 domain, unsigned long *freq,
|
u32 domain, unsigned long *freq,
|
||||||
unsigned long *power)
|
unsigned long *power)
|
||||||
{
|
{
|
||||||
struct scmi_perf_info *pi = ph->get_priv(ph);
|
|
||||||
struct perf_dom_info *dom;
|
struct perf_dom_info *dom;
|
||||||
unsigned long opp_freq;
|
unsigned long opp_freq;
|
||||||
int idx, ret = -EINVAL;
|
int idx, ret = -EINVAL;
|
||||||
struct scmi_opp *opp;
|
struct scmi_opp *opp;
|
||||||
|
|
||||||
dom = pi->dom_info + domain;
|
dom = scmi_perf_domain_lookup(ph, domain);
|
||||||
if (!dom)
|
if (IS_ERR(dom))
|
||||||
return -EIO;
|
return PTR_ERR(dom);
|
||||||
|
|
||||||
for (opp = dom->opp, idx = 0; idx < dom->opp_count; idx++, opp++) {
|
for (opp = dom->opp, idx = 0; idx < dom->opp_count; idx++, opp++) {
|
||||||
opp_freq = opp->perf * dom->mult_factor;
|
opp_freq = opp->perf * dom->mult_factor;
|
||||||
@@ -670,10 +703,16 @@ static int scmi_dvfs_est_power_get(const struct scmi_protocol_handle *ph,
|
|||||||
static bool scmi_fast_switch_possible(const struct scmi_protocol_handle *ph,
|
static bool scmi_fast_switch_possible(const struct scmi_protocol_handle *ph,
|
||||||
struct device *dev)
|
struct device *dev)
|
||||||
{
|
{
|
||||||
|
int domain;
|
||||||
struct perf_dom_info *dom;
|
struct perf_dom_info *dom;
|
||||||
struct scmi_perf_info *pi = ph->get_priv(ph);
|
|
||||||
|
|
||||||
dom = pi->dom_info + scmi_dev_domain_id(dev);
|
domain = scmi_dev_domain_id(dev);
|
||||||
|
if (domain < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
dom = scmi_perf_domain_lookup(ph, domain);
|
||||||
|
if (IS_ERR(dom))
|
||||||
|
return false;
|
||||||
|
|
||||||
return dom->fc_info && dom->fc_info[PERF_FC_LEVEL].set_addr;
|
return dom->fc_info && dom->fc_info[PERF_FC_LEVEL].set_addr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user