Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3674780pxb; Mon, 24 Jan 2022 15:04:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJxyBkTHtat/G7ueDayXfqKIBRP8jBjDicUIuelYO+LaY+s9ocCxG/MYhkHLry39ib5q+iL5 X-Received: by 2002:a05:6a00:1345:b0:4c8:fc0f:4495 with SMTP id k5-20020a056a00134500b004c8fc0f4495mr7411806pfu.29.1643065461212; Mon, 24 Jan 2022 15:04:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643065461; cv=none; d=google.com; s=arc-20160816; b=nxS6/4lfOkSkpRCyWhbU26jv5wBl3N7QgOwOY0qEOpi26JWtfEP8KWeyWKmZATF428 W/ALdS5z5IjmCv4n5uupYQg9nfuDgEpXYYZwW67Btx0EIjItAyJ85lOImEKzgDFCJotw /WucjgbrKlgRLuKX1+b+cFMTvsoxKW5limiX9G6qh7be3IYj4qRAZSsNmeVHfctIFhmZ WR8diYF+KLvW7FsmYLsyxw7yQ7nhIjv8VvMHyXy38gwZfAMaTwTJeA7O7m+U8uTFXGjW 2Cd1LjP+sYsKtTcYkVr83NOtV8ECNNqwVRxY1mVDlH4vbiaYo3vo04eDGsUB74gQy0Mf os9w== 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=hNi4CJGplxVSaM66TKiMIPbIFm8euaAkxocolOlTdyOaBCwnYufWPt2ubljyXq09G1 n3s+jhNo+fxkGd/COAsyW0u0QgKZnP5CF+FcWSif0XHYTebjSxqiped6wF+irWWmCD0w T+bLQGu/FjxnmmgOxd6HoZRDNyEP7+yKg2cunSHQFQ4LAUWDf9QOHOS+nk839yURflLW URKQT2F/bsZ7elriCwj0Ds3AHL/5bLOqA/Z/8+Ane7byKhoyH6eh67+HVV9Z/z93dRZ3 Lz2KYeY1cd0Qw0vw+rGFOIH2tinU/P78TSRoBeZLBiaY+ln+QNXLTUcTbVtglBzqYp7R RVYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=THHUj21M; 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 ij1si13148854plb.53.2022.01.24.15.04.09; Mon, 24 Jan 2022 15:04:21 -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=THHUj21M; 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 S1381818AbiAXW63 (ORCPT + 99 others); Mon, 24 Jan 2022 17:58:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1576001AbiAXV7I (ORCPT ); Mon, 24 Jan 2022 16:59:08 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB386C02B8DD; Mon, 24 Jan 2022 12:39:33 -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 6C333615A5; Mon, 24 Jan 2022 20:39:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F1D0C340E5; Mon, 24 Jan 2022 20:39:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643056772; bh=35lOTX6cm3m1nD+3sw8XpEL6aINTmKJuCTuO6dclzwU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=THHUj21Mo1YZ8beNGRP+28tW0XYlSOQAhLJv5fbmL6F6j7spJtwJPGsQDKTpl/jLG Dgh+Lm0AZMTbSzdGc+dWS+NBIiug7q/XwCXG7TTZzH6tKq+BV31cqLgbXqDVCF3yOM 5knxOQSBjANVQr4EAAFsy2rFE5l0e+ayPCBnOL1Y= 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.15 595/846] drm/amdgpu: Dont inherit GEM object VMAs in child process Date: Mon, 24 Jan 2022 19:41:52 +0100 Message-Id: <20220124184121.566094072@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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