Message ID | 20221103195154.21495-1-semen.protsenko@linaro.org |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp736648wru; Thu, 3 Nov 2022 12:54:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4OQS1UpYG07K7TMuzHowd1eQG5WBYsYU75nHWg1Vw2/8HWTg3IMalmMJxLM8eK9wDAqfwE X-Received: by 2002:a17:906:4f82:b0:7ad:c7d6:eee5 with SMTP id o2-20020a1709064f8200b007adc7d6eee5mr24620819eju.681.1667505248429; Thu, 03 Nov 2022 12:54:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667505248; cv=none; d=google.com; s=arc-20160816; b=TdXZQ17Z2tnJdMIKMCpyCGNA7tXbIQnTQMG6OVXVOUgxwvTNw7zlGBmCK5YPdXmh2t 05wSz6E73xVk3n9UvEnSou9Pug6uOaC7NOFroOdu5kFbHlnwViNBOOO9FW37zJmTdMna VHTWHhqrbPnGI/kZJ/l+eAxw0Xu1Djo34ourNCx36yDgVyGcPdhPNi5cw3Y0vqzKyjw9 rYqm0QFNMOlgIPW3ng5Xu8jJ9qksuy/NScHgnkOvEsifpKIENm/bsrhPRy21tZfxvfM/ HPxzmq567EhBuzkNwSM4uocClf64o9JSPori/DvpD9naIy2QjeGQ0PkuIXVraCHHkHob wGEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=dSoY1RFfLiYGbG6PVIWaPMns1WQq6G1mUH0o4v3ezJs=; b=N/bMh7I1SucBAiraH3PUDHS/ChtyS/YO46nltnN65uDl099sXtitsZQNotHAdeuQ7l C2i2Ev2MeOzgfnxHXTL4RbnhaLMkhyDy+IV2hz72JJ2sxiKEzC9uiJeCiQgABwL8wMjc kc71yaQ2yY7WiCOD15Hfqyjm5aBlizBFLhoXZg/y9JVSYjtWNc20FewG3ZCd+I/rUrNg kHHG3bZe1AG2vrF/D6yYky5mnz+MYiZ0tuelSUXOIp4No20QKuXqXGExTIrIc0YweShz MPAttoKa4sofwUVUe+t1m35PMozIC3qFwPvxe1jqU43XOZpDKnNv6ql8KrX1NhGZ7Y/8 rYTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jXb0goUM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s20-20020aa7d794000000b00462d53d6de6si1881277edq.10.2022.11.03.12.53.44; Thu, 03 Nov 2022 12:54:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jXb0goUM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229791AbiKCTwA (ORCPT <rfc822;yves.mi.zy@gmail.com> + 99 others); Thu, 3 Nov 2022 15:52:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229496AbiKCTv6 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 3 Nov 2022 15:51:58 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C68220183 for <linux-kernel@vger.kernel.org>; Thu, 3 Nov 2022 12:51:57 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id y14so8136689ejd.9 for <linux-kernel@vger.kernel.org>; Thu, 03 Nov 2022 12:51:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=dSoY1RFfLiYGbG6PVIWaPMns1WQq6G1mUH0o4v3ezJs=; b=jXb0goUM1eMoI1vo0YE498npOwxh/JsIH3dtk03GixxejFSVByMt5Dl6Oj9UpEy2W9 Pf8lK5SE9nKJLqX7fqqHjAKN4x8cTWoBC/ZO7NmVESWXWlgiku667ugCRTUlki6fNW62 4aJsr84+PNy515JKoqpLImWu/5xN8FtmAHgQKjqLtggAsm39S7frbEXGlFG59qD144CR 7+lrhEeKGAsBbKo5uOUH426MhT6SnUzT2vBvRxhCUrKOJtrcUrJovRbrtKy0VNuT5kOS Jfw13SRy0c7DWpiQN9LurfnyRJQXmhFBacMlSISHuC7N78xKzzX9rDrxxcNd6dhhmr1g DxIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dSoY1RFfLiYGbG6PVIWaPMns1WQq6G1mUH0o4v3ezJs=; b=ftD9xsf/226yVzZjpDTI8/JHvyWnY1mAwTupOevLEujqTJB8EMRurpv4q1PrJtmIs+ C4EBEFImq3EssTNXlo0Nyjir7gCUwZwtO0S/MNX8Gi28zQlF8s8HVyePJb3pr2JLDeav s4kfh+KXSL5rJ+BjTpWou5NkNqkbJtglB/qycND7sWxKsmS9kAbsTskBnOiyAy7YGx+I z4FokjchsroJBZGfCtBmWIDCJnoH30qTfS0d142Sctrv+nEUskb+TttVLVVb78zdjPXS OiK/W4DxBDKDwTOsHjmDvESmbqylG5J7nvywjbcMydzE+ZSormsQkmgKcbYyevJJrKNR pJtg== X-Gm-Message-State: ACrzQf3eXaMn/xaJ8aM+cWh8smwLf19kipe3JONFl9qWIUkdNFDpWbm5 B988BSsd6VPssnP9BdYe5z3Awg== X-Received: by 2002:a17:906:730d:b0:78e:9ca5:3269 with SMTP id di13-20020a170906730d00b0078e9ca53269mr31172648ejc.366.1667505115999; Thu, 03 Nov 2022 12:51:55 -0700 (PDT) Received: from localhost (cgw.msart-bajzova4.ke.cust.o2bs.sk. [90.176.4.227]) by smtp.gmail.com with ESMTPSA id j14-20020a1709062a0e00b007415f8ffcbbsm870386eje.98.2022.11.03.12.51.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 12:51:55 -0700 (PDT) From: Sam Protsenko <semen.protsenko@linaro.org> To: Marek Szyprowski <m.szyprowski@samsung.com>, Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Cc: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>, Robin Murphy <robin.murphy@arm.com>, Sumit Semwal <sumit.semwal@linaro.org>, Alim Akhtar <alim.akhtar@samsung.com>, Janghyuck Kim <janghyuck.kim@samsung.com>, Cho KyongHo <pullip.cho@samsung.com>, Daniel Mentz <danielmentz@google.com>, David Virag <virag.david003@gmail.com>, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org Subject: [PATCH v2 0/6] iommu/exynos: Convert to a module Date: Thu, 3 Nov 2022 20:51:48 +0100 Message-Id: <20221103195154.21495-1-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748505983695292053?= X-GMAIL-MSGID: =?utf-8?q?1748505983695292053?= |
Series |
iommu/exynos: Convert to a module
|
|
Message
Sam Protsenko
Nov. 3, 2022, 7:51 p.m. UTC
As exynos-iommu driver is not a critical platform driver, it can be converted to a loadable module to avoid loading it on non-Exynos platforms in order to improve the RAM footprint. This patch series converts it to a module and does some related cleanups. IOMMU/DMA specifics were taken into the account, so remove/exit methods weren't added. There are two drivers using CONFIG_EXYNOS_IOMMU in their code: DRM_EXYNOS and S5P_MFC. Both were checked, and only a slight change was needed for S5P_MFC driver (patch #6). Changes in v2: - Extracted the "shutdown" method addition into a separate patch - Added MODULE_DEVICE_TABLE(of, ...) to support hot-plug loading - Added MODULE_ALIAS("platform:exynos-sysmmu") - Added fix for S5P_MFC driver to work correctly with EXYNOS_IOMMU=m - Fixed checkpatch coding style suggestion with "--strict" flag - Rebased on top of most recent joro/iommu.git:next Sam Protsenko (6): iommu: Export iommu_group_default_domain() API iommu/exynos: Fix retval on getting clocks in probe iommu/exynos: Modularize the driver iommu/exynos: Implement shutdown driver method iommu/exynos: Rearrange the platform driver code media: platform: Use IS_ENABLED() to check EXYNOS_IOMMU in s5p_mfc drivers/iommu/Kconfig | 2 +- drivers/iommu/exynos-iommu.c | 355 +++++++++--------- drivers/iommu/iommu.c | 1 + .../platform/samsung/s5p-mfc/s5p_mfc_iommu.h | 4 +- 4 files changed, 191 insertions(+), 171 deletions(-)
Comments
On 03.11.2022 20:51, Sam Protsenko wrote: > As exynos-iommu driver is not a critical platform driver, it can be > converted to a loadable module to avoid loading it on non-Exynos > platforms in order to improve the RAM footprint. This patch series > converts it to a module and does some related cleanups. IOMMU/DMA > specifics were taken into the account, so remove/exit methods weren't > added. > > There are two drivers using CONFIG_EXYNOS_IOMMU in their code: > DRM_EXYNOS and S5P_MFC. Both were checked, and only a slight change was > needed for S5P_MFC driver (patch #6). Funny, compiling this driver as a module revealed an issue in the driver initialization sequence, here is a fix that need to be applied before this patchset: https://lore.kernel.org/all/20221104115511.28256-1-m.szyprowski@samsung.com/ Besides that, the driver nukes with NULL pointer dereference in exynos_iommu_of_xlate() when compiled as a module on ARM 64bit Exynos5433 based TM2e board. ARM 32bit based board works fine. I'm checking this issue now. > Changes in v2: > - Extracted the "shutdown" method addition into a separate patch > - Added MODULE_DEVICE_TABLE(of, ...) to support hot-plug loading > - Added MODULE_ALIAS("platform:exynos-sysmmu") > - Added fix for S5P_MFC driver to work correctly with EXYNOS_IOMMU=m > - Fixed checkpatch coding style suggestion with "--strict" flag > - Rebased on top of most recent joro/iommu.git:next > > Sam Protsenko (6): > iommu: Export iommu_group_default_domain() API > iommu/exynos: Fix retval on getting clocks in probe > iommu/exynos: Modularize the driver > iommu/exynos: Implement shutdown driver method > iommu/exynos: Rearrange the platform driver code > media: platform: Use IS_ENABLED() to check EXYNOS_IOMMU in s5p_mfc > > drivers/iommu/Kconfig | 2 +- > drivers/iommu/exynos-iommu.c | 355 +++++++++--------- > drivers/iommu/iommu.c | 1 + > .../platform/samsung/s5p-mfc/s5p_mfc_iommu.h | 4 +- > 4 files changed, 191 insertions(+), 171 deletions(-) > Best regards
On Fri, 4 Nov 2022 at 13:10, Marek Szyprowski <m.szyprowski@samsung.com> wrote: > > On 03.11.2022 20:51, Sam Protsenko wrote: > > As exynos-iommu driver is not a critical platform driver, it can be > > converted to a loadable module to avoid loading it on non-Exynos > > platforms in order to improve the RAM footprint. This patch series > > converts it to a module and does some related cleanups. IOMMU/DMA > > specifics were taken into the account, so remove/exit methods weren't > > added. > > > > There are two drivers using CONFIG_EXYNOS_IOMMU in their code: > > DRM_EXYNOS and S5P_MFC. Both were checked, and only a slight change was > > needed for S5P_MFC driver (patch #6). > > Funny, compiling this driver as a module revealed an issue in the driver > initialization sequence, here is a fix that need to be applied before > this patchset: > > https://lore.kernel.org/all/20221104115511.28256-1-m.szyprowski@samsung.com/ > I wonder why I didn't stumble upon that issue. Anyway, the fix looks valid. I'll wait until you finish looking into that NULL pointer dereference, and then we can figure out how to organize our patches. Maybe I could send v3, including your patches in the beginning of the series, etc. > Besides that, the driver nukes with NULL pointer dereference in > exynos_iommu_of_xlate() when compiled as a module on ARM 64bit > Exynos5433 based TM2e board. ARM 32bit based board works fine. I'm > checking this issue now. > Thanks for looking into that, Marek! I've tested the modularization patch series using my emulated translation driver [1,2]. It works fine, but exynos_iommu_of_xlate() is only executed once in my case, when the test driver module is loaded. It's finished successfully though. Not sure what is the cause of NULL pointer dereferences you're seeing, alas I still don't have real users of SysMMU driver on my platform, and my test driver is the only way for me to test it. Please let me know if I can help in any way (e.g. I can trace some calls on my board for you). [1] https://github.com/joe-skb7/linux/blob/e850-96-mainline-iommu/drivers/iommu/samsung-iommu-test.c#L263 [2] https://github.com/joe-skb7/linux/blob/e850-96-mainline-iommu/arch/arm64/boot/dts/exynos/exynos850.dtsi#L477 > > Changes in v2: > > - Extracted the "shutdown" method addition into a separate patch > > - Added MODULE_DEVICE_TABLE(of, ...) to support hot-plug loading > > - Added MODULE_ALIAS("platform:exynos-sysmmu") > > - Added fix for S5P_MFC driver to work correctly with EXYNOS_IOMMU=m > > - Fixed checkpatch coding style suggestion with "--strict" flag > > - Rebased on top of most recent joro/iommu.git:next > > > > Sam Protsenko (6): > > iommu: Export iommu_group_default_domain() API > > iommu/exynos: Fix retval on getting clocks in probe > > iommu/exynos: Modularize the driver > > iommu/exynos: Implement shutdown driver method > > iommu/exynos: Rearrange the platform driver code > > media: platform: Use IS_ENABLED() to check EXYNOS_IOMMU in s5p_mfc > > > > drivers/iommu/Kconfig | 2 +- > > drivers/iommu/exynos-iommu.c | 355 +++++++++--------- > > drivers/iommu/iommu.c | 1 + > > .../platform/samsung/s5p-mfc/s5p_mfc_iommu.h | 4 +- > > 4 files changed, 191 insertions(+), 171 deletions(-) > > > Best regards > -- > Marek Szyprowski, PhD > Samsung R&D Institute Poland >
On 04.11.2022 13:10, Marek Szyprowski wrote: > On 03.11.2022 20:51, Sam Protsenko wrote: >> As exynos-iommu driver is not a critical platform driver, it can be >> converted to a loadable module to avoid loading it on non-Exynos >> platforms in order to improve the RAM footprint. This patch series >> converts it to a module and does some related cleanups. IOMMU/DMA >> specifics were taken into the account, so remove/exit methods weren't >> added. >> >> There are two drivers using CONFIG_EXYNOS_IOMMU in their code: >> DRM_EXYNOS and S5P_MFC. Both were checked, and only a slight change was >> needed for S5P_MFC driver (patch #6). > > Funny, compiling this driver as a module revealed an issue in the > driver initialization sequence, here is a fix that need to be applied > before this patchset: > > https://lore.kernel.org/all/20221104115511.28256-1-m.szyprowski@samsung.com/ > > > Besides that, the driver nukes with NULL pointer dereference in > exynos_iommu_of_xlate() when compiled as a module on ARM 64bit > Exynos5433 based TM2e board. ARM 32bit based board works fine. I'm > checking this issue now. > I've finally made Exynos IOMMU working as a module on Exynos5433 based TM2e board. It looks that this will be a bit longer journey that I've initially thought. I've posted a simple update of the fix for the driver initialization sequence, but the real problem is in the platform driver framework and OF helpers. Basically to get it working as a module I had to apply the following changes: diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 3dda62503102..f6921f5fcab6 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -257,7 +257,7 @@ static int deferred_devs_show(struct seq_file *s, void *data) DEFINE_SHOW_ATTRIBUTE(deferred_devs); #ifdef CONFIG_MODULES -int driver_deferred_probe_timeout = 10; +int driver_deferred_probe_timeout = 30; #else int driver_deferred_probe_timeout; #endif diff --git a/drivers/of/property.c b/drivers/of/property.c index 967f79b59016..e5df6672fee6 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -1384,7 +1384,7 @@ static struct device_node *parse_interrupts(struct device_node *np, static const struct supplier_bindings of_supplier_bindings[] = { { .parse_prop = parse_clocks, }, { .parse_prop = parse_interconnects, }, - { .parse_prop = parse_iommus, .optional = true, }, + { .parse_prop = parse_iommus, }, { .parse_prop = parse_iommu_maps, .optional = true, }, { .parse_prop = parse_mboxes, }, { .parse_prop = parse_io_channels, }, Without that a really nasty things happened. Initialization of the built-in drivers and loading modules takes time, so the default 10s deferred probe timeout is not enough to ensure that the built-in driver won't be probed before the Exynos IOMMU driver is loaded. The second change fixes the problem that driver core probes Exynos IOMMU controllers in parallel to probing the master devices, what results in calling exynos_iommu_of_xlate() and exynos_iommu_probe_device() even on the partially initialized IOMMU controllers or initializing the dma_ops under the already probed and working master device. This was easy to observe especially on the master devices with multiple IOMMU controllers. I wasn't able to solve this concurrency/race issues inside the Exynos IOMMU driver. Frankly speaking I don't know what is the rationale for making the 'iommus' property optional, but this simply doesn't work well with IOMMU driver being a module. CCed Saravana and Rob for this. Without fixing the above issues, I would add a warning that compiling the driver as a module leads to serious issues. >> Changes in v2: >> - Extracted the "shutdown" method addition into a separate patch >> - Added MODULE_DEVICE_TABLE(of, ...) to support hot-plug loading >> - Added MODULE_ALIAS("platform:exynos-sysmmu") >> - Added fix for S5P_MFC driver to work correctly with EXYNOS_IOMMU=m >> - Fixed checkpatch coding style suggestion with "--strict" flag >> - Rebased on top of most recent joro/iommu.git:next >> >> Sam Protsenko (6): >> iommu: Export iommu_group_default_domain() API >> iommu/exynos: Fix retval on getting clocks in probe >> iommu/exynos: Modularize the driver >> iommu/exynos: Implement shutdown driver method >> iommu/exynos: Rearrange the platform driver code >> media: platform: Use IS_ENABLED() to check EXYNOS_IOMMU in s5p_mfc >> >> drivers/iommu/Kconfig | 2 +- >> drivers/iommu/exynos-iommu.c | 355 +++++++++--------- >> drivers/iommu/iommu.c | 1 + >> .../platform/samsung/s5p-mfc/s5p_mfc_iommu.h | 4 +- >> 4 files changed, 191 insertions(+), 171 deletions(-) >> > Best regards Best regards
On Thu, 10 Nov 2022 at 15:36, Marek Szyprowski <m.szyprowski@samsung.com> wrote: [snip] > I've finally made Exynos IOMMU working as a module on Exynos5433 based > TM2e board. It looks that this will be a bit longer journey that I've > initially thought. I've posted a simple update of the fix for the driver > initialization sequence, but the real problem is in the platform driver > framework and OF helpers. > > Basically to get it working as a module I had to apply the following > changes: > > diff --git a/drivers/base/dd.c b/drivers/base/dd.c > index 3dda62503102..f6921f5fcab6 100644 > --- a/drivers/base/dd.c > +++ b/drivers/base/dd.c > @@ -257,7 +257,7 @@ static int deferred_devs_show(struct seq_file *s, > void *data) > DEFINE_SHOW_ATTRIBUTE(deferred_devs); > > #ifdef CONFIG_MODULES > -int driver_deferred_probe_timeout = 10; > +int driver_deferred_probe_timeout = 30; > #else > int driver_deferred_probe_timeout; > #endif > diff --git a/drivers/of/property.c b/drivers/of/property.c > index 967f79b59016..e5df6672fee6 100644 > --- a/drivers/of/property.c > +++ b/drivers/of/property.c > @@ -1384,7 +1384,7 @@ static struct device_node *parse_interrupts(struct > device_node *np, > static const struct supplier_bindings of_supplier_bindings[] = { > { .parse_prop = parse_clocks, }, > { .parse_prop = parse_interconnects, }, > - { .parse_prop = parse_iommus, .optional = true, }, > + { .parse_prop = parse_iommus, }, > { .parse_prop = parse_iommu_maps, .optional = true, }, > { .parse_prop = parse_mboxes, }, > { .parse_prop = parse_io_channels, }, > > Without that a really nasty things happened. > > Initialization of the built-in drivers and loading modules takes time, > so the default 10s deferred probe timeout is not enough to ensure that > the built-in driver won't be probed before the Exynos IOMMU driver is > loaded. > Yeah, the whole time-based sync looks nasty... I remember coming across the slides by Andrzej Hajda called "Deferred Problem" [1], but I guess the proposed solution was never applied. Just hope that increasing the timeout is upstreamable solution. [1] https://events19.linuxfoundation.org/wp-content/uploads/2017/12/Deferred-Problem-Issues-With-Complex-Dependencies-Between-Devices-in-Linux-Kernel-Andrzej-Hajda-Samsung.pdf > The second change fixes the problem that driver core probes Exynos IOMMU > controllers in parallel to probing the master devices, what results in > calling exynos_iommu_of_xlate() and exynos_iommu_probe_device() even on > the partially initialized IOMMU controllers or initializing the dma_ops > under the already probed and working master device. This was easy to > observe especially on the master devices with multiple IOMMU > controllers. I wasn't able to solve this concurrency/race issues inside > the Exynos IOMMU driver. > > Frankly speaking I don't know what is the rationale for making the > 'iommus' property optional, but this simply doesn't work well with IOMMU > driver being a module. CCed Saravana and Rob for this. > The patch which makes 'iommus' optional doesn't provide much of insight on reasons in commit message either. > Without fixing the above issues, I would add a warning that compiling > the driver as a module leads to serious issues. > Nice catch! It doesn't reproduce on my platform, alas. Can I expect you to submit those patches? If so, I'll probably just wait for those to be applied, and then re-send my modularization series on top of it. Does that sounds reasonable? [snip] > > Best regards > -- > Marek Szyprowski, PhD > Samsung R&D Institute Poland >
On Fri, Nov 11, 2022 at 5:30 AM Sam Protsenko <semen.protsenko@linaro.org> wrote: > > On Thu, 10 Nov 2022 at 15:36, Marek Szyprowski <m.szyprowski@samsung.com> wrote: > > [snip] Hi Marek and Sam, I'm replying to both of your comments in this email. > > I've finally made Exynos IOMMU working as a module on Exynos5433 based > > TM2e board. It looks that this will be a bit longer journey that I've > > initially thought. I've posted a simple update of the fix for the driver > > initialization sequence, but the real problem is in the platform driver > > framework and OF helpers. > > > > Basically to get it working as a module I had to apply the following > > changes: > > > > diff --git a/drivers/base/dd.c b/drivers/base/dd.c > > index 3dda62503102..f6921f5fcab6 100644 > > --- a/drivers/base/dd.c > > +++ b/drivers/base/dd.c > > @@ -257,7 +257,7 @@ static int deferred_devs_show(struct seq_file *s, > > void *data) > > DEFINE_SHOW_ATTRIBUTE(deferred_devs); > > > > #ifdef CONFIG_MODULES > > -int driver_deferred_probe_timeout = 10; > > +int driver_deferred_probe_timeout = 30; > > #else > > int driver_deferred_probe_timeout; > > #endif > > diff --git a/drivers/of/property.c b/drivers/of/property.c > > index 967f79b59016..e5df6672fee6 100644 > > --- a/drivers/of/property.c > > +++ b/drivers/of/property.c > > @@ -1384,7 +1384,7 @@ static struct device_node *parse_interrupts(struct > > device_node *np, > > static const struct supplier_bindings of_supplier_bindings[] = { > > { .parse_prop = parse_clocks, }, > > { .parse_prop = parse_interconnects, }, > > - { .parse_prop = parse_iommus, .optional = true, }, > > + { .parse_prop = parse_iommus, }, > > { .parse_prop = parse_iommu_maps, .optional = true, }, > > { .parse_prop = parse_mboxes, }, > > { .parse_prop = parse_io_channels, }, > > > > Without that a really nasty things happened. I have a command line option to do this without code changes. Use fw_devlink.strict=1. That makes all optional properties into mandatory ones. I sent out a series[1] that tried to make fw_devlink.strict=1 the default and then use the timeout behavior (more details) to handle cases where iommu and dmas (or any other supplier) are optional on a specific board. The cover letter of [1] should give some more context. > > Initialization of the built-in drivers and loading modules takes time, > > so the default 10s deferred probe timeout is not enough to ensure that > > the built-in driver won't be probed before the Exynos IOMMU driver is > > loaded. The 10 second is the minimum delay from the time we hit late_initcall. If a driver is registered before the 10s expires, then the timer will be extended by another 10s. This behavior landed sometime around the end of May 2022. So it should have been in your tree when you tested this. I'm surprised this isn't sufficient for your case. Is there really a 10s gap in your boot sequence where no module is being loaded and then IOMMU modules get loaded later on? I'm kinda surprised by this. Is it this long because some serial UART is enabled and it's slowing down boot? Or something else? I'm not saying your case isn't valid or we shouldn't extend the timeout. I'm just trying to understand why the current timer behavior wasn't able to cover your case. > Yeah, the whole time-based sync looks nasty... I remember coming > across the slides by Andrzej Hajda called "Deferred Problem" [1], but > I guess the proposed solution was never applied. Just hope that > increasing the timeout is upstreamable solution. > > [1] https://events19.linuxfoundation.org/wp-content/uploads/2017/12/Deferred-Problem-Issues-With-Complex-Dependencies-Between-Devices-in-Linux-Kernel-Andrzej-Hajda-Samsung.pdf Sam, I kinda skimmed the slides right now. Looks like it talks about device links and why they aren't sufficient and makes an alternate proposal. fw_devlink is a solution that uses device links and I think addresses a lot of the issues that were raised about device links. There's still a bunch of TODOs left, but I think the end goal is the same. I'm hoping to keep chipping away at it. For now, I've tried to make the timer a bit more smart about detecting when modules are getting loaded and extending the timer. fw_devlink also enables something called sync_state() that's invaluable on a fully modular system (search lore for references to that to get some idea). The slides talk about a solution that will allow devices to probe with limited functionality with whatever suppliers are available and then reprobe as more suppliers are available. I'm not sure how well that'll work across the board. It's going to be a bit weird if your phone display goes off and then comes on again because an IOMMU driver got loaded (and it can now do DRM playback). For now, I'm not going to focus on that option because there are enough existing issues/TODOs to work on for fw_devlink. > > The second change fixes the problem that driver core probes Exynos IOMMU > > controllers in parallel to probing the master devices, what results in > > calling exynos_iommu_of_xlate() and exynos_iommu_probe_device() even on > > the partially initialized IOMMU controllers or initializing the dma_ops > > under the already probed and working master device. This was easy to > > observe especially on the master devices with multiple IOMMU > > controllers. I wasn't able to solve this concurrency/race issues inside > > the Exynos IOMMU driver. > > > > Frankly speaking I don't know what is the rationale for making the > > 'iommus' property optional, but this simply doesn't work well with IOMMU > > driver being a module. CCed Saravana and Rob for this. > > > > The patch which makes 'iommus' optional doesn't provide much of > insight on reasons in commit message either. This was the commit text: Not all DT bindings are mandatory bindings. Add support for optional DT bindings and mark iommus, iommu-map, dmas as optional DT bindings. I thought it was obvious enough, but I guess I could have done better. Geert convinced me that iommu's aren't always necessary and devices could work perfectly well without them or dmas. And he has a bunch of boards like that. So I went with adding optional and then introducing fw_devlink.strict. However, at this point in time, I believe none of them should be marked as optional because technically any property can be optional depending on what the firmware has set up and what the driver does. We should figure this out at runtime on a board level -- which is what [1] is trying to do. Yeah, not very pretty, but there hasn't been a better solution that's not "have userspace tell us it's done loading modules" (that's a "kernel depends on userspace to work correctly" thing that no one likes). I've fixed some of the issues raised in [1] in a fw_devlink improvement series[2] and I plan on continuing to work on this until hopefully [1] can land. > > Without fixing the above issues, I would add a warning that compiling > > the driver as a module leads to serious issues. > > > > Nice catch! It doesn't reproduce on my platform, alas. Can I expect > you to submit those patches? If so, I'll probably just wait for those > to be applied, and then re-send my modularization series on top of it. > Does that sounds reasonable? For now, maybe we could add a config to enable fw_devlink.strict=1 by default and then select it if you make specific iommu drivers into modules? And then Geert won't set it for his driver, but you can set it for your driver? Thanks, Saravana [1] - https://lore.kernel.org/lkml/20220601070707.3946847-1-saravanak@google.com/ [2] - https://lore.kernel.org/lkml/20230207014207.1678715-1-saravanak@google.com/
On Mon, 6 Feb 2023 at 21:33, Saravana Kannan <saravanak@google.com> wrote: > > On Fri, Nov 11, 2022 at 5:30 AM Sam Protsenko > <semen.protsenko@linaro.org> wrote: > > > > On Thu, 10 Nov 2022 at 15:36, Marek Szyprowski <m.szyprowski@samsung.com> wrote: > > > > [snip] > > Hi Marek and Sam, > > I'm replying to both of your comments in this email. > > > > I've finally made Exynos IOMMU working as a module on Exynos5433 based > > > TM2e board. It looks that this will be a bit longer journey that I've > > > initially thought. I've posted a simple update of the fix for the driver > > > initialization sequence, but the real problem is in the platform driver > > > framework and OF helpers. > > > > > > Basically to get it working as a module I had to apply the following > > > changes: > > > > > > diff --git a/drivers/base/dd.c b/drivers/base/dd.c > > > index 3dda62503102..f6921f5fcab6 100644 > > > --- a/drivers/base/dd.c > > > +++ b/drivers/base/dd.c > > > @@ -257,7 +257,7 @@ static int deferred_devs_show(struct seq_file *s, > > > void *data) > > > DEFINE_SHOW_ATTRIBUTE(deferred_devs); > > > > > > #ifdef CONFIG_MODULES > > > -int driver_deferred_probe_timeout = 10; > > > +int driver_deferred_probe_timeout = 30; > > > #else > > > int driver_deferred_probe_timeout; > > > #endif > > > diff --git a/drivers/of/property.c b/drivers/of/property.c > > > index 967f79b59016..e5df6672fee6 100644 > > > --- a/drivers/of/property.c > > > +++ b/drivers/of/property.c > > > @@ -1384,7 +1384,7 @@ static struct device_node *parse_interrupts(struct > > > device_node *np, > > > static const struct supplier_bindings of_supplier_bindings[] = { > > > { .parse_prop = parse_clocks, }, > > > { .parse_prop = parse_interconnects, }, > > > - { .parse_prop = parse_iommus, .optional = true, }, > > > + { .parse_prop = parse_iommus, }, > > > { .parse_prop = parse_iommu_maps, .optional = true, }, > > > { .parse_prop = parse_mboxes, }, > > > { .parse_prop = parse_io_channels, }, > > > > > > Without that a really nasty things happened. > > I have a command line option to do this without code changes. Use > fw_devlink.strict=1. That makes all optional properties into mandatory > ones. > > I sent out a series[1] that tried to make fw_devlink.strict=1 the > default and then use the timeout behavior (more details) to handle > cases where iommu and dmas (or any other supplier) are optional on a > specific board. The cover letter of [1] should give some more context. > > > > Initialization of the built-in drivers and loading modules takes time, > > > so the default 10s deferred probe timeout is not enough to ensure that > > > the built-in driver won't be probed before the Exynos IOMMU driver is > > > loaded. > > The 10 second is the minimum delay from the time we hit late_initcall. > If a driver is registered before the 10s expires, then the timer will > be extended by another 10s. This behavior landed sometime around the > end of May 2022. So it should have been in your tree when you tested > this. I'm surprised this isn't sufficient for your case. Is there > really a 10s gap in your boot sequence where no module is being loaded > and then IOMMU modules get loaded later on? I'm kinda surprised by > this. Is it this long because some serial UART is enabled and it's > slowing down boot? Or something else? > > I'm not saying your case isn't valid or we shouldn't extend the > timeout. I'm just trying to understand why the current timer behavior > wasn't able to cover your case. > > > Yeah, the whole time-based sync looks nasty... I remember coming > > across the slides by Andrzej Hajda called "Deferred Problem" [1], but > > I guess the proposed solution was never applied. Just hope that > > increasing the timeout is upstreamable solution. > > > > [1] https://events19.linuxfoundation.org/wp-content/uploads/2017/12/Deferred-Problem-Issues-With-Complex-Dependencies-Between-Devices-in-Linux-Kernel-Andrzej-Hajda-Samsung.pdf > > Sam, I kinda skimmed the slides right now. Looks like it talks about > device links and why they aren't sufficient and makes an alternate > proposal. fw_devlink is a solution that uses device links and I think > addresses a lot of the issues that were raised about device links. > There's still a bunch of TODOs left, but I think the end goal is the > same. I'm hoping to keep chipping away at it. For now, I've tried to > make the timer a bit more smart about detecting when modules are > getting loaded and extending the timer. fw_devlink also enables > something called sync_state() that's invaluable on a fully modular > system (search lore for references to that to get some idea). > > The slides talk about a solution that will allow devices to probe with > limited functionality with whatever suppliers are available and then > reprobe as more suppliers are available. I'm not sure how well that'll > work across the board. It's going to be a bit weird if your phone > display goes off and then comes on again because an IOMMU driver got > loaded (and it can now do DRM playback). For now, I'm not going to > focus on that option because there are enough existing issues/TODOs to > work on for fw_devlink. > > > > The second change fixes the problem that driver core probes Exynos IOMMU > > > controllers in parallel to probing the master devices, what results in > > > calling exynos_iommu_of_xlate() and exynos_iommu_probe_device() even on > > > the partially initialized IOMMU controllers or initializing the dma_ops > > > under the already probed and working master device. This was easy to > > > observe especially on the master devices with multiple IOMMU > > > controllers. I wasn't able to solve this concurrency/race issues inside > > > the Exynos IOMMU driver. > > > > > > Frankly speaking I don't know what is the rationale for making the > > > 'iommus' property optional, but this simply doesn't work well with IOMMU > > > driver being a module. CCed Saravana and Rob for this. > > > > > > > The patch which makes 'iommus' optional doesn't provide much of > > insight on reasons in commit message either. > > This was the commit text: > > Not all DT bindings are mandatory bindings. Add support for optional DT > bindings and mark iommus, iommu-map, dmas as optional DT bindings. > > I thought it was obvious enough, but I guess I could have done better. > Geert convinced me that iommu's aren't always necessary and devices > could work perfectly well without them or dmas. And he has a bunch of > boards like that. So I went with adding optional and then introducing > fw_devlink.strict. > > However, at this point in time, I believe none of them should be > marked as optional because technically any property can be optional > depending on what the firmware has set up and what the driver does. We > should figure this out at runtime on a board level -- which is what > [1] is trying to do. Yeah, not very pretty, but there hasn't been a > better solution that's not "have userspace tell us it's done loading > modules" (that's a "kernel depends on userspace to work correctly" > thing that no one likes). I've fixed some of the issues raised in [1] > in a fw_devlink improvement series[2] and I plan on continuing to work > on this until hopefully [1] can land. > > > > Without fixing the above issues, I would add a warning that compiling > > > the driver as a module leads to serious issues. > > > > > > > Nice catch! It doesn't reproduce on my platform, alas. Can I expect > > you to submit those patches? If so, I'll probably just wait for those > > to be applied, and then re-send my modularization series on top of it. > > Does that sounds reasonable? > > For now, maybe we could add a config to enable fw_devlink.strict=1 by > default and then select it if you make specific iommu drivers into > modules? And then Geert won't set it for his driver, but you can set > it for your driver? > Marek, what is your take on this? I probably can't provide any useful comments, as the issue is not even reproducible on my platform. Do you think some easy solution exists to make modularized IOMMU driver work? That series has been sitting for a while on ML now, so I wonder if we can handle it somehow, w.r.t. Saravana's input. > Thanks, > Saravana > > [1] - https://lore.kernel.org/lkml/20220601070707.3946847-1-saravanak@google.com/ > [2] - https://lore.kernel.org/lkml/20230207014207.1678715-1-saravanak@google.com/
Hi Saravana, I'm sorry for the delay again, but finally I managed to get back to this topic. On 07.02.2023 04:32, Saravana Kannan wrote: > On Fri, Nov 11, 2022 at 5:30 AM Sam Protsenko > <semen.protsenko@linaro.org> wrote: >> On Thu, 10 Nov 2022 at 15:36, Marek Szyprowski <m.szyprowski@samsung.com> wrote: >> >> [snip] > Hi Marek and Sam, > > I'm replying to both of your comments in this email. > >>> I've finally made Exynos IOMMU working as a module on Exynos5433 based >>> TM2e board. It looks that this will be a bit longer journey that I've >>> initially thought. I've posted a simple update of the fix for the driver >>> initialization sequence, but the real problem is in the platform driver >>> framework and OF helpers. >>> >>> Basically to get it working as a module I had to apply the following >>> changes: >>> >>> diff --git a/drivers/base/dd.c b/drivers/base/dd.c >>> index 3dda62503102..f6921f5fcab6 100644 >>> --- a/drivers/base/dd.c >>> +++ b/drivers/base/dd.c >>> @@ -257,7 +257,7 @@ static int deferred_devs_show(struct seq_file *s, >>> void *data) >>> DEFINE_SHOW_ATTRIBUTE(deferred_devs); >>> >>> #ifdef CONFIG_MODULES >>> -int driver_deferred_probe_timeout = 10; >>> +int driver_deferred_probe_timeout = 30; >>> #else >>> int driver_deferred_probe_timeout; >>> #endif >>> diff --git a/drivers/of/property.c b/drivers/of/property.c >>> index 967f79b59016..e5df6672fee6 100644 >>> --- a/drivers/of/property.c >>> +++ b/drivers/of/property.c >>> @@ -1384,7 +1384,7 @@ static struct device_node *parse_interrupts(struct >>> device_node *np, >>> static const struct supplier_bindings of_supplier_bindings[] = { >>> { .parse_prop = parse_clocks, }, >>> { .parse_prop = parse_interconnects, }, >>> - { .parse_prop = parse_iommus, .optional = true, }, >>> + { .parse_prop = parse_iommus, }, >>> { .parse_prop = parse_iommu_maps, .optional = true, }, >>> { .parse_prop = parse_mboxes, }, >>> { .parse_prop = parse_io_channels, }, >>> >>> Without that a really nasty things happened. > I have a command line option to do this without code changes. Use > fw_devlink.strict=1. That makes all optional properties into mandatory > ones. > > I sent out a series[1] that tried to make fw_devlink.strict=1 the > default and then use the timeout behavior (more details) to handle > cases where iommu and dmas (or any other supplier) are optional on a > specific board. The cover letter of [1] should give some more context. I'm for removing the optional properties or making them dependent on the whole subsystem availability (see my next comments). >>> Initialization of the built-in drivers and loading modules takes time, >>> so the default 10s deferred probe timeout is not enough to ensure that >>> the built-in driver won't be probed before the Exynos IOMMU driver is >>> loaded. > The 10 second is the minimum delay from the time we hit late_initcall. > If a driver is registered before the 10s expires, then the timer will > be extended by another 10s. This behavior landed sometime around the > end of May 2022. So it should have been in your tree when you tested > this. I'm surprised this isn't sufficient for your case. Is there > really a 10s gap in your boot sequence where no module is being loaded > and then IOMMU modules get loaded later on? I'm kinda surprised by > this. Is it this long because some serial UART is enabled and it's > slowing down boot? Or something else? > > I'm not saying your case isn't valid or we shouldn't extend the > timeout. I'm just trying to understand why the current timer behavior > wasn't able to cover your case. Well, I have almost all possible CONFIG_DEBUG_* options enabled in exynos_defconfig, as well as kernel messages routed to UART console, so all my test system are really slow, but I do this intentionally. I suspect that over half of the issues I've reported were found because of such 'unusual' config. Loading modules also takes time in such case, so maybe the timeout should be extended also by each loaded module? >> Yeah, the whole time-based sync looks nasty... I remember coming >> across the slides by Andrzej Hajda called "Deferred Problem" [1], but >> I guess the proposed solution was never applied. Just hope that >> increasing the timeout is upstreamable solution. >> >> [1] https://events19.linuxfoundation.org/wp-content/uploads/2017/12/Deferred-Problem-Issues-With-Complex-Dependencies-Between-Devices-in-Linux-Kernel-Andrzej-Hajda-Samsung.pdf > Sam, I kinda skimmed the slides right now. Looks like it talks about > device links and why they aren't sufficient and makes an alternate > proposal. fw_devlink is a solution that uses device links and I think > addresses a lot of the issues that were raised about device links. > There's still a bunch of TODOs left, but I think the end goal is the > same. I'm hoping to keep chipping away at it. For now, I've tried to > make the timer a bit more smart about detecting when modules are > getting loaded and extending the timer. fw_devlink also enables > something called sync_state() that's invaluable on a fully modular > system (search lore for references to that to get some idea). > > The slides talk about a solution that will allow devices to probe with > limited functionality with whatever suppliers are available and then > reprobe as more suppliers are available. I'm not sure how well that'll > work across the board. It's going to be a bit weird if your phone > display goes off and then comes on again because an IOMMU driver got > loaded (and it can now do DRM playback). For now, I'm not going to > focus on that option because there are enough existing issues/TODOs to > work on for fw_devlink. > >>> The second change fixes the problem that driver core probes Exynos IOMMU >>> controllers in parallel to probing the master devices, what results in >>> calling exynos_iommu_of_xlate() and exynos_iommu_probe_device() even on >>> the partially initialized IOMMU controllers or initializing the dma_ops >>> under the already probed and working master device. This was easy to >>> observe especially on the master devices with multiple IOMMU >>> controllers. I wasn't able to solve this concurrency/race issues inside >>> the Exynos IOMMU driver. >>> >>> Frankly speaking I don't know what is the rationale for making the >>> 'iommus' property optional, but this simply doesn't work well with IOMMU >>> driver being a module. CCed Saravana and Rob for this. >>> >> The patch which makes 'iommus' optional doesn't provide much of >> insight on reasons in commit message either. > This was the commit text: > > Not all DT bindings are mandatory bindings. Add support for optional DT > bindings and mark iommus, iommu-map, dmas as optional DT bindings. > > I thought it was obvious enough, but I guess I could have done better. > Geert convinced me that iommu's aren't always necessary and devices > could work perfectly well without them or dmas. And he has a bunch of > boards like that. So I went with adding optional and then introducing > fw_devlink.strict. Well, that depends heavily on the kernel config and the intentions behind it. Indeed one might have IOMMU driver not selected in the config (for various reasons, like forcing drivers to use contiguous memory buffers for max performance) and system should boot fine. That time one didn't consider the IOMMUs being compiled as modules. The main problem is how to distinguish between the first case (intentionally no IOMMU driver or even no IOMMU support) and the modularized case (driver not yet loaded). I assume that one can skip waiting for IOMMUs only if the whole IOMMU subsystem is not compiled in, otherwise the IOMMU driver can still come in and it cannot properly start operating if client device drivers already started their operation. DMAs, although similar a bit, are imho a bit different. Drivers usually have some kind of fallback if DMA is not yet available, but usually drivers can switch their operation on-fly between PIO and DMA (and some even do that intentionally and use PIO for very small transfers). > However, at this point in time, I believe none of them should be > marked as optional because technically any property can be optional > depending on what the firmware has set up and what the driver does. We > should figure this out at runtime on a board level -- which is what > [1] is trying to do. Yeah, not very pretty, but there hasn't been a > better solution that's not "have userspace tell us it's done loading > modules" (that's a "kernel depends on userspace to work correctly" > thing that no one likes). I've fixed some of the issues raised in [1] > in a fw_devlink improvement series[2] and I plan on continuing to work > on this until hopefully [1] can land. > >>> Without fixing the above issues, I would add a warning that compiling >>> the driver as a module leads to serious issues. >>> >> Nice catch! It doesn't reproduce on my platform, alas. Can I expect >> you to submit those patches? If so, I'll probably just wait for those >> to be applied, and then re-send my modularization series on top of it. >> Does that sounds reasonable? > For now, maybe we could add a config to enable fw_devlink.strict=1 by > default and then select it if you make specific iommu drivers into > modules? And then Geert won't set it for his driver, but you can set > it for your driver? I think the best we can do now is to either add a kconfig option to force strict fw_devlinks (so Exynos IOMMU can be selected as a module only if that one is selected) or do a runtime check during the Exynos IOMMU initalization - and fail with appropriate error message if fw_devlink.strict!=1. What do you think? Best regards