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=-19.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 3E9E7C4320A for ; Tue, 17 Aug 2021 17:22:10 +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 EC26560F38 for ; Tue, 17 Aug 2021 17:22:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EC26560F38 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.167982.306690 (Exim 4.92) (envelope-from ) id 1mG2me-0004Gj-Nq; Tue, 17 Aug 2021 17:21:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 167982.306690; Tue, 17 Aug 2021 17:21:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mG2me-0004Gc-Km; Tue, 17 Aug 2021 17:21:52 +0000 Received: by outflank-mailman (input) for mailman id 167982; Tue, 17 Aug 2021 17:21:51 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mG2md-0004GW-8z for xen-devel@lists.xenproject.org; Tue, 17 Aug 2021 17:21:51 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mG2md-0002f9-04; Tue, 17 Aug 2021 17:21:51 +0000 Received: from 54-240-197-224.amazon.com ([54.240.197.224] helo=a483e7b01a66.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mG2mc-0002JL-Pg; Tue, 17 Aug 2021 17:21:50 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject; bh=2JZdPGyyh5CI5AK4ag3uWk7fkcVlcYLk1ASCgdhk11g=; b=t3vQuPHXXZvfejSzNdLvBMrYJX oOEdGPawo0Y+2k6SfCboe6P04NhAUJOe14h55XouClLES7TmBBlE5WQ7/qY+zcdLucxmcTQoORHo1 la8uozO0miL3i0+srO+KV9vWSplbHDWv/x25m9sKbF5+rQU1RcGwqDh0DZeLLKPHdkp8=; Subject: Re: [PATCH] xen/arm: smmu: Set/clear IOMMU domain for device To: Oleksandr Andrushchenko , sstabellini@kernel.org, Volodymyr_Babchuk@epam.com, xen-devel@lists.xenproject.org Cc: Oleksandr Andrushchenko , Oleksandr Tyshchenko References: <20210811130356.1143743-1-andr2000@gmail.com> From: Julien Grall Message-ID: Date: Tue, 17 Aug 2021 18:21:48 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210811130356.1143743-1-andr2000@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Hi Oleksandr, Apologies for the late answer. On 11/08/2021 14:03, Oleksandr Andrushchenko wrote: > From: Oleksandr Andrushchenko > > When a device is assigned/de-assigned it is required to properly set > IOMMU domain used to protect the device. This assignment was missing, > thus it was not possible to de-assign the device: > > (XEN) Deassigning device 0000:03:00.0 from dom2 > (XEN) smmu: 0000:03:00.0: not attached to domain 2 > (XEN) d2: deassign (0000:03:00.0) failed (-3) > > Fix this by assigning IOMMU domain on arm_smmu_assign_dev and reset it > to NULL on arm_smmu_deassign_dev. I think this was introduced by commit 06d1f7a278dd "xen/arm: smmuv1: Keep track of S2CR state". If so, please add: Fixes: 06d1f7a278dd ("xen/arm: smmuv1: Keep track of S2CR state") Looking at the commit message, the IOMMU domain used to be set/unset in arm_smmu_{attach, detach}_dev() but Linux drop it because they now rely in the core IOMMU framework to track the domain. So I agree with the new position for... > > Signed-off-by: Oleksandr Andrushchenko > Signed-off-by: Oleksandr Tyshchenko > --- > xen/drivers/passthrough/arm/smmu.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c > index c234ad9c7f1e..373d9d4d123a 100644 > --- a/xen/drivers/passthrough/arm/smmu.c > +++ b/xen/drivers/passthrough/arm/smmu.c > @@ -2768,6 +2768,7 @@ static int arm_smmu_assign_dev(struct domain *d, u8 devfn, > arm_smmu_destroy_iommu_domain(domain); > } else { > atomic_inc(&domain->ref); > + dev_iommu_domain(dev) = domain; ... this one. However... > } > > out: > @@ -2794,7 +2795,10 @@ static int arm_smmu_deassign_dev(struct domain *d, struct device *dev) > atomic_dec(&domain->ref); > > if (domain->ref.counter == 0) > + { > arm_smmu_destroy_iommu_domain(domain); > + dev_iommu_domain(dev) = NULL; > + } ... I think this one is incorrect because you would only unset dev_iommu_domain() is the refcount drop to 0. You can have multiple device in the same domain, so the ref.counter may not be 0. So I think this needs to be moved outside of the if. Note that it is also a good practice to remove any reference (e.g. set to NULL) before freeing even if it doesn't much matter here. Lastly, the file is using the Linux coding style. So { needs to be on the same line as the if. Cheers, -- Julien Grall