Fix to VMAP virtual address leak

Fujitsu: POSTK_DEBUG_TEMP_FIX_51
Refs: #1024
Change-Id: I1692ee4f004cb4d1f725baf47a8ed31fce1bf42a
This commit is contained in:
Tomoki Shirasawa
2018-07-11 10:34:12 +09:00
committed by Masamichi Takagi
parent 3d365b0d7a
commit 67ebcca74d
16 changed files with 631 additions and 29 deletions

View File

@@ -306,7 +306,7 @@ int prepare_process_ranges_args_envs(struct thread *thread,
/* Only unmap remote address if it wasn't specified as an argument */
if (!args) {
ihk_mc_unmap_virtual(args_envs_r, args_envs_npages, 0);
ihk_mc_unmap_virtual(args_envs_r, args_envs_npages);
ihk_mc_unmap_memory(NULL, args_envs_rp, p->args_len);
}
flush_tlb();
@@ -341,7 +341,7 @@ int prepare_process_ranges_args_envs(struct thread *thread,
/* Only map remote address if it wasn't specified as an argument */
if (!envs) {
ihk_mc_unmap_virtual(args_envs_r, args_envs_npages, 0);
ihk_mc_unmap_virtual(args_envs_r, args_envs_npages);
ihk_mc_unmap_memory(NULL, args_envs_rp, p->envs_len);
}
flush_tlb();
@@ -449,7 +449,7 @@ static int process_msg_prepare_process(unsigned long rphys)
if((pn = kmalloc(sizeof(struct program_load_desc)
+ sizeof(struct program_image_section) * n,
IHK_MC_AP_NOWAIT)) == NULL){
ihk_mc_unmap_virtual(p, npages, 0);
ihk_mc_unmap_virtual(p, npages);
ihk_mc_unmap_memory(NULL, phys, sz);
return -ENOMEM;
}
@@ -460,7 +460,7 @@ static int process_msg_prepare_process(unsigned long rphys)
(unsigned long *)&p->cpu_set,
sizeof(p->cpu_set))) == NULL) {
kfree(pn);
ihk_mc_unmap_virtual(p, npages, 1);
ihk_mc_unmap_virtual(p, npages);
ihk_mc_unmap_memory(NULL, phys, sz);
return -ENOMEM;
}
@@ -542,14 +542,14 @@ static int process_msg_prepare_process(unsigned long rphys)
kfree(pn);
ihk_mc_unmap_virtual(p, npages, 1);
ihk_mc_unmap_virtual(p, npages);
ihk_mc_unmap_memory(NULL, phys, sz);
flush_tlb();
return 0;
err:
kfree(pn);
ihk_mc_unmap_virtual(p, npages, 1);
ihk_mc_unmap_virtual(p, npages);
ihk_mc_unmap_memory(NULL, phys, sz);
destroy_thread(thread);
return -ENOMEM;
@@ -653,7 +653,7 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
pp = ihk_mc_map_memory(NULL, packet->arg, sizeof(struct mcctrl_signal));
sp = (struct mcctrl_signal *)ihk_mc_map_virtual(pp, 1, PTATTR_WRITABLE | PTATTR_ACTIVE);
memcpy(&info, sp, sizeof(struct mcctrl_signal));
ihk_mc_unmap_virtual(sp, 1, 0);
ihk_mc_unmap_virtual(sp, 1);
ihk_mc_unmap_memory(NULL, pp, sizeof(struct mcctrl_signal));
pckt.msg = SCD_MSG_SEND_SIGNAL_ACK;
pckt.err = 0;
@@ -726,7 +726,7 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
kprintf("%s: SCD_MSG_PERF_CTRL unexpected ctrl_type\n", __FUNCTION__);
}
ihk_mc_unmap_virtual(pcd, 1, 0);
ihk_mc_unmap_virtual(pcd, 1);
ihk_mc_unmap_memory(NULL, pp, sizeof(struct perf_ctrl_desc));
pckt.msg = SCD_MSG_PERF_ACK;

View File

@@ -71,7 +71,7 @@ static int test_packet_handler(struct ihk_ikc_channel_desc *c,
testmem(v, 4 * 1024 * 1024);
ihk_mc_unmap_virtual(v, 4 * 1024, 1);
ihk_mc_unmap_virtual(v, 4 * 1024);
ihk_mc_unmap_memory(NULL, pp, 4 * 1024 * 1024);
} else if (packet->msg == 0x11110012) {
p.msg = 0x11110013;

View File

@@ -1671,7 +1671,7 @@ void *ihk_mc_map_virtual(unsigned long phys, int npages,
return (char *)p + offset;
}
void ihk_mc_unmap_virtual(void *va, int npages, int free_physical)
void ihk_mc_unmap_virtual(void *va, int npages)
{
unsigned long i;
@@ -1681,13 +1681,7 @@ void ihk_mc_unmap_virtual(void *va, int npages, int free_physical)
flush_tlb_single((unsigned long)(va + (i << PAGE_SHIFT)));
}
#ifdef POSTK_DEBUG_TEMP_FIX_51 /* ihk_mc_unmap_virtual() free_physical disabled */
ihk_pagealloc_free(vmap_allocator, (unsigned long)va, npages);
#else /* POSTK_DEBUG_TEMP_FIX_51 */
if (free_physical) {
ihk_pagealloc_free(vmap_allocator, (unsigned long)va, npages);
}
#endif /* POSTK_DEBUG_TEMP_FIX_51 */
}
#ifdef ATTACHED_MIC

View File

@@ -1886,7 +1886,6 @@ retry:
} else {
// Host Kernel memory space
const enum ihk_mc_pt_attribute attr = 0;
const int remove_vmap_allocator_entry = 1;
void* vmap;
vmap = ihk_mc_map_virtual(phys, npages, attr);
@@ -1897,7 +1896,7 @@ retry:
goto out;
}
memcpy(virt, vmap, pgsize);
ihk_mc_unmap_virtual(vmap, npages, remove_vmap_allocator_entry);
ihk_mc_unmap_virtual(vmap, npages);
}
#else /*POSTK_DEBUG_TEMP_FIX_14*/
memcpy(virt, phys_to_virt(phys), pgsize);

View File

@@ -689,7 +689,7 @@ void process_procfs_request(struct ikc_scd_packet *rpacket)
kprintf("unsupported procfs entry: %d/%s\n", pid, p);
end:
ihk_mc_unmap_virtual(buf, npages, 0);
ihk_mc_unmap_virtual(buf, npages);
dprintf("ret: %d, eof: %d\n", ans, eof);
r->ret = ans;
r->eof = eof;
@@ -697,7 +697,7 @@ end:
packet.err = 0;
bufunavail:
ihk_mc_unmap_memory(NULL, pbuf, r->count);
ihk_mc_unmap_virtual(r, 1, 0);
ihk_mc_unmap_virtual(r, 1);
dataunavail:
ihk_mc_unmap_memory(NULL, parg, sizeof(struct procfs_read));

View File

@@ -390,7 +390,7 @@ long do_syscall(struct syscall_request *req, int cpu, int pid)
requestp = ihk_mc_map_virtual(phys, 1,
PTATTR_WRITABLE | PTATTR_ACTIVE);
memcpy(&request, requestp, sizeof request);
ihk_mc_unmap_virtual(requestp, 1, 1);
ihk_mc_unmap_virtual(requestp, 1);
ihk_mc_unmap_memory(NULL, phys,
sizeof(struct syscall_request));
num = request.number;