Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3088744ybt; Mon, 29 Jun 2020 15:04:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOqOnIFk3iww1V+pSL3ZbLbu+r3DM+3+a4rphM7lEkxpmpXph7N1wc7w8k7bjM3MZ+HJlS X-Received: by 2002:a17:906:1f0d:: with SMTP id w13mr16452124ejj.0.1593468250255; Mon, 29 Jun 2020 15:04:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593468250; cv=none; d=google.com; s=arc-20160816; b=BxL3V5X2rwAJvMG3nvP5ZLfdx3KYiaTXC58ujWwpzDZ6kDawn/Auz6OlcoowGG0iwT jltNA+SVSxWWcRcuBrN/7gK04bJbpbCQu8Ts3VmBK4vU++yTOddF/Bgv6vDGRFMOgiS8 Hv6mib3KbP7rQ85jf9AJij2d5YKWGsSwWwmj25kFZPyv2Nzg8GX41SRgkf77fQujOY/H e1g8WVZrZCc5YyH1yQOJwNE3q5emp7zZb+DZUwedhEqEhkkOXmRxJy3V/vSmLExaceoh u8eMBnbUubK5gIPHJHXs7oo59nyDf9AZMsRJMH4b0Zwi/vaSlVN1847XEvgfrisNrl/n 7Srw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bClnjvTwRq+98f2Q5y4QCSvS7eTA7dzWpjXFuIHCGxk=; b=V2/TGPS04XbHu2fezbsn+Z9C3/VSg1FoRTexN3jwQ+V4SF4dYn8IfSJu4XID9kSWam GzSgDG3RHAu84yuNnPaxyzHmXR6F5YStt6m4c310b0EIS3nvkfhJExW4iwSvRxUPW1mA HBEopij86MG3pxOBCGpLB3mbrx+bzCUt7AoYRYSWuCZPa26bK28c8omKNpYsyXDNqJEE tpNsbNQze967TIO+I2KdHUMBdA98uYO/7FcsXqydVb3zlZzu5oNNsYMerjDMEqoaJ7/u 7dExq9NWkirZl2AUXQ/2gMK9MYjn4IGEwBbnhTuT1AzWJRjOJV2nKyv+L9drfS2/sOjT vK8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=T8qGowlu; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mm30si538995ejb.574.2020.06.29.15.03.46; Mon, 29 Jun 2020 15:04:10 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=T8qGowlu; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389857AbgF2WCo (ORCPT + 99 others); Mon, 29 Jun 2020 18:02:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:56892 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726266AbgF2SfX (ORCPT ); Mon, 29 Jun 2020 14:35:23 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 63542246A4; Mon, 29 Jun 2020 15:20:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593444002; bh=2k513+UrkGGITiaQ0qtxDh5+iDVfb8XZRjSUIWKSkMU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T8qGowlu7ytmv0FowQegGADhelJe9kFix0SaY1uEw/KzjPzKv9LsWJon3yUZYYXmw Z5bQoN32lVDDWqF/NfqJdJMQpBpsZktD/Se4xiha47RFM4U5+yGM7OjVpmM8O5yJ98 CeQqjFix9Locj92Z9i/KLeMR2YnwvEC8SwmhchXs= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Babu Moger , Borislav Petkov , Sasha Levin Subject: [PATCH 5.7 107/265] x86/resctrl: Fix memory bandwidth counter width for AMD Date: Mon, 29 Jun 2020 11:15:40 -0400 Message-Id: <20200629151818.2493727-108-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200629151818.2493727-1-sashal@kernel.org> References: <20200629151818.2493727-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.7.7-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.7.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.7.7-rc1 X-KernelTest-Deadline: 2020-07-01T15:14+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Babu Moger [ Upstream commit 2c18bd525c47f882f033b0a813ecd09c93e1ecdf ] Memory bandwidth is calculated reading the monitoring counter at two intervals and calculating the delta. It is the software’s responsibility to read the count often enough to avoid having the count roll over _twice_ between reads. The current code hardcodes the bandwidth monitoring counter's width to 24 bits for AMD. This is due to default base counter width which is 24. Currently, AMD does not implement the CPUID 0xF.[ECX=1]:EAX to adjust the counter width. But, the AMD hardware supports much wider bandwidth counter with the default width of 44 bits. Kernel reads these monitoring counters every 1 second and adjusts the counter value for overflow. With 24 bits and scale value of 64 for AMD, it can only measure up to 1GB/s without overflowing. For the rates above 1GB/s this will fail to measure the bandwidth. Fix the issue setting the default width to 44 bits by adjusting the offset. AMD future products will implement CPUID 0xF.[ECX=1]:EAX. [ bp: Let the line stick out and drop {}-brackets around a single statement. ] Fixes: 4d05bf71f157 ("x86/resctrl: Introduce AMD QOS feature") Signed-off-by: Babu Moger Signed-off-by: Borislav Petkov Link: https://lkml.kernel.org/r/159129975546.62538.5656031125604254041.stgit@naples-babu.amd.com Signed-off-by: Sasha Levin --- arch/x86/kernel/cpu/resctrl/core.c | 8 ++++---- arch/x86/kernel/cpu/resctrl/internal.h | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index d242e864726c0..c1551541c7a53 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -980,10 +980,10 @@ void resctrl_cpu_detect(struct cpuinfo_x86 *c) c->x86_cache_max_rmid = ecx; c->x86_cache_occ_scale = ebx; - if (c->x86_vendor == X86_VENDOR_INTEL) - c->x86_cache_mbm_width_offset = eax & 0xff; - else - c->x86_cache_mbm_width_offset = -1; + c->x86_cache_mbm_width_offset = eax & 0xff; + + if (c->x86_vendor == X86_VENDOR_AMD && !c->x86_cache_mbm_width_offset) + c->x86_cache_mbm_width_offset = MBM_CNTR_WIDTH_OFFSET_AMD; } } diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index 3dd13f3a8b231..0963864757143 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -37,6 +37,7 @@ #define MBA_IS_LINEAR 0x4 #define MBA_MAX_MBPS U32_MAX #define MAX_MBA_BW_AMD 0x800 +#define MBM_CNTR_WIDTH_OFFSET_AMD 20 #define RMID_VAL_ERROR BIT_ULL(63) #define RMID_VAL_UNAVAIL BIT_ULL(62) -- 2.25.1