From patchwork Mon Jan 13 13:25:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mika Kuoppala X-Patchwork-Id: 13937344 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A2C2CC02183 for ; Mon, 13 Jan 2025 13:25:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2548710E67D; Mon, 13 Jan 2025 13:25:00 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="DBLHwvGx"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4B38110E67A; Mon, 13 Jan 2025 13:24:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1736774699; x=1768310699; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=6lg1blOounFHBdTC/qCOhvdJYsSUPYUUFVjDjRUcGe8=; b=DBLHwvGxQFhQwHTFLNCcNf1kvgQFuPX6n0je6MjESRzIiZPHgTZz7T1A MVx+xTUQfLBbpcq/UHnkdi8ornluRntrjbFmJGFY2d1fiP/0Hnkf9HZt1 OZuZVnDd3rynYjWbx8YTiaybABvAqTVOQuYlHYrQ9kGns1Euupqxto083 rD4ZvWHAS+RovnOPdj8u+buIExdz6uHn+y0+qKQit4ph5AXEujvjP3aqq hc3BRzX5TTQoEbow/xRqrZ0baMVGqYUszCr9ufiKqyM046aA9wBS4s5j6 4yBxT/9hTQCj71x4YV7VoJygVwJ9NKoVEcFg3fqZYmNdERB1EC76qn9Jk g==; X-CSE-ConnectionGUID: nViWGp3NR+uYzArNIeMwPA== X-CSE-MsgGUID: Hy5Ry2hRScaQ/xHgrlIAOQ== X-IronPort-AV: E=McAfee;i="6700,10204,11314"; a="48417179" X-IronPort-AV: E=Sophos;i="6.12,310,1728975600"; d="scan'208";a="48417179" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2025 05:24:58 -0800 X-CSE-ConnectionGUID: 99pWCOJNRCaDJvNOne7SVw== X-CSE-MsgGUID: d+eSyepDTaecWA6qAgLZ6Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="105352710" Received: from unknown (HELO mkuoppal-desk.fi.intel.com) ([10.237.72.193]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2025 05:24:56 -0800 From: Mika Kuoppala To: intel-xe@lists.freedesktop.org Cc: dri-devel@lists.freedesktop.org, Mika Kuoppala , Matthew Brost , Andrzej Hajda , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , =?utf-8?q?Christian_K=C3=B6nig?= , Joonas Lahtinen , Simona Vetter Subject: [PATCH 13/27] mm: export access_remote_vm symbol for debugger use Date: Mon, 13 Jan 2025 15:25:53 +0200 Message-ID: <20250113132553.373422-1-mika.kuoppala@linux.intel.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Export access_remote_vm as GPL symbol to allow debuggers (eudebug) to access and modify memory in target VMs by tracking VM_BIND operations. While access_process_vm() is already exported, it would require maintaining task references in the debugger. Since the mm reference is already present in the userptr's mm notifier implementation, exporting access_remote_vm allows that existing reference to be used directly without needing to obtain and maintain additional task references just for memory access. Cc: Matthew Brost Cc: Andrzej Hajda Cc: Thomas Hellström Cc: Christian König Cc: Joonas Lahtinen Cc: Simona Vetter Signed-off-by: Mika Kuoppala --- mm/memory.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/memory.c b/mm/memory.c index 398c031be9ba..9b7c71c83db5 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -6690,6 +6690,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr, { return __access_remote_vm(mm, addr, buf, len, gup_flags); } +EXPORT_SYMBOL_GPL(access_remote_vm); /* * Access another process' address space. From patchwork Mon Jan 13 13:26:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mika Kuoppala X-Patchwork-Id: 13937345 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2C324C02183 for ; Mon, 13 Jan 2025 13:25:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9F9C410E67F; Mon, 13 Jan 2025 13:25:20 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="h5hQTI4z"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by gabe.freedesktop.org (Postfix) with ESMTPS id DAE2E10E67A; Mon, 13 Jan 2025 13:25:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1736774719; x=1768310719; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=2EpgXsnZKtFdEKmFB4ugPI9M5QuZ3Ls5yODFufgZaJY=; b=h5hQTI4znrd0yOhNY66ZD5fU4WgRjdzXSuOPwXMay7GJ5C+6qOynR4Nw hD4Qu3xgrN5XiHivKledSpin+A/KIDL62fzA1uKi0IhgpZTzGaLS9rND5 y6y/K1skYlu1bHglUDh9vxv12enAabjS4U9gQuz7dPqCijRhtiqc2mth0 BNdEzTolEcAoyIkj3GoXL+mELywGC3igo0KZp+2/vrw3qYLWgewQTCL3X iyirWaM8KfBb0SFhh//77vveJEcTJQRVkbTPStaXQkhD/GcH0CmcdR0iY AHBorcHtrdfWYhIFgDj7jiaMnTULEDggYRUFzxBKM2sElvnheZPwK8cEs w==; X-CSE-ConnectionGUID: +CBW+NGmT/20hcHldEbCMg== X-CSE-MsgGUID: 9ZuvT7CrR0OiA1UBnFsYyA== X-IronPort-AV: E=McAfee;i="6700,10204,11314"; a="54454091" X-IronPort-AV: E=Sophos;i="6.12,310,1728975600"; d="scan'208";a="54454091" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2025 05:25:19 -0800 X-CSE-ConnectionGUID: uK3c4JWPRhCi0opIIUz1uA== X-CSE-MsgGUID: Ac49AsNfTKe5JVWnSalQNQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,310,1728975600"; d="scan'208";a="104432390" Received: from unknown (HELO mkuoppal-desk.fi.intel.com) ([10.237.72.193]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2025 05:25:16 -0800 From: Mika Kuoppala To: intel-xe@lists.freedesktop.org Cc: dri-devel@lists.freedesktop.org, Mika Kuoppala , Matthew Brost , Andrzej Hajda , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Dominik Grzegorzek , =?utf-8?q?Christian_K?= =?utf-8?q?=C3=B6nig?= , Joonas Lahtinen , Simona Vetter Subject: [PATCH 14/27] drm/xe/eudebug: userptr vm access pread/pwrite Date: Mon, 13 Jan 2025 15:26:19 +0200 Message-ID: <20250113132619.373502-1-mika.kuoppala@linux.intel.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Implement debugger vm access for userptrs. When userptr bind is done, mmu notifier is added by core xe. Later when debugger wants to access the target memory, this notifier can be used as it carries the struct mm of target. Implement userptr vm access, for debugger pread/pwrite using notifier mm passed to access_remote_vm(). This is based on suggestions from Thomas, Joonas and Simona. v2: need to add offset into vma (Dominik) v3: use exported access_remote_vm (Thomas) Cc: Matthew Brost Cc: Andrzej Hajda Cc: Thomas Hellström Cc: Dominik Grzegorzek Cc: Christian König Cc: Joonas Lahtinen Cc: Simona Vetter Signed-off-by: Mika Kuoppala --- drivers/gpu/drm/xe/xe_eudebug.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/gpu/drm/xe/xe_eudebug.c b/drivers/gpu/drm/xe/xe_eudebug.c index 210d9eeab1a7..25f18aa5447b 100644 --- a/drivers/gpu/drm/xe/xe_eudebug.c +++ b/drivers/gpu/drm/xe/xe_eudebug.c @@ -3077,6 +3077,27 @@ static int xe_eudebug_vma_access(struct xe_vma *vma, xe_bo_put(bo); + return ret; + } else if (xe_vma_is_userptr(vma)) { + struct xe_userptr *userptr = &to_userptr_vma(vma)->userptr; + struct xe_vm *vm = xe_vma_vm(vma); + struct mm_struct *mm = NULL; + int ret; + + down_read(&vm->userptr.notifier_lock); + if (mmget_not_zero(userptr->notifier.mm)) + mm = userptr->notifier.mm; + up_read(&vm->userptr.notifier_lock); + + if (!mm) + return -EFAULT; + + ret = access_remote_vm(mm, + xe_vma_userptr(vma) + offset_in_vma, + buf, bytes, + write ? FOLL_WRITE : 0); + mmput(mm); + return ret; }