Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3165404imw; Mon, 11 Jul 2022 03:19:35 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vweG9n6pBAh1N2Rf+JOEyOF3lAokvLwaPdl+PqUR4/+vsCYNAKjKeOYS2eN7raE/7mbvR8 X-Received: by 2002:a17:907:6e13:b0:72b:509e:bd6b with SMTP id sd19-20020a1709076e1300b0072b509ebd6bmr5659815ejc.202.1657534774908; Mon, 11 Jul 2022 03:19:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657534774; cv=none; d=google.com; s=arc-20160816; b=VZ1xXoJAfeizQJtIEJGsygt/FVFthY3UvPxBn22q3XNgpQjcZFIHHXNbEkOjVA3V6/ vJWm85ytc5bEqL0SDmGd9EpRaCVIzwgLpLG3+8vo9lzbMHdD4rz4olvAo7jK/05pB4Md Gl7ZBdo/mnSd6/u3zZR15FkGIdxQTIA0tUvSdyJ+SqzaKbk6hmsD9/VgM6x28baks8di F2pv4TYZGToFRMB953mA8LVUyRStO+h9iUxjgLdT2J7oSwvMng0nOQP8z1zdxxKhRzCc v8vD42tqR/E4GnL/XZYGevUCzmEwXDgng54JscBO/JtZJBeSKiIIM7GxwyXkSCZxhzOo Rj3Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=W2mjJ3biCctLqUKQgrkrRMMts/McnVrAKQUjpsr5EzI=; b=yJHFQ+GlUqBRALHcby83ytKnNTf9lUF3XkidBPMpPSrv5SWw2+TkeQ6dl8HXYQDj/z hrpTDRvDIQZ1Z6E7zw6RtIROxIsNu5lqf8YWtHtazig5yOL7OO8xfJkt6jGgfJAdTiBk IKa5gcZmLDdrV9ldghnUzT7V+DD56IYgW7Qyefc+53xejpAkUB2LKukybL1Gw2sz+TXc xJw9uB/n42XQun+uXH/Msn4S3hCAQeyq71vs9oCX7C1jA/18RSmd98j0R6IZ6+pIp7jE e2+9Un2oe6iTCyCANYEy/YgY/Rd0lS2/Hm8zu0XrrlzwDVWuGE4W2BM4CDnTpfRKcTKs y8QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linuxfoundation.org header.s=korg header.b="XhV/g3LD"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mz13-20020a1709071b8d00b00726a3abf022si5870107ejc.781.2022.07.11.03.19.09; Mon, 11 Jul 2022 03:19:34 -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=fail header.i=@linuxfoundation.org header.s=korg header.b="XhV/g3LD"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231440AbiGKJTU (ORCPT + 99 others); Mon, 11 Jul 2022 05:19:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231449AbiGKJSf (ORCPT ); Mon, 11 Jul 2022 05:18:35 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EC0D4D4C9; Mon, 11 Jul 2022 02:11:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E5D65B80D2C; Mon, 11 Jul 2022 09:11:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B88AC34115; Mon, 11 Jul 2022 09:11:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657530709; bh=ruQ50WIOI0+7m3siYikWENO+ppOpQi5iT7iajfkpbn4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XhV/g3LDc/DHF6exZ9Fp29SevXhFRpr5W8rRyAEvYcPqOTPi01rOL6e9SzbGTAX68 AwaVamlIDYyE9zdzIKDAhRQ+rqt4oL2C2b5hx88jmGGfpZMzGz8SjoN/PIFz7bbPZx Zl42qiR7Fq/L0t4D0///z/bx1rCqp83BTfkOULXE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Zhang, Bernice" , Jacob Pan , Yian Chen , Joerg Roedel , Zhang@vger.kernel.org Subject: [PATCH 5.10 12/55] iommu/vt-d: Fix PCI bus rescan device hot add Date: Mon, 11 Jul 2022 11:07:00 +0200 Message-Id: <20220711090542.122959295@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220711090541.764895984@linuxfoundation.org> References: <20220711090541.764895984@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Yian Chen commit 316f92a705a4c2bf4712135180d56f3cca09243a upstream. Notifier calling chain uses priority to determine the execution order of the notifiers or listeners registered to the chain. PCI bus device hot add utilizes the notification mechanism. The current code sets low priority (INT_MIN) to Intel dmar_pci_bus_notifier and postpones DMAR decoding after adding new device into IOMMU. The result is that struct device pointer cannot be found in DRHD search for the new device's DMAR/IOMMU. Subsequently, the device is put under the "catch-all" IOMMU instead of the correct one. This could cause system hang when device TLB invalidation is sent to the wrong IOMMU. Invalidation timeout error and hard lockup have been observed and data inconsistency/crush may occur as well. This patch fixes the issue by setting a positive priority(1) for dmar_pci_bus_notifier while the priority of IOMMU bus notifier uses the default value(0), therefore DMAR decoding will be in advance of DRHD search for a new device to find the correct IOMMU. Following is a 2-step example that triggers the bug by simulating PCI device hot add behavior in Intel Sapphire Rapids server. echo 1 > /sys/bus/pci/devices/0000:6a:01.0/remove echo 1 > /sys/bus/pci/rescan Fixes: 59ce0515cdaf ("iommu/vt-d: Update DRHD/RMRR/ATSR device scope") Cc: stable@vger.kernel.org # v3.15+ Reported-by: Zhang, Bernice Signed-off-by: Jacob Pan Signed-off-by: Yian Chen Link: https://lore.kernel.org/r/20220521002115.1624069-1-yian.chen@intel.com Signed-off-by: Joerg Roedel Signed-off-by: Greg Kroah-Hartman --- drivers/iommu/intel/dmar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -385,7 +385,7 @@ static int dmar_pci_bus_notifier(struct static struct notifier_block dmar_pci_bus_nb = { .notifier_call = dmar_pci_bus_notifier, - .priority = INT_MIN, + .priority = 1, }; static struct dmar_drhd_unit *