From patchwork Mon Jan 13 13:32:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mika Kuoppala X-Patchwork-Id: 13937357 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 1A59FE7719F for ; Mon, 13 Jan 2025 13:31:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 84F1D10E688; Mon, 13 Jan 2025 13:31:10 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Zd+ICLPL"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id CC68E10E688; Mon, 13 Jan 2025 13:31:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1736775070; x=1768311070; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6lg1blOounFHBdTC/qCOhvdJYsSUPYUUFVjDjRUcGe8=; b=Zd+ICLPLNMsUZAtXpafhr96ZcKt68P9+yQ83B8trAbpFSl2TiaGaqorU rJne7L1PbTMtXzbHvajbRD2FWVSQthekf99lDfnKM5In0E3iEVcI0k4ah 9WN/sXmcrygS1GZBpOAPbIjXRV8wq2VGC9o6j5lDbhdxc0TenhNtTl5vI I4TKRE0b0cWfb1j0jnlh1w2vJxeli5Oxxhm1YDGTJzJBjywHv651bEplU r703BTc73H0UIMJs3xfXM+21q5+ubLz788wSILFgLVhMDut8vzeZgsSTF mpidzlvZcpEF2NnU8QAk8tNgpMUooQMQpGV21voLfwlSFrW6e2xeCNSTM w==; X-CSE-ConnectionGUID: qyBcxFZTTb214CyORV5CHg== X-CSE-MsgGUID: vR/VYL4zS/CHxdLNeL+jFQ== X-IronPort-AV: E=McAfee;i="6700,10204,11314"; a="40976185" X-IronPort-AV: E=Sophos;i="6.12,310,1728975600"; d="scan'208";a="40976185" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2025 05:31:09 -0800 X-CSE-ConnectionGUID: oD6fucdkSnqzTdHPSBowAw== X-CSE-MsgGUID: RqIZnKZ3SgmX9ifH2mZzzQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,310,1728975600"; d="scan'208";a="104655010" Received: from unknown (HELO mkuoppal-desk.fi.intel.com) ([10.237.72.193]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2025 05:31:07 -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:32:11 +0200 Message-ID: <20250113133212.374165-1-mika.kuoppala@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: 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:32:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mika Kuoppala X-Patchwork-Id: 13937358 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 2CCD7C02183 for ; Mon, 13 Jan 2025 13:31:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AA3B210E685; Mon, 13 Jan 2025 13:31:26 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="doHLN4Rl"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id BB7A310E685; Mon, 13 Jan 2025 13:31:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1736775085; x=1768311085; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2EpgXsnZKtFdEKmFB4ugPI9M5QuZ3Ls5yODFufgZaJY=; b=doHLN4Rl3i/PUxl5YTRBA1LDQo+P0SampGUjvfbRhvAle4gHffkOMSO7 Fl1PDCGaaHrXcNV5QH6mJ967DHYMKVPm9h2qxD4meaavi8ezlr2EdLXf+ +cmR1JisGP1MK6OpSvteGZ+7pa4F8jJG58q785LABh1uVh4AU57junDbR lzg94WPL+IkddIyaayvJrOWtDkulJwPwvhprDOdfNGGfz3BLKfOa3Zly+ zrjsnhiOM8Zdc16lXFQjNw6Ki8p5IJULpi6iFHHTxweIZxZFYPvDTZlVl Ss+3ri6JZa2FUJnZswM+7Z6MUwqAAf190fH3OUzvFuScaE5Cc+XWA7o19 A==; X-CSE-ConnectionGUID: nflwS5g2SKWEHF8M59HyqQ== X-CSE-MsgGUID: Ucp5gvzfSNaZx7fHtyO6sg== X-IronPort-AV: E=McAfee;i="6700,10204,11314"; a="40976199" X-IronPort-AV: E=Sophos;i="6.12,310,1728975600"; d="scan'208";a="40976199" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2025 05:31:25 -0800 X-CSE-ConnectionGUID: W1iCXJ7bSl+p2MvYuUjxjQ== X-CSE-MsgGUID: 9irlC6pCTSGTNVSiqyAOPg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,310,1728975600"; d="scan'208";a="104655077" Received: from unknown (HELO mkuoppal-desk.fi.intel.com) ([10.237.72.193]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2025 05:31:23 -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:32:31 +0200 Message-ID: <20250113133231.374242-1-mika.kuoppala@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: 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; }