Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3391061pxb; Mon, 17 Jan 2022 19:26:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJyHm6Bn8rCY2PttPPXkCrOtQF5awFcoYB/BCGlVx2xgDyaihhDiyVaoEpnAtHmyITWLj/DL X-Received: by 2002:a17:90b:1b12:: with SMTP id nu18mr12056319pjb.70.1642476369072; Mon, 17 Jan 2022 19:26:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642476369; cv=none; d=google.com; s=arc-20160816; b=0APYNhaoeYIP9hq3QCFybMw267JpK7RoErllU3RE1hjSfgbi1s9cOLlgtj8NPDbVzy /JKnNjQc5abzRIN6Lyv91h+fpjo0GggVPwlnA7xEJz392QbceRBQ4wmclZ3VgjeQRSSe 6IzCOBMlrkOhmS/VeMDx4vAhprTruMllRkNjB55T18gXA93+6LmVifVp2trork7Yusn7 BAwtiJgaqZR/IxmkGhPCC9aw4eyl6zjkppHHtmWeYsvIEY0A4/NhB66EolkRWMu8rY+2 76uvCG09UxL/MUhT3FA3ZF0K/iaDlhyBrnebW/VdZ0vQRKQ/LnsS/dEoZHgk/QW9ky3n Rz4w== 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=/2NgLPnD4f/iV9Rh/nYpAzRSMUpcGf0YTDs4Y+YH6yk=; b=0ehVVQQISmqFwKo+KumjqYFw6DW15vW9BWaNzgOQxTOYnRlFz8DZ6QCQvd8eLJ3tFA VzDH6WqpUuK9gOhj1j8fxvZ2ZYOjr6OgtihVerBhsfX3FshsyOoI1vRqNkfMi+C73iH6 Jn/k7HEVFtcKRD3xKkiqkrxnszkQTvwZBwi+EQ5vOaXJuP4+PPPGJ6fMIQJjvGExfvkv wHHzpolFcwjf5Qo2CJx9jGBm7+LoEZsLUsznfk4v8cHat3mOtL/rGpe1Bt5nojP6lPE7 dEzTYtUjoH7VIQtmtHnF+kjv2hz9xlV/Kk14E3NahRncyrWyG+dt7vMdEpWGSMLzSIyH 7Vow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XUpoT09W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c17si14433680pls.502.2022.01.17.19.25.55; Mon, 17 Jan 2022 19:26:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XUpoT09W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1344593AbiARCg4 (ORCPT + 99 others); Mon, 17 Jan 2022 21:36:56 -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