Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp33210pja; Fri, 22 Nov 2019 03:05:41 -0800 (PST) X-Google-Smtp-Source: APXvYqxPKbY5VxFWfpaHuAK69xADKx2VVoUjNYb4A1Ul5ATJv49uUzkg7Fmksd3I14yBpOcLBIpN X-Received: by 2002:a50:f296:: with SMTP id f22mr315889edm.26.1574420741804; Fri, 22 Nov 2019 03:05:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574420741; cv=none; d=google.com; s=arc-20160816; b=ZfI9zRGwa5DfVvRnBteeeBT9hcexbyTn2JqZjP9+56dsXMRxUHQo2NSOOACzevjdbC jvfsLTuAuIsfD9aTnoCq2jl6rUMuGGp1Q0eRcpbEHLgJzlwfwny8W2Nwiy3PE+pcZ8lT HJ1oi7aU1RiYPmMqh5Nf5GdzLqGtwa+uCA4vDp3WKmHHxOPVNOunX/esXck27+gq77+L ZvTFWcI/TbD8yrVd6vQTtXDSuIyPIHupHwO2IqTah9xk1iZS4KWZ4xqDGax5HRiK22uk ZgmnaofIFTYgqSvbRJ3woPpG/U3Dfu/ZxjUJ/Elb/X5AeKVUdpjJrcrSleLuaKDDQhCx Vo+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QhGCqoi4ZOtXH6bN2yDbZEhxTD83tyvVZFulTbYrWks=; b=fO+InWagx1STKirsKKXJLacB+TUWjuSwFHdY5rsin6beiJXse785akah2FCsyDUtFs S8AxttTtBd0dpfCiek3Bki9ytF45T+jiWU4qzRfTUMfjZqP6EaOxEYJ9ZnZCFz7foE7l AmIIoED5BMODAvqGS1KFJZp2GDeXMCTRvwowbkEKYuvivGUsD6P4i+/hpfl1lLLzepdC UZLILaYsB8jT9LMPu0buIZhboWRuBxrxInLRkKw3Q4vVuXQps0goVvLREja61bypIym5 SADy9xE3pnVQTijhg2LTGCr3+yN9eRw7o5LvjmJF+UoYcKDg83FUA0ih6h0q+7RZ2MK0 IGnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zteE0IRm; 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 a13si3591220ejy.365.2019.11.22.03.05.17; Fri, 22 Nov 2019 03:05:41 -0800 (PST) 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=@kernel.org header.s=default header.b=zteE0IRm; 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 S1731444AbfKVLDm (ORCPT + 99 others); Fri, 22 Nov 2019 06:03:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:57796 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730625AbfKVLDf (ORCPT ); Fri, 22 Nov 2019 06:03:35 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7E21A2073F; Fri, 22 Nov 2019 11:03:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574420614; bh=JwI+ye/StYPrNa8sOUciLaZ827yPQ6ei7loGtgzAWQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zteE0IRmnfyrW1yBgQdeu2yP3ivGtfcsDpEJirxmc6QI5mESgpzmqnuzJVVKp4MOB fxg3jZTYx6gupQSSfRzi2WGK5aqFcScbt1K6jNSzea2pmjBpxK3uEAa5IP5YZSrbMN CTyeWzCPLYiVJso74DtIXUsqXBfDl8nVQQikTEJ8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jithu Joseph , Reinette Chatre , Thomas Gleixner , Fenghua Yu , tony.luck@intel.com, gavin.hindman@intel.com, dave.hansen@intel.com, hpa@zytor.com, Ingo Molnar , Sasha Levin Subject: [PATCH 4.19 165/220] x86/intel_rdt: CBM overlap should also check for overlap with CDP peer Date: Fri, 22 Nov 2019 11:28:50 +0100 Message-Id: <20191122100924.645511490@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191122100912.732983531@linuxfoundation.org> References: <20191122100912.732983531@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Reinette Chatre [ Upstream commit e5f3530c391105fdd6174852e3ea6136d073b45a ] The CBM overlap test is used to manage the allocations of RDT resources where overlap is possible between resource groups. When a resource group is in exclusive mode then there should be no overlap between resource groups. The current overlap test only considers overlap between the same resources, for example, that usage of a RDT_RESOURCE_L2DATA resource in one resource group does not overlap with usage of a RDT_RESOURCE_L2DATA resource in another resource group. The problem with this is that it allows overlap between a RDT_RESOURCE_L2DATA resource in one resource group with a RDT_RESOURCE_L2CODE resource in another resource group - even if both resource groups are in exclusive mode. This is a problem because even though these appear to be different resources they end up sharing the same underlying hardware and thus does not fulfill the user's request for exclusive use of hardware resources. Fix this by including the CDP peer (if there is one) in every CBM overlap test. This does not impact the overlap between resources within the same exclusive resource group that is allowed. Fixes: 49f7b4efa110 ("x86/intel_rdt: Enable setting of exclusive mode") Reported-by: Jithu Joseph Signed-off-by: Reinette Chatre Signed-off-by: Thomas Gleixner Tested-by: Jithu Joseph Acked-by: Fenghua Yu Cc: tony.luck@intel.com Cc: gavin.hindman@intel.com Cc: dave.hansen@intel.com Cc: hpa@zytor.com Link: https://lkml.kernel.org/r/e538b7f56f7ca15963dce2e00ac3be8edb8a68e1.1538603665.git.reinette.chatre@intel.com Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 48 ++++++++++++++++++++---- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c index bf15ffc1248fd..0d8ea82acd930 100644 --- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c @@ -987,10 +987,9 @@ static int rdtgroup_mode_show(struct kernfs_open_file *of, * If a CDP peer was found, @r_cdp will point to the peer RDT resource * and @d_cdp will point to the peer RDT domain. */ -static int __attribute__((unused)) rdt_cdp_peer_get(struct rdt_resource *r, - struct rdt_domain *d, - struct rdt_resource **r_cdp, - struct rdt_domain **d_cdp) +static int rdt_cdp_peer_get(struct rdt_resource *r, struct rdt_domain *d, + struct rdt_resource **r_cdp, + struct rdt_domain **d_cdp) { struct rdt_resource *_r_cdp = NULL; struct rdt_domain *_d_cdp = NULL; @@ -1037,7 +1036,7 @@ static int __attribute__((unused)) rdt_cdp_peer_get(struct rdt_resource *r, } /** - * rdtgroup_cbm_overlaps - Does CBM for intended closid overlap with other + * __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. @@ -1056,8 +1055,8 @@ static int __attribute__((unused)) rdt_cdp_peer_get(struct rdt_resource *r, * * Return: false if CBM does not overlap, true if it does. */ -bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d, - unsigned long cbm, int closid, bool exclusive) +static bool __rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d, + unsigned long cbm, int closid, bool exclusive) { enum rdtgrp_mode mode; unsigned long ctrl_b; @@ -1092,6 +1091,41 @@ bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d, return false; } +/** + * rdtgroup_cbm_overlaps - Does CBM overlap with other use of hardware + * @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 + * + * Resources that can be allocated using a CBM can use the CBM to control + * the overlap of these allocations. rdtgroup_cmb_overlaps() is the test + * for overlap. Overlap test is not limited to the specific resource for + * which the CBM is intended though - when dealing with CDP resources that + * share the underlying hardware the overlap check should be performed on + * the CDP resource sharing the hardware also. + * + * Refer to description of __rdtgroup_cbm_overlaps() for the details of the + * overlap test. + * + * Return: true if CBM overlap detected, false if there is no overlap + */ +bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d, + unsigned long cbm, int closid, bool exclusive) +{ + struct rdt_resource *r_cdp; + struct rdt_domain *d_cdp; + + if (__rdtgroup_cbm_overlaps(r, d, cbm, closid, exclusive)) + return true; + + if (rdt_cdp_peer_get(r, d, &r_cdp, &d_cdp) < 0) + return false; + + return __rdtgroup_cbm_overlaps(r_cdp, d_cdp, cbm, closid, exclusive); +} + /** * rdtgroup_mode_test_exclusive - Test if this resource group can be exclusive * -- 2.20.1