From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D3B2C433EF for ; Tue, 18 Jan 2022 02:37:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344634AbiARCg6 (ORCPT ); Mon, 17 Jan 2022 21:36:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345531AbiARCbi (ORCPT ); Mon, 17 Jan 2022 21:31:38 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DC4BC061768; Mon, 17 Jan 2022 18:29:36 -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 E2BCAB8123A; Tue, 18 Jan 2022 02:29:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9B01C36AE3; Tue, 18 Jan 2022 02:29:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642472973; bh=35lOTX6cm3m1nD+3sw8XpEL6aINTmKJuCTuO6dclzwU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XUpoT09WMnww8FSzJFmKYdwDgYaKnRjjdwSLhsGPXizsEA6RmRww1ShDnXgoXU56z /HAo96TGK3Y07dxCQbBpcJs6TJvwo4/cvPjHcveDE/wNJ1ntvqCXp+YNkn+/pKEFHU m8pKd4VtC211ItgWnvTQsPMCgIBa98j/vG6rOueeo/KxjHjadQ2O5yaRkDZpA7XxMF 9rypR/mdL/7uKkth/PYlLzjyKETA+YbyyQD+dcKvBqad3rYKU20eZ0lM6piF7kmuz5 oJycPR/A5O3bVKXESHH4iKdBzPMelgSziWll9Z7wM/LVAsSrA2u1UKbh6hpbyOJ6rm DFFRHPUMTpbRQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Rajneesh Bhardwaj , Felix Kuehling , =?UTF-8?q?Christian=20K=C3=B6nig?= , David Yat Sin , Alex Deucher , Sasha Levin , Xinhui.Pan@amd.com, airlied@linux.ie, daniel@ffwll.ch, JinhuiEric.Huang@amd.com, nirmoy.das@amd.com, evan.quan@amd.com, tzimmermann@suse.de, colin.king@intel.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.16 185/217] drm/amdgpu: Don't inherit GEM object VMAs in child process Date: Mon, 17 Jan 2022 21:19:08 -0500 Message-Id: <20220118021940.1942199-185-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220118021940.1942199-1-sashal@kernel.org> References: <20220118021940.1942199-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rajneesh Bhardwaj [ Upstream commit fbcdbfde87509d523132b59f661a355c731139d0 ] When an application having open file access to a node forks, its shared mappings also get reflected in the address space of child process even though it cannot access them with the object permissions applied. With the existing permission checks on the gem objects, it might be reasonable to also create the VMAs with VM_DONTCOPY flag so a user space application doesn't need to explicitly call the madvise(addr, len, MADV_DONTFORK) system call to prevent the pages in the mapped range to appear in the address space of the child process. It also prevents the memory leaks due to additional reference counts on the mapped BOs in the child process that prevented freeing the memory in the parent for which we had worked around earlier in the user space inside the thunk library. Additionally, we faced this issue when using CRIU to checkpoint restore an application that had such inherited mappings in the child which confuse CRIU when it mmaps on restore. Having this flag set for the render node VMAs helps. VMAs mapped via KFD already take care of this so this is needed only for the render nodes. To limit the impact of the change to user space consumers such as OpenGL etc, limit it to KFD BOs only. Acked-by: Felix Kuehling Reviewed-by: Christian König Signed-off-by: David Yat Sin Signed-off-by: Rajneesh Bhardwaj Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c index a1e63ba4c54a5..630dc99e49086 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c @@ -264,6 +264,9 @@ static int amdgpu_gem_object_mmap(struct drm_gem_object *obj, struct vm_area_str !(vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC))) vma->vm_flags &= ~VM_MAYWRITE; + if (bo->kfd_bo) + vma->vm_flags |= VM_DONTCOPY; + return drm_gem_ttm_mmap(obj, vma); } -- 2.34.1