Skip to contentSkip to conversation

powercap/rapl: prevent overridding bits outside of the mask

PATCH In review Adam Lessnau 3 participants 3 messages Jun 1, 2017 – Jun 27, 2017 Power management core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powercap/rapl: prevent overridding bits outside of the mask

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.

---
 drivers/powercap/intel_rapl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/powercap/intel_rapl.c +3 -1
index 3c71f608b444..6dc27afb8527 100644
@@ -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];
Signature · 1 line
2.13.0
#1 lore raw
Quoted 6 lines · 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.

Jacob, any comments?

Quoted 20 lines
---
 drivers/powercap/intel_rapl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/powercap/intel_rapl.c +3 -1
index 3c71f608b444..6dc27afb8527 100644
@@ -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 lore raw
Quoted 11 lines · On Tue, 27 Jun 2017 02:17:32 +0200 "Rafael J. Wysocki" <[email protected]>…
Quoted 7 lines · 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.

Jacob, any comments?

Looks like a good fix. Thanks.

Quoted 18 lines
Quoted 18 lines
---
 drivers/powercap/intel_rapl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/powercap/intel_rapl.c index 3c71f608b444..6dc27afb8527 100644 --- a/drivers/powercap/intel_rapl.c
+++ b/drivers/powercap/intel_rapl.c

drivers/powercap/intel_rapl.c +3 -1
@@ -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));
 
Quoted 3 lines

drivers/powercap/intel_rapl.c static int rapl_write_data_raw(struct rapl_domain *rd, · line 895

Quoted 2 lines
drivers/powercap/intel_rapl.c +0 -0
 	ma.msr_no = rd->msrs[rp->id];

[Jacob Pan]