Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1901656imm; Sat, 23 Jun 2018 05:15:40 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJX5V0DlQSuEhPvV2+xa+g9Q7CdBwwQihnn9ogQ+voYEc2akNeSXQ9rWLKG3KqwmtW53Ca2 X-Received: by 2002:a62:ac14:: with SMTP id v20-v6mr5578221pfe.126.1529756140285; Sat, 23 Jun 2018 05:15:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529756140; cv=none; d=google.com; s=arc-20160816; b=cnEh2QJpJCxyvo1pP+o5s0geSpPdBhitSIL6pyEvl2sWQVFQOg71AnRvJY80uh4y89 VHr+3gZhyDUT2DXP8Af5cNAq3jWqbFoxkJYAngQg6xvKzickzJZelg8d2vU91aU+zAFk 9LIrMzQ5pqR+UMvB6HxOyu6bG/3qI84T5bUU+J19P9IHwoMLPFdfGfrQOrnLyf0rSWKJ NJm0V3BHStoMngwep4xjoj83Awnc5j0QpDrWQQpFvVymYUIvTt9yaQlKxgDTbQ55N8XX hIXBsMwkI7CUMlohkyBxde/dmgKaAuW0HplcPbCKEAKfOsTnV1iedNEgU96GdbjZoaGh hvlA== 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=v9u1w2N72+rDdTrE+wHWmg1h1hjXaRb223QG8cHvlLo=; b=wo1/a55NNv2OtQ3j+tELbpFHtiwaFYrnKQcCuvr0KRX7ss2M0GsNKhUUBiqzyFtol0 e2MBdIdP+Hi/j1jTYzifU1BviMHlHXig2INormkYLOQ77+SAkUd7pkA3eqLnyWQ7DALY Zve90oT0bRLTbS8X0eBlDWe0KDt4BYKsfYbva3xPR9ya/vW3JFEetV9wTRL9u/PsRN/1 6Muc3TpsaaSayYT/187WxaNg2g5cJir2G0fhD6PHywzctNhTaqRARGg9cpG/1PwBKjFk DZuDSYwv51z0uDA2tB7yvsnapw1OoqRZus0Kvf1KVaCf/OkkpyH071ltBv3TzemWKTTM PUWw== 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 3-v6si9502341plc.415.2018.06.23.05.15.25; Sat, 23 Jun 2018 05:15:40 -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 S1751966AbeFWMNi (ORCPT + 99 others); Sat, 23 Jun 2018 08:13:38 -0400 Received: from terminus.zytor.com ([198.137.202.136]:58281 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751520AbeFWMNh (ORCPT ); Sat, 23 Jun 2018 08:13:37 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w5NCDWWK463994 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 23 Jun 2018 05:13:32 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w5NCDWtl463991; Sat, 23 Jun 2018 05:13:32 -0700 Date: Sat, 23 Jun 2018 05:13:32 -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: linux-kernel@vger.kernel.org, mingo@kernel.org, hpa@zytor.com, reinette.chatre@intel.com, tglx@linutronix.de Reply-To: tglx@linutronix.de, reinette.chatre@intel.com, hpa@zytor.com, linux-kernel@vger.kernel.org, mingo@kernel.org In-Reply-To: References: To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/cache] x86/intel_rdt: Ensure requested schemata respects mode Git-Commit-ID: 9ab9aa15c3096000678891b61f7309c8729928e0 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: 9ab9aa15c3096000678891b61f7309c8729928e0 Gitweb: https://git.kernel.org/tip/9ab9aa15c3096000678891b61f7309c8729928e0 Author: Reinette Chatre AuthorDate: Fri, 22 Jun 2018 15:42:04 -0700 Committer: Thomas Gleixner CommitDate: Sat, 23 Jun 2018 13:03:43 +0200 x86/intel_rdt: Ensure requested schemata respects mode When the administrator requests a change in a resource group's schemata we have to ensure that the new schemata respects the current resource group as well as the other active resource groups' schemata. The new schemata is not allowed to overlap with the schemata of any exclusive resource groups. Similarly, if the resource group being changed is exclusive then its new schemata is not allowed to overlap with any schemata of any other active resource group. 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/b0c05b21110d3040fff45f4c1d2cfda8dba3f207.1529706536.git.reinette.chatre@intel.com --- arch/x86/kernel/cpu/intel_rdt.h | 2 ++ arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c | 49 ++++++++++++++++++++++------- arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 4 +-- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/arch/x86/kernel/cpu/intel_rdt.h b/arch/x86/kernel/cpu/intel_rdt.h index b2b2864150aa..362c8fe695f3 100644 --- a/arch/x86/kernel/cpu/intel_rdt.h +++ b/arch/x86/kernel/cpu/intel_rdt.h @@ -465,6 +465,8 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off); int rdtgroup_schemata_show(struct kernfs_open_file *of, struct seq_file *s, void *v); +bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d, + u32 _cbm, int closid, bool exclusive); enum rdtgrp_mode rdtgroup_mode_by_closid(int closid); struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r); int update_domains(struct rdt_resource *r, int closid); diff --git a/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c b/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c index ab4bb8731825..0e6210a043f0 100644 --- a/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c +++ b/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c @@ -123,13 +123,19 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r) return true; } +struct rdt_cbm_parse_data { + struct rdtgroup *rdtgrp; + char *buf; +}; + /* * Read one cache bit mask (hex). Check that it is valid for the current * resource type. */ int parse_cbm(void *_data, struct rdt_resource *r, struct rdt_domain *d) { - char *buf = _data; + struct rdt_cbm_parse_data *data = _data; + struct rdtgroup *rdtgrp = data->rdtgrp; u32 cbm_val; if (d->have_new_ctrl) { @@ -137,8 +143,24 @@ int parse_cbm(void *_data, struct rdt_resource *r, struct rdt_domain *d) return -EINVAL; } - if (!cbm_validate(buf, &cbm_val, r)) + if (!cbm_validate(data->buf, &cbm_val, r)) + return -EINVAL; + + /* + * The CBM may not overlap with the CBM of another closid if + * either is exclusive. + */ + if (rdtgroup_cbm_overlaps(r, d, cbm_val, rdtgrp->closid, true)) { + rdt_last_cmd_printf("overlaps with exclusive group\n"); return -EINVAL; + } + + if (rdtgroup_cbm_overlaps(r, d, cbm_val, rdtgrp->closid, false)) { + if (rdtgrp->mode == RDT_MODE_EXCLUSIVE) { + rdt_last_cmd_printf("overlaps with other group\n"); + return -EINVAL; + } + } d->new_ctrl = cbm_val; d->have_new_ctrl = true; @@ -152,8 +174,10 @@ int parse_cbm(void *_data, struct rdt_resource *r, struct rdt_domain *d) * separated by ";". The "id" is in decimal, and must match one of * the "id"s for this resource. */ -static int parse_line(char *line, struct rdt_resource *r) +static int parse_line(char *line, struct rdt_resource *r, + struct rdtgroup *rdtgrp) { + struct rdt_cbm_parse_data data; char *dom = NULL, *id; struct rdt_domain *d; unsigned long dom_id; @@ -170,7 +194,9 @@ next: dom = strim(dom); list_for_each_entry(d, &r->domains, list) { if (d->id == dom_id) { - if (r->parse_ctrlval(dom, r, d)) + data.buf = dom; + data.rdtgrp = rdtgrp; + if (r->parse_ctrlval(&data, r, d)) return -EINVAL; goto next; } @@ -223,13 +249,14 @@ done: return 0; } -static int rdtgroup_parse_resource(char *resname, char *tok, int closid) +static int rdtgroup_parse_resource(char *resname, char *tok, + struct rdtgroup *rdtgrp) { struct rdt_resource *r; for_each_alloc_enabled_rdt_resource(r) { - if (!strcmp(resname, r->name) && closid < r->num_closid) - return parse_line(tok, r); + if (!strcmp(resname, r->name) && rdtgrp->closid < r->num_closid) + return parse_line(tok, r, rdtgrp); } rdt_last_cmd_printf("unknown/unsupported resource name '%s'\n", resname); return -EINVAL; @@ -242,7 +269,7 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of, struct rdt_domain *dom; struct rdt_resource *r; char *tok, *resname; - int closid, ret = 0; + int ret = 0; /* Valid input requires a trailing newline */ if (nbytes == 0 || buf[nbytes - 1] != '\n') @@ -256,8 +283,6 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of, } rdt_last_cmd_clear(); - closid = rdtgrp->closid; - for_each_alloc_enabled_rdt_resource(r) { list_for_each_entry(dom, &r->domains, list) dom->have_new_ctrl = false; @@ -275,13 +300,13 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of, ret = -EINVAL; goto out; } - ret = rdtgroup_parse_resource(resname, tok, closid); + ret = rdtgroup_parse_resource(resname, tok, rdtgrp); if (ret) goto out; } for_each_alloc_enabled_rdt_resource(r) { - ret = update_domains(r, closid); + ret = update_domains(r, rdtgrp->closid); if (ret) goto out; } diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c index ba1410ced420..75a43f8b400e 100644 --- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c @@ -829,8 +829,8 @@ static int rdtgroup_mode_show(struct kernfs_open_file *of, * * 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) +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;