misc: mods: fix offset for large allocations

Fix MODS_VIRTUAL_TO_PHYSICAL for allocations exceeding 4GB

It's unlikely for us to support such large allocations,
but if we ever did, integer overflow would truncate the
allocation offset, resulting in the incorrect PA being
returned.

This change also brings the driver up to date with
the Perforce copy and fixes the version.

CID 421846

Change-Id: Ia9328dd91743631f39a16dfc3077261656384f2c
Signed-off-by: Chris Dragan <kdragan@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2810261
Reviewed-by: Sachin Nikam <snikam@nvidia.com>
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
This commit is contained in:
Chris Dragan
2022-11-16 02:37:10 -08:00
committed by Laxman Dewangan
parent 83161a6ce4
commit 8061cf233b
2 changed files with 12 additions and 10 deletions

View File

@@ -2057,13 +2057,15 @@ int esc_mods_get_mapped_phys_addr_3(struct mods_client *client,
int esc_mods_virtual_to_phys(struct mods_client *client, int esc_mods_virtual_to_phys(struct mods_client *client,
struct MODS_VIRTUAL_TO_PHYSICAL *p) struct MODS_VIRTUAL_TO_PHYSICAL *p)
{ {
struct MODS_GET_PHYSICAL_ADDRESS get_phys_addr; struct MODS_GET_PHYSICAL_ADDRESS_3 range;
struct list_head *head; struct list_head *head;
struct list_head *iter; struct list_head *iter;
int err; int err;
LOG_ENT(); LOG_ENT();
memset(&range, 0, sizeof(range));
err = mutex_lock_interruptible(&client->mtx); err = mutex_lock_interruptible(&client->mtx);
if (unlikely(err)) { if (unlikely(err)) {
LOG_EXT(); LOG_EXT();
@@ -2107,19 +2109,19 @@ int esc_mods_virtual_to_phys(struct mods_client *client,
&phys_offs) != OK) &phys_offs) != OK)
break; break;
get_phys_addr.memory_handle = range.memory_handle =
(u64)(size_t)p_map_mem->p_mem_info; (u64)(size_t)p_map_mem->p_mem_info;
get_phys_addr.offset = virt_offs + phys_offs; range.offset = virt_offs + phys_offs;
mutex_unlock(&client->mtx); mutex_unlock(&client->mtx);
err = esc_mods_get_phys_addr(client, &get_phys_addr); err = get_addr_range(client, &range, NULL);
if (err) { if (err) {
LOG_EXT(); LOG_EXT();
return err; return err;
} }
p->physical_address = get_phys_addr.physical_address; p->physical_address = range.physical_address;
cl_debug(DEBUG_MEM_DETAILED, cl_debug(DEBUG_MEM_DETAILED,
"get phys: map %p virt 0x%llx -> 0x%llx\n", "get phys: map %p virt 0x%llx -> 0x%llx\n",

View File

@@ -25,7 +25,7 @@
/* Driver version */ /* Driver version */
#define MODS_DRIVER_VERSION_MAJOR 4 #define MODS_DRIVER_VERSION_MAJOR 4
#define MODS_DRIVER_VERSION_MINOR 10 #define MODS_DRIVER_VERSION_MINOR 12
#define MODS_DRIVER_VERSION ((MODS_DRIVER_VERSION_MAJOR << 8) | \ #define MODS_DRIVER_VERSION ((MODS_DRIVER_VERSION_MAJOR << 8) | \
((MODS_DRIVER_VERSION_MINOR / 10) << 4) | \ ((MODS_DRIVER_VERSION_MINOR / 10) << 4) | \
(MODS_DRIVER_VERSION_MINOR % 10)) (MODS_DRIVER_VERSION_MINOR % 10))