Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2331888rwb; Thu, 17 Nov 2022 09:21:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ipTGygSsCo8K+gZUvsnUmTyOpRuSr5EpkkKeR4P217sGTXDpggkJZpNQzQ8KVC+UVjpAV X-Received: by 2002:aa7:d156:0:b0:468:51b0:295 with SMTP id r22-20020aa7d156000000b0046851b00295mr3010164edo.319.1668705662817; Thu, 17 Nov 2022 09:21:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668705662; cv=none; d=google.com; s=arc-20160816; b=KId6MBRYbKY9wdRWSfXrK949TPQwvqf7znxt0MyrGRvxqplm0lkJhy6xytRjtA4jRY hDCgceYfTKZ5MfyZJaz0WdpEamETk6CiMu1xjHXIWuWn6//OmNsTkH9VRurSnSFPCEm4 Pp09CPmv1czN41AgpFTYX7gd/ao+n/yc4iOf+qwWfSv8PCWcl5MDDYXwr9nYMGStGhTu DcRqRwe0SopmM4epZWY0V0yu+jpIsdTs1RnjZMXPswz7v+rdvL8bGj5izGJyacIa5PLP CYH4kREsomXNylcaS7e1BRAFqchNfgiw+qaWxQ28FbQ/8Ovn0N5E/EW9DOY9cEs8SjOi Eafg== 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=W07/tnx4hPLSYVOkfywLykzxGeQp6a51zeJr6HlzkXA=; b=KHoso66O471ojFXnTZygYRNbejchMcXClrwzmLmjSAND3afobOXhiz38e38NmrIH9X mudREfincAoxnz4FBOBFraWvZGuy7TT6LuUKwByjiiV5aHYSxNKcX3yq4BCVSNVQN4+0 tWY41Lq9I8pPibKFVflUT8qOt0ZBmWJlF61yHt9KISZPnCzQkPjDv7/hu39cyur1kOf4 +KNOpuUhkCeM7dhgcA0f2kdpZWUccLNo3wuL0rO7rpV8wDhpxWRyqP1cInz9T8OWR1BZ wkKaVkWeRLPAtc+KBqcCvEQwR0IcGTzWINdQxeZJzlpP7W16vxaUYgaNmPYcmNTaIoSC xRXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=m4M86P8J; 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 i14-20020a05640242ce00b0045cc02ce2aasi1532105edc.319.2022.11.17.09.20.36; Thu, 17 Nov 2022 09:21:02 -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=m4M86P8J; 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 S240517AbiKQQVB (ORCPT + 92 others); Thu, 17 Nov 2022 11:21:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240409AbiKQQUj (ORCPT ); Thu, 17 Nov 2022 11:20:39 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31130786F5 for ; Thu, 17 Nov 2022 08:20:18 -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 dfw.source.kernel.org (Postfix) with ESMTPS id BE836621A1 for ; Thu, 17 Nov 2022 16:20:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EE76C433C1; Thu, 17 Nov 2022 16:20:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668702017; bh=hxwBfzDVRHpZPJp/0PFGkD/rqrFUwxmnq4wJ7+7pWNQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m4M86P8J4Ph5qvZ/aI0wbH+YrK+DCRtCA6l8OHe3PyT8m7n66FZQ8R+2w663rOpE6 Tx304iQj55me/VwRXIM3ssBZUExhx12KNtKHkpag2usF4WddBIWHtWnDjYeknaEjdA MsjsJAJWYgp/fNsRftsn1DYv4aCUdPsaOGFasIqP8YmN5fMNalrV9SsRU1f+93/pOV kZUQixn1QVk0G4oVIq9BOlSrXIhJ0muyx01WCD81A3FPv+4Ed5D50jDOXaj+mBUV3k P7pMq4XzWBHYYVHGbddLuhUZDwgpvmRiAAUuGS4RRR/yeBf+ezvcK97RE6rTLAuKdW Ll6/76AtPLoPQ== From: Oded Gabbay To: linux-kernel@vger.kernel.org Cc: Tomer Tayar Subject: [PATCH 16/20] habanalabs: reset device if still in use when released Date: Thu, 17 Nov 2022 18:19:47 +0200 Message-Id: <20221117161951.845454-16-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 From: Tomer Tayar If the device file is released while a context is still held, it won't be possible to reopen it until the context is eventually released. If that doesn't happen, only a device reset will revert it back to an operational state, i.e. need to wait for a CS timeout or an error, or to wait for an external intervention of injecting a reset via sysfs. At this stage, after the device was released by user, context is held either because of CS which were left running on the device and are not relevant anymore, or due to missing cleanup steps from user side. All of this is in any case handled in the device reset flow, so initiate the reset at this point instead of waiting for it. Signed-off-by: Tomer Tayar Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/misc/habanalabs/common/device.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/misc/habanalabs/common/device.c b/drivers/misc/habanalabs/common/device.c index 708db0f48ee0..49640c8ca910 100644 --- a/drivers/misc/habanalabs/common/device.c +++ b/drivers/misc/habanalabs/common/device.c @@ -504,9 +504,10 @@ static int hl_device_release(struct inode *inode, struct file *filp) hdev->compute_ctx_in_release = 1; - if (!hl_hpriv_put(hpriv)) - dev_notice(hdev->dev, - "User process closed FD but device still in use\n"); + if (!hl_hpriv_put(hpriv)) { + dev_notice(hdev->dev, "User process closed FD but device still in use\n"); + hl_device_reset(hdev, HL_DRV_RESET_HARD); + } hdev->last_open_session_duration_jif = jiffies - hdev->last_successful_open_jif; -- 2.25.1