From patchwork Fri Aug 2 16:39:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 11073913 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 82B0D13AC for ; Fri, 2 Aug 2019 16:41:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7254C287DB for ; Fri, 2 Aug 2019 16:41:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 66ABD28874; Fri, 2 Aug 2019 16:41:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EC0AF28898 for ; Fri, 2 Aug 2019 16:41:43 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htab4-0003pL-F0; Fri, 02 Aug 2019 16:40:02 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htab3-0003jF-N3 for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 16:40:01 +0000 X-Inumbo-ID: 2b2d476e-b544-11e9-8980-bc764e045a96 Received: from mail-lj1-x241.google.com (unknown [2a00:1450:4864:20::241]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 2b2d476e-b544-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 16:40:00 +0000 (UTC) Received: by mail-lj1-x241.google.com with SMTP id z28so19232405ljn.4 for ; Fri, 02 Aug 2019 09:40:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=e4pGdvhE+q37x1oVubrx4AHVnvlXN791WoFJjsf1Djk=; b=rU3LhR+4usnQSOaXKDxOdma6fj79EoDO9No9ZHSNYS7B0EZJk/He2moq3nU23lQcru r4flqmOlvXJ09TMiTbBK8DtdWmOknzDNLPrtQsUJtvOmARxGU77XeZHRlI0PjQ2g1HM9 QOPd2OzF4uuQ9wVM7FkbZmFqKIXPF51l5RUKm1hziT5v4lVun7GwmwE3Ipwt4NqClAwW HLTPl3IpmgdsG3PwJNmHd+2NQe6C2Ic52C9tUHqZnG7sp70VHndwS4CiL7PexDsEcoii +eZnM7W0Z47hkhFtqIdwPpmBLNi6h41TPbUDY3LHu8qi7vyhLJOvF4Y78c5oOhyrDXya 7i9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=e4pGdvhE+q37x1oVubrx4AHVnvlXN791WoFJjsf1Djk=; b=WbhCEkHjt6xW6X43WkKozbH4aQXqLtqgKY5aDIovfmOdQOwZu1ooE0SRa/+kj4hzBB TC1N0u3Zqv0qyxxmirBtziZ9Qi7MzSaJlTjZD2k6SfYncdwvqLyPNMVL1RcYQtVKT0CT z7qhnkDG8cdyxepIx/3N/+WAS1YdBA/lQYwx8d7m5XvsI2LG8aQVohpsjbqSr44huy/C rQlvkLyvlhAZk8gyk9B/mlFcfP+UcHn/YSZ85ZmtbDpg0/7cfm6shfHjGyw4VseV3aiO CDo3NqRp6yklnfVQpqZBxsCAbZMyKFBgtwTcPL8icemxGX/uT4aXmdeJrZJ3wmRNDAiQ GxoA== X-Gm-Message-State: APjAAAV0sJMgdNtdN+symL0o2hREPB7ur4Mtqb0ZlwtnYuSJn0OLbO4A z6bo1wrhMFt19aht2bKbMbA88aClmeY= X-Google-Smtp-Source: APXvYqzaPoulz1r9rx+z0DrkiR0BgJsZmwFu3PSLBuy4+fcm2UZT2BtytBbpoj2v+oijjQT4yd7naQ== X-Received: by 2002:a2e:9dc1:: with SMTP id x1mr15792911ljj.0.1564763999230; Fri, 02 Aug 2019 09:39:59 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-22.209.223.85.sovam.net.ua. [85.223.209.22]) by smtp.gmail.com with ESMTPSA id q6sm15378998lji.70.2019.08.02.09.39.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 02 Aug 2019 09:39:58 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Fri, 2 Aug 2019 19:39:41 +0300 Message-Id: <1564763985-20312-3-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1564763985-20312-1-git-send-email-olekstysh@gmail.com> References: <1564763985-20312-1-git-send-email-olekstysh@gmail.com> Subject: [Xen-devel] [PATCH V2 2/6] iommu/arm: Add ability to handle deferred probing request X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Oleksandr Tyshchenko , julien.grall@arm.com, sstabellini@kernel.org MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Oleksandr Tyshchenko This patch adds minimal required support to General IOMMU framework to be able to handle a case when IOMMU driver requesting deferred probing for a device. In order not to pull Linux's error code (-EPROBE_DEFER) to Xen we have chosen -EAGAIN to be used for indicating that device probing is deferred. This is needed for the upcoming IPMMU driver which may request deferred probing depending on what device will be probed the first (there is some dependency between these devices, Root device must be registered before Cache devices. If not the case, driver will deny further Cache device probes until Root device is registered). As we can't guarantee a fixed pre-defined order for the device nodes in DT, we need to be ready for the situation where devices being probed in "any" order. Signed-off-by: Oleksandr Tyshchenko --- xen/common/device_tree.c | 1 + xen/drivers/passthrough/arm/iommu.c | 35 ++++++++++++++++++++++++++++++++++- xen/include/asm-arm/device.h | 6 +++++- xen/include/xen/device_tree.h | 1 + 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index e107c6f..6f37448 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -1774,6 +1774,7 @@ static unsigned long __init unflatten_dt_node(const void *fdt, /* By default the device is not protected */ np->is_protected = false; INIT_LIST_HEAD(&np->domain_list); + INIT_LIST_HEAD(&np->deferred_probe); if ( new_format ) { diff --git a/xen/drivers/passthrough/arm/iommu.c b/xen/drivers/passthrough/arm/iommu.c index 2135233..3195919 100644 --- a/xen/drivers/passthrough/arm/iommu.c +++ b/xen/drivers/passthrough/arm/iommu.c @@ -20,6 +20,12 @@ #include #include +/* + * Used to keep track of devices for which driver requested deferred probing + * (returns -EAGAIN). + */ +static LIST_HEAD(deferred_probe_list); + static const struct iommu_ops *iommu_ops; const struct iommu_ops *iommu_get_ops(void) @@ -42,7 +48,7 @@ void __init iommu_set_ops(const struct iommu_ops *ops) int __init iommu_hardware_setup(void) { - struct dt_device_node *np; + struct dt_device_node *np, *tmp; int rc; unsigned int num_iommus = 0; @@ -51,6 +57,33 @@ int __init iommu_hardware_setup(void) rc = device_init(np, DEVICE_IOMMU, NULL); if ( !rc ) num_iommus++; + else if (rc == -EAGAIN) + /* + * Driver requested deferred probing, so add this device to + * the deferred list for further processing. + */ + list_add(&np->deferred_probe, &deferred_probe_list); + } + + /* + * Process devices in the deferred list if at least one successfully + * probed device is present. + */ + while ( !list_empty(&deferred_probe_list) && num_iommus ) + { + list_for_each_entry_safe ( np, tmp, &deferred_probe_list, + deferred_probe ) + { + rc = device_init(np, DEVICE_IOMMU, NULL); + if ( !rc ) + num_iommus++; + if ( rc != -EAGAIN ) + /* + * Driver didn't request deferred probing, so remove this device + * from the deferred list. + */ + list_del_init(&np->deferred_probe); + } } return ( num_iommus > 0 ) ? 0 : -ENODEV; diff --git a/xen/include/asm-arm/device.h b/xen/include/asm-arm/device.h index 63a0f36..ee1c3bc 100644 --- a/xen/include/asm-arm/device.h +++ b/xen/include/asm-arm/device.h @@ -44,7 +44,11 @@ struct device_desc { enum device_class class; /* List of devices supported by this driver */ const struct dt_device_match *dt_match; - /* Device initialization */ + /* + * Device initialization. + * + * -EAGAIN is used to indicate that device probing is deferred. + */ int (*init)(struct dt_device_node *dev, const void *data); }; diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 8315629..71b0e47 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -93,6 +93,7 @@ struct dt_device_node { /* IOMMU specific fields */ bool is_protected; struct list_head domain_list; + struct list_head deferred_probe; struct device dev; };