Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1264667lqm; Thu, 2 May 2024 09:29:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVDE09Z8cuBId0v+sQh7bN9gFjEPRdW3Q+M6a+eZJQzUJPGJBigRt9nh9gh5ic/E92z1U8QSz7n4eBXx73hXxpiJ5khUZ0ISuxQ8drM/g== X-Google-Smtp-Source: AGHT+IEVDcp/tFRM3BrpaBqKnW1V/vDqvSIOc9gMktzzRMc6LYZ9/NqSD4cRzjzfc6dBaiKZVjPG X-Received: by 2002:a17:906:2b94:b0:a51:fef6:b7d6 with SMTP id m20-20020a1709062b9400b00a51fef6b7d6mr22006ejg.19.1714667356139; Thu, 02 May 2024 09:29:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714667356; cv=pass; d=google.com; s=arc-20160816; b=l2phveCux7WEnqPEiToc0KJrXz5l04QIDwFsFFbIvwiP6JhIEQJoD9IzcLwxdAwrhY y2ue2Lv7t9ty8Oer1hroW30flss43gcQiKGFtryNfw4dpNmzBAY/gy6sHMNYd5ZW4yzA ZMxaP+WGJ260sJ0BdL7iFwGaB0wgfJ/MfGqnFVQz1Up+iaco12S0YuzHBRxr8ZucPSNC Pppf1qsy/Fp1KZuTx9GKa3cv0Pbuo4iEVHv2WXT4d9y3kjNpyxL/BVmfx9xenomPD3xQ BFdjwekgCqJGBIolcVU/KKSlDzyXguSgL9ux3sFS3W/zahu3Iy5IForqApQt9OhyjFy7 eusQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-filter; bh=pGaAAC7U9OSU8oqKj4HdqFvQw4E0L+KuLXciIaLFu0k=; fh=qxBLNs11N0poJ5RI1YkohJRscdZwpiShH5QZAYJD/jY=; b=a/Oekms3sFeAnCLnteESzFo7IiSOyQrxrIfEWFc+71dgg+EqgUXg+djrnLi2rbDIqN n+abGAwe29GkJU4RwETdYRwwXLFbjXBZeoKc+JctKwMl7V1FGK+WzQhmyC4JPgybtWRG 1neW+dK/4ge1FZ2uR6SUutTLz4BUAaG/iR8YazyrVJTXiJk2h8H8/mTR79+9JnJDjdrK jasPoH4GHbWsugmf20ReIHe/yUxcN49u74hBrAKXRIDv+W/QK8lHNFYa0W9iGCHIziB9 0YQZ4y49+kPnu4WSTOdeLbuK44tvXOhk+exyo5Zkt/nt/s4TL7owVcuCnvAkkJ9Y+9xZ C6Rw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=oPsYETrx; arc=pass (i=1 spf=pass spfdomain=ispras.ru dkim=pass dkdomain=ispras.ru dmarc=pass fromdomain=ispras.ru); spf=pass (google.com: domain of linux-kernel+bounces-166726-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166726-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id cf22-20020a170906b2d600b00a55adfbdae8si646314ejb.12.2024.05.02.09.29.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 09:29:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-166726-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=oPsYETrx; arc=pass (i=1 spf=pass spfdomain=ispras.ru dkim=pass dkdomain=ispras.ru dmarc=pass fromdomain=ispras.ru); spf=pass (google.com: domain of linux-kernel+bounces-166726-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166726-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D3CE11F212FB for ; Thu, 2 May 2024 16:29:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C80D215EFD0; Thu, 2 May 2024 16:29:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b="oPsYETrx" Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DEB915E1EF for ; Thu, 2 May 2024 16:29:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.149.199.84 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714667344; cv=none; b=LyaS3M1RLE1eKGbFEeq7DdtfZU+FGeOYbHKjRw7k5/8zC9QA5bA3WwWJf5gy3vIkBk/M1lr6GWmCl0XRqCLQU18hRNF3+nhxpzmWfeL0nCtX0N2Df711Q4uhdyqkdpKh2SZMpJY14CdZRHM3gw4TizZDI1G8dYGRAD+wAFsgNMM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714667344; c=relaxed/simple; bh=V8KxA8VqpVmR+Zyu7dFeYSpT9k2Uk/1WVAAjXNpTZGw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y89NMpy/hNyLyuOcVf6rbX6Vbb+DXBsFLwzaJVtgEJyMnFvMEQVlsoHQsP220th2d/5m3jB4NDP2PMjue6IgWECPcJsfAMdkPC7NC1XunkkYXWbIqa3iKo0XzBfP9SGc7dOAaUzIcPhZbLL301naokH0mxOKhjYb2phPGTrUMBs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru; spf=pass smtp.mailfrom=ispras.ru; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b=oPsYETrx; arc=none smtp.client-ip=83.149.199.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ispras.ru Received: from fedor-21d0.intra.ispras.ru (unknown [10.10.165.8]) by mail.ispras.ru (Postfix) with ESMTPSA id DF41840762D9; Thu, 2 May 2024 16:18:53 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru DF41840762D9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1714666734; bh=pGaAAC7U9OSU8oqKj4HdqFvQw4E0L+KuLXciIaLFu0k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oPsYETrx1ZfxJcu5C//ePVQphhcDlzwZ5xiraGXybrLmid6kjpkmyKg/z9mi0STX+ +XK5DIZVh+QVfgdUIQIPkWPEqnTgwrPZtJjRltIw3k7XM0Cx4Kbql4/m0CPPXx4AaM DiGSV3v9OyUcMCJm2J+UhfV/UW235QEb8aKhArxU= From: Fedor Pchelkin To: Xiang Chen Cc: Fedor Pchelkin , Christoph Hellwig , Marek Szyprowski , Robin Murphy , Barry Song , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Alexey Khoroshilov , lvc-project@linuxtesting.org Subject: [PATCH 2/2] dma-mapping: benchmark: prevent potential kthread hang Date: Thu, 2 May 2024 19:18:26 +0300 Message-ID: <20240502161827.403338-3-pchelkin@ispras.ru> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240502161827.403338-1-pchelkin@ispras.ru> References: <20240502161827.403338-1-pchelkin@ispras.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit If some of kthreads executing map_benchmark_thread() return with an error code (e.g. due to a memory allocation failure), then the next kthreads in the array are not stopped and potentially loop for indefinite time. Call kthread_stop() for each started thread as map_benchmark_thread() expects that happening in order to exit. Found by Linux Verification Center (linuxtesting.org). Fixes: 65789daa8087 ("dma-mapping: add benchmark support for streaming DMA APIs") Signed-off-by: Fedor Pchelkin --- kernel/dma/map_benchmark.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kernel/dma/map_benchmark.c b/kernel/dma/map_benchmark.c index ea938bc6c7e3..7e39a4690331 100644 --- a/kernel/dma/map_benchmark.c +++ b/kernel/dma/map_benchmark.c @@ -140,13 +140,17 @@ static int do_map_benchmark(struct map_benchmark_data *map) msleep_interruptible(map->bparam.seconds * 1000); - /* wait for the completion of benchmark threads */ + /* wait for the completion of all started benchmark threads */ for (i = 0; i < threads; i++) { - ret = kthread_stop(tsk[i]); - if (ret) - goto out; + int kthread_ret = kthread_stop(tsk[i]); + + if (kthread_ret) + ret = kthread_ret; } + if (ret) + goto out; + loops = atomic64_read(&map->loops); if (likely(loops > 0)) { u64 map_variance, unmap_variance; -- 2.45.0