Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3178977imw; Mon, 11 Jul 2022 03:40:06 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uyAvwU5HNM6ivbnUHpXTQH3q7W6+FW0RvjkVn6q+rYegHSUgEp9PM7M74I8amYNJvhwIYN X-Received: by 2002:a05:6a00:1acb:b0:525:b64b:79c3 with SMTP id f11-20020a056a001acb00b00525b64b79c3mr17953322pfv.76.1657536006002; Mon, 11 Jul 2022 03:40:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657536005; cv=none; d=google.com; s=arc-20160816; b=DGcLAAMeoywn7h+adch4fpMSWwuoXfqB5p4cWcOUDalh3lwxf1XfoWX03JEY3wcwEC DJYZ7MpMkHZbDiPsxzVEYg1+QC11TLkaw/CLxzX2vrf8WcRE6jnBZ2Ng6cGqB9apvA8z xA4WWywcvEyMVik4Iu09fqr76I9hTkQ2zzhvezlWWG0UcYWCHgQiX6wS0fwo8CuOt23S LVgB9zNDIQW9klPdaLQY6/IkR+2A0o+2nXvWhVCotuoijWQFqyycAL9wsGr7yJtDOoXG 7GjiFrQ5/Fw0yKBpz6xlRJxTOQNa7ehi47r+ObTCfHxP9TGof6/Pz2vX0Dvezhs+aI2U 4zIw== 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=aIwn61Lp/J+XjviOjXTPNCwueg4GaRvtnwY4F/Kw174=; b=YQXrS9LTQmgTS0nqhMh9e0Y7YNXSVmqG3HbJYCu4s4NHBSXW4zkn2oKG9DMdPSyqOf +FIrfG6E7uX+4CH9GlCz8bjUdtgvfxWahOK2MpDu/3/2kb/x4E+5sHdutx7ASZ++GiMd ByNjIYSLuFxT58dDa+UKGCcTH4uzi8S3wahWHll8kqewTAdlkOMGYSXPL4+fHKWq4xfy x2hRGP2DWWgypxyN6m0xpqx8YtO+GtVJ0sqo5egaKd3O1rY3xJQWnzzF0DrL41igQeEa XHyuT81YffYMgZdQ/Jj9yNPFKqAU/bU/IC7m3AmR8SZXfQMF1FXR/RjpRkoFcwjXHLrz +Sng== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linuxfoundation.org header.s=korg header.b=QDnKRZXj; 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 j8-20020a170902690800b0016c0569c012si8165159plk.588.2022.07.11.03.39.53; Mon, 11 Jul 2022 03:40:05 -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=QDnKRZXj; 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 S231199AbiGKJHX (ORCPT + 99 others); Mon, 11 Jul 2022 05:07:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230527AbiGKJHO (ORCPT ); Mon, 11 Jul 2022 05:07:14 -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 68FF222534; Mon, 11 Jul 2022 02:07:06 -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 BC36FB80E7A; Mon, 11 Jul 2022 09:07:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2DE9FC341CA; Mon, 11 Jul 2022 09:07:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657530423; bh=S8GfHA3b6Zbarn8g73Z5/mfjji8h8RDNnKivTthVQsA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QDnKRZXjolUqS2Qte6wA1MrlslE3M9JCOFicfFSuE14liTX72wtmL3AtQ9umbSfOc XCR1aAh1A8CguWAHkJR0tP5qB5/1kSGUbJANc+N9qyvvHpOcwt0cFCoNb63svlgTAb B2lJoXG1DcIX3qXo1lpZnfFWrbF5/UuwHCbfcHAs= 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 4.9 06/14] iommu/vt-d: Fix PCI bus rescan device hot add Date: Mon, 11 Jul 2022 11:06:25 +0200 Message-Id: <20220711090535.707526215@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220711090535.517697227@linuxfoundation.org> References: <20220711090535.517697227@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/dmar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/iommu/dmar.c +++ b/drivers/iommu/dmar.c @@ -373,7 +373,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 *