From patchwork Thu Feb 16 13:08:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 58068 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp296632wrn; Thu, 16 Feb 2023 05:21:38 -0800 (PST) X-Google-Smtp-Source: AK7set88gNgHYb7URUPrsA1RQigAic3jpRpwj/9uvj9+yTKdiReXqYurQjTpmBmjhmBMzQ4cnVi0 X-Received: by 2002:a17:906:1906:b0:885:6a2e:f941 with SMTP id a6-20020a170906190600b008856a2ef941mr5979364eje.54.1676553698805; Thu, 16 Feb 2023 05:21:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676553698; cv=none; d=google.com; s=arc-20160816; b=A06vhY3MbGer9RRKqO1uBl5b0QonszOdKVXyknsCr5pJY1wLcWgBcjvGNXuRUCrMEe S/PEubyRIJbrftbdf42X9AJdQYqBc0EonJAQ03q43vX0/FUwGdGtDzQyfih5R3sChPZg 6G/CE8imuRCfhm9lHbDs28qUcPYwvR2v28/sPwqxvT8wye6HtTN+mrIORHJvUUbkRcgm fMtz3lnl3Vk1KKwrVj8wuNpgcQlyApKwfv+NSlNPyTqn3aOrCBIdL/liMWbyAMWZnVYo SSSKY9r4VihhYVDxLsf/lqekhJQfY/x9k+3g0Tou3f10jo4yWdDKry330j3l9WFq/MeF JArg== 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=DLwLts8HqAX9yR8RrJo0BbUnXCEPFvO6oHZ+FVknetQ=; b=Hwe9exYujd/pmcLE60m2wydCuK6beji91UCTf6KwKvYFkp+cfqGxLT7eHDmbSdDjGA cO0MeBO9k31sDxluM8XQFQ73QuZJzVLqtj5VQkJBEK1GnMnKWLg7rEED06Ir0yvycCis cGfrWpJe8eKIrc/3hFDNsbq8eQ5+Hlyzj7XJU1E2D/7IQKf7wQzFM91w6wTR9L1JTAUa cjjpHK0W7Ys2r9/qTclv2wyHrD3AyFQfl0EvOyNUHQu69ZuZj7p6FwkZRNXFUTtU3jj5 AtenNnTCv4VDp0K7idFfhuEo9yM2+iYpdAdQWVactN6srHn6sGEZk39mu1xzQAudslNQ PuEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=T1XUAA3M; 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 fd5-20020a1709072a0500b008b14c74c385si1783557ejc.364.2023.02.16.05.20.53; Thu, 16 Feb 2023 05:21:38 -0800 (PST) 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=T1XUAA3M; 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 S229935AbjBPNQq (ORCPT + 99 others); Thu, 16 Feb 2023 08:16:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229771AbjBPNQp (ORCPT ); Thu, 16 Feb 2023 08:16:45 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72BACE3AF for ; Thu, 16 Feb 2023 05:16:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676553404; x=1708089404; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sEeJE3lb+SBSL58VtACxqpXosFpusquhp6qgy5s/iGw=; b=T1XUAA3MWPFDgdtiknMKjYTjsN67QMu1fm75Ss7Fo18F1unez2T5iiYf 0Dwfu8Ql44DkonqeguWvUqWnsqh64swH4Lbqoj+6EK9oGdn4i/jSO7c0q qLlW4bW1Th5zV1dVi8IWmE4PtCur+a6E9QYbYBVj9WAXcGqJeb1u3XO9M TlFLt0o7weXbZ6Zz3GazEVRNySsxhnda+pXmkJ+LQwE4uKD2BUq0CeiXW JGrvwesUcJOPsrdY6fcFSsYBXZa2WjF2fMjP/bqwGV90HiyEdxMtM3XKV v9h96zAuXhT4AhhmHqxwFKkz5uZ5MWV+4ECLcrY2RZ3H5XnjxNb+tV/gG A==; X-IronPort-AV: E=McAfee;i="6500,9779,10623"; a="333883295" X-IronPort-AV: E=Sophos;i="5.97,302,1669104000"; d="scan'208";a="333883295" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2023 05:16:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10623"; a="647674924" X-IronPort-AV: E=Sophos;i="5.97,302,1669104000"; d="scan'208";a="647674924" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga006.jf.intel.com with ESMTP; 16 Feb 2023 05:16:42 -0800 From: Lu Baolu To: Joerg Roedel Cc: Jacob Pan , Tina Zhang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] iommu/vt-d: Fix error handling in sva enable/disable paths Date: Thu, 16 Feb 2023 21:08:13 +0800 Message-Id: <20230216130816.151824-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216130816.151824-1-baolu.lu@linux.intel.com> References: <20230216130816.151824-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,SPF_HELO_NONE, SPF_NONE 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757993971116046000?= X-GMAIL-MSGID: =?utf-8?q?1757993971116046000?= Roll back all previous actions in error paths of intel_iommu_enable_sva() and intel_iommu_disable_sva(). Fixes: d5b9e4bfe0d8 ("iommu/vt-d: Report prq to io-pgfault framework") Reviewed-by: Kevin Tian Signed-off-by: Lu Baolu Link: https://lore.kernel.org/r/20230208051559.700109-1-baolu.lu@linux.intel.com --- drivers/iommu/intel/iommu.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 59df7e42fd53..994dffa1db57 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4642,8 +4642,12 @@ static int intel_iommu_enable_sva(struct device *dev) return -EINVAL; ret = iopf_queue_add_device(iommu->iopf_queue, dev); - if (!ret) - ret = iommu_register_device_fault_handler(dev, iommu_queue_iopf, dev); + if (ret) + return ret; + + ret = iommu_register_device_fault_handler(dev, iommu_queue_iopf, dev); + if (ret) + iopf_queue_remove_device(iommu->iopf_queue, dev); return ret; } @@ -4655,8 +4659,12 @@ static int intel_iommu_disable_sva(struct device *dev) int ret; ret = iommu_unregister_device_fault_handler(dev); - if (!ret) - ret = iopf_queue_remove_device(iommu->iopf_queue, dev); + if (ret) + return ret; + + ret = iopf_queue_remove_device(iommu->iopf_queue, dev); + if (ret) + iommu_register_device_fault_handler(dev, iommu_queue_iopf, dev); return ret; }