Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2275563iof; Wed, 8 Jun 2022 01:08:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxw+WRNXPdt/W6wVIymitAO2261Ete8ARW9b6k1k7NAP51CvlOfpfIDGa3iWIsy2jySJ1xT X-Received: by 2002:a05:6a00:18a7:b0:51b:c63f:1989 with SMTP id x39-20020a056a0018a700b0051bc63f1989mr31948904pfh.49.1654675733716; Wed, 08 Jun 2022 01:08:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654675733; cv=none; d=google.com; s=arc-20160816; b=yZQCttdpp6/XtV6hwXaX2pIAFCiFoTlO0eA8O/vN3Qw5tvX3mRugygD3I650LebLuQ wYebw2kbgOCIypv1NFbaVnWPhNNOjBC16+ZvBUnK7X7R+IXU6qwDZG5GBBa6RLaq1c9E 3HN4nsZkLMPSqwMgz+Q4VnabvreisptKPnvI+/Efz5FbnUmRAsdEBeJsLmi325n685Vb s0TXHtQFKF5KpXhkmvx3bjedClbABu/ZO4DICRFaiEXainpH/bpbAW2PTkMEcU7eI09N iGzlyMCHo6IPtFA9r40o7U39Z/SOOKsBhdrHSEgHvZRUqZvHiBtX6tg51IZXu72XRQwG NJ7w== 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=7kmw1zhfWaEdLKRSGDpCHho6lQbkMCOFpgLX+BRhZXI=; b=Z9IUKaoaj10WBmKjL3vsQm5ZwocrOLEi2c7fUFNrIdnv+UOpesSiHjoHVx9C7nenz2 0f62RjMQ8jrYb0s68VEzHow/M2M6MIA/TZWLw3bG6EUXqQoIBEj6cUvy2zcjUkuzfpYR D8a+2UNwPUqosbfCqivvyyX1PI29yiEpuF31IXuirTIhyTYJwYmT9tm4Jpsbk71pqhwR G6iaJSZtkDhhc8dGhTUL5suGF1XaRmGsynsTXlT4XqpOkFI88ASNMHQdFDW5YdvQ/kiP S6LTwQ1BOqZ68WuVZrKmr32Xwe7r6PFGVFPPA1iz/RxodBIHY5t7d0O1xxwJsXrIJzjj GzBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vTu+0ou5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id t13-20020a17090340cd00b001675d8490e4si13353327pld.563.2022.06.08.01.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 01:08:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vTu+0ou5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A9DAE29B150; Wed, 8 Jun 2022 00:39:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442089AbiFHAxx (ORCPT + 99 others); Tue, 7 Jun 2022 20:53:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383005AbiFGWEv (ORCPT ); Tue, 7 Jun 2022 18:04:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE14A28E09; Tue, 7 Jun 2022 12:16:02 -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 7E0E461846; Tue, 7 Jun 2022 19:16:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90C43C385A2; Tue, 7 Jun 2022 19:16:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629361; bh=9sepHHtUi18mB/sNM9vPJeMOF6rk7ZfA+svdQRMycS8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vTu+0ou5KpNd90Ze451I/ugSwunjoZD78rxH0tS3Ef8hRY8+yCXmQhN7HvWkPUrCi XW1Oa2St+hyPmdJkn/RUZGblyF0XQUnFjG2OrQPE7hLuZtGWmVF6e7Il6AUZXNolzU ZGI05TpwGXGdWcpuHJRqfZ3OQ4kIZkaO7aGgj8zQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Suravee Suthikulpanit , Joerg Roedel , Sasha Levin Subject: [PATCH 5.18 663/879] iommu/amd: Do not call sleep while holding spinlock Date: Tue, 7 Jun 2022 19:03:01 +0200 Message-Id: <20220607165022.091002816@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: Suravee Suthikulpanit [ Upstream commit 5edde870d3283edeaa27ab62ac4fac5ee8cae35a ] Smatch static checker warns: drivers/iommu/amd/iommu_v2.c:133 free_device_state() warn: sleeping in atomic context Fixes by storing the list of struct device_state in a temporary list, and then free the memory after releasing the spinlock. Reported-by: Dan Carpenter Fixes: 9f968fc70d85 ("iommu/amd: Improve amd_iommu_v2_exit()") Signed-off-by: Suravee Suthikulpanit Link: https://lore.kernel.org/r/20220314024321.37411-1-suravee.suthikulpanit@amd.com Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/amd/iommu_v2.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/amd/iommu_v2.c b/drivers/iommu/amd/iommu_v2.c index e56b137ceabd..afb3efd565b7 100644 --- a/drivers/iommu/amd/iommu_v2.c +++ b/drivers/iommu/amd/iommu_v2.c @@ -956,6 +956,7 @@ static void __exit amd_iommu_v2_exit(void) { struct device_state *dev_state, *next; unsigned long flags; + LIST_HEAD(freelist); if (!amd_iommu_v2_supported()) return; @@ -975,11 +976,20 @@ static void __exit amd_iommu_v2_exit(void) put_device_state(dev_state); list_del(&dev_state->list); - free_device_state(dev_state); + list_add_tail(&dev_state->list, &freelist); } spin_unlock_irqrestore(&state_lock, flags); + /* + * Since free_device_state waits on the count to be zero, + * we need to free dev_state outside the spinlock. + */ + list_for_each_entry_safe(dev_state, next, &freelist, list) { + list_del(&dev_state->list); + free_device_state(dev_state); + } + destroy_workqueue(iommu_wq); } -- 2.35.1