From patchwork Tue Apr 11 06:48:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 81775 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2380421vqo; Tue, 11 Apr 2023 00:11:29 -0700 (PDT) X-Google-Smtp-Source: AKy350Za+20VAdJKkQkE1UOFawgVH72CVR01A3cSDRqmFxgdeJV7AkaxZfMY+HoKncReOGjBGoZd X-Received: by 2002:a05:6a20:a926:b0:bb:b903:d836 with SMTP id cd38-20020a056a20a92600b000bbb903d836mr1483431pzb.54.1681197089080; Tue, 11 Apr 2023 00:11:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681197089; cv=none; d=google.com; s=arc-20160816; b=LpazrFtyeHTbk/9YM9PQddnchDp7qitAnS7BUtSE1GwjQ0T8sQ+Wp6S0fnALY9VW94 AJa05mn4XAt+B8pDheMOXWfQLeLEWkclwl/z58itfhMkTltRXiz36yKY1dn9rxU3T0KF UZ/tRcFOSuoxsN7ILD7jJJb827QDuo1USU5n6hs9wv+Nh9hdz3e5Gr/uyllwJBpV+q6W bG1fF5fZh3htbAy0DXWBZsYrX9oIHOL+5HxlG3MZ+ICZV6eOJC73DMEN0rLzRxH+kiIH t/gkUP5U0VW6/VMcZT1U5DMkBF49TXusAVWaCOOpTo30Naqkia+XmyE+Pd+Mm2Oz9qDp GuJw== 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=3lqyxVFiCeY9TSGILleT5k7M8saB/ecNiGz9Hk1gUdA=; b=HzZb7rkpyzz/7LhQlQrJd3As4qWarLuR9621BCQOUQaaaRU6/2IL4TYnfiPVhOWmzL Olgl3I677veEFAgO1JdbRMnYp6WbcYry2VZwmRcQ3hvxcKzHGvJBR10NMfcyuQdF3U+r /DncdKWXaqoAMfRPSrvq6gLh7rujNyaS1GFIczZDAja/g6/48EaEqjiApDTyTuuIe7VU TYkdjx3Q5P2wNPw0+IQLCo5sVnGNbfIHykquUotLNmsdlhKHnN6FJBZaLkPaAM+45klV bVmnO8c8HXr7kToncr7kpxvtyyIyWaSHYvCvOV9RUovgJsW8dVZp5MON+pl1n6/MUMZv gyCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kIW+aCys; 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 t5-20020aa79465000000b0063ae78d57f7si1638650pfq.69.2023.04.11.00.11.16; Tue, 11 Apr 2023 00:11:29 -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=kIW+aCys; 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 S230322AbjDKGvZ (ORCPT + 99 others); Tue, 11 Apr 2023 02:51:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230455AbjDKGvB (ORCPT ); Tue, 11 Apr 2023 02:51:01 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B6D53AA2 for ; Mon, 10 Apr 2023 23:50:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681195826; x=1712731826; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fGa6nb2+nmNFRDt+vgd1O06FQw1KI1Dbhhp5ECOkeNE=; b=kIW+aCys4lD6hXZtiL/eY38VZpRNUEXGUnU2IGka7+I/EDddG/NC3A0X YtHTHVADt8IckfaouP2LRtuU/Pf1hNaD2ccmxnoeQFh3oJKSY2HB/twSg gxafYtrvy58YlJNt6dTGwN7wy9MVTRsYXR7AcNFnLuYkL3+TxxsykPCCk FyWLj59aFdt4P+4k684doDKHjsL2BWexkn3UHYryPOvx4xaUX2pfeMhqc o8BN9+OODFEDg/UokQtJtjI2m8ESJ6joPWAdEWaFgyxOlyXOE2OKrSwuU v65vgfcp11AlHaihglSXcl3NhmUVwkH4I9MO7QoN8sILh3uKxtble8LST Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="341028642" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="341028642" 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:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10676"; a="1018256664" X-IronPort-AV: E=Sophos;i="5.98,336,1673942400"; d="scan'208";a="1018256664" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2023 23:48:46 -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 17/17] iommu/vt-d: Remove BUG_ON in dmar_insert_dev_scope() Date: Tue, 11 Apr 2023 14:48:15 +0800 Message-Id: <20230411064815.31456-18-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?1762862918771950698?= X-GMAIL-MSGID: =?utf-8?q?1762862918771950698?= From: Tina Zhang The dmar_insert_dev_scope() could fail if any unexpected condition is encountered. However, in this situation, the kernel should attempt recovery and proceed with execution. Remove BUG_ON with WARN_ON, so that kernel can avoid being crashed when an unexpected condition occurs. Signed-off-by: Tina Zhang Link: https://lore.kernel.org/r/20230406065944.2773296-8-tina.zhang@intel.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/dmar.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index 9346c6e7ebae..e35be3786bde 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -262,7 +262,8 @@ int dmar_insert_dev_scope(struct dmar_pci_notify_info *info, get_device(dev)); return 1; } - BUG_ON(i >= devices_cnt); + if (WARN_ON(i >= devices_cnt)) + return -EINVAL; } return 0;