From patchwork Fri Sep 13 15:35:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 11144937 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2780317E6 for ; Fri, 13 Sep 2019 15:37:30 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0349520717 for ; Fri, 13 Sep 2019 15:37:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GP4OLD+0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0349520717 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8ncJ-00022S-CN; Fri, 13 Sep 2019 15:36:11 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8ncI-00022A-I6 for xen-devel@lists.xenproject.org; Fri, 13 Sep 2019 15:36:10 +0000 X-Inumbo-ID: 30043322-d63c-11e9-b299-bc764e2007e4 Received: from mail-lf1-x143.google.com (unknown [2a00:1450:4864:20::143]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 30043322-d63c-11e9-b299-bc764e2007e4; Fri, 13 Sep 2019 15:36:01 +0000 (UTC) Received: by mail-lf1-x143.google.com with SMTP id d10so22473633lfi.0 for ; Fri, 13 Sep 2019 08:36: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=jNELGovieW5A1vlGGP+yeKfUr+N8KkmQkzo2/6JYh8s=; b=GP4OLD+0UIuswLBMjcNEGi6UJ5m/B39N6IXMA8ndF5YnsWuRPCw0FE4SLQO8Hbm78u gu07vzrFAJPdbClEsVfeGIBM1aJ025LQTFfQg57T6rdC4mLhoLH87TlRzjt9LHXzymNz qleZjr7iWzwb66LE2M5J/FPVSBPx3R/jrwaKQ22Zfr2RjAKFCew0FuBX501hZ8wDZcTk +7b2sl2SafMMg36wyobwI0KZmrAY3l9+ifSPIHGQZZoTGgrLcDnIm1zNUT7ZGuH8J1iD cqC35yF766lbUMXrdZs3ikLkvtxJ4dybCOfjBHRIScYiA7uw0CjTgk9I6kMKdpqFu7+9 iEJg== 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=jNELGovieW5A1vlGGP+yeKfUr+N8KkmQkzo2/6JYh8s=; b=bRefPhoR/Q2R1C4uqi8SpyGFiKNhOkugWI/T5yKtt6066QrvlpF/PUCPcCvoxwKmIi fZU30BJhwUUbCDbpgBOwfgstpqdaERXJGO5EpSBVqS9prOqr9gGXveWo63Q+RYAPoCS/ DetYsNpsJ3BJNEBWD6iMsS8MEBA9i7Nju+XKvyUGf4H+/L6dX2LHiPW8NkuB+SQzrk65 eLXww1vVxr0D5krW8wwLdSU9jxylm3OwF43LcSpy+6kGth82Oi+3DOBmtc1hiNhsABIM SIJLEPxffre6i5aZs7QpGYQRsWgCbGcUbDbtEp2t/G2PeilZUufdArMx1GCOuhcnBG7L ETrw== X-Gm-Message-State: APjAAAUi81e+u1SaNW/AtEqUUmLFt4/Sl/rsPA+NK2SkHDO45YgLyxiY DcFJTtV/c6cxzUFn0c2C6A5hcaZKF/8= X-Google-Smtp-Source: APXvYqzL344Gxcrj0bIOpx6IDFB7Jxt7cibEJAqWnib2hVdAVdI9sGrQIYDlh1QWVBPAyzRz+jyu/A== X-Received: by 2002:a19:c3d3:: with SMTP id t202mr32555596lff.48.1568388959763; Fri, 13 Sep 2019 08:35:59 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-74.141.223.85.sovam.net.ua. [85.223.141.74]) by smtp.gmail.com with ESMTPSA id c16sm6969765lfj.8.2019.09.13.08.35.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Sep 2019 08:35:59 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Fri, 13 Sep 2019 18:35:11 +0300 Message-Id: <1568388917-7287-3-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1568388917-7287-1-git-send-email-olekstysh@gmail.com> References: <1568388917-7287-1-git-send-email-olekstysh@gmail.com> Subject: [Xen-devel] [PATCH V4 2/8] 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, Volodymyr_Babchuk@epam.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 CC: Julien Grall Reviewed-by: Julien Grall --- Changes V3 -> V4: - moved changes related to the "headers ordering" to a separate patch - added explaination why domain_list is re-used - removed the unnecessary pair of outermost parentheses when checking the list_empty Changes V2 -> V3: - removed deferred_probe field from struct dt_device_node, re-used domain_list instead - documented domain_list usage - added ASSERT to check that np->domain_list is empty before re-using it - put deferred_probe_list to init section - used more strict logic regarding processing devices in the deferred list - added more comments to code - put headers in alphabetical order --- xen/drivers/passthrough/arm/iommu.c | 56 +++++++++++++++++++++++++++++++++++-- xen/include/asm-arm/device.h | 6 +++- xen/include/xen/device_tree.h | 7 +++++ 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/xen/drivers/passthrough/arm/iommu.c b/xen/drivers/passthrough/arm/iommu.c index f219de9..555acfc 100644 --- a/xen/drivers/passthrough/arm/iommu.c +++ b/xen/drivers/passthrough/arm/iommu.c @@ -20,6 +20,12 @@ #include #include +/* + * Deferred probe list is used to keep track of devices for which driver + * requested deferred probing (returned -EAGAIN). + */ +static __initdata 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,21 @@ int __init iommu_hardware_setup(void) rc = device_init(np, DEVICE_IOMMU, NULL); if ( !rc ) num_iommus++; + else if ( rc == -EAGAIN ) + { + /* + * We expect nobody uses device's domain_list at such early stage, + * so we can re-use it to link the device in the deferred list to + * avoid introducing extra list_head field in struct dt_device_node. + */ + ASSERT(list_empty(&np->domain_list)); + + /* + * Driver requested deferred probing, so add this device to + * the deferred list for further processing. + */ + list_add(&np->domain_list, &deferred_probe_list); + } /* * Ignore the following error codes: * - EBADF: Indicate the current not is not an IOMMU @@ -61,7 +82,38 @@ int __init iommu_hardware_setup(void) return rc; } - return ( num_iommus > 0 ) ? 0 : -ENODEV; + /* Return immediately if there are no initialized devices. */ + if ( !num_iommus ) + return list_empty(&deferred_probe_list) ? -ENODEV : -EAGAIN; + + rc = 0; + + /* + * Process devices in the deferred list if it is not empty. + * Check that at least one device is initialized at each loop, otherwise + * we may get an infinite loop. Also stop processing if we got an error + * other than -EAGAIN. + */ + while ( !list_empty(&deferred_probe_list) && num_iommus ) + { + num_iommus = 0; + + list_for_each_entry_safe ( np, tmp, &deferred_probe_list, domain_list ) + { + rc = device_init(np, DEVICE_IOMMU, NULL); + if ( !rc ) + { + num_iommus++; + + /* Remove initialized device from the deferred list. */ + list_del_init(&np->domain_list); + } + else if ( rc != -EAGAIN ) + return rc; + } + } + + return rc; } void __hwdom_init arch_iommu_check_autotranslated_hwdom(struct domain *d) 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 9a7a8f2..3702e9b 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -92,6 +92,13 @@ struct dt_device_node { /* IOMMU specific fields */ bool is_protected; + /* + * The main purpose of this list node is to link the structure in the list + * of devices assigned to domain. + * + * Boot code (iommu_hardware_setup) re-uses this list to link the structure + * in the list of devices for which driver requested deferred probing. + */ struct list_head domain_list; struct device dev;