From patchwork Fri Sep 9 11:16:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Stach X-Patchwork-Id: 12971578 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5963ECAAD3 for ; Fri, 9 Sep 2022 11:16:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 66A678D0001; Fri, 9 Sep 2022 07:16:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 560658D0006; Fri, 9 Sep 2022 07:16:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 275A68D0002; Fri, 9 Sep 2022 07:16:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 0F9678D0001 for ; Fri, 9 Sep 2022 07:16:47 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D973BAADED for ; Fri, 9 Sep 2022 11:16:46 +0000 (UTC) X-FDA: 79892294412.07.359A070 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [85.220.165.71]) by imf22.hostedemail.com (Postfix) with ESMTP id 77D05C00A0 for ; Fri, 9 Sep 2022 11:16:46 +0000 (UTC) Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1oWc04-0002dP-Ir; Fri, 09 Sep 2022 13:16:44 +0200 From: Lucas Stach To: linux-mm@kvack.org, dri-devel@lists.freedesktop.org Cc: Daniel Vetter , David Airlie , Andrew Morton , Michal Hocko , =?utf-8?q?Christian_K=C3=B6nig?= , linux-fsdevel@vger.kernel.org, kernel@pengutronix.de Subject: [RFC PATCH 2/5] drm/gem: track mm struct of allocating process in gem object Date: Fri, 9 Sep 2022 13:16:37 +0200 Message-Id: <20220909111640.3789791-3-l.stach@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220909111640.3789791-1-l.stach@pengutronix.de> References: <20220909111640.3789791-1-l.stach@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::28 X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-mm@kvack.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662722206; a=rsa-sha256; cv=none; b=2bFyl9hUby7q7IMS67TxJdo1Sf8fb2odnJdhsuyJ7hVKh9QpkGpQhs8fe93V2ITZ2ZlOUW iU+9uJqslEsesynjyAkZHY8WSJ0TGnlKwZLgQd9nXiDqgR1XdzCp40aQkAmybj115UnnDV LLkHKLaa30V0K27yM5inYNZCx/Aw0GU= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of l.stach@pengutronix.de designates 85.220.165.71 as permitted sender) smtp.mailfrom=l.stach@pengutronix.de; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662722206; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H7S0WIoeL/jW74nVwQoll38jdUlJbQ7EZKZ1IRFnRj8=; b=7/tahXjXfP1p/2zM0F6hSTmV4+NdemBWaoiJD2IFw3UJAaQay3M8geqfknWG43DuXd5PaU FUJMpoR623P8T9A9sErDlfhAWpsqZfW4AbO+eWPGUN9aFV7EqpdAyUSRbt7JONaUzyfH3o //2tzFG+sOkTFNZ3dWx0vkrrfs760lw= X-Rspamd-Server: rspam03 X-Rspam-User: X-Stat-Signature: wjzmccgcqzr7dhn3orsz8p7jn1ewsz5c X-Rspamd-Queue-Id: 77D05C00A0 Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of l.stach@pengutronix.de designates 85.220.165.71 as permitted sender) smtp.mailfrom=l.stach@pengutronix.de; dmarc=none X-HE-Tag: 1662722206-445727 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This keeps around a weak reference to the struct mm of the process allocating the GEM object. This allows us to charge/uncharge the process with the allocated backing store memory, even if this is happening from another context. Signed-off-by: Lucas Stach --- drivers/gpu/drm/drm_gem.c | 5 +++++ include/drm/drm_gem.h | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 86d670c71286..b882f935cd4b 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -157,6 +158,9 @@ void drm_gem_private_object_init(struct drm_device *dev, obj->dev = dev; obj->filp = NULL; + mmgrab(current->mm); + obj->mm = current->mm; + kref_init(&obj->refcount); obj->handle_count = 0; obj->size = size; @@ -949,6 +953,7 @@ drm_gem_object_release(struct drm_gem_object *obj) if (obj->filp) fput(obj->filp); + mmdrop(obj->mm); dma_resv_fini(&obj->_resv); drm_gem_free_mmap_offset(obj); } diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index 87cffc9efa85..d021a083c282 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -234,6 +234,18 @@ struct drm_gem_object { */ struct drm_vma_offset_node vma_node; + /** + * @mm: + * + * mm struct of the process creating the object. Used to account the + * allocated backing store memory. + * + * Note that this is a weak reference created by mmgrab(), so any + * manipulation needs to make sure the address space is still around by + * calling mmget_not_zero(). + */ + struct mm_struct *mm; + /** * @size: *