* [PATCH] powercap/rapl: prevent overridding bits outside of the mask
@ 2017-06-01 9:21 Adam Lessnau
2017-06-27 0:17 ` Rafael J. Wysocki
0 siblings, 1 reply; 3+ messages in thread
From: Adam Lessnau @ 2017-06-01 9:21 UTC (permalink / raw)
To: rjw; +Cc: linux-pm, Adam Lessnau
Fixes wrong bits shift operation in the rapl_write_data_raw function, which
might cause overridding bits outside of the mask.
For example, writing new TIME_WINDOW1 value can override POWER_LIMIT1.
Signed-off-by: Adam Lessnau <adam.lessnau@intel.com>
---
drivers/powercap/intel_rapl.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c
index 3c71f608b444..6dc27afb8527 100644
--- a/drivers/powercap/intel_rapl.c
+++ b/drivers/powercap/intel_rapl.c
@@ -887,7 +887,9 @@ static int rapl_write_data_raw(struct rapl_domain *rd,
cpu = rd->rp->lead_cpu;
bits = rapl_unit_xlate(rd, rp->unit, value, 1);
- bits |= bits << rp->shift;
+ bits <<= rp->shift;
+ bits &= rp->mask;
+
memset(&ma, 0, sizeof(ma));
ma.msr_no = rd->msrs[rp->id];
--
2.13.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] powercap/rapl: prevent overridding bits outside of the mask
2017-06-01 9:21 [PATCH] powercap/rapl: prevent overridding bits outside of the mask Adam Lessnau
@ 2017-06-27 0:17 ` Rafael J. Wysocki
2017-06-27 16:25 ` Jacob Pan
0 siblings, 1 reply; 3+ messages in thread
From: Rafael J. Wysocki @ 2017-06-27 0:17 UTC (permalink / raw)
To: Adam Lessnau, Jacob Pan; +Cc: linux-pm
On Thursday, June 01, 2017 11:21:50 AM Adam Lessnau wrote:
> Fixes wrong bits shift operation in the rapl_write_data_raw function, which
> might cause overridding bits outside of the mask.
>
> For example, writing new TIME_WINDOW1 value can override POWER_LIMIT1.
>
> Signed-off-by: Adam Lessnau <adam.lessnau@intel.com>
Jacob, any comments?
> ---
> drivers/powercap/intel_rapl.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c
> index 3c71f608b444..6dc27afb8527 100644
> --- a/drivers/powercap/intel_rapl.c
> +++ b/drivers/powercap/intel_rapl.c
> @@ -887,7 +887,9 @@ static int rapl_write_data_raw(struct rapl_domain *rd,
>
> cpu = rd->rp->lead_cpu;
> bits = rapl_unit_xlate(rd, rp->unit, value, 1);
> - bits |= bits << rp->shift;
> + bits <<= rp->shift;
> + bits &= rp->mask;
> +
> memset(&ma, 0, sizeof(ma));
>
> ma.msr_no = rd->msrs[rp->id];
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] powercap/rapl: prevent overridding bits outside of the mask
2017-06-27 0:17 ` Rafael J. Wysocki
@ 2017-06-27 16:25 ` Jacob Pan
0 siblings, 0 replies; 3+ messages in thread
From: Jacob Pan @ 2017-06-27 16:25 UTC (permalink / raw)
To: Rafael J. Wysocki; +Cc: Adam Lessnau, linux-pm, jacob.jun.pan
On Tue, 27 Jun 2017 02:17:32 +0200
"Rafael J. Wysocki" <rjw@rjwysocki.net> wrote:
> On Thursday, June 01, 2017 11:21:50 AM Adam Lessnau wrote:
> > Fixes wrong bits shift operation in the rapl_write_data_raw
> > function, which might cause overridding bits outside of the mask.
> >
> > For example, writing new TIME_WINDOW1 value can override
> > POWER_LIMIT1.
> >
> > Signed-off-by: Adam Lessnau <adam.lessnau@intel.com>
>
> Jacob, any comments?
>
Looks like a good fix. Thanks.
> > ---
> > drivers/powercap/intel_rapl.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/powercap/intel_rapl.c
> > b/drivers/powercap/intel_rapl.c index 3c71f608b444..6dc27afb8527
> > 100644 --- a/drivers/powercap/intel_rapl.c
> > +++ b/drivers/powercap/intel_rapl.c
> > @@ -887,7 +887,9 @@ static int rapl_write_data_raw(struct
> > rapl_domain *rd,
> > cpu = rd->rp->lead_cpu;
> > bits = rapl_unit_xlate(rd, rp->unit, value, 1);
> > - bits |= bits << rp->shift;
> > + bits <<= rp->shift;
> > + bits &= rp->mask;
> > +
> > memset(&ma, 0, sizeof(ma));
> >
> > ma.msr_no = rd->msrs[rp->id];
> >
>
[Jacob Pan]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-06-27 16:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-01 9:21 [PATCH] powercap/rapl: prevent overridding bits outside of the mask Adam Lessnau
2017-06-27 0:17 ` Rafael J. Wysocki
2017-06-27 16:25 ` Jacob Pan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).