Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3249096rwa; Tue, 23 Aug 2022 01:08:05 -0700 (PDT) X-Google-Smtp-Source: AA6agR4sf2Uo8DfzMzo34ttubDUuCIY1/hLJC7fKWS5yAvwuSVH62nFXMqeTDVySdRcr70SmIe24 X-Received: by 2002:a17:902:a411:b0:172:766e:7f3d with SMTP id p17-20020a170902a41100b00172766e7f3dmr22479014plq.24.1661242085267; Tue, 23 Aug 2022 01:08:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661242085; cv=none; d=google.com; s=arc-20160816; b=fBSR1bwwU0RSArB3Pst5hbz4f6cTqoj2vY/Gr6abywtnU2VCNNg9Dm8eWskXt5qYXA ctsj0p0DZBe86C6UMI3BP0Muo5jI0bhWqSjj8HaHAVFiwEBzl7F65Ha7GlnbXh+7ZC5o leZsvwPAmBZnFSEglHpBH6W6/nHGp0xSJUXOp5WxqaenYsAIgwCzYhX0m+Nc3vGjqC/m 4qapmwkaoz98EVS5P8UsF7gtyGvjK6PoXRLEiYhFIMx01YsF4Mdj/S6xhWKhoE8FT1Qr CWIvBxZoOXtyxrKxO7I6iiM3rDCAYpe6GZg03UXB41IeuTmlMwaKy3A8FEMGcZHNSEFy MHOA== 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 :references:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=Zjcwr+TQnFnm1B3uUZ1r/zuahp1zoyaLOwmIqpW/c1U=; b=R6WrHEbaCyLlpogbG2/WU2PYTo0ztipct0IFMh/P3hcqb7yceSOKWfBObSW3io0Xar iBo4dk/vPAJDGqyL6kC6S7C84So52KWjIObOE+NvHrKJjJYmZ9qrkqTYLtizr0vPAAbL QYmZR7bGQNvijgJwmwvmET360Xh7HniUhEClcO6qcl0FgjTxFs7WL+4WndmYa+LeJjlk VzcrzXeQufK993w74PDkWKjISm652NOMxCOQCYIb5f1i+5Bn70FPVGdws5Gcnvy5KCV9 4siNIEhU8bUAJ8svJPhd//2wTMj2N7DHWOHGeEfLIrPVppN7elExNIWzch2fS6PeGoxF v/GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZUyqWmxm; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i13-20020a63130d000000b003fea0415b5asi14348256pgl.834.2022.08.23.01.07.54; Tue, 23 Aug 2022 01:08:05 -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=@intel.com header.s=Intel header.b=ZUyqWmxm; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241058AbiHWHdT (ORCPT + 99 others); Tue, 23 Aug 2022 03:33:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240694AbiHWHdL (ORCPT ); Tue, 23 Aug 2022 03:33:11 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEE3163F34; Tue, 23 Aug 2022 00:33:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661239990; x=1692775990; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=nlUMuSoXu7uI2fet/FjE+vAKf53pL4Yjk/EYF4av+Jo=; b=ZUyqWmxmpN9aQ/KKhyAMaUD/ZN1Smp8UbuiIJskVz3F7l91wyCwGZvmC pk/MNhNTKF47tKW6HVFLreE/fgSSXFlQYshWZV6bPM/r2sB17fDVHBBLY /gRCX03qZogVJyQy/FyNMUJaErJMCBFeskhBjyiYi7PVibwJ1g/TSSyCm SmJNR9i6ARvfcAnO0dIkJD5QoyENPvcFBwGMMQ1jceGOsC2vvJ3qMBhnm TAEUJByIV7YLqWitOcERk+Y4e6GQAupUslEm6PBeGvxRAT1XadzGfDpeU E9UBcr7sE73qFeVcjqkiss9mvHrQXqXF7mEIan8cTpPYaz95gLWCXtRFR g==; X-IronPort-AV: E=McAfee;i="6500,9779,10447"; a="292357205" X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="292357205" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2022 00:33:10 -0700 X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="642345669" Received: from xujinlon-mobl.ccr.corp.intel.com (HELO [10.254.211.102]) ([10.254.211.102]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2022 00:33:05 -0700 Message-ID: <4e958e77-be17-4428-2fc3-48c1e66914fa@linux.intel.com> Date: Tue, 23 Aug 2022 15:33:04 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Cc: baolu.lu@linux.intel.com, Joerg Roedel , Christoph Hellwig , Bjorn Helgaas , Kevin Tian , Ashok Raj , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Dave Jiang , Vinod Koul , Eric Auger , Liu Yi L , Jacob jun Pan , Zhangfei Gao , Zhu Tony , iommu@lists.linux.dev, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v11 07/13] iommu/vt-d: Add SVA domain support Content-Language: en-US To: Jason Gunthorpe References: <20220817012024.3251276-1-baolu.lu@linux.intel.com> <20220817012024.3251276-8-baolu.lu@linux.intel.com> From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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: X-Mailing-List: linux-kernel@vger.kernel.org On 2022/8/18 21:36, Jason Gunthorpe wrote: > On Wed, Aug 17, 2022 at 09:20:18AM +0800, Lu Baolu wrote: > >> +static int intel_svm_set_dev_pasid(struct iommu_domain *domain, >> + struct device *dev, ioasid_t pasid) >> +{ >> + struct device_domain_info *info = dev_iommu_priv_get(dev); >> + struct intel_iommu *iommu = info->iommu; >> + struct iommu_sva *sva; >> + int ret = 0; >> + >> + mutex_lock(&pasid_mutex); >> + /* >> + * Detach the domain if a blocking domain is set. Check the >> + * right domain type once the IOMMU driver supports a real >> + * blocking domain. >> + */ >> + if (!domain || domain->type == IOMMU_DOMAIN_UNMANAGED) { >> + intel_svm_unbind_mm(dev, pasid); > > See, I think this is exactly the wrong way to use the ops > > The blockin domain ops should have its own function that just > unconditionally calls intel_svm_unbind_mm() > >> + } else { >> + struct mm_struct *mm = domain->mm; >> + >> + sva = intel_svm_bind_mm(iommu, dev, mm); >> + if (IS_ERR(sva)) >> + ret = PTR_ERR(sva); > > And similarly the SVA domain should have its own op that does this SVM > call. > > Muxing the ops with tests on the domain is an anti-pattern. In fact I > would say any time you see an op testing the domain->type it is very > suspicious. Both agreed. Will fix them in the next version. Best regards, baolu