From: "Jan Beulich" Subject: Re: [PATCH v7 1/5] x86: allow reading MSR_IA32_TSC with XENPF_resource_op Date: Tue, 27 Jan 2015 08:49:11 +0000 Message-ID: <54C75F170200007800059C24@mail.emea.novell.com> References: <1422339204-6711-1-git-send-email-chao.p.peng@linux.intel.com> <1422339204-6711-2-git-send-email-chao.p.peng@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1422339204-6711-2-git-send-email-chao.p.peng@linux.intel.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Chao Peng Cc: wei.liu2@citrix.com, Ian.Campbell@citrix.com, stefano.stabellini@eu.citrix.com, andrew.cooper3@citrix.com, Ian.Jackson@eu.citrix.com, xen-devel@lists.xen.org, will.auld@intel.com, keir@xen.org List-Id: xen-devel@lists.xenproject.org >>> On 27.01.15 at 07:13, wrote: > Memory bandwidth monitoring requires system time information returned > along with the monitoring counter to verify the correctness of the > counter value and to calculate the time elapsed between two samplings. > > Add MSR_IA32_TSC to the read path and it returns scaled system time(ns) > instead of raw timestamp to elimanate the needs to convert. The return > time is obfuscated with booting random to eliminate the potential abuse > of it. RESOURCE_ACCESS_MAX_ENTRIES is also increased to 3 so MSR_IA32_TSC > can be used. ... together with an MSR write/read operation pair. > @@ -133,10 +135,39 @@ static void resource_access(void *info) > switch ( entry->u.cmd ) > { > case XEN_RESOURCE_OP_MSR_READ: > - ret = rdmsr_safe(entry->idx, entry->val); > + if ( unlikely(entry->idx == MSR_IA32_TSC) ) > + { > + /* Return obfuscated scaled time instead of raw timestamp */ > + entry->val = get_s_time_fixed(tsc) + boot_random; I think obfuscating the low 32 bits is pretty pointless. I'd rather see you use SECONDS(boot_random) here, or even SECONDS(boot_random) [-+^] boot_random. Jan