From patchwork Tue Aug 20 14:36:05 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: 13770257 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 5A0A4C531DF for ; Tue, 20 Aug 2024 14:38:06 +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:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=xT6huOC6T7Yu7zfFRkWYs+RyZWH6K8VkXHaDH7bLRdw=; b=hmAltrgCi528R6xStyal6OoVWM 6AfVWf8JvhDDIa19JBtBtRO3d41MsfJ+XMEPUX6iblMlTndpGKwulSuCzHv7RAD1YUj7COZTYxRt1 S6mr60Racr6R5Iz0XQ4qyTg48w6mADQymtLI6Viq/TosGpq3mXcd3NEl14adp+5l0rB2d9g5CLsm7 hKVIUKut24h1cEnIDGdxCUPfcckFGSAkAEOgeo0/QIiIKG7klij8Iz3SpPbMGYkJxdtflBIb5I1Ch XMMreKXkk03XrLIwemHCu6+Iv//oNYgmOfhL3evkaXC44P+27QuqOP3kBV1F/8PFtbSYA2pMU7+QY gvJdigJA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgPzd-00000005aUe-3rVt; Tue, 20 Aug 2024 14:37:53 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgPy4-00000005ZvW-2COL for linux-arm-kernel@lists.infradead.org; Tue, 20 Aug 2024 14:36:19 +0000 Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-5bf0261f162so2092189a12.0 for ; Tue, 20 Aug 2024 07:36:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1724164575; x=1724769375; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=xT6huOC6T7Yu7zfFRkWYs+RyZWH6K8VkXHaDH7bLRdw=; b=O2/xpZl9d35FGQE02tPQSxTBafmwg1COIyrWsKPDDBhYYefiaeeay23JkMuraFEdUi ZiROvQPaJFjNs6+8MQ7DXeMgjDxDZoVdXrYlidUfUt3Z+nTLkUiNti/2Ipy7HR33kWN+ Mdqzm9B8M7S2UPC7cNDmoxqrCLBgGBy0sYRbKTlsLksQ7zqoscKDRhWd+pNmKhFrT3EI OS02tS+x5TzVj9nagYIPEG91K+T5BQwXK8pWv6avWH3o0fF7/ERH0vXvIuRhQEhddb9W W4bFTJhUdvFf4r1VFzi2/LNi3HtKi0UgcTJENITInvFruOjIrJ6tTI5Py/izeTIBqEy5 FjOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724164575; x=1724769375; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xT6huOC6T7Yu7zfFRkWYs+RyZWH6K8VkXHaDH7bLRdw=; b=OJz1TGbFp7Oq0HcHFXn7DgEQLTDycER0jzR7kDaVZaNfe91H1ntSnEBfg43qRSnZr1 ehaf6UxgpmNr61zFqn6hDyTjN8iOQWC5iwPn3LbWlxuaZBuLui9J/qnLVA1bFGCjNxut eZWofYJYcWHpRwNtXAz6myOwIg7wJp8jre8Dyyyzw8uFSbCq1Bmm6Fo4QrNIxWU23ZQs fIqZkRp0ZIPMsGypYUh6yGN8L3mxCSFrOLK86n8mizM8avq/ueqcJ3b4fV6deijPNwZ5 54TBarzWC5dQ5M7+99xIW7iIBS3Qitd/ysyR5GCXaQ36VYa+4IBCGt0BYF+UbRxciOHB 3PzA== X-Forwarded-Encrypted: i=1; AJvYcCV2Vq8Jeh9oFgv4KpT4U/tmNvt7TISpQoBfaRQ+oK3ODdcAGvm3JxYrULBBN9PxjQngnQ7LmAmGwo3SvKedls6Z@lists.infradead.org X-Gm-Message-State: AOJu0Yz7KvkhN3+vm6KfZqG/S0LncxbJmWBbi4jCep3bq62zElFR/rOM ob1T1KfqT7XC/kt3GDQutFVDy7e/7gB6C8CjWABrl73sQ7iGZEqDpEMAks3Bsbk= X-Google-Smtp-Source: AGHT+IGQKwDr2ogZrSzCgclLvBAiT9X7zYngYAlcDJL0KUFwXPaOBp69ElOzx3FbUUgrmqZUdz3wjQ== X-Received: by 2002:a05:6402:520c:b0:5be:fadc:8707 with SMTP id 4fb4d7f45d1cf-5befadc893emr4836516a12.7.1724164574347; Tue, 20 Aug 2024 07:36:14 -0700 (PDT) Received: from localhost ([87.13.33.30]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bebc0817a8sm6821446a12.84.2024.08.20.07.36.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 07:36:14 -0700 (PDT) From: Andrea della Porta To: Andrea della Porta , Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Florian Fainelli , Broadcom internal kernel review list , Linus Walleij , Catalin Marinas , Will Deacon , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Nicolas Ferre , Claudiu Beznea , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Saravana Kannan , Bjorn Helgaas , 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-gpio@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, Lee Jones , Andrew Lunn , Stefan Wahren Subject: [PATCH 03/11] PCI: of_property: Sanitize 32 bit PCI address parsed from DT Date: Tue, 20 Aug 2024 16:36:05 +0200 Message-ID: <8b4fa91380fc4754ea80f47330c613e4f6b6592c.1724159867.git.andrea.porta@suse.com> 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-20240820_073616_585431_FE65CFDC X-CRM114-Status: GOOD ( 17.25 ) 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 The of_pci_set_address() function parse devicetree PCI range specifier assuming the address is 'sanitized' at the origin, i.e. without checking whether the incoming address is 32 or 64 bit has specified in the flags. In this way an address with no OF_PCI_ADDR_SPACE_MEM64 set in the flagss could leak through and the upper 32 bits of the address will be set too, and this violates the PCI specs stating that ion 32 bit address the upper bit should be zero. This could cause mapping translation mismatch on PCI devices (e.g. RP1) that are expected to be addressed with a 64 bit address while advertising a 32 bit address in the PCI config region. Add a check in of_pci_set_address() to set upper 32 bits to zero in case the address has no 64 bit flag set. Signed-off-by: Andrea della Porta --- drivers/pci/of_property.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/pci/of_property.c b/drivers/pci/of_property.c index 5a0b98e69795..77865facdb4a 100644 --- a/drivers/pci/of_property.c +++ b/drivers/pci/of_property.c @@ -60,7 +60,10 @@ static void of_pci_set_address(struct pci_dev *pdev, u32 *prop, u64 addr, prop[0] |= flags | reg_num; if (!reloc) { prop[0] |= OF_PCI_ADDR_FIELD_NONRELOC; - prop[1] = upper_32_bits(addr); + if (FIELD_GET(OF_PCI_ADDR_FIELD_SS, flags) == OF_PCI_ADDR_SPACE_MEM64) + prop[1] = upper_32_bits(addr); + else + prop[1] = 0; prop[2] = lower_32_bits(addr); } }