Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1899279imm; Sat, 23 Jun 2018 05:12:55 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIw7VPAgf83OlPRnko6C4vk2Qr3U+RjEaY9+HC5YqxSvzc+lF6v95KhsaCsrWoYOAGFeGFi X-Received: by 2002:a62:154a:: with SMTP id 71-v6mr5793702pfv.170.1529755975034; Sat, 23 Jun 2018 05:12:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529755975; cv=none; d=google.com; s=arc-20160816; b=0gHRHjboNTumR97frlGp3lGG7lDlsFhLk4B7GJlM8D/KvgECFuIQAYGfPXMELxqRuP O5XUNoa8cbfknzK3skSLNtOah8+OZWXeL7iu8qZDAsovFX5c2U5ZigiwIGtwqjYXo0QS k6YJZSluTyytKc7bvxI2HA5wkkQNac2J7W9JBiw+Z0MuPMHNC95GHF6tX2h/3f7eziaB INNELSDI+ADF7CLcvO/EFOSpg3nv+nZaes+IIQiChAz2zv2MrivEmkv6Uq0s50nwVTFY af/SJxZt97evwdDP65J5ko/WKv4HciX2Ub0yK3YbA7DKtLO7s8GwXOunLhQZYNE7/pRG uJsQ== 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:arc-authentication-results; bh=ZLntZ4iR2A+X2iG7XX6jsqQByvVlz9c86+zejViow7Y=; b=s04bTVMKSnuqz21QiDT0drnBDv7a/XkmNaa/1uoBufTX7CzwHVom9roLa2d2C3GqFS DVM+oW4GFhzKik8UwaYzRQHtPb8GGWJwgOir9KqD7BC8ISkggI9rBsiuO3zzSpO2I1HL U6t81I4zBZ3jcxC1hDIBn8aJiD5aA0s+EMoiH/l6pFoKS693vdUy7/3GlDPQrdb2LSoa D+tpS7+cs9oqpofEjXfY7FRqNXVkjwS0OkuKLp+Uf6LeChaU8x+ASyEtfKXjztIVI1g/ fnYCdfjwGjZa+MD5LFxW+3P8WEUV45tRvEe7Gr12+TaXRkI2AnLRCnpMbq49Zvk1rbH/ X7/A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u22-v6si9394745pfg.62.2018.06.23.05.12.40; Sat, 23 Jun 2018 05:12:54 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751879AbeFWMME (ORCPT + 99 others); Sat, 23 Jun 2018 08:12:04 -0400 Received: from terminus.zytor.com ([198.137.202.136]:35541 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751808AbeFWMMD (ORCPT ); Sat, 23 Jun 2018 08:12:03 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w5NCBwnO463708 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 23 Jun 2018 05:11:58 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w5NCBvBN463705; Sat, 23 Jun 2018 05:11:57 -0700 Date: Sat, 23 Jun 2018 05:11:57 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Reinette Chatre Message-ID: Cc: reinette.chatre@intel.com, linux-kernel@vger.kernel.org, mingo@kernel.org, tglx@linutronix.de, hpa@zytor.com Reply-To: tglx@linutronix.de, hpa@zytor.com, reinette.chatre@intel.com, linux-kernel@vger.kernel.org, mingo@kernel.org In-Reply-To: <83642cbba3c8c21db7fa6bb36fe7d385d3b275f2.1529706536.git.reinette.chatre@intel.com> References: <83642cbba3c8c21db7fa6bb36fe7d385d3b275f2.1529706536.git.reinette.chatre@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/cache] x86/intel_rdt: Enable setting of exclusive mode Git-Commit-ID: 49f7b4efa1101bbc143a960eff3a9c8f9d6f7358 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=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) 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: 49f7b4efa1101bbc143a960eff3a9c8f9d6f7358 Gitweb: https://git.kernel.org/tip/49f7b4efa1101bbc143a960eff3a9c8f9d6f7358 Author: Reinette Chatre AuthorDate: Fri, 22 Jun 2018 15:42:01 -0700 Committer: Thomas Gleixner CommitDate: Sat, 23 Jun 2018 13:03:42 +0200 x86/intel_rdt: Enable setting of exclusive mode The new "mode" file now accepts "exclusive" that means that the allocations of this resource group cannot be shared. Enable users to modify a resource group's mode to "exclusive". To succeed it is required that there is no overlap between resource group's current schemata and that of all the other active resource groups as well as cache regions potentially used by other hardware entities. Signed-off-by: Reinette Chatre Signed-off-by: Thomas Gleixner Cc: fenghua.yu@intel.com Cc: tony.luck@intel.com Cc: vikas.shivappa@linux.intel.com Cc: gavin.hindman@intel.com Cc: jithu.joseph@intel.com Cc: dave.hansen@intel.com Cc: hpa@zytor.com Link: https://lkml.kernel.org/r/83642cbba3c8c21db7fa6bb36fe7d385d3b275f2.1529706536.git.reinette.chatre@intel.com --- arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 97 +++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c index 910febef55e8..ba1410ced420 100644 --- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c @@ -812,6 +812,93 @@ static int rdtgroup_mode_show(struct kernfs_open_file *of, return 0; } +/** + * rdtgroup_cbm_overlaps - Does CBM for intended closid overlap with other + * @r: Resource to which domain instance @d belongs. + * @d: The domain instance for which @closid is being tested. + * @cbm: Capacity bitmask being tested. + * @closid: Intended closid for @cbm. + * @exclusive: Only check if overlaps with exclusive resource groups + * + * Checks if provided @cbm intended to be used for @closid on domain + * @d overlaps with any other closids or other hardware usage associated + * with this domain. If @exclusive is true then only overlaps with + * resource groups in exclusive mode will be considered. If @exclusive + * is false then overlaps with any resource group or hardware entities + * will be considered. + * + * Return: false if CBM does not overlap, true if it does. + */ +static bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d, + u32 _cbm, int closid, bool exclusive) +{ + unsigned long *cbm = (unsigned long *)&_cbm; + unsigned long *ctrl_b; + enum rdtgrp_mode mode; + u32 *ctrl; + int i; + + /* Check for any overlap with regions used by hardware directly */ + if (!exclusive) { + if (bitmap_intersects(cbm, + (unsigned long *)&r->cache.shareable_bits, + r->cache.cbm_len)) + return true; + } + + /* Check for overlap with other resource groups */ + ctrl = d->ctrl_val; + for (i = 0; i < r->num_closid; i++, ctrl++) { + ctrl_b = (unsigned long *)ctrl; + if (closid_allocated(i) && i != closid) { + if (bitmap_intersects(cbm, ctrl_b, r->cache.cbm_len)) { + mode = rdtgroup_mode_by_closid(i); + if (exclusive) { + if (mode == RDT_MODE_EXCLUSIVE) + return true; + continue; + } + return true; + } + } + } + + return false; +} + +/** + * rdtgroup_mode_test_exclusive - Test if this resource group can be exclusive + * + * An exclusive resource group implies that there should be no sharing of + * its allocated resources. At the time this group is considered to be + * exclusive this test can determine if its current schemata supports this + * setting by testing for overlap with all other resource groups. + * + * Return: true if resource group can be exclusive, false if there is overlap + * with allocations of other resource groups and thus this resource group + * cannot be exclusive. + */ +static bool rdtgroup_mode_test_exclusive(struct rdtgroup *rdtgrp) +{ + int closid = rdtgrp->closid; + struct rdt_resource *r; + struct rdt_domain *d; + + for_each_alloc_enabled_rdt_resource(r) { + list_for_each_entry(d, &r->domains, list) { + if (rdtgroup_cbm_overlaps(r, d, d->ctrl_val[closid], + rdtgrp->closid, false)) + return false; + } + } + + return true; +} + +/** + * rdtgroup_mode_write - Modify the resource group's mode + * + */ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off) { @@ -834,11 +921,19 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, mode = rdtgrp->mode; - if ((!strcmp(buf, "shareable") && mode == RDT_MODE_SHAREABLE)) + if ((!strcmp(buf, "shareable") && mode == RDT_MODE_SHAREABLE) || + (!strcmp(buf, "exclusive") && mode == RDT_MODE_EXCLUSIVE)) goto out; if (!strcmp(buf, "shareable")) { rdtgrp->mode = RDT_MODE_SHAREABLE; + } else if (!strcmp(buf, "exclusive")) { + if (!rdtgroup_mode_test_exclusive(rdtgrp)) { + rdt_last_cmd_printf("schemata overlaps\n"); + ret = -EINVAL; + goto out; + } + rdtgrp->mode = RDT_MODE_EXCLUSIVE; } else { rdt_last_cmd_printf("unknown/unsupported mode\n"); ret = -EINVAL;