From patchwork Tue Nov 6 12:39:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 150270 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3840400ljp; Tue, 6 Nov 2018 04:44:57 -0800 (PST) X-Google-Smtp-Source: AJdET5c7dmNbTLVN64IPNriJkidZKPH64U8fGgI7f4dR2bnrXEOJg4Mj3xudQbU/xdNxjaktU4xd X-Received: by 2002:a17:902:1c9:: with SMTP id b67-v6mr13159319plb.152.1541508297645; Tue, 06 Nov 2018 04:44:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541508297; cv=none; d=google.com; s=arc-20160816; b=yzC+4ADLjmm8J9XuxvoLM8Tmnf+rHwrhqZK2RvBlCjRX2KiP2aXKXUUKHiX9wNFtVw hw5zw8AxA6whWGs1AVrvnpt5wvn+BVKlv3TY0Dy8X6H/owRj7k2lebtSCRfIpCrbx/fq CSCwZYCuMfCa5KGwI7DL0MkhGqaXA7sBolOTTm2gjNb1Non7ebEFWtSlQbP9uhdDi+Dg pXEfsZZFwm1i8jUv6iIrjAiqAyd17Aeq5INUakTQrQ50WgitPA17rwCO2bNrbUHEr/lQ FUr83Ebjqb6iZAJLNR9HDZBPV4ngXYa110b/E1vWxJPE0Kpn33BzSGXMT6lsvZwF4o17 4acQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=AXfxamZqAqHQtgakcKsbbVMzO3CQbKchudFYQNBUoTo=; b=j4gSm+HmCKwiCibbmf8waYWVg/AkeR7wVfJbDPQvZY8opacMzSNAcWXDuve+1MaEVy 3GNILLrB4NFI/TtvAmUECcT9VKD/78lQ08B3J+ZlkUWL1x0o9ma7zbksKQcQ4ThFiZkg mJexh6+QreOCR1GGAOGn2eonCMHWC42aAxYnoVsKrgqezs6fix807lT0Q6yMF2hLEsKU LtacegZFR20WaV+ozsHQXwWx1OKgeBj3wbo4+xjPi5RjOk887e5Sr0bJjR5CvY169Ifh JhVUA2ay0aF2fx35jlO890tCZu9cN/bYS/JV4Ve4+W4FFUutlVGAv8EUchQm1TsaVmhI Nd/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 i20-v6si32348584pgg.503.2018.11.06.04.44.57; Tue, 06 Nov 2018 04:44:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-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 devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387941AbeKFWJ7 (ORCPT + 6 others); Tue, 6 Nov 2018 17:09:59 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:47597 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387704AbeKFWJ7 (ORCPT ); Tue, 6 Nov 2018 17:09:59 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 19DE1D1928E0C; Tue, 6 Nov 2018 20:44:53 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.408.0; Tue, 6 Nov 2018 20:44:44 +0800 From: John Garry To: , CC: , , , , , , John Garry Subject: [PATCH] of, numa: Validate some distance map rules Date: Tue, 6 Nov 2018 20:39:33 +0800 Message-ID: <1541507973-149965-1-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Currently the NUMA distance map parsing does not validate the distance table for the distance-matrix rules 1-2 in [1]. However the arch NUMA code may enforce some of these rules, but not all. Such is the case for the arm64 port, which does not enforce the rule that the distance between separates nodes cannot equal LOCAL_DISTANCE. The patch adds the following rules validation: - distance of node to self equals LOCAL_DISTANCE - distance of separate nodes > LOCAL_DISTANCE A note on dealing with symmetrical distances between nodes: Validating symmetrical distances between nodes is difficult. If it were mandated in the bindings that every distance must be recorded in the table, validating symmetrical distances would be straightforward. However, it isn't. In addition to this, it is also possible to record [b, a] distance only (and not [a, b]). So, when processing the table for [b, a], we cannot assert that current distance of [a, b] != [b, a] as invalid, as [a, b] distance may not be present in the table and current distance would be default at REMOTE_DISTANCE. As such, we maintain the policy that we overwrite distance [a, b] = [b, a] for b > a. This policy is different to kernel ACPI SLIT validation, which allows non-symmetrical distances (ACPI spec SLIT rules allow it). However, the debug message is dropped as it may be misleading (for a distance which is later overwritten). Some final notes on semantics: - It is implied that it is the responsibility of the arch NUMA code to reset the NUMA distance map for an error in distance map parsing. - It is the responsibility of the FW NUMA topology parsing (whether OF or ACPI) to enforce NUMA distance rules, and not arch NUMA code. [1] Documents/devicetree/bindings/numa.txt Signed-off-by: John Garry -- 1.9.1 Acked-by: Will Deacon diff --git a/drivers/of/of_numa.c b/drivers/of/of_numa.c index 35c64a4295e0..fe6b13608e51 100644 --- a/drivers/of/of_numa.c +++ b/drivers/of/of_numa.c @@ -104,9 +104,14 @@ static int __init of_numa_parse_distance_map_v1(struct device_node *map) distance = of_read_number(matrix, 1); matrix++; + if ((nodea == nodeb && distance != LOCAL_DISTANCE) || + (nodea != nodeb && distance <= LOCAL_DISTANCE)) { + pr_err("Invalid distance[node%d -> node%d] = %d\n", + nodea, nodeb, distance); + return -EINVAL; + } + numa_set_distance(nodea, nodeb, distance); - pr_debug("distance[node%d -> node%d] = %d\n", - nodea, nodeb, distance); /* Set default distance of node B->A same as A->B */ if (nodeb > nodea)