get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/131332/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 131332,
    "url": "https://patches.dpdk.org/api/patches/131332/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/20230911082229.1479773-1-ming3.li@intel.com/",
    "project": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20230911082229.1479773-1-ming3.li@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20230911082229.1479773-1-ming3.li@intel.com",
    "date": "2023-09-11T08:22:29",
    "name": "windows/virt2phys: fix block MDL not updated",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "38bbcb236e1ab6f3731f84299612a575b7670746",
    "submitter": {
        "id": 3182,
        "url": "https://patches.dpdk.org/api/people/3182/?format=api",
        "name": "Ric Li",
        "email": "ming3.li@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/20230911082229.1479773-1-ming3.li@intel.com/mbox/",
    "series": [
        {
            "id": 29474,
            "url": "https://patches.dpdk.org/api/series/29474/?format=api",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=29474",
            "date": "2023-09-11T08:22:29",
            "name": "windows/virt2phys: fix block MDL not updated",
            "version": 1,
            "mbox": "https://patches.dpdk.org/series/29474/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/131332/comments/",
    "check": "warning",
    "checks": "https://patches.dpdk.org/api/patches/131332/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 2C04A4256D;\n\tMon, 11 Sep 2023 10:22:35 +0200 (CEST)",
            "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id ED8E6402DD;\n\tMon, 11 Sep 2023 10:22:34 +0200 (CEST)",
            "from mgamail.intel.com (mgamail.intel.com [134.134.136.65])\n by mails.dpdk.org (Postfix) with ESMTP id 42AEE402DA\n for <dev@dpdk.org>; Mon, 11 Sep 2023 10:22:33 +0200 (CEST)",
            "from orsmga004.jf.intel.com ([10.7.209.38])\n by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 11 Sep 2023 01:22:32 -0700",
            "from media-ric-kahawai-icl.sh.intel.com ([10.67.119.129])\n by orsmga004.jf.intel.com with ESMTP; 11 Sep 2023 01:22:30 -0700"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple;\n d=intel.com; i=@intel.com; q=dns/txt; s=Intel;\n t=1694420553; x=1725956553;\n h=from:to:cc:subject:date:message-id:mime-version:\n content-transfer-encoding;\n bh=13GXEwyLgjr/KBVzWL2Ml+1QfbJ35pJzl5PenNGubZI=;\n b=KQ5qEgaaDzaD7y73pXZyeAy4neWZnyoQPXQegrcDq/gOfGlFTo/Bz/6s\n vrk+7/HtB2o7LSejVGXhsPtjitCCUS4kXJrAGw4LRa7SMB7ORnuBAWmhU\n QiLwmqgnBxSdAnQpUybeIkQCBTtBTtpYLjZ3vC4esoHE7QmWnb+B7wPLf\n 1pSrwQe53ZmayZbSrY61ITHtopuhkhhSJj6XWDPhv8vdKdsp5anXNrrH4\n H24tHd9TDO8zB6PV6eflC0rM0et07Mvi7uvCelQQ+sEO5CIlOPvC3GjKi\n Gf1xGXuD5+XY/7ZeAFrcsid1aOzfWc6fzcfm0r+KzqvnZ0nb8v2nsHVUv g==;",
        "X-IronPort-AV": [
            "E=McAfee;i=\"6600,9927,10829\"; a=\"381826491\"",
            "E=Sophos;i=\"6.02,243,1688454000\"; d=\"scan'208\";a=\"381826491\"",
            "E=McAfee;i=\"6600,9927,10829\"; a=\"866852558\"",
            "E=Sophos;i=\"6.02,243,1688454000\"; d=\"scan'208\";a=\"866852558\""
        ],
        "X-ExtLoop1": "1",
        "From": "Ric Li <ming3.li@intel.com>",
        "To": "dmitry.kozliuk@gmail.com",
        "Cc": "dev@dpdk.org",
        "Subject": "[PATCH] windows/virt2phys: fix block MDL not updated",
        "Date": "Mon, 11 Sep 2023 16:22:29 +0800",
        "Message-Id": "<20230911082229.1479773-1-ming3.li@intel.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org"
    },
    "content": "The virt2phys_translate function previously scanned existing blocks,\nreturning the physical address from the stored MDL info if present.\nThis method was problematic when a virtual address pointed to a freed\nand reallocated memory segment, potentially changing the physical\naddress mapping. Yet, virt2phys_translate would consistently return\nthe originally stored physical address, which could be invalid.\n\nThis issue surfaced when allocating a memory region larger than 2MB\nusing rte_malloc. This action would allocate a new memory segment\nand use virt2phy to set the iova. The driver would store the MDL\nand lock the pages initially. When this region was freed, the memory\nsegment used as a whole page could be freed, invalidating the virtual\nto physical mapping. It then needed to be deleted from the driver's\nblock MDL info. Before this fix, the driver would only return the\ninitial physical address, leading to illegal iova for some pages when\nallocating a new memory region of the same size.\n\nTo address this, a refresh function has been added. If a block with the\nsame base address is detected in the driver's context, the MDL's\nphysical address is compared with the real physical address.\nIf they don't match, the MDL within the block is released and rebuilt\nto store the correct mapping.\n\nAlso refine the access of MDL StartVa field and fix the printing\nof PVOID type.\n\nSigned-off-by: Ric Li <ming3.li@intel.com>\n---\n windows/virt2phys/virt2phys.c       |  7 ++--\n windows/virt2phys/virt2phys_logic.c | 60 +++++++++++++++++++++++++----\n 2 files changed, 57 insertions(+), 10 deletions(-)",
    "diff": "diff --git a/windows/virt2phys/virt2phys.c b/windows/virt2phys/virt2phys.c\nindex f4d5298..b64a13d 100644\n--- a/windows/virt2phys/virt2phys.c\n+++ b/windows/virt2phys/virt2phys.c\n@@ -182,7 +182,7 @@ virt2phys_device_EvtIoInCallerContext(WDFDEVICE device, WDFREQUEST request)\n {\n \tWDF_REQUEST_PARAMETERS params;\n \tULONG code;\n-\tPVOID *virt;\n+\tPVOID *pvirt, virt;\n \tPHYSICAL_ADDRESS *phys;\n \tsize_t size;\n \tNTSTATUS status;\n@@ -207,12 +207,13 @@ virt2phys_device_EvtIoInCallerContext(WDFDEVICE device, WDFREQUEST request)\n \t}\n \n \tstatus = WdfRequestRetrieveInputBuffer(\n-\t\t\trequest, sizeof(*virt), (PVOID *)&virt, &size);\n+\t\t\trequest, sizeof(*pvirt), (PVOID *)&pvirt, &size);\n \tif (!NT_SUCCESS(status)) {\n \t\tTraceWarning(\"Retrieving input buffer: %!STATUS!\", status);\n \t\tWdfRequestComplete(request, status);\n \t\treturn;\n \t}\n+\tvirt = *pvirt;\n \n \tstatus = WdfRequestRetrieveOutputBuffer(\n \t\trequest, sizeof(*phys), (PVOID *)&phys, &size);\n@@ -222,7 +223,7 @@ virt2phys_device_EvtIoInCallerContext(WDFDEVICE device, WDFREQUEST request)\n \t\treturn;\n \t}\n \n-\tstatus = virt2phys_translate(*virt, phys);\n+\tstatus = virt2phys_translate(virt, phys);\n \tif (NT_SUCCESS(status))\n \t\tWdfRequestSetInformation(request, sizeof(*phys));\n \ndiff --git a/windows/virt2phys/virt2phys_logic.c b/windows/virt2phys/virt2phys_logic.c\nindex e3ff293..5bf6734 100644\n--- a/windows/virt2phys/virt2phys_logic.c\n+++ b/windows/virt2phys/virt2phys_logic.c\n@@ -40,7 +40,7 @@ virt2phys_block_create(PMDL mdl)\n static void\n virt2phys_block_free(struct virt2phys_block *block, BOOLEAN unmap)\n {\n-\tTraceInfo(\"VA = %p, unmap = %!bool!\", block->mdl->StartVa, unmap);\n+\tTraceInfo(\"VA = %p, unmap = %!bool!\", MmGetMdlBaseVa(block->mdl), unmap);\n \n \tif (unmap)\n \t\tMmUnlockPages(block->mdl);\n@@ -114,7 +114,7 @@ virt2phys_process_find_block(struct virt2phys_process *process, PVOID virt)\n \n \tfor (node = process->blocks.Next; node != NULL; node = node->Next) {\n \t\tcur = CONTAINING_RECORD(node, struct virt2phys_block, next);\n-\t\tif (cur->mdl->StartVa == virt)\n+\t\tif (MmGetMdlBaseVa(cur->mdl) == virt)\n \t\t\treturn cur;\n \t}\n \treturn NULL;\n@@ -182,7 +182,7 @@ virt2phys_process_cleanup(HANDLE process_id)\n }\n \n static struct virt2phys_block *\n-virt2phys_find_block(HANDLE process_id, void *virt,\n+virt2phys_find_block(HANDLE process_id, PVOID virt,\n \tstruct virt2phys_process **process)\n {\n \tPLIST_ENTRY node;\n@@ -214,7 +214,7 @@ virt2phys_add_block(struct virt2phys_process *process,\n \tstruct virt2phys_process *existing;\n \tsize_t size;\n \n-\tTraceInfo(\"ID = %p, VA = %p\", process->id, block->mdl->StartVa);\n+\tTraceInfo(\"ID = %p, VA = %p\", process->id, MmGetMdlBaseVa(block->mdl));\n \n \texisting = virt2phys_process_find(process->id);\n \t*process_exists = existing != NULL;\n@@ -250,7 +250,7 @@ virt2phys_add_block(struct virt2phys_process *process,\n }\n \n static NTSTATUS\n-virt2phys_query_memory(void *virt, void **base, size_t *size)\n+virt2phys_query_memory(PVOID virt, PVOID *base, size_t *size)\n {\n \tMEMORY_BASIC_INFORMATION info;\n \tSIZE_T info_size;\n@@ -321,7 +321,7 @@ virt2phys_check_memory(PMDL mdl)\n }\n \n static NTSTATUS\n-virt2phys_lock_memory(void *virt, size_t size, PMDL *mdl)\n+virt2phys_lock_memory(PVOID virt, size_t size, PMDL *mdl)\n {\n \t*mdl = IoAllocateMdl(virt, (ULONG)size, FALSE, FALSE, NULL);\n \tif (*mdl == NULL)\n@@ -346,12 +346,53 @@ virt2phys_unlock_memory(PMDL mdl)\n \tIoFreeMdl(mdl);\n }\n \n+static NTSTATUS\n+virt2phys_block_refresh(struct virt2phys_block *block, PVOID base, size_t size)\n+{\n+\tNTSTATUS status;\n+\tPMDL mdl = block->mdl;\n+\n+\t/*\n+\t * Check if we need to refresh MDL in block.\n+\t * The virtual to physical memory mapping may be changed when the\n+\t * virtual memory region is freed by the user process and malloc again,\n+\t * then we need to unlocked the physical memory and lock again to\n+\t * refresh the MDL information stored in block.\n+\t */\n+\tPHYSICAL_ADDRESS block_phys, real_phys;\n+\n+\tblock_phys = virt2phys_block_translate(block, base);\n+\treal_phys = MmGetPhysicalAddress(base);\n+\n+\tif (block_phys.QuadPart == real_phys.QuadPart)\n+\t\t/* No need to refresh block. */\n+\t\treturn STATUS_SUCCESS;\n+\n+\tvirt2phys_unlock_memory(mdl);\n+\tmdl = NULL;\n+\n+\tstatus = virt2phys_lock_memory(base, size, &mdl);\n+\tif (!NT_SUCCESS(status))\n+\t\treturn status;\n+\n+\tstatus = virt2phys_check_memory(mdl);\n+\tif (!NT_SUCCESS(status)) {\n+\t\tvirt2phys_unlock_memory(mdl);\n+\t\treturn status;\n+\t}\n+\tblock->mdl = mdl;\n+\n+\tTraceInfo(\"Block refreshed from %llx to %llx\", block_phys.QuadPart, real_phys.QuadPart);\n+\n+\treturn STATUS_SUCCESS;\n+}\n+\n NTSTATUS\n virt2phys_translate(PVOID virt, PHYSICAL_ADDRESS *phys)\n {\n \tPMDL mdl;\n \tHANDLE process_id;\n-\tvoid *base;\n+\tPVOID base;\n \tsize_t size;\n \tstruct virt2phys_process *process;\n \tstruct virt2phys_block *block;\n@@ -371,6 +412,11 @@ virt2phys_translate(PVOID virt, PHYSICAL_ADDRESS *phys)\n \n \t/* Don't lock the same memory twice. */\n \tif (block != NULL) {\n+\t\tKeAcquireSpinLock(g_lock, &irql);\n+\t\tstatus = virt2phys_block_refresh(block, base, size);\n+\t\tKeReleaseSpinLock(g_lock, irql);\n+\t\tif (!NT_SUCCESS(status))\n+\t\t\treturn status;\n \t\t*phys = virt2phys_block_translate(block, virt);\n \t\treturn STATUS_SUCCESS;\n \t}\n",
    "prefixes": []
}