Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2265324rwb; Thu, 17 Nov 2022 08:31:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf7ODxIAzHkAiiQ0bsgk1DvkByiLgRpPKmtrX3fNIbb/wnPFYwvosPYM8AiM5W/RgrVqCa/b X-Received: by 2002:a17:90a:d50c:b0:218:722e:cac7 with SMTP id t12-20020a17090ad50c00b00218722ecac7mr3592880pju.47.1668702680211; Thu, 17 Nov 2022 08:31:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668702680; cv=none; d=google.com; s=arc-20160816; b=lu88zXFTri0S5F/38A3KPxZE3lq1HWo083O/pbITlfhBmVnmaBpYx+fzAfAJaMcO/r yCKsT+Lq7d8HjQHJZRWnUDI5J5VqI4lcSPCgqvhaVQk84k94zeRGbtrHo3Kz1o2G9xCS zPehf4pFwHzihkvsOec/uJrJiv0znEp/suZ6V3LHbRc/+JWL15cA/Mo/zEjLNVd1wzJF 9extqwtLZSmYz9t6qvCSEuSRiz5dfWO3y8RkGr2zm87VR8RcrxOVvuaiqiYQZJtPky4u GurQImgFZJZ8wLTImkKIiDFHyUVvVNB0mLDjvHniTwGgourVJ4rJOkHVcpNpoTua3kjg mMiA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6Zz9ziSom7Tl1La/0lp2vIf1hw7aWyCS9zu2uWflvJQ=; b=Sqq+FKD2q09flgc+d6BoTivOsxI7gNbTFiVSYNSyDxlNWdP8y2arIQl4tAApTQ1Qw8 JNjSaErThCXbn5Nki2+Uslov7mueC3A9/Hrk4Mxrhm4USGvrWI0/0Ca2ORyN7O41qecM t5SmGWwDMkxh4rSKOBH0VGMBrjA3AoVrzaszWCKpvl1sFGGMsr4layU5qTWSZ5+haAie R7RtDiO4pO+E0OkNDE5YnTjAUJGOAQnOczTJGP8PgvYYT2K5CcALNNJOBawrAN2Q92JE 33lUPvzDnKZQi060VWVIFdho9H+fSCu0WrYzzdc3LQ6MEsYmIenff0Z+knKkd28w3+UJ VvwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kZwM2Aou; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i8-20020a1709026ac800b001884e351466si1235346plt.467.2022.11.17.08.31.06; Thu, 17 Nov 2022 08:31:20 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=kZwM2Aou; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240562AbiKQQVR (ORCPT + 92 others); Thu, 17 Nov 2022 11:21:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240428AbiKQQUl (ORCPT ); Thu, 17 Nov 2022 11:20:41 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95AC87AF7C for ; Thu, 17 Nov 2022 08:20:22 -0800 (PST) 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 31A14B8210B for ; Thu, 17 Nov 2022 16:20:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07BE9C433C1; Thu, 17 Nov 2022 16:20:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668702019; bh=YAKqdM7h7qVJaewu+jPaUrt4aE7EX+bze99EdvKRQ1E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kZwM2AouHs7ushJpOB6Qdgx6wLFdtb0ll/NY5k8wwRtCWIq1ZI1UKi8GlweqkxNQ+ 1Qf2IhtZVySQgUjaE9jLe65eqcADBYC2n8iqPBdNWqUBHh2zuw85Ayq/IfBSPRTb/o /QuKU5p8KVMp2YWjZkHphnvI5ntpLO3QT4fdYEgMiC03vuQ2l0UrCnhiIDdkIgOd5R eR11WCfr/1odA6k4Nvpbhkb0WfbYxeiJLZnJ/8vUvKWvAt8nPqCApJHdr/lN63f7UO iOSciE3H5p3uWsZ88V421gLS5nNemQopMWNDTHYHJA/HAfA88tyMoDOt+wL6SEA/8w JaSJyBTbpf8dQ== From: Oded Gabbay To: linux-kernel@vger.kernel.org Cc: Tomer Tayar Subject: [PATCH 18/20] habanalabs: extend process wait timeout in device fine Date: Thu, 17 Nov 2022 18:19:49 +0200 Message-Id: <20221117161951.845454-18-ogabbay@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221117161951.845454-1-ogabbay@kernel.org> References: <20221117161951.845454-1-ogabbay@kernel.org> MIME-Version: 1.0 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 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 Processes that use our device are likely to use at the same time other devices such as remote storage. In case our device is removed and a user process is still using the device, we need to kill the user process. However, if that process has a thread waiting for i/o to complete on remote storage, for example, the process won't terminate. Let's give it enough time to terminate before giving up. Signed-off-by: Oded Gabbay Reviewed-by: Tomer Tayar --- drivers/misc/habanalabs/common/device.c | 6 ++++-- drivers/misc/habanalabs/common/habanalabs.h | 11 ++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/misc/habanalabs/common/device.c b/drivers/misc/habanalabs/common/device.c index 0650e511a0f5..63d0cb7087e8 100644 --- a/drivers/misc/habanalabs/common/device.c +++ b/drivers/misc/habanalabs/common/device.c @@ -2300,14 +2300,16 @@ void hl_device_fini(struct hl_device *hdev) */ dev_info(hdev->dev, "Waiting for all processes to exit (timeout of %u seconds)", - HL_PENDING_RESET_LONG_SEC); + HL_WAIT_PROCESS_KILL_ON_DEVICE_FINI); - rc = device_kill_open_processes(hdev, HL_PENDING_RESET_LONG_SEC, false); + hdev->process_kill_trial_cnt = 0; + rc = device_kill_open_processes(hdev, HL_WAIT_PROCESS_KILL_ON_DEVICE_FINI, false); if (rc) { dev_crit(hdev->dev, "Failed to kill all open processes\n"); device_disable_open_processes(hdev, false); } + hdev->process_kill_trial_cnt = 0; rc = device_kill_open_processes(hdev, 0, true); if (rc) { dev_crit(hdev->dev, "Failed to kill all control device open processes\n"); diff --git a/drivers/misc/habanalabs/common/habanalabs.h b/drivers/misc/habanalabs/common/habanalabs.h index 0781b8698f74..e7f89868428d 100644 --- a/drivers/misc/habanalabs/common/habanalabs.h +++ b/drivers/misc/habanalabs/common/habanalabs.h @@ -50,9 +50,14 @@ struct hl_fpriv; #define HL_MMAP_OFFSET_VALUE_MASK (0x1FFFFFFFFFFFull >> PAGE_SHIFT) #define HL_MMAP_OFFSET_VALUE_GET(off) (off & HL_MMAP_OFFSET_VALUE_MASK) -#define HL_PENDING_RESET_PER_SEC 10 -#define HL_PENDING_RESET_MAX_TRIALS 60 /* 10 minutes */ -#define HL_PENDING_RESET_LONG_SEC 60 +#define HL_PENDING_RESET_PER_SEC 10 +#define HL_PENDING_RESET_MAX_TRIALS 60 /* 10 minutes */ +#define HL_PENDING_RESET_LONG_SEC 60 +/* + * In device fini, wait 10 minutes for user processes to be terminated after we kill them. + * This is needed to prevent situation of clearing resources while user processes are still alive. + */ +#define HL_WAIT_PROCESS_KILL_ON_DEVICE_FINI 600 #define HL_HARD_RESET_MAX_TIMEOUT 120 #define HL_PLDM_HARD_RESET_MAX_TIMEOUT (HL_HARD_RESET_MAX_TIMEOUT * 3) -- 2.25.1