From patchwork Thu Jul 27 05:48:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 126697 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp906954vqo; Thu, 27 Jul 2023 00:05:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlHbeTytTNL7cuxKBZNyi1tXBSQHM/SyWCZPfKG+izOvEXw1yGf2gwDJ6u9lEGZCTDwxC3JV X-Received: by 2002:a05:6a20:6a1a:b0:134:2b31:e2a9 with SMTP id p26-20020a056a206a1a00b001342b31e2a9mr4359722pzk.0.1690441545075; Thu, 27 Jul 2023 00:05:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690441545; cv=none; d=google.com; s=arc-20160816; b=UMNl0BY3tnMEhxkLEZMXEOjipkrYZIA6Ck8x0yPGYuiW3T7E+WbWM8sMYGwqCLrm8a CdqKlBSrmvUGFWMGWZrDBBN/sFk2EmrNooQCWekrNHEMy4sm8XGv2vgJB+W7ERJaEW8d 0RYHIom27UkNLV1zdw7oiQACzqG62CAPEZZnxngkaoLxox5A8f9aovuwoDoWSfXOiGu0 pFWxMtau+ZgZVS3Ulab4kQNiXRfAOpgUdBXx8/753zFJ8DmXHVLYpYOmlcleqFVecnue KamxbNjNlSmP+HWuxBYwENwVIJ9CMvd5WvkUu/AmScL+Vd4NDzfcO6b9+AuCJhFm2Kvr epzw== 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=3uWG+CmJuJOctC6H7zLve+75aZR2b+kaHeS7GkULJqk=; fh=5v0QJkujOnxKSzhmeWiMX/0q9X35NwMz+SRMkKa4moc=; b=SLKZogA6SeEexkdkS2WeO3yAFiccyDe0Q5yeGKesVpOEDujlA1tWvXcjJdlT84IhOi jba1qBSPO1BsMA62PSsll4MCS3AETMPpBZFS+zwElrMmwpMrlO5W06uQCwEnYA9CN0CN Mdasct41Tut3zBMOeeeNREgcj30XBEfLx0d8kdQYjeUYsihjVOMSP6RPdJZ6mzlTmcnQ 91S7czb1AUtiIwLEJmKQb+9G0E9/aeW8PWIdNwPlE8opCJ5RsbVM0ccb1XJZuowxj381 gDNIV1VnzP+p04krIzOyPrkfAU0R+thXetn7EOtnOfgV87E6GcKyx3o/b8EePbYGA/gE 9G2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IfNRmMbs; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l184-20020a6388c1000000b00563e70c270bsi824900pgd.781.2023.07.27.00.05.31; Thu, 27 Jul 2023 00:05:45 -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=IfNRmMbs; 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 S232696AbjG0Fwc (ORCPT + 99 others); Thu, 27 Jul 2023 01:52:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232660AbjG0FwD (ORCPT ); Thu, 27 Jul 2023 01:52:03 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9825B35B5; Wed, 26 Jul 2023 22:51:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690437105; x=1721973105; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GLGfwzE0Y7wFUcyclBPwhDRKj0nvBYdZjZRsBpwb4Wc=; b=IfNRmMbswWBIb9Doh4aym6QWqeristnoRaSulUsxxheVkxs72vG41R1H TegsUjY4P6q4BxsRetGA3HXX1Ti+YQvpqOLAmav1/BPdjBPskjBAVRI+I C1fF01i/BiK1lnHUIws6dFuAssWXphX+X3RQsMt8EBLBReMzJgGmLoZFJ iJ9GizF552Bns6FfTVcXYYHZwrB0Hv+PZBGEjpb+F0JXDKq1P0SQRNE5k ZUrxEzaEbkqcDS/Wd7uoGwo7xv2CMt4dhkAsD/9U62OGuVHtKjzUDc5Kq jcEe4nR47HmO0QMy3M4LHDKMHT0/9GAj5lUTjh8lLyfJPHvMA1r0FlxFc g==; X-IronPort-AV: E=McAfee;i="6600,9927,10783"; a="399152554" X-IronPort-AV: E=Sophos;i="6.01,234,1684825200"; d="scan'208";a="399152554" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jul 2023 22:51:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10783"; a="840585294" X-IronPort-AV: E=Sophos;i="6.01,234,1684825200"; d="scan'208";a="840585294" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga002.fm.intel.com with ESMTP; 26 Jul 2023 22:51:05 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian , Jean-Philippe Brucker , Nicolin Chen Cc: Yi Liu , Jacob Pan , iommu@lists.linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 06/12] iommu: Make dev->fault_param static Date: Thu, 27 Jul 2023 13:48:31 +0800 Message-Id: <20230727054837.147050-7-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230727054837.147050-1-baolu.lu@linux.intel.com> References: <20230727054837.147050-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772556433221856235 X-GMAIL-MSGID: 1772556433221856235 The iommu faults, including recoverable faults (IO page faults) and unrecoverable faults (DMA faults), are generic to all devices. The iommu faults could possibly be triggered for every device. The fault_param pointer under struct dev_iommu is the per-device fault data. Therefore, the fault_param pointer could be static and allocated during iommu device probe and freed when the device is released. With this done, the individual iommu drivers that support iopf have no need to call iommu_[un]register_device_fault_handler() any more. This will make it easier for the iommu drivers to support iopf, and it will also make the fault_param allocation and free simpler. Signed-off-by: Lu Baolu --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 13 +------------ drivers/iommu/intel/iommu.c | 18 ++++-------------- drivers/iommu/iommu.c | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index a5a63b1c947e..fa8ab9d413f8 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -437,7 +437,6 @@ bool arm_smmu_master_sva_enabled(struct arm_smmu_master *master) static int arm_smmu_master_sva_enable_iopf(struct arm_smmu_master *master) { - int ret; struct device *dev = master->dev; /* @@ -450,16 +449,7 @@ static int arm_smmu_master_sva_enable_iopf(struct arm_smmu_master *master) if (!master->iopf_enabled) return -EINVAL; - ret = iopf_queue_add_device(master->smmu->evtq.iopf, dev); - if (ret) - return ret; - - ret = iommu_register_device_fault_handler(dev, iommu_queue_iopf, dev); - if (ret) { - iopf_queue_remove_device(master->smmu->evtq.iopf, dev); - return ret; - } - return 0; + return iopf_queue_add_device(master->smmu->evtq.iopf, dev); } static void arm_smmu_master_sva_disable_iopf(struct arm_smmu_master *master) @@ -469,7 +459,6 @@ static void arm_smmu_master_sva_disable_iopf(struct arm_smmu_master *master) if (!master->iopf_enabled) return; - iommu_unregister_device_fault_handler(dev); iopf_queue_remove_device(master->smmu->evtq.iopf, dev); } diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index d5ca2387e65c..e94e833638a7 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4587,23 +4587,14 @@ static int intel_iommu_enable_iopf(struct device *dev) if (ret) return ret; - ret = iommu_register_device_fault_handler(dev, iommu_queue_iopf, dev); - if (ret) - goto iopf_remove_device; - ret = pci_enable_pri(pdev, PRQ_DEPTH); - if (ret) - goto iopf_unregister_handler; + if (ret) { + iopf_queue_remove_device(iommu->iopf_queue, dev); + return ret; + } info->pri_enabled = 1; return 0; - -iopf_unregister_handler: - iommu_unregister_device_fault_handler(dev); -iopf_remove_device: - iopf_queue_remove_device(iommu->iopf_queue, dev); - - return ret; } static int intel_iommu_disable_iopf(struct device *dev) @@ -4630,7 +4621,6 @@ static int intel_iommu_disable_iopf(struct device *dev) * fault handler and removing device from iopf queue should never * fail. */ - WARN_ON(iommu_unregister_device_fault_handler(dev)); WARN_ON(iopf_queue_remove_device(iommu->iopf_queue, dev)); return 0; diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 4ba3bb692993..3e4ff984aa85 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -302,7 +302,15 @@ static int dev_iommu_get(struct device *dev) return -ENOMEM; mutex_init(¶m->lock); + param->fault_param = kzalloc(sizeof(*param->fault_param), GFP_KERNEL); + if (!param->fault_param) { + kfree(param); + return -ENOMEM; + } + mutex_init(¶m->fault_param->lock); + INIT_LIST_HEAD(¶m->fault_param->faults); dev->iommu = param; + return 0; } @@ -315,6 +323,12 @@ static void dev_iommu_free(struct device *dev) fwnode_handle_put(param->fwspec->iommu_fwnode); kfree(param->fwspec); } + /* + * All pending faults should have been drained before + * device release. + */ + WARN_ON_ONCE(!list_empty(¶m->fault_param->faults)); + kfree(param->fault_param); kfree(param); }