Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4602261yba; Wed, 17 Apr 2019 15:15:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqxUwIeD+nbkkoVDfqkH3HpxuSEfQEUCPmRgvtqZ4Vj0lRXud70E+RwGDG4UwmLn0XhP4wwr X-Received: by 2002:aa7:83ce:: with SMTP id j14mr4904734pfn.57.1555539313845; Wed, 17 Apr 2019 15:15:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555539313; cv=none; d=google.com; s=arc-20160816; b=WBK0qwz7k0h/bKTtp0KN1R3hrdpRM8IWIcnMY34Yi8/IH9Dap63DxVOB8EiJM+LMQP DDo2x2tieHjaSVq8E6LT2obHm5sCLPYHt3zstmRf5tJxfuZf4KMOQhikR+pELeH6AM6D 2FMJziXltMXT4dB9b8mTSrQLxyj+esw0kXYzGT5rhPmLiqEefOMPI8H8b2IrtbeRbsU+ 9Z+0OaQV5F8l3YCAF6K54HYUbrZfYw6RMwa0g5U+V+hIIY3SGaP+iH3J1/Y2YRA5jE86 CYDqYpKxjTeAutHbyVidYpnMbT4hDaRCVhNspJklkzFTQdF52pKPni+dowFhHUR7vp3f C0iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=mTxY5At5zwFUiu61wwSyXV92rNLjpnNhfQHcXdR0FnY=; b=u5NzHUFCD8BCKh2jjXjhfzbCOL/kDgx8h3EFD6X1/6pkDmvmNQPOYsCSpaycK2UTxh Ci/YRrfh3ZCcsGrG4Re9bcr3rSzrO6Zwsdvdwt4xt2M1VkwzbINQz3HRMty1eFs3F4KR czMTyQIhwOSVCeA9BAg5uyGQQOqLAHKELGURsBi5WPFOW+/2kHsYefnSTyV6o9BdTx+5 SxcX0xiFGGqdCz0Ak+RVMLur+PtXYM4W3C3CJRYIp5hWccfymTZ/w+GXl2xmJr6+lOVS acMaeqHfrScWfb4lbCG0ejo1ya1eeUMVG1SbOOhjVJ5TpTAaczdp5XkgPpXGh2uoLKQn 262g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019041745 header.b=G1vAqnfZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b23si164331pls.430.2019.04.17.15.14.58; Wed, 17 Apr 2019 15:15:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@zytor.com header.s=2019041745 header.b=G1vAqnfZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387478AbfDQWNo (ORCPT + 99 others); Wed, 17 Apr 2019 18:13:44 -0400 Received: from terminus.zytor.com ([198.137.202.136]:53331 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727013AbfDQWNn (ORCPT ); Wed, 17 Apr 2019 18:13:43 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x3HMDQ7a4101467 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Wed, 17 Apr 2019 15:13:26 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x3HMDQ7a4101467 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019041745; t=1555539207; bh=mTxY5At5zwFUiu61wwSyXV92rNLjpnNhfQHcXdR0FnY=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=G1vAqnfZ2uAHsuRugMtabYbjmb02rWCzu3sw/G5BCmJgRyEreLQmkGfc6HbcWda26 8J5PNkFOZLPLFqgHNMQUvMVD0rHFfo6IahaUWCGH1t6HcAD5rEalMx32gDkUVjdEqi kD8t+5XhGj4LaIeC2r/x2Ku5B0YOjGUgWqDr4h3m4UZVpqUecKum8r3gW8HZmVwh46 3ep0SemsGrojpw1f8NMSIhfX9eJ2Yg+LrNhU4HDS3hHvStpZo1qVTJJ1GZI8XWTsA/ qnQH+8E6hOW2xoCC72Q+7h2Dh4JXWHNuijdoCGoGRquWuTv+VVez0yp7iQSxPyEK1V 9c0ngJtcKvvIw== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x3HMDQEx4101464; Wed, 17 Apr 2019 15:13:26 -0700 Date: Wed, 17 Apr 2019 15:13:26 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Xiaochen Shen Message-ID: Cc: reinette.chatre@intel.com, fenghua.yu@intel.com, hpa@zytor.com, x86@kernel.org, linux-kernel@vger.kernel.org, mingo@kernel.org, bp@suse.de, mingo@redhat.com, xiaochen.shen@intel.com, tglx@linutronix.de, tony.luck@intel.com Reply-To: tony.luck@intel.com, xiaochen.shen@intel.com, tglx@linutronix.de, bp@suse.de, mingo@redhat.com, mingo@kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, hpa@zytor.com, fenghua.yu@intel.com, reinette.chatre@intel.com In-Reply-To: <1555499329-1170-2-git-send-email-xiaochen.shen@intel.com> References: <1555499329-1170-2-git-send-email-xiaochen.shen@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/cache] x86/resctrl: Move per RDT domain initialization to a separate function Git-Commit-ID: 7390619ab9ea9fd0ba9f4c3e4749ee20262cba7d X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-3.1 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 7390619ab9ea9fd0ba9f4c3e4749ee20262cba7d Gitweb: https://git.kernel.org/tip/7390619ab9ea9fd0ba9f4c3e4749ee20262cba7d Author: Xiaochen Shen AuthorDate: Wed, 17 Apr 2019 19:08:48 +0800 Committer: Borislav Petkov CommitDate: Wed, 17 Apr 2019 23:59:56 +0200 x86/resctrl: Move per RDT domain initialization to a separate function Carve out per rdt_domain initialization code from rdtgroup_init_alloc() into a separate function. No functional change, make the code more readable and save us at least two indentation levels. Signed-off-by: Xiaochen Shen Signed-off-by: Borislav Petkov Cc: Fenghua Yu Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: pei.p.jia@intel.com Cc: Reinette Chatre Cc: Thomas Gleixner Cc: Tony Luck Cc: x86-ml Link: https://lkml.kernel.org/r/1555499329-1170-2-git-send-email-xiaochen.shen@intel.com --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 131 ++++++++++++++++++--------------- 1 file changed, 72 insertions(+), 59 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 85212a32b54d..36ace51ee705 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -2516,28 +2516,86 @@ static void cbm_ensure_valid(u32 *_val, struct rdt_resource *r) bitmap_clear(val, zero_bit, cbm_len - zero_bit); } +/* + * Initialize cache resources per RDT domain + * + * Set the RDT domain up to start off with all usable allocations. That is, + * all shareable and unused bits. All-zero CBM is invalid. + */ +static int __init_one_rdt_domain(struct rdt_domain *d, struct rdt_resource *r, + u32 closid) +{ + struct rdt_resource *r_cdp = NULL; + struct rdt_domain *d_cdp = NULL; + u32 used_b = 0, unused_b = 0; + unsigned long tmp_cbm; + enum rdtgrp_mode mode; + u32 peer_ctl, *ctrl; + int i; + + rdt_cdp_peer_get(r, d, &r_cdp, &d_cdp); + d->have_new_ctrl = false; + d->new_ctrl = r->cache.shareable_bits; + used_b = r->cache.shareable_bits; + ctrl = d->ctrl_val; + for (i = 0; i < closids_supported(); i++, ctrl++) { + if (closid_allocated(i) && i != closid) { + mode = rdtgroup_mode_by_closid(i); + if (mode == RDT_MODE_PSEUDO_LOCKSETUP) + break; + /* + * If CDP is active include peer domain's + * usage to ensure there is no overlap + * with an exclusive group. + */ + if (d_cdp) + peer_ctl = d_cdp->ctrl_val[i]; + else + peer_ctl = 0; + used_b |= *ctrl | peer_ctl; + if (mode == RDT_MODE_SHAREABLE) + d->new_ctrl |= *ctrl | peer_ctl; + } + } + if (d->plr && d->plr->cbm > 0) + used_b |= d->plr->cbm; + unused_b = used_b ^ (BIT_MASK(r->cache.cbm_len) - 1); + unused_b &= BIT_MASK(r->cache.cbm_len) - 1; + d->new_ctrl |= unused_b; + /* + * Force the initial CBM to be valid, user can + * modify the CBM based on system availability. + */ + cbm_ensure_valid(&d->new_ctrl, r); + /* + * Assign the u32 CBM to an unsigned long to ensure that + * bitmap_weight() does not access out-of-bound memory. + */ + tmp_cbm = d->new_ctrl; + if (bitmap_weight(&tmp_cbm, r->cache.cbm_len) < r->cache.min_cbm_bits) { + rdt_last_cmd_printf("No space on %s:%d\n", r->name, d->id); + return -ENOSPC; + } + d->have_new_ctrl = true; + + return 0; +} + /** * rdtgroup_init_alloc - Initialize the new RDT group's allocations * * A new RDT group is being created on an allocation capable (CAT) * supporting system. Set this group up to start off with all usable - * allocations. That is, all shareable and unused bits. + * allocations. * - * All-zero CBM is invalid. If there are no more shareable bits available - * on any domain then the entire allocation will fail. + * If there are no more shareable bits available on any domain then + * the entire allocation will fail. */ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp) { - struct rdt_resource *r_cdp = NULL; - struct rdt_domain *d_cdp = NULL; - u32 used_b = 0, unused_b = 0; - u32 closid = rdtgrp->closid; struct rdt_resource *r; - unsigned long tmp_cbm; - enum rdtgrp_mode mode; struct rdt_domain *d; - u32 peer_ctl, *ctrl; - int i, ret; + int ret; for_each_alloc_enabled_rdt_resource(r) { /* @@ -2547,54 +2605,9 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp) if (r->rid == RDT_RESOURCE_MBA) continue; list_for_each_entry(d, &r->domains, list) { - rdt_cdp_peer_get(r, d, &r_cdp, &d_cdp); - d->have_new_ctrl = false; - d->new_ctrl = r->cache.shareable_bits; - used_b = r->cache.shareable_bits; - ctrl = d->ctrl_val; - for (i = 0; i < closids_supported(); i++, ctrl++) { - if (closid_allocated(i) && i != closid) { - mode = rdtgroup_mode_by_closid(i); - if (mode == RDT_MODE_PSEUDO_LOCKSETUP) - break; - /* - * If CDP is active include peer - * domain's usage to ensure there - * is no overlap with an exclusive - * group. - */ - if (d_cdp) - peer_ctl = d_cdp->ctrl_val[i]; - else - peer_ctl = 0; - used_b |= *ctrl | peer_ctl; - if (mode == RDT_MODE_SHAREABLE) - d->new_ctrl |= *ctrl | peer_ctl; - } - } - if (d->plr && d->plr->cbm > 0) - used_b |= d->plr->cbm; - unused_b = used_b ^ (BIT_MASK(r->cache.cbm_len) - 1); - unused_b &= BIT_MASK(r->cache.cbm_len) - 1; - d->new_ctrl |= unused_b; - /* - * Force the initial CBM to be valid, user can - * modify the CBM based on system availability. - */ - cbm_ensure_valid(&d->new_ctrl, r); - /* - * Assign the u32 CBM to an unsigned long to ensure - * that bitmap_weight() does not access out-of-bound - * memory. - */ - tmp_cbm = d->new_ctrl; - if (bitmap_weight(&tmp_cbm, r->cache.cbm_len) < - r->cache.min_cbm_bits) { - rdt_last_cmd_printf("No space on %s:%d\n", - r->name, d->id); - return -ENOSPC; - } - d->have_new_ctrl = true; + ret = __init_one_rdt_domain(d, r, rdtgrp->closid); + if (ret < 0) + return ret; } }