linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [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

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).