From patchwork Tue Jan 10 19:04:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 41600 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2920243wrt; Tue, 10 Jan 2023 11:06:05 -0800 (PST) X-Google-Smtp-Source: AMrXdXv/T63EARMswjcBwlvAvV1pDpjxHqHYQ/EzOv+3dTmL8imB5PQFPDoIEt7aP2h0mLhD7BSV X-Received: by 2002:a17:907:7676:b0:7c1:7183:2d32 with SMTP id kk22-20020a170907767600b007c171832d32mr61836541ejc.56.1673377565207; Tue, 10 Jan 2023 11:06:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673377565; cv=none; d=google.com; s=arc-20160816; b=HAQVEfSXu8TdI9od8GuSCUZEhqR1NeqKV/q/u/XsjiNTNBZGFHzY7QczN+ZkZBEttm OqeH+put2Aq98iOxaYAoQ0MFuRl6fIYvUnm3XzqBURDXfl1hFHDkf2ceivx4tP+GcLLy 0IbdvuAcXssp3pJHzukJEdfyk/HDJYbkbokBg6ULilrtSAyvyYqqLZPIqYpUJjsFr7iy NVM6DSnMyLf6lUy9gf70pkYyDIrJrL8fq+WjQnHQP/qw8hnpYCX7g/KfLYo8P/OLF31l xuMoaToXvqdNsR/OIltXtRfVSXsymxyLOaOVDtfh1ojVb/E8D9hppbVZiFaUK6HbZnqH +o4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=T2zfOUkSSsQd15/kg4FW6QV2wYwvyiy76WI+8wldUuE=; b=IMCX7+S7TYoJQX7kIM3NFbnsliMcPZoUIw789FM5R/NKpmXbS810YBLc/Fm/eKCuiJ BXgfeMYJ9woH2O36AeeZRNcm14MgJfKlFswkjHgkoclW94Qbfg+lguQN1SnSnCvYLMEZ 1mNqlnIQ77+c5rYHYn+FoYIMME56G+02AC259tus+HC6BTDUF/acoMcA5E8bT90n94jL loB/ZYP1rkm2vNCqdLRjjOxi31zawD9aUbCYNkuZs7SPdIOEhKcKsN1KKpCIyj96Bd7D u9r7qqc8lvJ55B50dcNeO6yFSlkeCERMfESzDxxVzczlG29d/b08NrW8P0cKe3+iPw33 Dw+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=nrcLo5oL; dkim=neutral (no key) header.i=@linutronix.de header.b=XJaNo1Tv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs18-20020a170906f19200b0084c6438e6bdsi9347199ejb.805.2023.01.10.11.05.41; Tue, 10 Jan 2023 11:06:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=nrcLo5oL; dkim=neutral (no key) header.i=@linutronix.de header.b=XJaNo1Tv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239697AbjAJTFR (ORCPT + 99 others); Tue, 10 Jan 2023 14:05:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239676AbjAJTEN (ORCPT ); Tue, 10 Jan 2023 14:04:13 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0738AE53; Tue, 10 Jan 2023 11:04:12 -0800 (PST) Date: Tue, 10 Jan 2023 19:04:10 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1673377451; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T2zfOUkSSsQd15/kg4FW6QV2wYwvyiy76WI+8wldUuE=; b=nrcLo5oLu4k3yMNjLU/qV/r47/1/2oliMQnodtUP1U1NYHKMqc5CA98ytZrFEh6rxXIM5P RlwBWjF/9G62+J6lCRUcwcVHEQ4AYCa8g0aMh4W8gbeII8hcUNLZhGxUAoW+sQjJga8rny IhtTI+nbAr2zPlR4+pE4MyKlaO5l1yg7JVPZSoS0Q1GD1FSJo/bBvrbbF3nVe7NhBrCICn /rddFUCFOrebcaUr55XHUGXzTmSZiV3rAx1gaBi8BtDSZo8H7ee0R931GugD4eYfH7YeTa UmZbzvmElz1HlADTbopb+lZa7i3PUKqaJZAEF4Bu+sNTpsTzDGbFmAmiiD+gyg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1673377451; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T2zfOUkSSsQd15/kg4FW6QV2wYwvyiy76WI+8wldUuE=; b=XJaNo1TvY+pbF1kvoxeUd6+S+w8azYT2tsuL/B4JtilNOQCaYy2SNStK3mw5VLEwT64NqN GkB5Vk+KcoJONXAQ== From: "tip-bot2 for Peter Newman" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/resctrl: Fix event counts regression in reused RMIDs Cc: Peter Newman , "Borislav Petkov (AMD)" , Reinette Chatre , Babu Moger , stable@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20221220164132.443083-1-peternewman@google.com> References: <20221220164132.443083-1-peternewman@google.com> MIME-Version: 1.0 Message-ID: <167337745062.4906.5845664655522796641.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752752382697241786?= X-GMAIL-MSGID: =?utf-8?q?1754663553889792776?= The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 2a81160d29d65b5876ab3f824fda99ae0219f05e Gitweb: https://git.kernel.org/tip/2a81160d29d65b5876ab3f824fda99ae0219f05e Author: Peter Newman AuthorDate: Tue, 20 Dec 2022 17:41:31 +01:00 Committer: Borislav Petkov (AMD) CommitterDate: Tue, 10 Jan 2023 19:51:59 +01:00 x86/resctrl: Fix event counts regression in reused RMIDs When creating a new monitoring group, the RMID allocated for it may have been used by a group which was previously removed. In this case, the hardware counters will have non-zero values which should be deducted from what is reported in the new group's counts. resctrl_arch_reset_rmid() initializes the prev_msr value for counters to 0, causing the initial count to be charged to the new group. Resurrect __rmid_read() and use it to initialize prev_msr correctly. Unlike before, __rmid_read() checks for error bits in the MSR read so that callers don't need to. Fixes: 1d81d15db39c ("x86/resctrl: Move mbm_overflow_count() into resctrl_arch_rmid_read()") Signed-off-by: Peter Newman Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Reinette Chatre Tested-by: Babu Moger Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20221220164132.443083-1-peternewman@google.com --- arch/x86/kernel/cpu/resctrl/monitor.c | 49 +++++++++++++++++--------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index efe0c30..77538ab 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -146,6 +146,30 @@ static inline struct rmid_entry *__rmid_entry(u32 rmid) return entry; } +static int __rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val) +{ + u64 msr_val; + + /* + * As per the SDM, when IA32_QM_EVTSEL.EvtID (bits 7:0) is configured + * with a valid event code for supported resource type and the bits + * IA32_QM_EVTSEL.RMID (bits 41:32) are configured with valid RMID, + * IA32_QM_CTR.data (bits 61:0) reports the monitored data. + * IA32_QM_CTR.Error (bit 63) and IA32_QM_CTR.Unavailable (bit 62) + * are error bits. + */ + wrmsr(MSR_IA32_QM_EVTSEL, eventid, rmid); + rdmsrl(MSR_IA32_QM_CTR, msr_val); + + if (msr_val & RMID_VAL_ERROR) + return -EIO; + if (msr_val & RMID_VAL_UNAVAIL) + return -EINVAL; + + *val = msr_val; + return 0; +} + static struct arch_mbm_state *get_arch_mbm_state(struct rdt_hw_domain *hw_dom, u32 rmid, enum resctrl_event_id eventid) @@ -172,8 +196,12 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d, struct arch_mbm_state *am; am = get_arch_mbm_state(hw_dom, rmid, eventid); - if (am) + if (am) { memset(am, 0, sizeof(*am)); + + /* Record any initial, non-zero count value. */ + __rmid_read(rmid, eventid, &am->prev_msr); + } } static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width) @@ -191,25 +219,14 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d, struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d); struct arch_mbm_state *am; u64 msr_val, chunks; + int ret; if (!cpumask_test_cpu(smp_processor_id(), &d->cpu_mask)) return -EINVAL; - /* - * As per the SDM, when IA32_QM_EVTSEL.EvtID (bits 7:0) is configured - * with a valid event code for supported resource type and the bits - * IA32_QM_EVTSEL.RMID (bits 41:32) are configured with valid RMID, - * IA32_QM_CTR.data (bits 61:0) reports the monitored data. - * IA32_QM_CTR.Error (bit 63) and IA32_QM_CTR.Unavailable (bit 62) - * are error bits. - */ - wrmsr(MSR_IA32_QM_EVTSEL, eventid, rmid); - rdmsrl(MSR_IA32_QM_CTR, msr_val); - - if (msr_val & RMID_VAL_ERROR) - return -EIO; - if (msr_val & RMID_VAL_UNAVAIL) - return -EINVAL; + ret = __rmid_read(rmid, eventid, &msr_val); + if (ret) + return ret; am = get_arch_mbm_state(hw_dom, rmid, eventid); if (am) {