From patchwork Fri Nov 8 10:39:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea della Porta X-Patchwork-Id: 13868083 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9C70FD5AE5C for ; Fri, 8 Nov 2024 11:58:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/azjLItm0kRcZGnRsfAiDqYz09Bjkw+3gf50DzO5cz0=; b=uZkifSrJ5tl8YqepVpm9u2RP7o HrOOkKjeg4idgqYNS951Josr7AnRnpeFhPBFSsqQO5ZaLymYopZpaKIhcO9TGhLkyRo/G4OAV7SV2 ugcam8LoH4AK0OAVuWVpvrh4Por4Y0S5ifibCVgONcEdIMIMa/9CE9MAStZqRGuQtw2673v3CMCxY SWvMkrlGejUUdzpvDgyyiKjoC6qVUyrhqR/vygu44sOoo6Q4gSsuAIBneay/hYNW47CkDRUXA//S4 kwxuBOzUJl7zw670hHcPOmcbIiw+JIsBrdg/MOIpMechnX5qnOA7y9TGWLhrW2VLrFihcrIjmcCT8 6FgHMopw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t9Nd4-0000000AQp3-1JzY; Fri, 08 Nov 2024 11:58:18 +0000 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t9MOJ-0000000A9Nv-05ip for linux-arm-kernel@lists.infradead.org; Fri, 08 Nov 2024 10:39:02 +0000 Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5c96b2a10e1so2722708a12.2 for ; Fri, 08 Nov 2024 02:38:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1731062337; x=1731667137; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/azjLItm0kRcZGnRsfAiDqYz09Bjkw+3gf50DzO5cz0=; b=H5aTJSF62AYcGNmTEzuaArKVZYXc6Nqb4GMTN24nO7U2WyXTY+ATd+Jqsj3jNlOGpS Lh5+rl0vJafSOxK0TEOct/s8IFDuiU4/jIk23rfJOU1TMHvL+zR1Zr48i5bp2BfgqRcR U683Lft7OEO6ixLQgMEXwftCParo2dvVT29rZbDm8UHlO61Sbm0QTNt5TAc4D02eoo+U VhCfuXDo+WZis1s+7DXHCluCG0HeA+Cy7MKBwWdWJVAABmk1IWj3RSlOyAM0dK35TXq4 Ymrgst0pRs3pqZqqNmjcuqA6ogZ1haVwGnfuOvy9ZPbnqny/Jue+6Fmgs8dMymoMzscB n2Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731062337; x=1731667137; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/azjLItm0kRcZGnRsfAiDqYz09Bjkw+3gf50DzO5cz0=; b=il+tHVGep9PF7881j4eXrreDNJd7V11zSsTIEN+AnweQi49Sc8MBvktASTUNmALoav wWxhsIyGnv82WEMH4nBpiUpaPwzf0IhhQhQb4VW5YDo5bBRezoiWDUi6XuCWOuFqkqgx it7ykkSLlA8ufhHGdjS/Trt9qu+ys/2Dx/BDMFSR15zoltZkBKmiNXHt+vNeD0JIDfMM wJBlTZl8Wy8zI6TuB+FixotykPP9BrdpiLbSiWwiOax3NDA6YllA0liDTvudUtOXMQZQ Vt8L1AEMcyToLbTi1EgdLqoB2bMOwOT4iUuem/WlLX6WboUrb390G7IhTwHd0H2fYIRW TXJg== X-Forwarded-Encrypted: i=1; AJvYcCULdV/L44OqOqJ3jvAhkvL6cA849MQIND2ZMgXkITVUJ+xbzcIrbCj/owWKSf+H3QeEGJstzgg+6vSkvo8a5CKx@lists.infradead.org X-Gm-Message-State: AOJu0YyR/0mSiqgcqVql0f0WqyNj6wd+W176GWU6IL40lKxldz1xFMJj Ji1iL7bi6+dZ1mtXT8F+bPwUOPLoB9fPKdrSeAGHb54b2qAgp+WHlfHGVxf045E= X-Google-Smtp-Source: AGHT+IHc0Nm4EeujQTsSiAthZ5sn/djXgAGGTqX7CDsdQwDobH57OcRUGR+bcR0+ZbLG2wRvWj+K1A== X-Received: by 2002:a17:907:6d28:b0:a9a:2afc:e4cc with SMTP id a640c23a62f3a-a9ef0050e63mr178709966b.58.1731062337230; Fri, 08 Nov 2024 02:38:57 -0800 (PST) Received: from localhost (host-79-35-211-193.retail.telecomitalia.it. [79.35.211.193]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9ee0def8ecsm213746366b.152.2024.11.08.02.38.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 02:38:56 -0800 (PST) From: Andrea della Porta To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Florian Fainelli , Broadcom internal kernel review list , Lorenzo Pieralisi , Krzysztof Wilczynski , Manivannan Sadhasivam , Bjorn Helgaas , Linus Walleij , Catalin Marinas , Will Deacon , Bartosz Golaszewski , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Saravana Kannan , linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-gpio@vger.kernel.org, Masahiro Yamada , Stefan Wahren , Herve Codina , Luca Ceresoli , Thomas Petazzoni , Andrew Lunn Cc: Andrea della Porta Subject: [PATCH 1/2] of/unittest: Add empty dma-ranges address translation tests Date: Fri, 8 Nov 2024 11:39:20 +0100 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241108_023859_168059_4A9D0738 X-CRM114-Status: GOOD ( 17.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Intermediate DT PCI nodes dynamically generated by enabling CONFIG_PCI_DYNAMIC_OF_NODES have empty dma-ranges property. PCI address specifiers have 3 cells and when dma-ranges is missing or empty, of_translate_one() is currently dropping the flag portion of PCI addresses which are subnodes of the aforementioned ones, failing the translation. Add new tests covering this case. With this test, we get 1 new failure which is fixed in subsequent commit: FAIL of_unittest_pci_empty_dma_ranges():1245 for_each_of_pci_range wrong CPU addr (ffffffffffffffff) on node /testcase-data/address-tests2/pcie@d1070000/pci@0,0/dev@0,0/local-bus@0 Signed-off-by: Andrea della Porta --- drivers/of/unittest-data/tests-address.dtsi | 2 ++ drivers/of/unittest.c | 39 +++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/drivers/of/unittest-data/tests-address.dtsi b/drivers/of/unittest-data/tests-address.dtsi index 3344f15c3755..f02a181bb125 100644 --- a/drivers/of/unittest-data/tests-address.dtsi +++ b/drivers/of/unittest-data/tests-address.dtsi @@ -114,6 +114,7 @@ pcie@d1070000 { device_type = "pci"; ranges = <0x82000000 0 0xe8000000 0 0xe8000000 0 0x7f00000>, <0x81000000 0 0x00000000 0 0xefff0000 0 0x0010000>; + dma-ranges = <0x43000000 0x10 0x00 0x00 0x00 0x00 0x10000000>; reg = <0x00000000 0xd1070000 0x20000>; pci@0,0 { @@ -142,6 +143,7 @@ local-bus@0 { #size-cells = <0x01>; ranges = <0xa0000000 0 0 0 0x2000000>, <0xb0000000 1 0 0 0x1000000>; + dma-ranges = <0xc0000000 0x43000000 0x10 0x00 0x10000000>; dev@e0000000 { reg = <0xa0001000 0x1000>, diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index daf9a2dddd7e..80483e38d7b4 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -1213,6 +1213,44 @@ static void __init of_unittest_pci_dma_ranges(void) of_node_put(np); } +static void __init of_unittest_pci_empty_dma_ranges(void) +{ + struct device_node *np; + struct of_pci_range range; + struct of_pci_range_parser parser; + + if (!IS_ENABLED(CONFIG_PCI)) + return; + + np = of_find_node_by_path("/testcase-data/address-tests2/pcie@d1070000/pci@0,0/dev@0,0/local-bus@0"); + if (!np) { + pr_err("missing testcase data\n"); + return; + } + + if (of_pci_dma_range_parser_init(&parser, np)) { + pr_err("missing dma-ranges property\n"); + return; + } + + /* + * Get the dma-ranges from the device tree + */ + for_each_of_pci_range(&parser, &range) { + unittest(range.size == 0x10000000, + "for_each_of_pci_range wrong size on node %pOF size=%llx\n", + np, range.size); + unittest(range.cpu_addr == 0x00000000, + "for_each_of_pci_range wrong CPU addr (%llx) on node %pOF", + range.cpu_addr, np); + unittest(range.pci_addr == 0xc0000000, + "for_each_of_pci_range wrong DMA addr (%llx) on node %pOF", + range.pci_addr, np); + } + + of_node_put(np); +} + static void __init of_unittest_bus_ranges(void) { struct device_node *np; @@ -4272,6 +4310,7 @@ static int __init of_unittest(void) of_unittest_dma_get_max_cpu_address(); of_unittest_parse_dma_ranges(); of_unittest_pci_dma_ranges(); + of_unittest_pci_empty_dma_ranges(); of_unittest_bus_ranges(); of_unittest_bus_3cell_ranges(); of_unittest_reg(); From patchwork Fri Nov 8 10:39:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea della Porta X-Patchwork-Id: 13868073 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 34376D5E15A for ; Fri, 8 Nov 2024 11:29:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jJXmxMV9Abc1uTINb2xUxHegsV2x5Sbl3192+49JM4w=; b=r1pzW5xWnmYzO02PF/Zm97wHM7 fPi3JIeuuRf1SELk7a2XjLRVhtzwCo4rgDIlLo63i1FqHlDlWSb6nN3Exn2sN3ObXrD1AuKrukPIn 0B+QJbO4MiP1nOkdOeNuMg70EzeRO7T77TkfY9XVKgi4mkANUbQbDQfhSd3MUGvMtaVFJo4TGNBW1 dQB6O6dmjSA97BdSWt/uNBfnwe+RZ977b0ZQjxuvfz+9JBmkNG2zZxIUhnkhJLzwKsbOFaYwWhAZi qMptGRJsaR0ZrzEplKRpDwC8uEmilhr0Q4kLQqKnfJPqR2txA4m9m5D8JBQYXvyI9jfaCPFZrk+nl XqOSbIUQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t9NAu-0000000ALZ1-12e3; Fri, 08 Nov 2024 11:29:12 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t9MOL-0000000A9Or-0vQU for linux-arm-kernel@lists.infradead.org; Fri, 08 Nov 2024 10:39:03 +0000 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a9eb68e0bd1so271437866b.3 for ; Fri, 08 Nov 2024 02:39:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1731062339; x=1731667139; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jJXmxMV9Abc1uTINb2xUxHegsV2x5Sbl3192+49JM4w=; b=AKW3sP9kDCY91XEKmiaHCGoo2jzM5W+i+FwIkX/tCD8OTS8rn5bIgbkshCCaKSpRBo uIMHOrXtCUV5z+KsPxu2ELn+iTuorenQ7XcZZ5ntlNeiuzu+ZpcTXrGIzCMV7w/hnNcZ 8kqmdsB5NlUjC3wG9UeMJRIV91SmAGwFGngUNZ6R5rVuhMTV1Fg0EEot9GHEiZ1Nadnu 7TgY6AazGjGTzzyA3mSy2ekD9ITu8wegnSJdq1dU+JCiRfAvgHP86ig3vBoLD9hQCXlY C83QHALEpZ64E+xds16pdq/Bk2lYSwA/KSyH6ZPptFFK1pXL4J5pddBYkyIzvmi1BPny SXUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731062339; x=1731667139; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jJXmxMV9Abc1uTINb2xUxHegsV2x5Sbl3192+49JM4w=; b=dUOhyPsZYQ2R99HgctMK1sCbEMgBq/yRce7OGkbvt2qcTMoufltyIaR35FMEHgBOJy 5BgRePNis8J3P11VCo5s7cl3cFLg2MHAe/cYAY5EwIzABp3o7PiuQdt3YATtOQhOydkY ZuvXIONOqtWsupiUiCLWeIZ5IW9le7lQEzmbEzHT5Ao3Hs+LIwrF6PltAAQKliZoIUaF KnRBmWmhp9joB2QYxlgTymvOFtzdkZHY9A1K+Fockzl4gPeVe6bTD350b+PPLtp+VJIc TVd7z/WuKHCLj+SoEqeOVckHUAp9X/cpSZqnLhcHPIki2xrPv8Ab3DQpISfN6mb2NiKN VFyw== X-Forwarded-Encrypted: i=1; AJvYcCWt2CItGZuevwbiTkhQE5Ogd6exutUQYsuLtkqDn89MlIv6nxPI+L12MXvw3df6ReE+u1PuH1FAnbuwulxHlo5y@lists.infradead.org X-Gm-Message-State: AOJu0YxkmsjZNoa6Y5XAawfJwjlTiJh8sG+0mJuAnQnBo4DeSlRK7Sso 9l/6Se+ufmmyfEPmVIG7bmzRJFznixJ9gS16ce8g8P9uMd5PzC+RR9AFqdAFFAY= X-Google-Smtp-Source: AGHT+IHiQxW5gF9yi4X8bacvXjxGkk6fIrYEA4STUTYGNxpcC1/v9Tb+L2h7W5kVMF2aOK5bJYki5Q== X-Received: by 2002:a17:906:eecb:b0:a9e:b150:a99d with SMTP id a640c23a62f3a-a9eefeb4d57mr208775166b.5.1731062338980; Fri, 08 Nov 2024 02:38:58 -0800 (PST) Received: from localhost (host-79-35-211-193.retail.telecomitalia.it. [79.35.211.193]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9ee0a188besm213593566b.8.2024.11.08.02.38.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 02:38:58 -0800 (PST) From: Andrea della Porta To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Florian Fainelli , Broadcom internal kernel review list , Lorenzo Pieralisi , Krzysztof Wilczynski , Manivannan Sadhasivam , Bjorn Helgaas , Linus Walleij , Catalin Marinas , Will Deacon , Bartosz Golaszewski , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Saravana Kannan , linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-gpio@vger.kernel.org, Masahiro Yamada , Stefan Wahren , Herve Codina , Luca Ceresoli , Thomas Petazzoni , Andrew Lunn Cc: Andrea della Porta , stable@vger.kernel.org Subject: [PATCH 2/2] of: address: Preserve the flags portion on 1:1 dma-ranges mapping Date: Fri, 8 Nov 2024 11:39:21 +0100 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241108_023901_338497_97365B89 X-CRM114-Status: GOOD ( 15.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org A missing or empty dma-ranges in a DT node implies a 1:1 mapping for dma translations. In this specific case, the current behaviour is to zero out the entire specifier so that the translation could be carried on as an offset from zero. This includes address specifier that has flags (e.g. PCI ranges). Once the flags portion has been zeroed, the translation chain is broken since the mapping functions will check the upcoming address specifier against mismatching flags, always failing the 1:1 mapping and its entire purpose of always succeeding. Set to zero only the address portion while passing the flags through. Fixes: dbbdee94734b ("of/address: Merge all of the bus translation code") Cc: stable@vger.kernel.org Signed-off-by: Andrea della Porta Tested-by: Herve Codina --- drivers/of/address.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 286f0c161e33..72b6accff21c 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -455,7 +455,8 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus, } if (ranges == NULL || rlen == 0) { offset = of_read_number(addr, na); - memset(addr, 0, pna * 4); + /* copy the address while preserving the flags */ + memset(addr + pbus->flag_cells, 0, (pna - pbus->flag_cells) * 4); pr_debug("empty ranges; 1:1 translation\n"); goto finish; }