Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2878351pxu; Sat, 19 Dec 2020 05:06:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzryH1TBHqYJHKL9keJZBsm2N6rxeMpvIVlv9rR0otEtawWcpoIj9mV0vumdK8MBQNaQVfU X-Received: by 2002:a05:6402:a53:: with SMTP id bt19mr8889677edb.104.1608383195010; Sat, 19 Dec 2020 05:06:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608383195; cv=none; d=google.com; s=arc-20160816; b=LExJenyzuel8za5RpW2NcNp0tvx28wis4yxlO2B/kpQTlUNEuhvsO/ql6EH8++LyjA /CcO7KsI8CDDzqsZ7+JGazVr+QueXCL6PqsQCpD7pU455RT5Br4UNppeGnzOKngGxc8N SKIaX+GFg+W6Gr8Df5kE4m0SLmWfZNOpNT4MpCPCtWLqpHTGtT3joTYPPb3EZNBhFLR9 iPGdYt5VpSXcP5pvaMtvUr3zMP6TaE8YILAml6SVJ2W3a6Dn0SwNVQ1uVHMJVjOm9LXu X6ogMiC+cV+n+wTWft2e9Gz2w65FICIsG5IxJ0cpcaGeQLXTqyQFdoYLQqdr3JXkEC8d uR4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=aZSCx5jT8+80j6SrOuUwyknA04REOWI9nDZVK7nsEmY=; b=ZZIGwxPXPXGhIEtlq85m7lYpjcjA6qyIOq8EU5yCI3JB+IqYsk9HOIHBKwqidYIL1n EuKjUbYhu12/mD6btDbWhPlMA2uaS6imxKUcvRCQkkzk1a578XfjsHKonlE4JNn9h9EI j9GJ4cbf1Avzx42PfHAM06ML0/lwV8E1FJB8/0YUzfY9i7f+PmJLXG09BC6jppV34fMs sV21sNSiLarZ+G9BAQJGUZGBiVl1MdeF+OWnZfrjWj7etxuBIl4ZTC1jtO9BCloV3rnM kDZgW9IFUFyNIM+I0bNVKWDbdLIs/GA5mxK6G9bwYONU2puoT8JTOQUG4oUoRzibfBPA GeWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hb44si6378674ejc.150.2020.12.19.05.06.12; Sat, 19 Dec 2020 05:06:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728244AbgLSNEn (ORCPT + 99 others); Sat, 19 Dec 2020 08:04:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:52450 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728868AbgLSNE3 (ORCPT ); Sat, 19 Dec 2020 08:04:29 -0500 From: Greg Kroah-Hartman Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaochen Shen , Borislav Petkov , Tony Luck , Sudip Mukherjee Subject: [PATCH 5.4 34/34] x86/resctrl: Fix incorrect local bandwidth when mba_sc is enabled Date: Sat, 19 Dec 2020 14:03:31 +0100 Message-Id: <20201219125343.067191922@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201219125341.384025953@linuxfoundation.org> References: <20201219125341.384025953@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiaochen Shen commit 06c5fe9b12dde1b62821f302f177c972bb1c81f9 upstream The MBA software controller (mba_sc) is a feedback loop which periodically reads MBM counters and tries to restrict the bandwidth below a user-specified value. It tags along the MBM counter overflow handler to do the updates with 1s interval in mbm_update() and update_mba_bw(). The purpose of mbm_update() is to periodically read the MBM counters to make sure that the hardware counter doesn't wrap around more than once between user samplings. mbm_update() calls __mon_event_count() for local bandwidth updating when mba_sc is not enabled, but calls mbm_bw_count() instead when mba_sc is enabled. __mon_event_count() will not be called for local bandwidth updating in MBM counter overflow handler, but it is still called when reading MBM local bandwidth counter file 'mbm_local_bytes', the call path is as below: rdtgroup_mondata_show() mon_event_read() mon_event_count() __mon_event_count() In __mon_event_count(), m->chunks is updated by delta chunks which is calculated from previous MSR value (m->prev_msr) and current MSR value. When mba_sc is enabled, m->chunks is also updated in mbm_update() by mistake by the delta chunks which is calculated from m->prev_bw_msr instead of m->prev_msr. But m->chunks is not used in update_mba_bw() in the mba_sc feedback loop. When reading MBM local bandwidth counter file, m->chunks was changed unexpectedly by mbm_bw_count(). As a result, the incorrect local bandwidth counter which calculated from incorrect m->chunks is shown to the user. Fix this by removing incorrect m->chunks updating in mbm_bw_count() in MBM counter overflow handler, and always calling __mon_event_count() in mbm_update() to make sure that the hardware local bandwidth counter doesn't wrap around. Test steps: # Run workload with aggressive memory bandwidth (e.g., 10 GB/s) git clone https://github.com/intel/intel-cmt-cat && cd intel-cmt-cat && make ./tools/membw/membw -c 0 -b 10000 --read # Enable MBA software controller mount -t resctrl resctrl -o mba_MBps /sys/fs/resctrl # Create control group c1 mkdir /sys/fs/resctrl/c1 # Set MB throttle to 6 GB/s echo "MB:0=6000;1=6000" > /sys/fs/resctrl/c1/schemata # Write PID of the workload to tasks file echo `pidof membw` > /sys/fs/resctrl/c1/tasks # Read local bytes counters twice with 1s interval, the calculated # local bandwidth is not as expected (approaching to 6 GB/s): local_1=`cat /sys/fs/resctrl/c1/mon_data/mon_L3_00/mbm_local_bytes` sleep 1 local_2=`cat /sys/fs/resctrl/c1/mon_data/mon_L3_00/mbm_local_bytes` echo "local b/w (bytes/s):" `expr $local_2 - $local_1` Before fix: local b/w (bytes/s): 11076796416 After fix: local b/w (bytes/s): 5465014272 Fixes: ba0f26d8529c (x86/intel_rdt/mba_sc: Prepare for feedback loop) Signed-off-by: Xiaochen Shen Signed-off-by: Borislav Petkov Reviewed-by: Tony Luck Cc: Link: https://lkml.kernel.org/r/1607063279-19437-1-git-send-email-xiaochen.shen@intel.com [sudip: adjust context] Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/resctrl/monitor.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -280,7 +280,6 @@ static void mbm_bw_count(u32 rmid, struc return; chunks = mbm_overflow_count(m->prev_bw_msr, tval); - m->chunks += chunks; cur_bw = (chunks * r->mon_scale) >> 20; if (m->delta_comp) @@ -450,15 +449,14 @@ static void mbm_update(struct rdt_domain } if (is_mbm_local_enabled()) { rr.evtid = QOS_L3_MBM_LOCAL_EVENT_ID; + __mon_event_count(rmid, &rr); /* * Call the MBA software controller only for the * control groups and when user has enabled * the software controller explicitly. */ - if (!is_mba_sc(NULL)) - __mon_event_count(rmid, &rr); - else + if (is_mba_sc(NULL)) mbm_bw_count(rmid, &rr); } }