From patchwork Thu Nov 8 10:05: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: 150491 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp632595ljp; Thu, 8 Nov 2018 02:06:42 -0800 (PST) X-Google-Smtp-Source: AJdET5eSF53yj+hzHxfj/01YySjb0K3LR226JCmDpUo/lFFhx3mn9wv9IeyAGKvfw66WEGkcZzFa X-Received: by 2002:a62:1cc6:: with SMTP id c189-v6mr3936267pfc.49.1541671602114; Thu, 08 Nov 2018 02:06:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541671602; cv=none; d=google.com; s=arc-20160816; b=Nlssrd2WIeuOPQXCt+KpXmerDGybIENjbMTNElYdAZIOAFphJeaDFpMqsvMzgileYU DwYZUB3ZAroJlgZ3GwRlBG91rBhD+5HyDV4X/xa7vLLvpjexfZof8SkswmxNn1t+JHrj dL0pZSRsMFVaGfhggvd5wywagKHbYmUyveOzlm/JiK6ArOUm2b+DCWN4s9VbcpwCU/eI Y17Myn+6HJf6xCiGDedj7ThLnW9s5sv1nXH6cGrFdOSfh+5K/VqH8wEpl6GYWU1wiht/ XP5TC5Mn1ksy4ItL7VXHMi/iU8Tnx+7PkmH2CKBh6gttcNXH8arvj6avVRzDRWKGMCsc GJaQ== 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=PxOKiuC1sAW7/HnRgpvGfPB3PPmAGic2yton2PQVFAY=; b=QXNb1tv71ecSUlh8qWLHd2BHlGMfTbBrBTiYyaJ6+bo2sygUHS+6j1SmdydQgh1cUu g9tsUVcvXOI3s5vT2ia0Fwqqc/fKkyw+cgDycgWMJzDR3OAXyAQlbjsaXv0koiqQ8o/3 gfsW866i5agdzL85squgspCoreF9QX6VHnz5arPWHC3uKPIDejc9v89tj5NUKKRC8VFx 1jygvTCZBIr7CyzcZtVupQsjb2CB4hJavMKcRcwSxMss5U99PppzwvyAYwaEkpVY0qqj 0SiNUgh6S8Fxy1Ywdxa2jBruPCY01ybSvtxywF6MtbL0cVQezowDZQNWevVFmKmD7IMF kOOA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 c134-v6si3944992pfb.139.2018.11.08.02.06.41; Thu, 08 Nov 2018 02:06:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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 stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726283AbeKHTlX (ORCPT + 15 others); Thu, 8 Nov 2018 14:41:23 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:14614 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726274AbeKHTlX (ORCPT ); Thu, 8 Nov 2018 14:41:23 -0500 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 57658C741F9BF; Thu, 8 Nov 2018 18:06:37 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.408.0; Thu, 8 Nov 2018 18:06:31 +0800 From: John Garry To: CC: John Garry , Subject: [PATCH v2] of, numa: Validate some distance map rules Date: Thu, 8 Nov 2018 18:05:33 +0800 Message-ID: <1541671533-111674-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: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 Signed-off-by: John Garry Acked-by: Will Deacon --- Change from v1: - A note of 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)