Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1377477imm; Fri, 22 Jun 2018 15:51:05 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLtkxQ+0R6mTXTyQW7o+AP8IaNRTMGMuFlMFXKg9tYt3gJHLPi1ytV9V/0hCl+NXVQAJ6Nk X-Received: by 2002:a65:48cd:: with SMTP id o13-v6mr2869109pgs.99.1529707865891; Fri, 22 Jun 2018 15:51:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529707865; cv=none; d=google.com; s=arc-20160816; b=h3bo0k8zAH7wRCtPM8w4kOKFF7MAQK89SO1+PhcB6ch1emKgGLdorzB1xbUbZC6QtL A5NYyr5mXKUP4BF5iA4ZWv45tw1WIoYCXqKBWNr1ktpUVNCK1IT+BcoP3Kv/oBqPjjPC KULm5DO99qT1aRk2yjmG0wLKJC71k2rVf2AayVX62rA97vzCoTA+4WlMk71BjFicysSl WSH4slE2JZ6qxqqdPln5IZNOh7Yz9qJk0/hrLGltqcdkUuQmY3Od00aONNq6ZgTiwyb2 yoIK6RPKUuNRftV4OIFebnFnHLlrO5RPUvNEHT/bDj0/MZ9LIfgUDNB55UnbhBaFClqI nSxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=LNyU3b/LRoHLluao+/eIC57BzRHuLTde3r/4QH7jels=; b=ESl2R0UfaXx2c/rbhya1e2qrueozoPGPFTC/ioB4s+FRlpjrDVnn3jzdpy2zYqiwFi 58qDCrKDZCr8C+zrdnAi2bZmL6/AByu0lxZYZ4sh13ONbREz/b4OlTPEhKd+nqfutZJj ericc2fghSvtDa3QHSC+d+ObsqQcFYO9dux02kd4KjP6Obo22B4TkOBvea//x/ncIDuB xLrTz+TpHLDl3fb66FSCYdVIKelprMBYFoZlwLqhNzzclbRgIbrNpDSvJ4+6fDc9CYnn BShkt3Yry/gjQLCTguTmcKAybyQCFLJlPScR3PryPI2M4UTfCVE7ArTSqfrSdp2HFPqC blCw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bd1-v6si8445886plb.338.2018.06.22.15.50.51; Fri, 22 Jun 2018 15:51:05 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754779AbeFVWsk (ORCPT + 99 others); Fri, 22 Jun 2018 18:48:40 -0400 Received: from mga02.intel.com ([134.134.136.20]:22312 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754654AbeFVWmv (ORCPT ); Fri, 22 Jun 2018 18:42:51 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Jun 2018 15:42:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,259,1526367600"; d="scan'208";a="234843378" Received: from rchatre-s.jf.intel.com ([10.54.70.76]) by orsmga005.jf.intel.com with ESMTP; 22 Jun 2018 15:42:47 -0700 From: Reinette Chatre To: tglx@linutronix.de, fenghua.yu@intel.com, tony.luck@intel.com, vikas.shivappa@linux.intel.com Cc: gavin.hindman@intel.com, jithu.joseph@intel.com, dave.hansen@intel.com, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, linux-kernel@vger.kernel.org, Reinette Chatre Subject: [PATCH V7 10/41] x86/intel_rdt: Enable setting of exclusive mode Date: Fri, 22 Jun 2018 15:42:01 -0700 Message-Id: <83642cbba3c8c21db7fa6bb36fe7d385d3b275f2.1529706536.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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/de6b02cb2da65d3abd492ad115ed9813940869a1.1527593970.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 0bee382fcad5..7f24e0808eef 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; -- 2.17.0