From patchwork Wed Feb 8 05:15:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 54185 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3270493wrn; Tue, 7 Feb 2023 21:35:19 -0800 (PST) X-Google-Smtp-Source: AK7set+O6auTKNbfUbhEEeH3aHDAWyBnmz6mlTk+MYYBP4qo1R0gpr6KRXeuhWTClvmXw6boNYTT X-Received: by 2002:aa7:989d:0:b0:5a8:4883:4213 with SMTP id r29-20020aa7989d000000b005a848834213mr223921pfl.20.1675834518681; Tue, 07 Feb 2023 21:35:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675834518; cv=none; d=google.com; s=arc-20160816; b=FasCfQL6daI370Bk5ob7hbMF45BACgBGdY70+bUf2RcKsI+jk1KImE/L2rcwz3I43i j/zhVHhAERefLuv2BE3Tw8vCzFpftJngBzqZn6ViW8cS++svxRKFCFW5JNAONP1SJBqD f3VgiOP1IjKioCHmJLJ1dkNHEcp7meSsQugTWQ/eznOF3/05FIoaks7l1BoOOWBPnf1p 6pzo5QSENtrFvi+4SGmEY8fEi0eBII15CyEZgaAMivCCgKFsRHvcRtm/bYw/YipUnvYc TbQcwdlykl0TSRUWxigKfttEz2V73KLoEcHUOyy8Lx61V+VFP+kpt8LpvuCuzSsxAL6i jUvg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=juWIZMpl3aNQwMSesl1ig8vvYxPcZSICKs/CT14gX0g=; b=NXoIL/UWRezW6Ok12Xy4x+NC/IBOE/Srlwm3MYC3Z4mHX1TRI+m0h+mlt+8NvD2mTP 6LrEkwMerHkWALM8WawQ2u8v9dRKlNfLxM5ry9D8A6gsmw+ydsFugslVTYHDaV9uvVnX VBha7MfwPOskOMVQjA9cWNfOmnfmo9O6PmoTspe/aq+Dsj81Fv+fAhYK5QfxP1kGukdg LXKb/Cm8KJkyFNFvcvKXGBtEfsoE3sCP+WMNcx3+7QavUMM+xI2jzcoN/wa7p5Wmym51 tpVsDNOCRkRYiYPfxaq6Rb/sMGHcNpsP0gtKV7YqVL0fELEE0LB/0pFwWPWGiR6U5Omp CqdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NINetG02; 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 m67-20020a625846000000b0058d95922151si16394028pfb.287.2023.02.07.21.35.05; Tue, 07 Feb 2023 21:35:18 -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=NINetG02; 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 S229557AbjBHFY0 (ORCPT + 99 others); Wed, 8 Feb 2023 00:24:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjBHFYZ (ORCPT ); Wed, 8 Feb 2023 00:24:25 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8D9535AE for ; Tue, 7 Feb 2023 21:24:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675833864; x=1707369864; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=dU7w0TBrSrIdIYJms8Qb9NuKI4fw5vUjPE8FdmU+g/s=; b=NINetG02ERaPJ6nKF9xPTQuAHtja4E+baS+iCh0XsAVbNbK29omQqy23 st11CKcUACw22hllpTMfBikzk9LWbmsSVoBFSjAhJ4ibn5WNdCe7YvjLE qsQ5dST3mjQEAlAHamwvVDm5MnMLxh5oJr6eJP4q0HpjPvJV/DLNuln6F 2QC5wVMFX3eka+eM5HyedG4ctn0U6OZNnaG7vdvKFr66K/E4H6zli2eYv qZxPW7Pzud9Fyw+LQQ9qnKJqLaaAPbFuhw1Q8ZStTUngVdYap+VHYcB73 4EZNlx8wsO44AYlJrFHSsSq33fbnTbb3+a6QVdFM9HCztPcZwlw9/GuZx Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10614"; a="329741325" X-IronPort-AV: E=Sophos;i="5.97,280,1669104000"; d="scan'208";a="329741325" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2023 21:24:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10614"; a="841045809" X-IronPort-AV: E=Sophos;i="5.97,280,1669104000"; d="scan'208";a="841045809" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga005.jf.intel.com with ESMTP; 07 Feb 2023 21:24:22 -0800 From: Lu Baolu To: iommu@lists.linux.dev Cc: Joerg Roedel , Will Deacon , Robin Murphy , Kevin Tian , linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 1/1] iommu/vt-d: Fix error handling in sva enable/disable paths Date: Wed, 8 Feb 2023 13:15:59 +0800 Message-Id: <20230208051559.700109-1-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 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?1757239856229585051?= X-GMAIL-MSGID: =?utf-8?q?1757239856229585051?= 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") Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- 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 a049178cd9f8..36d1867159d7 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4650,8 +4650,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; } @@ -4663,8 +4667,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; }