Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp953106rwl; Fri, 24 Mar 2023 04:27:09 -0700 (PDT) X-Google-Smtp-Source: AKy350YznGjsAQ26ouUSs229sdjGEFY2cYixuQUrjyuTcfUyyX4r2gnKZuOnWPgJvyvNHKuJWY+/ X-Received: by 2002:a17:907:a648:b0:8aa:875d:9d9a with SMTP id vu8-20020a170907a64800b008aa875d9d9amr2531690ejc.50.1679657229214; Fri, 24 Mar 2023 04:27:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679657229; cv=none; d=google.com; s=arc-20160816; b=GQlWyPIUcMOLFR0ElImbQR9aLxQ1VKs4jMcGTahd6koNUX5qTbEd2xHojEOUrVO+jw o65hZ7nP+Fgf++LPPksTCFHRqW07RcemHPWnPZoUlGxJ/zq9hL4oPWyOF81bBXYCHhR7 7PPk5if8Rn9hsLpw5lB62zCUTNTj/xRtQDjAg4KMTmXbjjuEFoq4RTCxItjmA2omIgsf T0f+rJ2UovZaNBLm73rWqVc16sHfGiPxe6l9vVjpcMtl3KNix85RcZvmj8GhJq09in8x P+2JJwBHXI9JwM5R4qClDHiF7UorExQegh4Wy1Vx5e9ytP/WtCENE8eXkEKaUh6ZQ/u/ Hl8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id; bh=o4a4+P/W8H3bEKwqg1wA6WFBP5fm8LSyhjU0TsHwULQ=; b=MLkxZkY2+YUFB038PFh9INLEydV+jsSNMnKnR1wm3NmcRvMTTW6Dju9nm0nuEGGWCK NONcZp0Z8ckV7Qx7zXC8hJczenlyur3PzDeuzx3nzzyiaH74uMViwTO6EoIFSo/H9TZl n9XxdjBQoYTqKqebnu8ZtAO1AhDooGG0+IHPoFTHmaP0Yep9a52ObjnvKvC/PD/7gFFm SMixHjynLS98fSbsGAIaRyv6t/0TBdV43nVWEIlg1tC4jViFbCl7T97q03swKU6BoSk/ 8CO6F0SfOA3505Khfn/915KhqFMAuxJBJYCRwsVtbVfXZIBXYcbB5vxz928jh37kiWtz +4hQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gy19-20020a170906f25300b00925de8df75asi19444993ejb.75.2023.03.24.04.26.44; Fri, 24 Mar 2023 04:27:09 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230350AbjCXLRk (ORCPT + 99 others); Fri, 24 Mar 2023 07:17:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229536AbjCXLRi (ORCPT ); Fri, 24 Mar 2023 07:17:38 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D94D3193F9 for ; Fri, 24 Mar 2023 04:17:36 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9776411FB; Fri, 24 Mar 2023 04:18:20 -0700 (PDT) Received: from [10.1.28.32] (e122027.cambridge.arm.com [10.1.28.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EEF9D3F6C4; Fri, 24 Mar 2023 04:17:33 -0700 (PDT) Message-ID: <80238e1b-15d7-23b7-b2a9-77078e64e056@arm.com> Date: Fri, 24 Mar 2023 11:17:32 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH] iommu/rockchip: Add missing set_platform_dma_ops callback To: Jason Gunthorpe Cc: Heiko Stuebner , Joerg Roedel , Will Deacon , Robin Murphy , iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Lu Baolu References: <20230315164152.333251-1-steven.price@arm.com> <85607806-b888-2d5e-67a4-e9d63ebd1976@arm.com> Content-Language: en-GB From: Steven Price In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.3 required=5.0 tests=NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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: X-Mailing-List: linux-kernel@vger.kernel.org On 22/03/2023 17:36, Jason Gunthorpe wrote: > On Wed, Mar 22, 2023 at 04:04:25PM +0000, Steven Price wrote: >> On 22/03/2023 15:16, Jason Gunthorpe wrote: >>> On Wed, Mar 22, 2023 at 03:08:41PM +0000, Steven Price wrote: >>>> @@ -1035,8 +1055,9 @@ static int rk_iommu_attach_device(struct iommu_domain *domain, >>>> if (iommu->domain == domain) >>>> return 0; >>>> >>>> - if (iommu->domain) >>>> - rk_iommu_detach_device(iommu->domain, dev); >>>> + ret = rk_iommu_identity_attach(&rk_identity_domain, dev); >>>> + if (ret) >>>> + return ret; >>> >>>> >>>> iommu->domain = domain; >>>> >>>> @@ -1049,8 +1070,6 @@ static int rk_iommu_attach_device(struct iommu_domain *domain, >>>> return 0; >>>> >>>> ret = rk_iommu_enable(iommu); >>>> - if (ret) >>>> - rk_iommu_detach_device(iommu->domain, dev); >>> >>> I think this still needs error handling, it should put it back to the >>> identity domain and return an error code if it fails to attach to the >>> requested domain. >> >> What confused me here is that there's already a call to >> rk_iommu_identity_attach() just above. But I can obviously add a... > > I don't know this driver at all, but to me it looks like this is > perhaps undoing a partially failed rk_iommu_enable() since it doesn't > seem to enetirely fix itself. Ie it zeros the INT_MASK and DTE_ADDR > > Maybe it would be better to put that error cleanup direclty into > enable and just move the iommu->domain assignment to after enable > success. While I agree this would be better - I don't feel I understand the driver enough to have confidence in doing this. And I don't know how to trigger the error conditions to test this either. >> if (ret) >> rk_iommu_identity_attach(&rk_identity_domain, dev); >> >> ... in here. But I don't know how to handle an error from >> rk_iommu_identity_attach() at this point. Does it need handling - is a >> WARN_ON sufficient? > > WARN_ON should be fine, that is kind of hacky, it would be better to > organize things so there is an identity attach function that cannot > fail, ie pre-assumes all the validation is done alread.y As the code currently stands rk_iommu_identity_attach can fail for exactly one reason: if rk_iommu_from_dev() fails. And since that check is already done in rk_iommu_attach_device() this cannot fail (baring memory corruption etc). So I'll stick to WARN_ON for now. >> >>> It should also initlaize iommu->domain to the identity domain when the >>> iommu struct is allocated. The iommu->domain should never be >>> NULL. identity domain means the IOMMU is turned off which was >>> previously called "detached". >> >> I presume you mean in rk_iommu_probe()? > > It would be best if it was setup at allocation time so in > rk_iommu_of_xlate() before dev_iommu_priv_set() I've already put an assignment in rk_iommu_of_xlate() just before dev_iommu_priv_set(). Steve