Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp36112297rwd; Mon, 10 Jul 2023 18:21:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlExA1x66zBJvlGimXv2Oje3w2nPp05VIgm/p5AsXSkSwv1//kTVMwZn0quuTCfJfadOME6z X-Received: by 2002:a05:6358:c1f:b0:135:615a:309d with SMTP id f31-20020a0563580c1f00b00135615a309dmr3976695rwj.7.1689038483178; Mon, 10 Jul 2023 18:21:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689038483; cv=none; d=google.com; s=arc-20160816; b=zCp7kEJKzZ8iJZ20Xb4685/iX1awLz7zl8WIzmwiEHvo5BUAa7wH5dJu7khD2eSTPR yudgP0W0P0y5idyLRIDbr234n27oraLSfThvJeE1L1m9PcFOvWK5r0RgMBw3FyKp3L5t bVLQBvFjIGY9+v63bdxA5y5LFhrG+0FTOiGhGkX+LsRBplUcSYVfTGN0MDCxmYGLAKKR xF1W5iA6NbvB3uxjU7tj/B6uZbubWPDgz9b0kArhPlm1ygduHYDAuxq+tnBXpkLQQ9UL WgpNoxe+qg/OEleZAIqpHTx+HEIGrb6SGhEylosE6Hfr1OIpHpG/OBV/FNBixlIP3QVD BMWw== 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=OLcj3zPdqQKstn0ZuynWrYYJ5lKSBGxe27DOV1hHD5w=; fh=5v0QJkujOnxKSzhmeWiMX/0q9X35NwMz+SRMkKa4moc=; b=JdZPd6NWxpU0iykp3jGR57YISu4d+3/NJSbw8mvTbFaj2pdl7Sb16kNCHT8JoSsWTT /FCE3mJoAvw3W+u0VxTnM07yJD9r4TvV4qEWmaKVnVnF1RWlzCchBwlsENcx5eksYdZS B6X+4lOo6yEjiATX5XKhi3aSy43zByM7lBiJ7n7Ccifng1JFZnhaL0OhLcu3e7Skij6J gBEOfqymp/BNO2LFcx35Hqgf6Z+4RfEpN//tr36YzKw1FGm0yzbUpyJB5x2qy2OMiFVI QAWaLEw2+VobgpNf2GrkOOJL6IBpATf/Nxd4uMDr3N6fvtC9EA7V2K7X6NlZnHsA2NSH KIFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=j+bLA1HV; 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 o30-20020a637e5e000000b0055b52ba0a00si534618pgn.48.2023.07.10.18.21.11; Mon, 10 Jul 2023 18:21:23 -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=j+bLA1HV; 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 S231229AbjGKBJr (ORCPT + 99 others); Mon, 10 Jul 2023 21:09:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231213AbjGKBJp (ORCPT ); Mon, 10 Jul 2023 21:09:45 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B2D21715; Mon, 10 Jul 2023 18:09:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689037757; x=1720573757; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+AYwr3bKWy7rpxtl+3/vsQbCiRF0Z5vJWyLMxV8Tnsg=; b=j+bLA1HVho0kUV6c5hloOBr5qerIUVXDKyMUuNqKhwvv29AoI1Wos/y6 CumZQZauMYoNPLWe5QSmzHJBgNbv0aoFo724mZXbkgwURec+OSsmwyXhz I6E1H+e51DIA9iubp1ztP8WnxkqoKf+YBOP4syd8LiGrN5AbCBL6gBkYj DeocInu0a42cKYaDBkR8o+wo7GovbveqnLi0MYtb0BWZiFjTj729X+vsS d1sAFTvYxrRUUXryQZOxiokwdUGVMDDsyNKP6RNUDsY+NhbvDZ+6z4PBb m3WaAXk89/Mq3cxGw1UVZpmp0fll+7FWk1SrQU5wiK6sdXDekY6blGK+u Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10767"; a="344816168" X-IronPort-AV: E=Sophos;i="6.01,195,1684825200"; d="scan'208";a="344816168" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jul 2023 18:09:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10767"; a="810999967" X-IronPort-AV: E=Sophos;i="6.01,195,1684825200"; d="scan'208";a="810999967" Received: from allen-box.sh.intel.com ([10.239.159.127]) by FMSMGA003.fm.intel.com with ESMTP; 10 Jul 2023 18:09:06 -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 9/9] iommu: Use fault cookie to store iopf_param Date: Tue, 11 Jul 2023 09:06:42 +0800 Message-Id: <20230711010642.19707-10-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230711010642.19707-1-baolu.lu@linux.intel.com> References: <20230711010642.19707-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Remove the static iopf_param pointer from struct iommu_fault_param to save memory. Signed-off-by: Lu Baolu --- include/linux/iommu.h | 2 -- drivers/iommu/io-pgfault.c | 47 +++++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index ffd6fe1317f4..5fe37a7c5a55 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -551,7 +551,6 @@ struct iommu_fault_param { * struct dev_iommu - Collection of per-device IOMMU data * * @fault_param: IOMMU detected device fault reporting data - * @iopf_param: I/O Page Fault queue and data * @fwspec: IOMMU fwspec data * @iommu_dev: IOMMU device this device is linked to * @priv: IOMMU Driver private data @@ -564,7 +563,6 @@ struct iommu_fault_param { struct dev_iommu { struct mutex lock; struct iommu_fault_param *fault_param; - struct iopf_device_param *iopf_param; struct iommu_fwspec *fwspec; struct iommu_device *iommu_dev; void *priv; diff --git a/drivers/iommu/io-pgfault.c b/drivers/iommu/io-pgfault.c index 1749e0869f2e..6a3a4e08e67e 100644 --- a/drivers/iommu/io-pgfault.c +++ b/drivers/iommu/io-pgfault.c @@ -158,7 +158,7 @@ int iommu_queue_iopf(struct iommu_fault *fault, struct device *dev) * As long as we're holding param->lock, the queue can't be unlinked * from the device and therefore cannot disappear. */ - iopf_param = param->iopf_param; + iopf_param = iommu_get_device_fault_cookie(dev, 0); if (!iopf_param) return -ENODEV; @@ -235,7 +235,7 @@ int iopf_queue_flush_dev(struct device *dev) return -ENODEV; mutex_lock(¶m->lock); - iopf_param = param->iopf_param; + iopf_param = iommu_get_device_fault_cookie(dev, 0); if (iopf_param) flush_workqueue(iopf_param->queue->wq); else @@ -286,9 +286,9 @@ EXPORT_SYMBOL_GPL(iopf_queue_discard_partial); */ int iopf_queue_add_device(struct iopf_queue *queue, struct device *dev) { - int ret = -EBUSY; - struct iopf_device_param *iopf_param; + struct iopf_device_param *iopf_param, *curr; struct dev_iommu *param = dev->iommu; + int ret; if (!param) return -ENODEV; @@ -303,16 +303,27 @@ int iopf_queue_add_device(struct iopf_queue *queue, struct device *dev) mutex_lock(&queue->lock); mutex_lock(¶m->lock); - if (!param->iopf_param) { - list_add(&iopf_param->queue_list, &queue->devices); - param->iopf_param = iopf_param; - ret = 0; + curr = iommu_set_device_fault_cookie(dev, 0, iopf_param); + if (IS_ERR(curr)) { + ret = PTR_ERR(curr); + goto err_free; } + + if (curr) { + ret = -EBUSY; + goto err_restore; + } + list_add(&iopf_param->queue_list, &queue->devices); mutex_unlock(¶m->lock); mutex_unlock(&queue->lock); - if (ret) - kfree(iopf_param); + return 0; +err_restore: + iommu_set_device_fault_cookie(dev, 0, curr); +err_free: + mutex_unlock(¶m->lock); + mutex_unlock(&queue->lock); + kfree(iopf_param); return ret; } @@ -329,7 +340,6 @@ EXPORT_SYMBOL_GPL(iopf_queue_add_device); */ int iopf_queue_remove_device(struct iopf_queue *queue, struct device *dev) { - int ret = -EINVAL; struct iopf_fault *iopf, *next; struct iopf_device_param *iopf_param; struct dev_iommu *param = dev->iommu; @@ -339,16 +349,17 @@ int iopf_queue_remove_device(struct iopf_queue *queue, struct device *dev) mutex_lock(&queue->lock); mutex_lock(¶m->lock); - iopf_param = param->iopf_param; - if (iopf_param && iopf_param->queue == queue) { - list_del(&iopf_param->queue_list); - param->iopf_param = NULL; - ret = 0; + iopf_param = iommu_get_device_fault_cookie(dev, 0); + if (!iopf_param || iopf_param->queue != queue) { + mutex_unlock(¶m->lock); + mutex_unlock(&queue->lock); + return -EINVAL; } + + list_del(&iopf_param->queue_list); + iommu_set_device_fault_cookie(dev, 0, NULL); mutex_unlock(¶m->lock); mutex_unlock(&queue->lock); - if (ret) - return ret; /* Just in case some faults are still stuck */ list_for_each_entry_safe(iopf, next, &iopf_param->partial, list) -- 2.34.1