From patchwork Tue Dec 20 16:41:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 35148 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3068092wrn; Tue, 20 Dec 2022 08:48:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXtEVpOkoTam9Y5RDXPnrq/FO1F2bZ6q7bukUi29x0fM3WtJsTCkyX4VS45WX0/VH/tZwY5i X-Received: by 2002:a17:906:4c94:b0:7b5:860d:7039 with SMTP id q20-20020a1709064c9400b007b5860d7039mr4219968eju.10.1671554930395; Tue, 20 Dec 2022 08:48:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671554930; cv=none; d=google.com; s=arc-20160816; b=dz+09rcOVjCDXOOJoPfu9nnlQM9A3Cn5AcBPZ6r3+2Os9ijLLrwGtYrpX+L2U5UX6/ WW3n6n21Pa11jq6XjsFpeEujjrje8KjwWMfEt2SHfw149j3mT8ho+4BFAOwmw5LK+cHc cgFnHrD8nzjahh/F4yQ6jKxRLpBDl0hAUzk3UYkL949l3gzpP/WDKSYB4SPsplyQTo28 NXp/m/kw4JUg1OVzF7hCDUO5rF9B1KVnH9oUOmTR4TaBmmtwNGkVxqZmfleiK6SwaCW0 3nzWe1hUHnmnXXbk09gteOc0ay/BzXO4xzd3L0V4E8ZBxG54vqq66OmtKVpiDiMj4jgD eDqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=OTNceY23AA38a0nnsKzPgPMXfy0S7X52/MJzcro4EXc=; b=kbvWVvIj/lQ9ZjwrffrKdZ0e2YVOiOba+jbO609rD6hgUiq4f9WE3BKMxa5aMFPGhC bx5MQyYcfeYOZg/dB+4frmn25M7WR1+3iRk+wQiHq4TVnQOa13TfNQxm8V/pmAoChz9F WOHX/ZWczK5kKXpwwMzbzAS0zzSE2nBqApUxyInyQ67F2lITEmLWdF0SKvAJF3/nmTWm 0KaxcoJdJqMuRLoWPHkQUqEAMG2hN5HAs6vmTw00wCBoTUDlW+S+gusnSiwcnIsbCzS7 HUZGah1TlkJRwNMWHT4gHlodZJSMiZ0cNCsYWIRbEe8oShfvykGvDgI5G8X7r8hhyi+o GeEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="MP6A5o/s"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hg4-20020a1709072cc400b007d97d797c8dsi9653891ejc.215.2022.12.20.08.48.27; Tue, 20 Dec 2022 08:48:50 -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=@google.com header.s=20210112 header.b="MP6A5o/s"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233890AbiLTQmN (ORCPT + 99 others); Tue, 20 Dec 2022 11:42:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229560AbiLTQlq (ORCPT ); Tue, 20 Dec 2022 11:41:46 -0500 Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 211081581B for ; Tue, 20 Dec 2022 08:41:45 -0800 (PST) Received: by mail-wm1-x349.google.com with SMTP id o5-20020a05600c510500b003cfca1a327fso6785986wms.8 for ; Tue, 20 Dec 2022 08:41:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=OTNceY23AA38a0nnsKzPgPMXfy0S7X52/MJzcro4EXc=; b=MP6A5o/sswJ8AVbWgBG0Qiw5G/Sd/4XmeRK871/E+itWC425/UWTA+3yF6kdSm+y8V CVIMwkHnWvHBP02oJEBGOusy/IimIHMH20oQcvGdaucSMpckrK/S1d18048ion+N8iMa 0L94kAXC18YKiQ1kbAkxVDSUlL5i+GLOmkR3U5kBpqz5wgDaVzfdvX74/Ev+/FSQ3+fu AS8gSxVy1gYemsu0YepZKSSWc2l4dQOL0XoIdA5XUnCT9xGssF2Oq5ETLvKC66AkYE1d jH9zjD39wPvfcrfb2JO6psmcYWc150l8BXEMxmIKSKdyi65HIhm1CSan7e6Uto3SlRhH ZwrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=OTNceY23AA38a0nnsKzPgPMXfy0S7X52/MJzcro4EXc=; b=ZAzIQG/SrCPGtYuHQYlONjtZadaL79i14MYUhhP1SuendJgjhG65QGzM4b1IbkukeJ IxLmbPBpNKX2HKcu/Q50sNI85n9llFxX+CKvT6X5UNcIynRasDwx/RC/8X2xxKMPT3k/ AnZ51rcZeSb71rDUy5rjdim2pUwKpZeaDLF0MIqwQMG2xOlhIpjkgo2SLO67px2gIYfq AW6XtpD0aN5lQJiCi9TVWRktFW4tRocBZyJAv0w95rSVATOxjA+4+54O6w927fkeClzB NQg0z0YtimKwbpUSAVC2AiVOovkd6JwTabGQJAL+J4MPZ8D+7tF/1M4Y9SM2aXxeYiWf jq8Q== X-Gm-Message-State: AFqh2kpj/NtagKpWeUNKlpm0hJuM8fMuyPEPpmWed1zXDA/OKNxsIPOj CkYdwDk3XpHjW/HtETLPi1yEYdzfGiOlcpoJlw== X-Received: from peternewman10.zrh.corp.google.com ([2a00:79e0:9d:6:8175:5362:6754:c66d]) (user=peternewman job=sendgmr) by 2002:a05:600c:3553:b0:3cf:6f23:a3e3 with SMTP id i19-20020a05600c355300b003cf6f23a3e3mr56813wmq.1.1671554503082; Tue, 20 Dec 2022 08:41:43 -0800 (PST) Date: Tue, 20 Dec 2022 17:41:31 +0100 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221220164132.443083-1-peternewman@google.com> Subject: [PATCH v3 1/2] x86/resctrl: Fix event counts regression in reused RMIDs From: Peter Newman To: reinette.chatre@intel.com, fenghua.yu@intel.com Cc: Babu.Moger@amd.com, bp@alien8.de, dave.hansen@linux.intel.com, eranian@google.com, hpa@zytor.com, james.morse@arm.com, linux-kernel@vger.kernel.org, mingo@redhat.com, quic_jiles@quicinc.com, tan.shaopeng@fujitsu.com, tglx@linutronix.de, x86@kernel.org, Peter Newman , stable@vger.kernel.org X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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?1752752382697241786?= 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 Reviewed-by: Reinette Chatre Cc: stable@vger.kernel.org Tested-by: Babu Moger 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) {