Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3654667pxb; Mon, 24 Jan 2022 14:32:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4YLpRABE5EMeHx8//vyV2bR/a9hGZlAFAiN8Ol6g3zsxWlvfpPVGAU5i6zwV9BsIyo7Es X-Received: by 2002:a17:90b:1e53:: with SMTP id pi19mr340660pjb.223.1643063471537; Mon, 24 Jan 2022 14:31:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643063471; cv=none; d=google.com; s=arc-20160816; b=CgOFqvX3WkKQjg5FpdL/l4NLF9BUGo4ojJx6xpwHbzdwosuKSj6aCSHY68wUm5AAOK fsC3InlLZt4x3Ccnw2YYGLpLOo5NlGNV8Lb8uSFp65sdMnwtEvqOvNbbigJcMSQACjN2 ohK8TpdmknIgPEYGY03GaA9MeGV7cSrjA6OafsbDxgEEXYr6TCxji+8MFoctlqNtGUJT fymYSiDEiM3zFspzp0ZeBG28LVJOo8AVDh7A4rsY1Haqe5JTy/RuvP5W1GnPYVPtzP9p THSCS/nPGD0HMIUWQQOzMaEOR91gQH3KhTK6/WkKzt83vFl+AXkOTA6bIiNL3Gp3G4k1 UBBQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/2NgLPnD4f/iV9Rh/nYpAzRSMUpcGf0YTDs4Y+YH6yk=; b=GxR7fpIOfB7E12oFIluYJUDRqNjWzBZMrMrTzBM5EUML56Kc7mKIlBZZvwN/BHb80N 58vAcFJcR39AHMy7uSOn3cPcDN1REIcXPR68SBcqvZS6XcN7t4cvZxHWAL1C08y3j2tS loD4LvIX+HxeXek0oLFgOzjAxwC7d2tTk1XToLOwOwoXve5AlWfbQYBcGK8Mi6GBId31 cbu3/Mir+QCcFFxfxKs0APwdMFMX0irA4oMMFNlvyji+nKULQm8xAqKrSfH4WORBUMPQ oOcFlJ0CgK1ZMx2I955PJgB/P8I3YigNB9C78JtrnPC+rtFVuzXmHRsI5XtbZNZmC/HS iOdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bQuRHEZc; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rj6si518459pjb.103.2022.01.24.14.30.59; Mon, 24 Jan 2022 14:31:11 -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=@linuxfoundation.org header.s=korg header.b=bQuRHEZc; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1586249AbiAXW0C (ORCPT + 99 others); Mon, 24 Jan 2022 17:26:02 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:41684 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1449207AbiAXV2W (ORCPT ); Mon, 24 Jan 2022 16:28:22 -0500 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 34FA8B815B0; Mon, 24 Jan 2022 21:28:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 618C3C340E8; Mon, 24 Jan 2022 21:28:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059691; bh=35lOTX6cm3m1nD+3sw8XpEL6aINTmKJuCTuO6dclzwU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bQuRHEZcTqyNPV91LVDf3kYVGiB7f8brIbslg0f7Q5nWAZq2xohyGBdz8F4bzfeEu QqiF9FvyXiF/LUb1kJ/YNPhN3iVyt6uVR9OuVbZpo8hqJbr626/ftmqltGirqbB+w5 KuSi4k955uqne2Df+HpztccqaHZHKytO7Cg2aL8E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Felix Kuehling , =?UTF-8?q?Christian=20K=C3=B6nig?= , David Yat Sin , Rajneesh Bhardwaj , Alex Deucher , Sasha Levin Subject: [PATCH 5.16 0702/1039] drm/amdgpu: Dont inherit GEM object VMAs in child process Date: Mon, 24 Jan 2022 19:41:31 +0100 Message-Id: <20220124184148.931014095@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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