From patchwork Tue Oct 17 03:20:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Tina" X-Patchwork-Id: 153888 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3872633vqb; Mon, 16 Oct 2023 20:22:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJup1y4iexPQCLuvEoGENQGfop4iAkoP7pJBqKMyT5TJTBlcyU8oo/dAv+cp/zb/hkXMZi X-Received: by 2002:a05:6359:2c43:b0:166:d9b7:2ba5 with SMTP id qv3-20020a0563592c4300b00166d9b72ba5mr919564rwb.2.1697512973336; Mon, 16 Oct 2023 20:22:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697512973; cv=none; d=google.com; s=arc-20160816; b=Omez+Eluxd9Sixhu3F9d4U7yxOB8hspoV7Yg/kX4Pr54HHZnETXXoeG7BPj3BC5LLM xY6o7NxhmxgglyMENiyJ8rDIRxIVAob3klMF4Qe+jFbUlQuJv9xmEJVhOTwHOCXkbuS8 3J8qOeMvvKOxjh9d6iGbQEJ3y5gVA8hvuycy9tEqAJl8h3W9zC/CBpnCBrTeK72bysZg fzhqJc5LmV1KX1nqWdrF0KjY2zFvNsIyrFCg2irpPCBih8Jug4IdBBG/7XUaeAgxI7Zx bHzkii39QfN3ToiWS9Kp5cZD9XAtcv9v+elAa7iOpoPsAH/rs/7252zMCeSEgV7gCcE0 pxxg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=efvZ3MpTnxe4ynl0KjNTTZuOZRgZpuVue8Lc70tz9+g=; fh=R49q8kPD/ziIvsyYshS2LccDCxkbN9TSdzSyy3EleF0=; b=ET91WAcGoi4+hNPZWvI/6+ulMc+yHhbzF95hTj5YLmEX1SAaRZPwbKbIZx3ET5w3Ur ZQwwW3sAUmb6MKSh7+tcusZ5WkJtfv7zGXHi/ujdeRtfcwBxKPow7+WWlZsPcgIsZXld viY5h52xzr7GkfjZqFmGrThVFomlrI/EqYFD9VJMoGB6yh2s/a0aIsDJQE3b07fl2Cpl RgoMvZi5+V4dlAROeEiXcQg8y6a4ve4NCHkvXUHV3khCqK//d05g43oA/2WE3cj6187I qDL4p9dv5ELkrZaNuRDiY3PVsC8JXCZ0awiLWMPnAPtEQRqtymvDhYyB0wPwzXl+dN4q /RmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=crPElB6n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id t15-20020a056a0021cf00b006be1a0457c2si712301pfj.208.2023.10.16.20.22.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 20:22:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=crPElB6n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 454AD80412F0; Mon, 16 Oct 2023 20:22:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234704AbjJQDW2 (ORCPT + 19 others); Mon, 16 Oct 2023 23:22:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234535AbjJQDWK (ORCPT ); Mon, 16 Oct 2023 23:22:10 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53CEAD5E; Mon, 16 Oct 2023 20:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697512899; x=1729048899; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rIP4lGeh4l++76KLDIftiMSwqqH2jZrP09tAxFYTrFc=; b=crPElB6nP4LYtoSQdKRUeQg6WyDq65K+8nc2sfN7skGa6au6SQmibSmh OA7Bfp1JacUr6Nn1o7RfMt3qmlsOD6ulflrioRUTCu2wocU/gz5Vntc8v 2C3ISssR15vGDzSUVYaz2p1NVUSjaOrBSkXRwR65QfFH3nrr5gGiUFz49 MHvX+NX0cIVmvkCUNruuxCvm+nncF9xZpXK3e1NcNnsuUttA4QIgXSkvs 2nkBmjaRW3lkqoHVqpwhE5Uyjt1uVUDcmKgWf0BHzUnv3BrOdegvhk38u 8O4XpRjN8P+PoYmmB98KKMNWg/840HCFn86e8oVQ0qLcZ5cgkIgX8BqHD A==; X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="389560895" X-IronPort-AV: E=Sophos;i="6.03,231,1694761200"; d="scan'208";a="389560895" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 20:21:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="826270102" X-IronPort-AV: E=Sophos;i="6.03,231,1694761200"; d="scan'208";a="826270102" Received: from sqa-gate.sh.intel.com (HELO spr-2s5.tsp.org) ([10.239.48.212]) by fmsmga004.fm.intel.com with ESMTP; 16 Oct 2023 20:21:35 -0700 From: Tina Zhang To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: David Woodhouse , Lu Baolu , Joerg Roedel , Jason Gunthorpe , Kevin Tian , Tina Zhang Subject: [RFC PATCH 11/12] iommu/vt-d: Use intel_iommu_set_dev_pasid() for sva domain Date: Tue, 17 Oct 2023 11:20:44 +0800 Message-Id: <20231017032045.114868-13-tina.zhang@intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231017032045.114868-1-tina.zhang@intel.com> References: <20231017032045.114868-1-tina.zhang@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 16 Oct 2023 20:22:49 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779971363110334590 X-GMAIL-MSGID: 1779971363110334590 Let intel_svm_set_dev_pasid() use intel_iommu_set_dev_pasid() for set_dev_pasid operation. Signed-off-by: Tina Zhang --- drivers/iommu/intel/svm.c | 44 +++++++-------------------------------- 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index 7f98c8acd04f..c9a703935908 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -231,13 +231,9 @@ static const struct mmu_notifier_ops intel_mmuops = { static int intel_svm_set_dev_pasid(struct iommu_domain *domain, struct device *dev, ioasid_t pasid) { - struct dmar_domain *dmar_domain = to_dmar_domain(domain); - struct device_domain_info *info = dev_iommu_priv_get(dev); - struct intel_iommu *iommu = info->iommu; struct mm_struct *mm = domain->mm; - struct dev_pasid_info *dev_pasid; - unsigned long sflags; - int ret = 0; + struct dmar_domain *dmar_domain = to_dmar_domain(domain); + int ret; /* * The sva domain can be shared among multiple devices. Make sure @@ -250,37 +246,11 @@ static int intel_svm_set_dev_pasid(struct iommu_domain *domain, return ret; } - dev_pasid = kzalloc(sizeof(*dev_pasid), GFP_KERNEL); - if (!dev_pasid) { - ret = -ENOMEM; - goto out_unregister; - } - - dev_pasid->dev = dev; - dev_pasid->sid = PCI_DEVID(info->bus, info->devfn); - if (info->ats_enabled) { - dev_pasid->qdep = info->ats_qdep; - if (dev_pasid->qdep >= QI_DEV_EIOTLB_MAX_INVS) - dev_pasid->qdep = 0; + ret = intel_iommu_set_dev_pasid(domain, dev, pasid); + if (ret) { + if (list_empty(&dmar_domain->dev_pasids)) + mmu_notifier_unregister(&domain->notifier, mm); } - - /* Setup the pasid table: */ - sflags = cpu_feature_enabled(X86_FEATURE_LA57) ? PASID_FLAG_FL5LP : 0; - ret = intel_pasid_setup_first_level(iommu, dev, mm->pgd, pasid, - FLPT_DEFAULT_DID, sflags); - if (ret) - goto out_free_dev_pasid; - - list_add_rcu(&dev_pasid->link_domain, &dmar_domain->dev_pasids); - - return 0; - -out_free_dev_pasid: - kfree(dev_pasid); -out_unregister: - if (list_empty(&dmar_domain->dev_pasids)) - mmu_notifier_unregister(&domain->notifier, mm); - return ret; } @@ -696,6 +666,8 @@ struct iommu_domain *intel_svm_domain_alloc(void) return NULL; domain->domain.ops = &intel_svm_domain_ops; INIT_LIST_HEAD(&domain->dev_pasids); + spin_lock_init(&domain->lock); + xa_init(&domain->iommu_array); return &domain->domain; }