procfs: if memory_range_lock fails, process later
Change-Id: I3c5f24548455a63d8d5a4482f5081347f631885a Refs: #452
This commit is contained in:
committed by
Masamichi Takagi
parent
37605740a4
commit
ed21b6849d
@@ -601,6 +601,20 @@ extern unsigned long do_kill(struct thread *, int, int, int, struct siginfo *, i
|
||||
extern void terminate_host(int pid);
|
||||
extern void debug_log(long);
|
||||
|
||||
void send_procfs_answer(struct ikc_scd_packet *packet, int err)
|
||||
{
|
||||
struct ikc_scd_packet pckt;
|
||||
struct ihk_ikc_channel_desc *resp_channel = cpu_local_var(ikc2linux);
|
||||
|
||||
pckt.msg = SCD_MSG_PROCFS_ANSWER;
|
||||
pckt.ref = packet->ref;
|
||||
pckt.arg = packet->arg;
|
||||
pckt.err = err;
|
||||
pckt.reply = packet->reply;
|
||||
pckt.pid = packet->pid;
|
||||
syscall_channel_send(resp_channel, &pckt);
|
||||
}
|
||||
|
||||
static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
||||
void *__packet, void *ihk_os)
|
||||
{
|
||||
@@ -745,13 +759,7 @@ out_remote_pf:
|
||||
|
||||
case SCD_MSG_PROCFS_REQUEST:
|
||||
case SCD_MSG_PROCFS_RELEASE:
|
||||
pckt.msg = SCD_MSG_PROCFS_ANSWER;
|
||||
pckt.ref = packet->ref;
|
||||
pckt.arg = packet->arg;
|
||||
pckt.err = process_procfs_request(packet);
|
||||
pckt.reply = packet->reply;
|
||||
pckt.pid = packet->pid;
|
||||
syscall_channel_send(resp_channel, &pckt);
|
||||
process_procfs_request(packet);
|
||||
ret = 0;
|
||||
break;
|
||||
|
||||
|
||||
@@ -412,6 +412,7 @@ struct procfs_file {
|
||||
};
|
||||
|
||||
int process_procfs_request(struct ikc_scd_packet *rpacket);
|
||||
void send_procfs_answer(struct ikc_scd_packet *packet, int err);
|
||||
|
||||
#define RUSAGE_SELF 0
|
||||
#define RUSAGE_CHILDREN -1
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
extern int snprintf(char *buf, size_t size, const char *fmt, ...);
|
||||
extern int sscanf(const char * buf, const char * fmt, ...);
|
||||
extern int scnprintf(char * buf, size_t size, const char *fmt, ...);
|
||||
static int do_procfs_backlog(void *arg);
|
||||
|
||||
struct mckernel_procfs_buffer {
|
||||
unsigned long next_pa;
|
||||
@@ -148,12 +149,28 @@ procfs_delete_thread(struct thread *thread)
|
||||
procfs_thread_ctl(thread, SCD_MSG_PROCFS_TID_DELETE);
|
||||
}
|
||||
|
||||
static int procfs_backlog(struct process_vm *vm, struct ikc_scd_packet *rpacket)
|
||||
{
|
||||
void *arg;
|
||||
int err;
|
||||
|
||||
if (!(arg = kmalloc(sizeof(struct ikc_scd_packet), IHK_MC_AP_NOWAIT))) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
memcpy(arg, rpacket, sizeof(struct ikc_scd_packet));
|
||||
if ((err = add_backlog(do_procfs_backlog, arg))) {
|
||||
kfree(arg);
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief The callback function for mckernel procfs files.
|
||||
*
|
||||
* \param rarg returned argument
|
||||
*/
|
||||
int process_procfs_request(struct ikc_scd_packet *rpacket)
|
||||
static int _process_procfs_request(struct ikc_scd_packet *rpacket, int *result)
|
||||
{
|
||||
unsigned long rarg = rpacket->arg;
|
||||
unsigned long parg, pbuf;
|
||||
@@ -419,7 +436,17 @@ int process_procfs_request(struct ikc_scd_packet *rpacket)
|
||||
if (strcmp(p, "maps") == 0) {
|
||||
struct vm_range *range;
|
||||
|
||||
ihk_mc_spinlock_lock_noirq(&vm->memory_range_lock);
|
||||
if (!ihk_mc_spinlock_trylock_noirq(&vm->memory_range_lock)) {
|
||||
if (!result) {
|
||||
if ((err = procfs_backlog(vm, rpacket))) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
else {
|
||||
*result = -EAGAIN;
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
|
||||
range = lookup_process_memory_range(vm, 0, -1);
|
||||
while (range) {
|
||||
@@ -455,14 +482,15 @@ int process_procfs_request(struct ikc_scd_packet *rpacket)
|
||||
|
||||
if (ans < 0 || ans > count ||
|
||||
buf_add(&buf_top, &buf_cur, buf, ans) < 0) {
|
||||
ihk_mc_spinlock_unlock_noirq(&vm->memory_range_lock);
|
||||
ihk_mc_spinlock_unlock_noirq(
|
||||
&vm->memory_range_lock);
|
||||
goto err;
|
||||
}
|
||||
range = next_process_memory_range(vm, range);
|
||||
}
|
||||
|
||||
|
||||
ihk_mc_spinlock_unlock_noirq(&vm->memory_range_lock);
|
||||
|
||||
|
||||
ans = 0;
|
||||
goto end;
|
||||
}
|
||||
@@ -483,8 +511,18 @@ int process_procfs_request(struct ikc_scd_packet *rpacket)
|
||||
|
||||
start = (offset / sizeof(uint64_t)) << PAGE_SHIFT;
|
||||
end = start + ((count / sizeof(uint64_t)) << PAGE_SHIFT);
|
||||
|
||||
ihk_mc_spinlock_lock_noirq(&vm->memory_range_lock);
|
||||
|
||||
if (!ihk_mc_spinlock_trylock_noirq(&vm->memory_range_lock)) {
|
||||
if (!result) {
|
||||
if ((err = procfs_backlog(vm, rpacket))) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
else {
|
||||
*result = -EAGAIN;
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
|
||||
while (start < end) {
|
||||
*_buf = ihk_mc_pt_virt_to_pagemap(proc->vm->address_space->page_table, start);
|
||||
@@ -495,7 +533,7 @@ int process_procfs_request(struct ikc_scd_packet *rpacket)
|
||||
}
|
||||
|
||||
ihk_mc_spinlock_unlock_noirq(&vm->memory_range_lock);
|
||||
|
||||
|
||||
dprintf("/proc/pagemap: 0x%lx - 0x%lx, count: %d\n",
|
||||
start, end, count);
|
||||
|
||||
@@ -526,14 +564,24 @@ int process_procfs_request(struct ikc_scd_packet *rpacket)
|
||||
goto err;
|
||||
}
|
||||
|
||||
ihk_mc_spinlock_lock_noirq(&proc->vm->memory_range_lock);
|
||||
if (!ihk_mc_spinlock_trylock_noirq(&vm->memory_range_lock)) {
|
||||
if (!result) {
|
||||
if ((err = procfs_backlog(vm, rpacket))) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
else {
|
||||
*result = -EAGAIN;
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
range = lookup_process_memory_range(vm, 0, -1);
|
||||
while (range) {
|
||||
if(range->flag & VR_LOCKED)
|
||||
lockedsize += range->end - range->start;
|
||||
range = next_process_memory_range(vm, range);
|
||||
}
|
||||
ihk_mc_spinlock_unlock_noirq(&proc->vm->memory_range_lock);
|
||||
ihk_mc_spinlock_unlock_noirq(&vm->memory_range_lock);
|
||||
|
||||
cpu_bitmask = &bitmasks[bitmasks_offset];
|
||||
bitmasks_offset += bitmap_scnprintf(cpu_bitmask,
|
||||
@@ -786,6 +834,9 @@ end:
|
||||
if (r->pbuf == PA_NULL && buf_top)
|
||||
r->pbuf = virt_to_phys(buf_top);
|
||||
err:
|
||||
send_procfs_answer(rpacket, err);
|
||||
|
||||
out:
|
||||
if (vbuf) {
|
||||
ihk_mc_unmap_virtual(vbuf, npages);
|
||||
ihk_mc_unmap_memory(NULL, pbuf, r->count);
|
||||
@@ -807,3 +858,20 @@ err:
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int process_procfs_request(struct ikc_scd_packet *rpacket)
|
||||
{
|
||||
return _process_procfs_request(rpacket, NULL);
|
||||
}
|
||||
|
||||
static int do_procfs_backlog(void *arg)
|
||||
{
|
||||
struct ikc_scd_packet *rpacket = arg;
|
||||
int result = 0;
|
||||
|
||||
_process_procfs_request(rpacket, &result);
|
||||
if (!result) {
|
||||
kfree(arg);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user