Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2882327rwb; Mon, 15 Aug 2022 13:14:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR6HGtESEvHEz4HcW8XnVKTNOne6GfNhX1ZuhifKB9X1wmQfFQJfEkrTsRNY2oPnRbI486kO X-Received: by 2002:aa7:cd51:0:b0:440:595d:aeed with SMTP id v17-20020aa7cd51000000b00440595daeedmr15909479edw.143.1660594460278; Mon, 15 Aug 2022 13:14:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660594460; cv=none; d=google.com; s=arc-20160816; b=UK19JlEAB8FzndRKUcaTEVY550UElNvhqB7ojW4SRsIsQRBQfygP+0FQHc7lPpPBwP 2nOySiHzProo0ozlSb4+JFOpB1YYggJgLfgzKOXquuiXSWfZYzcWy7sqQt++Rt4EQD3+ /hEzjG5qOc6n3kJ7J52adeFi5O5ZgAKBcCIUaXYjmeeFQ71NgYnlFk97+sB+YHuXRX3b 8YQG40FmfFWjq6+LeyVIXkuA6f0c35hXNBzpw5RThzKoHAylFGU/73jqC/VzFbqoue3y KzEcBhdKeqZ8AAT6/9amMspc+jJ6i4FTv3a+ceZB2A4HL82aRU6MZBOkSH0ZRI6dIF/y 1Yyw== 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=hlBN0ZX2F09swRYuUcnRiKrVn8Kh/HPU4sGAaLMYmXA=; b=S7odToWFywLXlVYaWzAWUsRCOAnSVR3UWJXspqzmTaueGVKuKDzM5TEqQniGSjfIjH skOtFzlEZVruavDfzTZTv4Ny5VMtrwGvAnE8L3ZbR6nHG9oedd/Cc1E9PS99J2KYeMBn tpJOkkFTUkl3gGuzPXnTyWGC7+p7GB8HwTa1kp5oz98gDAcIpUo9DHwZ7kOFeZHPSi9P Mgn5gqtThKK9YfC3CYOnVaSPHcmFaCuFLUX6e2SD3FCyrH02GZpoGkadvyYik9hNAXr3 kNSp2D0Gs3VMwZxrBUG9FNUBkkrRJJo7XLg8e2rUUhQXs5j6SECnJz4CWAlxvfGjhXZf hMyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cjI7B6Gt; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w14-20020a05640234ce00b0043be308c841si9170073edc.251.2022.08.15.13.13.54; Mon, 15 Aug 2022 13:14:20 -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=@linuxfoundation.org header.s=korg header.b=cjI7B6Gt; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344350AbiHOTkN (ORCPT + 99 others); Mon, 15 Aug 2022 15:40:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244340AbiHOTg6 (ORCPT ); Mon, 15 Aug 2022 15:36:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECD3F31235; Mon, 15 Aug 2022 11:46:15 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 7E3CF611DD; Mon, 15 Aug 2022 18:46:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8AFA3C433C1; Mon, 15 Aug 2022 18:46:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660589174; bh=CM7F2rOUBmfcXUgNZhY9n4+a8WWv8wo3ROGfc/dqlQo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cjI7B6GtJBSDb2QKNois5N9NfLoAxFd1hZ1jfUHOCf2pcqANjc0j+pApBP9/W5Xoy nfZfS9RUQ5Hwt93xJnkVn+WFGoxEXjtCsBGPLSGPkY+WaffFHDCXMrrL6O2HtEp6Qc voK50F0rVuzHcZaHFdaRvNcKnf8zZNla1c/AP8DM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexey Kardashevskiy , Michael Ellerman , Sasha Levin Subject: [PATCH 5.15 637/779] powerpc/iommu: Fix iommu_table_in_use for a small default DMA window case Date: Mon, 15 Aug 2022 20:04:41 +0200 Message-Id: <20220815180404.569679022@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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: Alexey Kardashevskiy [ Upstream commit d80f6de9d601c30b53c17f00cb7cfe3169f2ddad ] The existing iommu_table_in_use() helper checks if the kernel is using any of TCEs. There are some reserved TCEs: 1) the very first one if DMA window starts from 0 to avoid having a zero but still valid DMA handle; 2) it_reserved_start..it_reserved_end to exclude MMIO32 window in case the default window spans across that - this is the default for the first DMA window on PowerNV. When 1) is the case and 2) is not the helper does not skip 1) and returns wrong status. This only seems occurring when passing through a PCI device to a nested guest (not something we support really well) so it has not been seen before. This fixes the bug by adding a special case for no MMIO32 reservation. Fixes: 3c33066a2190 ("powerpc/kernel/iommu: Add new iommu_table_in_use() helper") Signed-off-by: Alexey Kardashevskiy Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20220714081119.3714605-1-aik@ozlabs.ru Signed-off-by: Sasha Levin --- arch/powerpc/kernel/iommu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c index 07093b7cdcb9..a67fd54ccc57 100644 --- a/arch/powerpc/kernel/iommu.c +++ b/arch/powerpc/kernel/iommu.c @@ -776,6 +776,11 @@ bool iommu_table_in_use(struct iommu_table *tbl) /* ignore reserved bit0 */ if (tbl->it_offset == 0) start = 1; + + /* Simple case with no reserved MMIO32 region */ + if (!tbl->it_reserved_start && !tbl->it_reserved_end) + return find_next_bit(tbl->it_map, tbl->it_size, start) != tbl->it_size; + end = tbl->it_reserved_start - tbl->it_offset; if (find_next_bit(tbl->it_map, end, start) != end) return true; -- 2.35.1