From patchwork Tue Apr 11 06:48:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 81769 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2373220vqo; Mon, 10 Apr 2023 23:55:11 -0700 (PDT) X-Google-Smtp-Source: AKy350ZibTZKWBhF1QxodLV60dAhIqOHgKHNwMPNXrUHiXsZglFNP54XYN6n8F+Qq0peCOuYBCak X-Received: by 2002:aa7:c54f:0:b0:504:8014:1554 with SMTP id s15-20020aa7c54f000000b0050480141554mr8709760edr.28.1681196111144; Mon, 10 Apr 2023 23:55:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681196111; cv=none; d=google.com; s=arc-20160816; b=w70E6QKnw4q+Id4LwdBWbvKuK+VbsMjiYfwOrTO9ePs43x72TAtbp7i7uJxrcsNAxw pdNwObvTkdvyNZDPTVH9GDs0oQcGHQbjq4S2JZvHpV23/mZfAkxJo4Ql2mjN94Jwq7zh HnSChxjyWMuxx339QcZrEIHqlrQgNb+1hVFDFvH3xzGxRTb8u987LkZL/N4ZvbaXfOII TdERvLfSgu5IqFc85az380H87dFd1K5GA4I2Xhf7vU6a5UaG08XK7BI6L1NZH1PpQIKn WzJjbUJ1flZQgSrOcwxtGOY6ZBT90GLBEWK3lRJbYW9mSTEc3QCjvYRPUCyM5UWf1ht6 yZTA== 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=hMuiJvcXemHYX/dZDy8Z65W61JRJJZl/+NLpuc0cxxM=; b=xjjgivjfwPvj3qXXGDO3pnsibRBnJFFMoDJPPjOZFq9Wr3Grytv+KSRECF+2yfOGjw MnsMFkuvcDPQ/rq5uH/cky7oZB7RXqA18Itr1I4gU+cyvVO5HmhWrzSoByrJP62Tgd7Q ZOo/+rATEBBU1/HhsVJsTKJoi2WRwS6Zxz+jYwlM1IWoQXiAcQMErnhezj2l00GheoIJ zOkMAGYvV+ctM2O7c5SMDSyUcIQ2ejC6v7O0QR7lNh0WyODMLeF7xdU9uzXQFBVPbfmy LsjfpdGvmoqjX96evrNFr6MWjxJjnUEQ/S0UlMqIlsUoYIgxP0hrcmC7zPCijTCKQn74 W0MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ai0sXJeg; 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 w23-20020aa7dcd7000000b00504b99d69basi943078edu.418.2023.04.10.23.54.45; Mon, 10 Apr 2023 23:55:11 -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=ai0sXJeg; 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 S230339AbjDKGun (ORCPT + 99 others); Tue, 11 Apr 2023 02:50:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230417AbjDKGuS (ORCPT ); Tue, 11 Apr 2023 02:50:18 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64F673AB8 for ; Mon, 10 Apr 2023 23:49:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681195786; x=1712731786; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fSH+9CuukwrVCuz9aJxEFN4y0MR5HKb9VSv4IIAZmfM=; b=ai0sXJeg+xpfqy16spN0Y5xT8RWsQ14duWiBqNrHWgerd2B9sJnRvC+w dGyHwCjA4GH1f/D5dF/3ATwYs9kaT+xqRjP74kCljco+5dpcv0Wg4JJi2 5ztxAo/y+1aQvkBQi3qPY8vBQTB3QFg4QOoSj82+e8JMkGFkAe09sUKI9 78dTL1aH7UtcOsa2wk5hNaEY91DsO7QATTAgA/SCzHVdh9QXm8DHDyIzQ 5L3+PtVUAFd+CW9BC75m6XGTnKQKmfeKbXpjmP7jsG0yYZyselbdfvFy+ DmAsJqSh94nP8mav56QGMDGGxLWGWUGT0LLy+Sv4SDiRo/l8A8ZvFxirr w==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028610" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028610" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2023 23:48:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256626" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256626" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:35 -0700 From: Lu Baolu To: Joerg Roedel Cc: Vinod Koul , Tina Zhang , Jacob Pan , Christophe JAILLET , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 12/17] iommu/vt-d: Remove BUG_ON on checking valid pfn range Date: Tue, 11 Apr 2023 14:48:10 +0800 Message-Id: <20230411064815.31456-13-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411064815.31456-1-baolu.lu@linux.intel.com> References: <20230411064815.31456-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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?1762861893633356793?= X-GMAIL-MSGID: =?utf-8?q?1762861893633356793?= From: Tina Zhang When encountering an unexpected invalid pfn range, the kernel should attempt recovery and proceed with execution. Therefore, using WARN_ON to replace BUG_ON to avoid halting the machine. Besides, one redundant checking is reduced. Signed-off-by: Tina Zhang Link: https://lore.kernel.org/r/20230406065944.2773296-3-tina.zhang@intel.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index acbf82fa90e7..c4847a5aaf52 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1005,9 +1005,9 @@ static void dma_pte_clear_range(struct dmar_domain *domain, unsigned int large_page; struct dma_pte *first_pte, *pte; - BUG_ON(!domain_pfn_supported(domain, start_pfn)); - BUG_ON(!domain_pfn_supported(domain, last_pfn)); - BUG_ON(start_pfn > last_pfn); + if (WARN_ON(!domain_pfn_supported(domain, last_pfn)) || + WARN_ON(start_pfn > last_pfn)) + return; /* we don't need lock here; nobody else touches the iova range */ do { @@ -1166,9 +1166,9 @@ static void dma_pte_clear_level(struct dmar_domain *domain, int level, static void domain_unmap(struct dmar_domain *domain, unsigned long start_pfn, unsigned long last_pfn, struct list_head *freelist) { - BUG_ON(!domain_pfn_supported(domain, start_pfn)); - BUG_ON(!domain_pfn_supported(domain, last_pfn)); - BUG_ON(start_pfn > last_pfn); + if (WARN_ON(!domain_pfn_supported(domain, last_pfn)) || + WARN_ON(start_pfn > last_pfn)) + return; /* we don't need lock here; nobody else touches the iova range */ dma_pte_clear_level(domain, agaw_to_level(domain->agaw),