From patchwork Thu Nov 8 10:16:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 150492 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp639791ljp; Thu, 8 Nov 2018 02:15:01 -0800 (PST) X-Google-Smtp-Source: AJdET5ceBT9q/GRAauj3UQ8Jhuvu4e576X+7ZyIwTXIc90bF0nnJexMyQmFr3h2zpN+r74CrXDHI X-Received: by 2002:a17:902:bccc:: with SMTP id o12-v6mr4004609pls.281.1541672101594; Thu, 08 Nov 2018 02:15:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541672101; cv=none; d=google.com; s=arc-20160816; b=UBJ6ho9Xz4v0drhusGxe+V+wvm0MSkdTBlKoi0gBv/LJ9oJxqomtU2jcxWsFZkAyJU 5zskWk7C6gMbaNQCEAGBpaR6EgVvvM3H0N0LvwWVPuK24i/Ga8Rh/ccNzcSNR3aYvg/E puHQPCtdizxdPfSX4UzDlKWFLo96QfprfJh+Oy5wo2e6/c3wzX7Vaq0YNeFG/aOdW5yD ytkFSuNGGa638Tqvp4R0+F/RDW1Z0O0wG6XWA80imWQhnGcrBGEki02oAiBPFS/Ztrr3 /EIgKC85ookkvUSkEoBt2rv/0XSeWBJVPJBw8Do2s5HA/SD76NwZrRtW1NcDRz8MQEpH yIYQ== 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=mwP+MfDXPOvP3ykM7br238azUq+y+Hmm7otiE/ORps0FdfKQZXXxvJZQAqw1WGRiQ2 FfKZNyppGgsLtvMmzsZ+xfjLA/N0CL3iKWKVNx6/5hG/C+yMWB0DuHvmls1r4UdbHr0O PXBzws8OeMFxxMd5KDypSCo6tGfABVtKWmBBqi6ffXJ01r293LZAOBH4WXgfscsf5KHt IdlkPS0yhrXbJEhiQzkIMwwPKx5tUcU2DiFtHBRkrEPKVz365bhU+kzcNfBeXPSgM9vN hTICo92yhkPeyT5GKK5CDEgqoruMpcHmRMeCq75UMCMZtYwKSsQ5AbAW4wawoqbUTKkR zqnQ== 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 f4-v6si4560197plm.393.2018.11.08.02.15.01; Thu, 08 Nov 2018 02:15:01 -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; 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 S1727390AbeKHTto (ORCPT + 32 others); Thu, 8 Nov 2018 14:49:44 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:32850 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726955AbeKHTtn (ORCPT ); Thu, 8 Nov 2018 14:49:43 -0500 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 02E68BBCEB710; Thu, 8 Nov 2018 18:14:56 +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:14:49 +0800 From: John Garry To: , CC: , , , , , Subject: [PATCH v2] of, numa: Validate some distance map rules Date: Thu, 8 Nov 2018 18:16:42 +0800 Message-ID: <1541672202-131229-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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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)