Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17928090ybl; Thu, 2 Jan 2020 15:00:30 -0800 (PST) X-Google-Smtp-Source: APXvYqzIeG8CThQqSW1gcaft4yIlo8THiLyeGsfmFdmfnINnE0Mt40CKD5w3CHO6/laKhJ8Bp1gE X-Received: by 2002:a9d:66ca:: with SMTP id t10mr93983053otm.352.1578006030455; Thu, 02 Jan 2020 15:00:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578006030; cv=none; d=google.com; s=arc-20160816; b=W9XXFiKMRa3QSl2GCHkSYIj3ScsrLqbeIXA6r1qRNrhDjAsdmCpjYC/qV35yBX2Pms qG33PG0FMpCw35/ByWnO4zgneN1yzm61dzC0mvGUlyAoDEo7pRW5hew7im9mK4k6cMQT hIZepWQ5T4AP6sxe3/RXKdffKTQXT/kv18DFFO96wMx5Ya8BUcP18l27rfDx+MEBNGNk mAqivaLHZaxudRRelX56KkvJzIjHbGeHfcibUdZBU+b/Jj8tsyodlTiEu4nbzc6UaNuf x8mhPEWhWmlS74R9TkeZfZd5sUjxZTVRW7WzmWoNl3SI0ZxQTdUkrz53xR/z8dW81Rdc PUrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/ySoq10ureW+nXuHI2Y66vlOHHk8vGZqgSW19FPAA9g=; b=kBkpZ+4IjnFoqtY8BRZqfe3gYyBPt5L7E/fmzHVhSaK5kcVgDvQBHPjNYdSvj2WDQU L9K/S6f8RPB8qm23GJGaAGKFMhMNJ3XJxyEeJFQuyWzCVH+AJXcx6z90KhhK8iUKZwsR Z639mylxDHNpX3oiG77OduM+oxDnMgUieaEEXkcaQ75M7jySVWdZesLByZ3K7Br39W/A 16Lqjw1bfURC9lEWIxD8MuLFa/r9PrJaMl6ula8nsuJgyO9bpqRoj4J4YO2cZ4nu0HT+ wmUc53BZqFd2WEeUW3Bfvc4itMteNvzmHoKbN+2yk4kHA5RiKMbSIrO0G4qmyy0QP90Z CRvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=q8ki3vhR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u191si23746686oia.86.2020.01.02.15.00.18; Thu, 02 Jan 2020 15:00:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=q8ki3vhR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728293AbgABW7K (ORCPT + 99 others); Thu, 2 Jan 2020 17:59:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:55116 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727948AbgABWOn (ORCPT ); Thu, 2 Jan 2020 17:14:43 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3F60E21D7D; Thu, 2 Jan 2020 22:14:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003282; bh=rvBKXNL2zspQZcX54WvZYh3lHndspUwQyuz6IcZK5+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q8ki3vhRs3l0HpqlUbkSObj13hpA9NRgpInDCpWBabHCOEOKTepPF22/EJE3RTZHu zaWHmv2/eW/TmoPd4W0kgZbYQGLf5EuzX7CalQuOLoSGabb6JbShJ3U5EzNlNWgK7/ HdDwz+5sMoNNrhtOAeKuTrH0dl5EbWe9cy0ys1Xk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Omer Shpigelman , Oded Gabbay , Sasha Levin Subject: [PATCH 5.4 096/191] habanalabs: skip VA block list update in reset flow Date: Thu, 2 Jan 2020 23:06:18 +0100 Message-Id: <20200102215840.195594801@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102215829.911231638@linuxfoundation.org> References: <20200102215829.911231638@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Omer Shpigelman [ Upstream commit 71c5e55e7c077fa17c42fbda91a8d14322825c44 ] Reduce context close time by skipping the VA block free list update in order to avoid hard reset with open contexts. Reset with open contexts can potentially lead to a kernel crash as the generic pool of the MMU hops is destroyed while it is not empty because some unmap operations are not done. The commit affect mainly when running on simulator. Signed-off-by: Omer Shpigelman Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay Signed-off-by: Sasha Levin --- drivers/misc/habanalabs/memory.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/drivers/misc/habanalabs/memory.c b/drivers/misc/habanalabs/memory.c index 365fb0cb8dff..22566b75ca50 100644 --- a/drivers/misc/habanalabs/memory.c +++ b/drivers/misc/habanalabs/memory.c @@ -965,17 +965,19 @@ init_page_pack_err: * * @ctx : current context * @vaddr : device virtual address to unmap + * @ctx_free : true if in context free flow, false otherwise. * * This function does the following: * - Unmap the physical pages related to the given virtual address * - return the device virtual block to the virtual block list */ -static int unmap_device_va(struct hl_ctx *ctx, u64 vaddr) +static int unmap_device_va(struct hl_ctx *ctx, u64 vaddr, bool ctx_free) { struct hl_device *hdev = ctx->hdev; struct hl_vm_phys_pg_pack *phys_pg_pack = NULL; struct hl_vm_hash_node *hnode = NULL; struct hl_userptr *userptr = NULL; + struct hl_va_range *va_range; enum vm_type_t *vm_type; u64 next_vaddr, i; u32 page_size; @@ -1003,6 +1005,7 @@ static int unmap_device_va(struct hl_ctx *ctx, u64 vaddr) if (*vm_type == VM_TYPE_USERPTR) { is_userptr = true; + va_range = &ctx->host_va_range; userptr = hnode->ptr; rc = init_phys_pg_pack_from_userptr(ctx, userptr, &phys_pg_pack); @@ -1014,6 +1017,7 @@ static int unmap_device_va(struct hl_ctx *ctx, u64 vaddr) } } else if (*vm_type == VM_TYPE_PHYS_PACK) { is_userptr = false; + va_range = &ctx->dram_va_range; phys_pg_pack = hnode->ptr; } else { dev_warn(hdev->dev, @@ -1052,12 +1056,18 @@ static int unmap_device_va(struct hl_ctx *ctx, u64 vaddr) mutex_unlock(&ctx->mmu_lock); - if (add_va_block(hdev, - is_userptr ? &ctx->host_va_range : &ctx->dram_va_range, - vaddr, - vaddr + phys_pg_pack->total_size - 1)) - dev_warn(hdev->dev, "add va block failed for vaddr: 0x%llx\n", - vaddr); + /* + * No point in maintaining the free VA block list if the context is + * closing as the list will be freed anyway + */ + if (!ctx_free) { + rc = add_va_block(hdev, va_range, vaddr, + vaddr + phys_pg_pack->total_size - 1); + if (rc) + dev_warn(hdev->dev, + "add va block failed for vaddr: 0x%llx\n", + vaddr); + } atomic_dec(&phys_pg_pack->mapping_cnt); kfree(hnode); @@ -1189,8 +1199,8 @@ int hl_mem_ioctl(struct hl_fpriv *hpriv, void *data) break; case HL_MEM_OP_UNMAP: - rc = unmap_device_va(ctx, - args->in.unmap.device_virt_addr); + rc = unmap_device_va(ctx, args->in.unmap.device_virt_addr, + false); break; default: @@ -1620,7 +1630,7 @@ void hl_vm_ctx_fini(struct hl_ctx *ctx) dev_dbg(hdev->dev, "hl_mem_hash_node of vaddr 0x%llx of asid %d is still alive\n", hnode->vaddr, ctx->asid); - unmap_device_va(ctx, hnode->vaddr); + unmap_device_va(ctx, hnode->vaddr, true); } spin_lock(&vm->idr_lock); -- 2.20.1