Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp2120536lkv; Thu, 20 May 2021 03:54:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx99lqrr5aRGFueAFoNtFeDAUrQnhY3eof04MKoHDIOZYfv4KGPDCvVexTKIhxtyiMF2LDz X-Received: by 2002:a17:907:76d9:: with SMTP id kf25mr4147434ejc.340.1621508058150; Thu, 20 May 2021 03:54:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621508058; cv=none; d=google.com; s=arc-20160816; b=kCFqyrGy+E7Wg0HRL+mvfiV2IdmTzYbr+aosXlN0r0vk72t7B4EjUBqHT/ol5n/yuD o5HvZmg7cbKt796F1iGyyJije49px7YuHHrqA9W3bWGeh2O5KY5T3ijtQlTgEZPi1b0W VpQyZKJVRsHVjiHUcbqXBo9NapzXdikEneRUYo3t2ddtYIwxUKEqh70YowbaunJcWsXm XZKv/nfbsZcY0IGwXFo5rKald5GP+ZqxkCrPjhdKyixiWJIG5F5QJum4RawiCPDWpXUQ 2n0eJrhpyRFf5A+aNGFTW8JDCT7EGZ4Xj31OpIeRau2Tn/P1AShme6hOEqnWoh2icYVq I+4g== 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=NKSCrVoVh/WYzPI+jzmcaXmxZT8v3E7i7tmyxGp5dOg=; b=sovgfT5gt5Tk6bZP2wcedyPZXpNlV/HbyQ2p5KMMd6KjXBlwG6OM1yQe3zJ2vLWGXY y5ZRemEu2Uw129nNNLv3z3OH2BKP+kRUVcUhE/Gfkz/MUl65XLHlHraNcRJYXFqFaUxn RcR5gq8VKQf9edXSoADq36/P1FCoy0GQC9P+prZ2Hy/7eV7bTP5GJZ1ICdjOTypXKWkJ bANlDGLRrWHrWqDqpsT81rRe+7R1TgwH/ToQ910FWIX6ti83j4FF9abT7R9CiOPMOqsh oEMWYPEu5luAQZeoJxoBVNXYrPQv0RGm3LciV5ahNYq/GV4Dlqp4ifW1W/m4zC1HZzBW jgHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aaO076N+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p5si2239325edt.116.2021.05.20.03.53.44; Thu, 20 May 2021 03:54:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aaO076N+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S238497AbhETKwI (ORCPT + 99 others); Thu, 20 May 2021 06:52:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:39712 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237117AbhETKgo (ORCPT ); Thu, 20 May 2021 06:36:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 791B761C6B; Thu, 20 May 2021 09:54:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504459; bh=0/4WVdzc0NSCjcjf7ars5PvVyLaxOrQk0Auir7Ha9TE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aaO076N+MQplrm4bu6HVLKJ1dIfQVp7n9W/VH7s7EN7JHYxXuKfKOmA8UbJn49csu NZOub2JSM/UyddO22IcErVbiW0l+DLjQM9+3dGpAE0N16sXhpaw6no+IiFmTGSFREV Jo6HzbdA5sb/qub54ndtv8bdHj83JZVj/OyyRRFs= 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 4.14 256/323] powerpc/iommu: Annotate nested lock for lockdep Date: Thu, 20 May 2021 11:22:28 +0200 Message-Id: <20210520092128.984931586@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexey Kardashevskiy [ Upstream commit cc7130bf119add37f36238343a593b71ef6ecc1e ] The IOMMU table is divided into pools for concurrent mappings and each pool has a separate spinlock. When taking the ownership of an IOMMU group to pass through a device to a VM, we lock these spinlocks which triggers a false negative warning in lockdep (below). This fixes it by annotating the large pool's spinlock as a nest lock which makes lockdep not complaining when locking nested locks if the nest lock is locked already. === WARNING: possible recursive locking detected 5.11.0-le_syzkaller_a+fstn1 #100 Not tainted -------------------------------------------- qemu-system-ppc/4129 is trying to acquire lock: c0000000119bddb0 (&(p->lock)/1){....}-{2:2}, at: iommu_take_ownership+0xac/0x1e0 but task is already holding lock: c0000000119bdd30 (&(p->lock)/1){....}-{2:2}, at: iommu_take_ownership+0xac/0x1e0 other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&(p->lock)/1); lock(&(p->lock)/1); === Signed-off-by: Alexey Kardashevskiy Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20210301063653.51003-1-aik@ozlabs.ru Signed-off-by: Sasha Levin --- arch/powerpc/kernel/iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c index 80b6caaa9b92..87af91937c8a 100644 --- a/arch/powerpc/kernel/iommu.c +++ b/arch/powerpc/kernel/iommu.c @@ -1055,7 +1055,7 @@ int iommu_take_ownership(struct iommu_table *tbl) spin_lock_irqsave(&tbl->large_pool.lock, flags); for (i = 0; i < tbl->nr_pools; i++) - spin_lock(&tbl->pools[i].lock); + spin_lock_nest_lock(&tbl->pools[i].lock, &tbl->large_pool.lock); if (tbl->it_offset == 0) clear_bit(0, tbl->it_map); @@ -1084,7 +1084,7 @@ void iommu_release_ownership(struct iommu_table *tbl) spin_lock_irqsave(&tbl->large_pool.lock, flags); for (i = 0; i < tbl->nr_pools; i++) - spin_lock(&tbl->pools[i].lock); + spin_lock_nest_lock(&tbl->pools[i].lock, &tbl->large_pool.lock); memset(tbl->it_map, 0, sz); -- 2.30.2