Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3024229rwb; Mon, 15 Aug 2022 16:22:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR4rek7PBQ3onTti7wdqBHTzp+sgFpvqoRezgSwnF5JD4Uia8PLTpjeQTYryf+dF8IugOyWr X-Received: by 2002:a17:90b:3e86:b0:1f5:2b4f:7460 with SMTP id rj6-20020a17090b3e8600b001f52b4f7460mr30768315pjb.97.1660605607821; Mon, 15 Aug 2022 16:20:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605607; cv=none; d=google.com; s=arc-20160816; b=FtPPaVDfsPFl3Vm6FylFQMLALCkKfOoSLllQr6IeD5BqRt5rlstVYG+T+XyHlJjyWt tUEV8o50DZWQHNPpwPS4MZ0iVhXRYnGqu0zaGP0Wq/KXioVhguMPDlPP/PcBxqE+WqbH sFdHgDAN00Z29YFmolJQiZHbSLhGJ4ls5mqMBTS5R5Tp7CpvcVCleY7Fv2pXwUZss1RQ d6vA9lR8q04Jlk0ohn2//fu9ZUF4LkOgdzNIHbrXbUhnJ/B4YQpMMiC+4WME61/vJpzM ll3R34dI2TZfNS1PiMrm7JeUUJ392IQ5SNpukF1kcCFWu7lbzQZIcVEUk6QVKuzdEODa LxSw== 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=AT05tdH4T3ZwrsL9MOKFQZjQYE4ow1u9yFhucrxYPMx6cxCATqsLjDhB7Ly0WnYrp1 D3ogmjeD+whW/jf4/1RZUNmiqwc6WeqtQBe6KY3/muFsNC/3V3aCfGAmU2qeYeD6rHAk T8OEpKw1U8ftEq1BKjatFDDWukZjUAJ5byMoS5TEESYFTDrs2V20sjpRAxSHULipaOzZ v6fNxD/iMia8RSui2XHVC7B+GppqLrJc98FaK22rk8iLpZmiuZ3cKySwHaNWpHOi8ysc LbsCpkXNO36/nV4a7XZ7alW2xKK2jEIndg7yKkKhO7F7KYABa4n6rePq/OOA2es9r90d Ro9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cvuPv5vV; 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 x3-20020a17090a2b0300b001f7283763fesi17293116pjc.44.2022.08.15.16.19.56; Mon, 15 Aug 2022 16:20:07 -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=cvuPv5vV; 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 S1352226AbiHOWxV (ORCPT + 99 others); Mon, 15 Aug 2022 18:53:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352428AbiHOWvt (ORCPT ); Mon, 15 Aug 2022 18:51:49 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F2BE1394C4; Mon, 15 Aug 2022 12:54:28 -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 4CB63B80EAD; Mon, 15 Aug 2022 19:54:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A29F3C433D6; Mon, 15 Aug 2022 19:54:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660593266; bh=CM7F2rOUBmfcXUgNZhY9n4+a8WWv8wo3ROGfc/dqlQo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cvuPv5vVf+Dnn6imBD68MUdYsSap3IZwqiHj/30lVoQBXKYwR/IhspWhvmQ41VW7i PC7xj4gRboc5XBV4/98p5E8VOjO2AOpNBKNeFK8SlPNkSZs3ufWBjEfo99xMrXBYA3 CwhTdgbubTJ6gItPlITSNEBvbsEm48UbtsrMiq50= 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.18 0920/1095] powerpc/iommu: Fix iommu_table_in_use for a small default DMA window case Date: Mon, 15 Aug 2022 20:05:19 +0200 Message-Id: <20220815180507.336070485@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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