From patchwork Thu Nov 8 10:17:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 150493 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp640098ljp; Thu, 8 Nov 2018 02:15:21 -0800 (PST) X-Google-Smtp-Source: AJdET5eL3J6kdYLRTGAkKZkmlZJSSxUSlF36pWNvnMXXYxbwia19a6ngncinRM2w2hii7uY3gxxU X-Received: by 2002:a63:f34b:: with SMTP id t11mr3301983pgj.341.1541672121373; Thu, 08 Nov 2018 02:15:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541672121; cv=none; d=google.com; s=arc-20160816; b=JGLos5JNMwZTv7icJhnt1pL6jJSH9bU6wvdraCMCMj/S3YU4gRda/Mh3xAJjR4pNK+ iLymq+Q3KkmQuxlv+GQFxrgV7HuGDR2UX77FdsbKPtbNMzq3oANWSzGjiL9vM/qtYudT OpZEw5SQCHCLEQp99aurqbS9gromNVQOwMggKiEMyO0TD+nLVyYtXeEKQwXeFioIAqNY BMUm/GEmQ2qFZ392ogV9WpI1Y8gZBxHpta0CPJUAykkZpD2B2XMqbxotSaEpXszvXB1n bAqjDUUIwdFlKlQGrH1ZlX6euLAzNhN70Q0k0ljwwgfKHQlQS90TFrNXn3RYIIckP1oV zNQw== 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=0Fm/MuG15IQyQmVWvvczeinB4iPx2yJOa44Y1P2zmSM=; b=YAVN0nhNAaAqg35+u3nggjCg/9ziKh5M/GAwVOvK1eunM7n3zZz2TmRN+fCGDiW4zl mssfQw42J0vde6zH6SQAKzIyFsCobhKSJ9nIRywdUnElh2KJNAZMgOwOdhc3mEtR8AVm TNaUDWgxyY+U0we6eN648c4DPl3gnPqfMgXih+WiUGfq2YJ0yX+VT3OiZmvNvigtUV80 vsE0gH94LNX+CkGpihJZqrLtoVaIbG7hM2k3xu8RMeDVnxU/6xN9SfLvE3v/Yc99EMHC E8FEsWkKYKPwjQEYuurZ0aRbnDU5NJaMwPkzjzyC2AV3myE7B95+xBobizNCuHCo2ZtT e2qQ== 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 ay4-v6si3918123plb.410.2018.11.08.02.15.21; Thu, 08 Nov 2018 02:15:21 -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 S1727343AbeKHTuE (ORCPT + 6 others); Thu, 8 Nov 2018 14:50:04 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:14615 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726955AbeKHTuE (ORCPT ); Thu, 8 Nov 2018 14:50:04 -0500 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 3DADD162ADF3F; Thu, 8 Nov 2018 18:15:16 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.408.0; Thu, 8 Nov 2018 18:15:10 +0800 From: John Garry To: , CC: , , , , , Subject: [PATCH v2] of, numa: Validate some distance map rules Date: Thu, 8 Nov 2018 18:17:03 +0800 Message-ID: <1541672223-131326-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 This change avoids a yet-unresolved crash reported in [2]. 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, then it would be easy. 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 distance 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 [2] https://www.spinics.net/lists/arm-kernel/msg683304.html Cc: stable@vger.kernel.org # 4.7 Signed-off-by: John Garry Acked-by: Will Deacon --- Changes from v1: - Add note on masking crash reported - Add Will's tag - Add cc stable -- 1.9.1 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)