From patchwork Thu Apr 13 04:06:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 82780 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp775600vqo; Wed, 12 Apr 2023 21:22:57 -0700 (PDT) X-Google-Smtp-Source: AKy350aF4qW6VZt1YMQSJhvXfabMs0Jv2YUB7YdiV9juAGcbcklcmiFoeBOGBQcL82QROTIAJacw X-Received: by 2002:a17:906:556:b0:94d:fd87:44eb with SMTP id k22-20020a170906055600b0094dfd8744ebmr1081264eja.63.1681359776982; Wed, 12 Apr 2023 21:22:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681359776; cv=none; d=google.com; s=arc-20160816; b=Udfk58omsBKQ8emp6Yvarl4GD3SbR8DqiEk1ULnkT3Eyxigny2Yqh3Fj+7wNogymDQ NA+Kbd776JcorG5lLJ3IJRv2Kk5nIPVdyqNOxao8syJNMWg0S9vnWKWcPVhp/k8nSMYO SfplNl/xFtkFRh0aEPtruJkPCB5Wgo2qXvQaqxvdPrszZimZCDzwy8ILD+5Vq1f1cyxy PbRqvJDE8jFTbshOYFjqgl1PvwxYi17KjU3caQ58Y0W2FwGF4arKBg7hSwU9BldIHvga 9Zw67kLKYqEryriwI4CR4QptFa3BF6QzKx0+3jxrGjI68ucYm61F3Nxiy1Im7a5JzI9G kVEw== 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=py4L1jtJZLQJLTfwPtuzz8WsWGIjDXabocbPTycsMGg=; b=js34Eu6uXOl+4Tr8AMMdi51OYaLoUMMqkD/7VrMe/+XQEDR5qeMs3M+dQBFwFcL1PC 8oI9SvM4PZY7xBqp5UjaIwSUCI16QxHGZFC3JtM9vqN3KWRAyyc7kXUqv5DngT8rf7iU 44oxBvVNhyGrY5K0p9l9MMx0UhhYEfe2VI/xy3eRbjOKPWRKCQ6fcXoWJA4/OgIXK/ov Ehqddj4Zo7mf9YXfj0l5WtqvGvwiTvRy+d/viRETpg+q2G9S1tEOzYPv5JjqLz9AfwaU wG671/cNL7AatyKZH8fFgInuwdciZnMmp0GwYcCF0tt66G+kHivkEK5DCbR7egG3gHjW pNag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fFItq+Ek; 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 y16-20020a170906471000b0094e918d3a4csi831335ejq.881.2023.04.12.21.22.28; Wed, 12 Apr 2023 21:22:56 -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=fFItq+Ek; 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 S229895AbjDMEIH (ORCPT + 99 others); Thu, 13 Apr 2023 00:08:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229954AbjDMEHM (ORCPT ); Thu, 13 Apr 2023 00:07:12 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 431D976BB for ; Wed, 12 Apr 2023 21:07:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681358831; x=1712894831; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=INsqM7kHCgplauDTVYgaDtYvmiBKWDtVPT9hnQCqHlE=; b=fFItq+EkNtBBobiEP+RYlqv5pWUBrCugfOue5vslmgUU7Wjw3/Ut8IFb bayUGN6DeDOatzn0auVtFbbpU/nZmbapqKDUoPXhFO/21WuI5yl4m+3gX t1HYB1OTqQMD2RgHEWQh36TpU/8CSqv4l5dDbCfH6iXRdhmiKNbHFsFDM +nSrTHUPRkFlr+hiy1jylmXwSBmVdQJ5ny8Og/0GxFQbfdELyAZB02PAF AVHwaB4ZTdoTeuGvMDmZhnzsi6RIMKI9OpQSIlu6Ng5y27wkZw0eg+XWM pmcOuy3wufa6PuNckLZzsFnfSE7x5rnzMsoTJOe6RzaB/9zXUYdxMGsux w==; X-IronPort-AV: E=McAfee;i="6600,9927,10678"; a="332786660" X-IronPort-AV: E=Sophos;i="5.98,339,1673942400"; d="scan'208";a="332786660" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2023 21:07:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10678"; a="935361108" X-IronPort-AV: E=Sophos;i="5.98,339,1673942400"; d="scan'208";a="935361108" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga006.fm.intel.com with ESMTP; 12 Apr 2023 21:07:08 -0700 From: Lu Baolu To: Joerg Roedel Cc: Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 15/17] iommu/vt-d: Remove BUG_ON in map/unmap() Date: Thu, 13 Apr 2023 12:06:43 +0800 Message-Id: <20230413040645.46157-16-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230413040645.46157-1-baolu.lu@linux.intel.com> References: <20230413040645.46157-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, 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763033509289681876?= X-GMAIL-MSGID: =?utf-8?q?1763033509289681876?= From: Tina Zhang Domain map/unmap with invalid parameters shouldn't crash the kernel. Therefore, using if() replaces the BUG_ON. Signed-off-by: Tina Zhang Link: https://lore.kernel.org/r/20230406065944.2773296-6-tina.zhang@intel.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index f11347a590d7..ab21ef1ddb3c 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -2159,7 +2159,8 @@ __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn, phys_addr_t pteval; u64 attr; - BUG_ON(!domain_pfn_supported(domain, iov_pfn + nr_pages - 1)); + if (unlikely(!domain_pfn_supported(domain, iov_pfn + nr_pages - 1))) + return -EINVAL; if ((prot & (DMA_PTE_READ|DMA_PTE_WRITE)) == 0) return -EINVAL; @@ -4314,8 +4315,9 @@ static size_t intel_iommu_unmap(struct iommu_domain *domain, /* Cope with horrid API which requires us to unmap more than the size argument if it happens to be a large-page mapping. */ - BUG_ON(!pfn_to_dma_pte(dmar_domain, iova >> VTD_PAGE_SHIFT, &level, - GFP_ATOMIC)); + if (unlikely(!pfn_to_dma_pte(dmar_domain, iova >> VTD_PAGE_SHIFT, + &level, GFP_ATOMIC))) + return 0; if (size < VTD_PAGE_SIZE << level_to_offset_bits(level)) size = VTD_PAGE_SIZE << level_to_offset_bits(level);