From patchwork Wed Feb 2 02:01:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajat Jain X-Patchwork-Id: 12732503 X-Patchwork-Delegate: bhelgaas@google.com 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B276AC433FE for ; Wed, 2 Feb 2022 02:01:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243659AbiBBCBJ (ORCPT ); Tue, 1 Feb 2022 21:01:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232709AbiBBCBJ (ORCPT ); Tue, 1 Feb 2022 21:01:09 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB8C3C061714 for ; Tue, 1 Feb 2022 18:01:08 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id v70-20020a25c549000000b006130de5790aso37062082ybe.4 for ; Tue, 01 Feb 2022 18:01:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=+oZZAJ93Jy4UHYgQMOKgcZ+Tafx++iolBtq7+r39Tt8=; b=UbQZqjK39u6TMbV7ooe4Qpn8t7EH7BRXJ+czxhC1600IQy3DDw3FS+kVkxYDRRl3vl Ryu5jR9neodQl/6jvFh9Itjq0tGpjiD6UDIEYHIjTiGLW+Dr9d0DquZtsolJ8wU/yLeV edZ7QX5teM86K1tiHqNfPmwJk6yv7wXaTydlOGgEb6JUrWd8/6RbIPYhG69X6u6ja0qR caNw/+3fgrg89vkjtWhoe1MWYAQUmpI+F1beyh/a70yzqnjgnfn0M0O54A9/kgtIrrNj BmfLvZ2l8DMl2mjOvF2QduGDI5LZISh7vBChoJ/FIS4R2MvS4J76ywRsWeJVLFMSs6d9 YVMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=+oZZAJ93Jy4UHYgQMOKgcZ+Tafx++iolBtq7+r39Tt8=; b=JXfDksgeRMRMr0KuPtgRjwF8BZdUFJPjhBlg1rmV6EGbGxHzu/ZF+waiMFOkzAUuGX gjaohR2owIuOSCI7R+mCtWJyVoohT8VK00rr0MYqZlvXeZP2NVLnv0rE3J05lmqMFIEX j9bqYYY+Kp9jxkTnBAwUcz+1Uos2WJdfP1iKoOTOa/Vo97gVvOsMKxaCre+5hpJ4HFN3 3ZhRxDbgeSYZMvvj/5xbVKov6cQ8rJ8AH5dJqcz2SasYJd4dO92RpH6fTpJg/ftzE29U v85pZk885sxXlgKeikPhwkp2Lf/o8V5ZtnsuV+X8hLqjFEP6tG+R/PitMSsoI+u9eLdS apwg== X-Gm-Message-State: AOAM531kJMLXsaM1C4x7WvzlEn8m2svcPeK66vT8YpgDR4DRU3PnfgZ7 gMGxHBSzHz9oyGYLsU540RRp4ETlleS7 X-Google-Smtp-Source: ABdhPJyY11MiO9c+Nqia5AcbphlMlCViWeU/vlCMo+UMffUd5Y5GEWLyzan3ovSdlF4GgrZlbtU4lO1oPpBm X-Received: from rajat2.mtv.corp.google.com ([2620:15c:202:201:57dc:f744:660d:72d]) (user=rajatja job=sendgmr) by 2002:a25:e7d7:: with SMTP id e206mr24915081ybh.695.1643767267984; Tue, 01 Feb 2022 18:01:07 -0800 (PST) Date: Tue, 1 Feb 2022 18:01:02 -0800 Message-Id: <20220202020103.2149130-1-rajatja@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog Subject: [PATCH v2 1/2] PCI: Allow internal devices to be marked as untrusted From: Rajat Jain To: Rob Herring , "Rafael J. Wysocki" , Len Brown , linux-pci@vger.kernel.org, devicetree@vger.kernel.org, Mika Westerberg , Greg Kroah-Hartman , Bjorn Helgaas , Bjorn Helgaas , ACPI Devel Maling List , Linux Kernel Mailing List , Rajat Jain , Dmitry Torokhov , Jesse Barnes , Jean-Philippe Brucker , Pavel Machek , "Oliver O'Halloran" , Joerg Roedel Cc: Rajat Jain Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Today the pci_dev->untrusted is set for any devices sitting downstream an external facing port (determined via "ExternalFacingPort" or the "external-facing" properties). However, currently there is no way for internal devices to be marked as untrusted. There are use-cases though, where a platform would like to treat an internal device as untrusted (perhaps because it runs untrusted firmware or offers an attack surface by handling untrusted network data etc). Introduce a new "UntrustedDevice" property that can be used by the firmware to mark any device as untrusted. Signed-off-by: Rajat Jain --- v2: * Also use the same property for device tree based systems. * Add documentation (next patch) drivers/pci/of.c | 2 ++ drivers/pci/pci-acpi.c | 1 + drivers/pci/pci.c | 9 +++++++++ drivers/pci/pci.h | 2 ++ 4 files changed, 14 insertions(+) diff --git a/drivers/pci/of.c b/drivers/pci/of.c index cb2e8351c2cc..e8b804664b69 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -24,6 +24,8 @@ void pci_set_of_node(struct pci_dev *dev) dev->devfn); if (dev->dev.of_node) dev->dev.fwnode = &dev->dev.of_node->fwnode; + + pci_set_untrusted(dev); } void pci_release_of_node(struct pci_dev *dev) diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index a42dbf448860..2bffbd5c6114 100644 --- a/drivers/pci/pci-acpi.c +++ b/drivers/pci/pci-acpi.c @@ -1356,6 +1356,7 @@ void pci_acpi_setup(struct device *dev, struct acpi_device *adev) pci_acpi_optimize_delay(pci_dev, adev->handle); pci_acpi_set_external_facing(pci_dev); + pci_set_untrusted(pci_dev); pci_acpi_add_edr_notifier(pci_dev); pci_acpi_add_pm_notifier(adev, pci_dev); diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 9ecce435fb3f..41e887c27004 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -6869,3 +6869,12 @@ static int __init pci_realloc_setup_params(void) return 0; } pure_initcall(pci_realloc_setup_params); + +void pci_set_untrusted(struct pci_dev *pdev) +{ + u8 val; + + if (!device_property_read_u8(&pdev->dev, "UntrustedDevice", &val) + && val) + pdev->untrusted = 1; +} diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 3d60cabde1a1..6c273ce5e0ba 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -761,4 +761,6 @@ static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev) } #endif +void pci_set_untrusted(struct pci_dev *pdev); + #endif /* DRIVERS_PCI_H */ From patchwork Wed Feb 2 02:01:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajat Jain X-Patchwork-Id: 12732504 X-Patchwork-Delegate: bhelgaas@google.com 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12986C433FE for ; Wed, 2 Feb 2022 02:01:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243755AbiBBCBO (ORCPT ); Tue, 1 Feb 2022 21:01:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243747AbiBBCBL (ORCPT ); Tue, 1 Feb 2022 21:01:11 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 313C0C061714 for ; Tue, 1 Feb 2022 18:01:11 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id v70-20020a25c549000000b006130de5790aso37062427ybe.4 for ; Tue, 01 Feb 2022 18:01:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=q1oi/RXvkD8Dq7uJmeyWkylsnr5bf/ofiDPgwV3XBxs=; b=HxhJFx8m1xXWPSkOOlyIHZ6TrBS88zHq/VAT9Azm8OrGOXPZ9brzpZt4GDmYgOJy5d ynIOdFCljbEHCcUOgSq9oY6YBG5ym7KHqVPEvqeLPOvSDDelPg+wpmLbl7w+c1e1tUfz zzoKk/HVz+AOO/D8kD1g0E3cghS3LbDh588/FaPOBvMytF3sr93ri6+p0AEEHJexUu2q hIQT6OliOYVL+oHVbUo1X8dX3Cwh744nCTUT30tFFRnxC5XkOVyX9VOjZcNPmqFSMiCi C3A4uhN+FsT2AEv6udiM3Cib0xVhFo7fiC74QvwT5yC88rcxCP4xT4vwK63dV4piNsaq roVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=q1oi/RXvkD8Dq7uJmeyWkylsnr5bf/ofiDPgwV3XBxs=; b=QgulxgPFT598FjMxlOE4XLLIYU7OOSeqU0wQxLddfPlbjw07GCB+OFeJIEAIchJNIx 6+a3VDOWkHUorqAx8xniCHEP113eInDeZ3WV7CMEWtjzMCu6kkcO2zOxG7ZxpDc83mVB jT8UesDLT3/duOOyd5ukohW4SSP4df25GiKPBbdE7J8gZxN9U63v88FIWgoFm90BUL2t iNsHeISBW9KbvD2RyP5oN411VZwh2WWe8Q15yCi3MQNShlsjvn9HniYjRp04IMTI65x1 4ABxfRWgDQBHVM5h62P6FwGSEH4lqwqxjBJQlPaOizo0TX+JaHFKLpJveAPXFVXS1gdn yZxw== X-Gm-Message-State: AOAM533U+BLT7A+8GjCLeH3fJbetA3tfJFFts+nf6/cBvv8/NT27BmZg LbjOx56ziD32kqcUgvejPL8Znr4NYKux X-Google-Smtp-Source: ABdhPJwEpwwsb0wPv1uBzyjNY2EpARcBgOMHZ0zvO/DbYf2KSjn9bDzFDRksVosNRbsKOee80RK5err37Kpz X-Received: from rajat2.mtv.corp.google.com ([2620:15c:202:201:57dc:f744:660d:72d]) (user=rajatja job=sendgmr) by 2002:a25:e5c7:: with SMTP id c190mr29691167ybh.175.1643767270447; Tue, 01 Feb 2022 18:01:10 -0800 (PST) Date: Tue, 1 Feb 2022 18:01:03 -0800 In-Reply-To: <20220202020103.2149130-1-rajatja@google.com> Message-Id: <20220202020103.2149130-2-rajatja@google.com> Mime-Version: 1.0 References: <20220202020103.2149130-1-rajatja@google.com> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog Subject: [PATCH v2 2/2] dt-bindings: Document "UntrustedDevice" property for PCI devices From: Rajat Jain To: Rob Herring , "Rafael J. Wysocki" , Len Brown , linux-pci@vger.kernel.org, devicetree@vger.kernel.org, Mika Westerberg , Greg Kroah-Hartman , Bjorn Helgaas , Bjorn Helgaas , ACPI Devel Maling List , Linux Kernel Mailing List , Rajat Jain , Dmitry Torokhov , Jesse Barnes , Jean-Philippe Brucker , Pavel Machek , "Oliver O'Halloran" , Joerg Roedel Cc: Rajat Jain Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Add the new "UntrustedDevice" property for PCI devices. This property is optional and can be applied to any PCI device. Signed-off-by: Rajat Jain --- v2: Initial version (added documentation based on comments) v1: Does not exist. Documentation/devicetree/bindings/pci/pci.txt | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Documentation/devicetree/bindings/pci/pci.txt b/Documentation/devicetree/bindings/pci/pci.txt index 6a8f2874a24d..bc1ba10f51e1 100644 --- a/Documentation/devicetree/bindings/pci/pci.txt +++ b/Documentation/devicetree/bindings/pci/pci.txt @@ -82,3 +82,38 @@ pcie@10000000 { external-facing; }; }; + +PCI Device Properties +--------------------- +Following optional properties may be present for any PCI device: + +- UntrustedDevice: + When present, this property is an indicator that this PCI device (and + any downstream devices) are to be treated as untrusted by the kernel. + The kernel can, for example, use this information to isolate such + devices using a strict DMA protection via the IOMMU. + + Example device tree node: + pcie@0008 { + /* PCI device 00:01.0 is an untrusted device */ + reg = <0x00000800 0 0 0 0>; + UntrustedDevice = <1>; + }; + + Example ACPI node: + Scope (\_SB.PCI0.WFA3) + { + Name (_DSD, Package (0x02) // _DSD: Device-Specific Data + { + ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device + Properties for _DSD */, + Package (0x01) + { + Package (0x02) + { + "UntrustedDevice", + One + } + } + }) + }