Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp3062972img; Mon, 25 Mar 2019 03:02:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqw/tw9+EBUp5hDdqXNI15pDym5MRkdyL4Qm6SYbh2N3mhva1d1AEvI59cyr7Okx4ta3BbRo X-Received: by 2002:a65:43cc:: with SMTP id n12mr21524848pgp.218.1553508149763; Mon, 25 Mar 2019 03:02:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553508149; cv=none; d=google.com; s=arc-20160816; b=sm3E3Qh9jeBPSOae1U5EvgI6qJPekbWIy21aBMarSuoFuuOZL1y/q4lnsiutlJutzi Fxvm14R96m0FhkKfZtG3S+HP/6gk1dORk0FcIbMMlqZpQsAeJhsNe+CUBaf0zmXIYMsg tfE9AnujOBplGLG1CM1bJDhFWAggZTfRulN/oPvCa5hDQccAtjnAOJfeNfmlYwONTz7N KSebaXTVCLPP+41s6Wk5n0kSTTfTg4X3fKXScfdmwQGbQpt+hnQWYppcGOzl5R28ZIUf jmTMu0FV8cBuAYiYlIJL4Syc5tz1phYbANXRhmwdrsnKhgqjvCfeKZjxLK+7TJ0dc6iu C+4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=3mZCdUMQ/EmpArie8AgSdBX+Pv8ZoaXYZbo9SgN/d8c=; b=XNdIrVUf5O780SdtKsCEsNRaFHAEiJysigas3mjbvOBafcz1cEtyuQ0MG5EtVW8qod WHYOi4kdbc/iQ9IWrHDv4nQJb6B2p5JYZHRtbiK8W5NkfG/HEzRtuCf6RX3N9ALpeuD6 k2A528XP21tDK0B74Tc0B67Hd9pEMJ+HJCqGKST11lnBuH0jcfNmLZld6dteZ7EOn0Co nDCqARZDv4mjEnS4SBbhMpKunThy/J0OgkPi4TT9Bl3DIP5ni+2HloUV7W1OCSIWK9UE hhjql1LB7zc44F4RcP5GvMxakB4XSndpQYSH46wldagvIMdlatsy2uf1+41w3hR3xcX/ 9lWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 76si10375427pge.555.2019.03.25.03.02.14; Mon, 25 Mar 2019 03:02:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730549AbfCYKBU (ORCPT + 99 others); Mon, 25 Mar 2019 06:01:20 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:39358 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729912AbfCYKBT (ORCPT ); Mon, 25 Mar 2019 06:01:19 -0400 Received: by mail-ot1-f67.google.com with SMTP id f10so7444750otb.6; Mon, 25 Mar 2019 03:01:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3mZCdUMQ/EmpArie8AgSdBX+Pv8ZoaXYZbo9SgN/d8c=; b=FD0qOWIraQzp18uUKRlRfxUmWw4htKceKuvx7pYGzIbToxWdNoLB11gm0P68RN0Er2 x6B6cCgbac2IIhch3erg2BUKLU+z+hOlLv1Pi2wDheuJjacMBg4oyS+vueSNB2yxuulE DaWobUx8RvtH6Uu9cBZ4OIuKvIaPNTbfbbbpdXyV1FHzyvjpfTd8J3PNVZSPcuWyi9TU W9ReuaAK24cpzA7ASRVMjE6Q3uYddx6enz3KnRNmBWOUjyCs8gFjv+7roxapd2Yt4R1C xIrRPXNQTupxQNMINlco6MyF2YkLe3UQLFxt/cCJ+zeJ1e4YumGMXjdOIWpkFLGdFo0r 4C9w== X-Gm-Message-State: APjAAAUuZqEvCBdQO8kRPoCMhrKTsFetZT9Mnch+nB+nDCt9stplbR1q bTafkTOoCs+Fd9fbbv2doVqwy/W9PGucyTuD37k= X-Received: by 2002:a9d:36a:: with SMTP id 97mr16259753otv.124.1553508079246; Mon, 25 Mar 2019 03:01:19 -0700 (PDT) MIME-Version: 1.0 References: <1637073.gl2OfxWTjI@aspire.rjw.lan> <1762575.ER2xjzr9E1@aspire.rjw.lan> <20190322144629.GC12472@zn.tnic> In-Reply-To: <20190322144629.GC12472@zn.tnic> From: "Rafael J. Wysocki" Date: Mon, 25 Mar 2019 11:01:08 +0100 Message-ID: Subject: Re: [PATCH 2/2] PM / arch: x86: MSR_IA32_ENERGY_PERF_BIAS sysfs interface To: Borislav Petkov Cc: "Rafael J. Wysocki" , x86 , LKML , Len Brown , Linux PM , Srinivas Pandruvada , Laura Abbott , Thomas Gleixner , Peter Zijlstra , Ingo Molnar , Simon Schricker , Hannes Reinecke Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 22, 2019 at 3:46 PM Borislav Petkov wrote: > > First of all, thanks a lot for doing that! > > This is a good example for how we should convert all the /dev/msr > accessing tools. > > Nitpicks below. > > On Thu, Mar 21, 2019 at 11:20:17PM +0100, Rafael J. Wysocki wrote: > > From: Rafael J. Wysocki > > > > The Performance and Energy Bias Hint (EPB) is expected to be set by > > user space through the generic MSR interface, but that interface is > > not particularly nice and there are security concerns regarding it, > > so it is not always available. > > > > For this reason, add a sysfs interface for reading and updating the > > EPB, in the form of a new attribute, energy_perf_bias, located > > under /sys/devices/system/cpu/cpu#/power/ for online CPUs that > > support the EPB feature. > > > > Signed-off-by: Rafael J. Wysocki > > --- > > Documentation/ABI/testing/sysfs-devices-system-cpu | 18 ++++ > > Documentation/admin-guide/pm/intel_epb.rst | 27 ++++++ > > arch/x86/kernel/cpu/intel_epb.c | 93 ++++++++++++++++++++- > > 3 files changed, 134 insertions(+), 4 deletions(-) > > ... > > > +static ssize_t energy_perf_bias_show(struct device *dev, > > + struct device_attribute *attr, > > + char *buf) > > +{ > > + unsigned int cpu = dev->id; > > + u64 epb; > > + int ret; > > + > > + ret = rdmsrl_on_cpu(cpu, MSR_IA32_ENERGY_PERF_BIAS, &epb); > > That's an IPI and an MSR read each time. You could dump saved_epb > instead, no? No, because the MSR can change in ways beyond control of this code sometimes. Generally, saved_epb only is the right value at the CPU online time. > > + if (ret < 0) > > + return ret; > > + > > + return sprintf(buf, "%llu\n", epb); > > +} > > + > > +static ssize_t energy_perf_bias_store(struct device *dev, > > + struct device_attribute *attr, > > + const char *buf, size_t count) > > +{ > > + unsigned int cpu = dev->id; > > + u64 epb, val; > > + int ret; > > + > > + ret = __sysfs_match_string(energy_perf_strings, > > + ARRAY_SIZE(energy_perf_strings), buf); > > + if (ret >= 0) > > + val = energ_perf_values[ret]; > > + else if (kstrtou64(buf, 0, &val) || val > MAX_EPB) > > Range is 0 - 15 but u64? Maybe make it an u8? :) At the cost of an extra conversion below, right? > > + return -EINVAL; > > + > > + ret = rdmsrl_on_cpu(cpu, MSR_IA32_ENERGY_PERF_BIAS, &epb); > > + if (ret < 0) > > + return ret; > > + > > + ret = wrmsrl_on_cpu(cpu, MSR_IA32_ENERGY_PERF_BIAS, > > + (epb & ~EPB_MASK) | val); > > + if (ret < 0) > > + return ret; > > + > > + return count; > > +} > > --