From patchwork Thu Nov 19 16:58:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 11918383 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E01EC56201 for ; Thu, 19 Nov 2020 17:02:51 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 9558B221FB for ; Thu, 19 Nov 2020 17:02:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="PjJ9r68J" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9558B221FB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=QOCxII/A0uAPr0Kxiomq8W5zltieBOVnumw240Tl3OY=; b=PjJ9r68Jsrln7QIxkayV+7VcqH xqt7FhBSheIzwKOkWWOQXw3kDaDZi/UWnGel8lK5vHaO+kouODgHRpnlBk0pLnlltOdfcrMAdATHo V615is1/1AiquQDIKWNoS2BJ+pgAOjhByHVqeep4OlYIQJuoAKQTFWsquOqHgBlwBTWu3YUhWsDan enVNzvPiZ7hds2pIMPa3sp7DuoMkn4l+2UZR05dp2veIALwKAaNpd9QJT8fQ/EKP+t80dD1Lzn+3w ja/voB9dP1CwAolW5fQFM2ggWA7Y1sMoJfH2LEm46B8Y1EDyDE8GBcshf0IkkF/MFGgSPi9LCzdjX HbBaGfLw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfnJE-0007Dw-9U; Thu, 19 Nov 2020 17:01:24 +0000 Received: from szxga05-in.huawei.com ([45.249.212.191]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfnIY-0006uJ-PU for linux-arm-kernel@lists.infradead.org; Thu, 19 Nov 2020 17:01:10 +0000 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CcQsY5PPyzhdHQ; Fri, 20 Nov 2020 01:00:17 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.210.168.73) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Fri, 20 Nov 2020 01:00:22 +0800 From: Shameer Kolothum To: , Subject: [PATCH] iommu: Check return of __iommu_attach_device() Date: Thu, 19 Nov 2020 16:58:46 +0000 Message-ID: <20201119165846.34180-1-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.210.168.73] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201119_120043_157825_F7865BF2 X-CRM114-Status: GOOD ( 13.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: joro@8bytes.org, robin.murphy@arm.com, linuxarm@huawei.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently iommu_create_device_direct_mappings() is called without checking the return of __iommu_attach_device(). This may result in failures in iommu driver if dev attach returns error. Fixes: ce574c27ae27("iommu: Move iommu_group_create_direct_mappings() out of iommu_group_add_device()") Signed-off-by: Shameer Kolothum --- Crash log: [ 31.353605] hns3 0000:7d:00.3: Adding to iommu group 10 [ 31.358822] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000018 [ 31.367567] Mem abort info: [ 31.370350] ESR = 0x96000004 [ 31.373391] EC = 0x25: DABT (current EL), IL = 32 bits [ 31.378680] SET = 0, FnV = 0 [ 31.381720] EA = 0, S1PTW = 0 [ 31.384847] Data abort info: [ 31.387716] ISV = 0, ISS = 0x00000004 [ 31.391535] CM = 0, WnR = 0 [ 31.394491] [0000000000000018] user address but active_mm is swapper [ 31.400818] Internal error: Oops: 96000004 [#1] PREEMPT SMP [ 31.406365] Modules linked in: [ 31.409409] CPU: 21 PID: 1 Comm: swapper/0 Not tainted 5.10.0-rc4-00008-gdd5aba9d719-dirty #79 [ 31.417980] Hardware name: Huawei TaiShan 200 (Model 2280)/BC82AMDD, BIOS 2280-V2 CS V3.B220.01 03/19/2020 [ 31.427588] pstate: 00c00009 (nzcv daif +PAN +UAO -TCO BTYPE=--) [ 31.433566] pc : arm_smmu_tlb_inv_range+0x178/0x1f0 [ 31.438422] lr : arm_smmu_tlb_inv_range+0x5c/0x1f0 [ 31.443190] sp : ffff80001043b4e0 ... [ 31.531175] Call trace: [ 31.533613] arm_smmu_tlb_inv_range+0x178/0x1f0 [ 31.538122] arm_smmu_iotlb_sync+0x2c/0x38 [ 31.542200] iommu_unmap+0x60/0x90 [ 31.545585] __iommu_map+0x110/0x1f0 [ 31.549144] iommu_create_device_direct_mappings.isra.34+0x1ac/0x250 [ 31.555468] iommu_probe_device+0x6c/0x110 [ 31.559551] iort_iommu_configure_id+0x114/0x218 [ 31.564148] acpi_dma_configure_id+0x94/0xe0 [ 31.568402] pci_dma_configure+0xc8/0xf0 [ 31.572310] really_probe+0xd4/0x3e0 [ 31.575871] driver_probe_device+0x5c/0xc0 --- drivers/iommu/iommu.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index b53446bb8c6b..0f4dc25d46c9 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -264,16 +264,18 @@ int iommu_probe_device(struct device *dev) */ iommu_alloc_default_domain(group, dev); - if (group->default_domain) + if (group->default_domain) { ret = __iommu_attach_device(group->default_domain, dev); + if (ret) { + iommu_group_put(group); + goto err_release; + } + } iommu_create_device_direct_mappings(group, dev); iommu_group_put(group); - if (ret) - goto err_release; - if (ops->probe_finalize) ops->probe_finalize(dev);