Messages in this thread Patch in this message | | | Date | Mon, 14 Nov 2022 17:24:52 +0800 | Subject | Re: [External] Re: [PATCH v2] mm: add new syscall pidfd_set_mempolicy(). | From | Zhongkun He <> |
| |
Hi Andrew, > This sounds a bit suspicious. Please share much more detail about > these races. If we proced with this design then mpol_put_async() > shouild have comments which fully describe the need for the async free. >
Add some comments for async free, and use the TWA_SIGNAL_NO_IPI to notify the @task.
-/* - * mpol destructor for pidfd_set_mempolicy(). +/** + * mpol_put_async - free mempolicy asynchronously. + * @task: the target task to free mempolicy. + * @p : mempolicy to free + * + * @task must be specified by user. * free mempolicy directly if task is null or task_work_add() failed. + * + * A mempolicy can be either associated with a process or with a VMA. + * All vma manipulation is protected by mmap_lock.In process context + * there is no locking. If we need to apply mempolicy to other's + * task specified in pidfd, the original mempolicy may about to be + * freed by pidfd_set_mempolicy() while target task is using it. + * So,mpol_put_async() is used for free old mempolicy asynchronously. */ -void mpol_put_async(struct task_struct *task, struct mempolicy *p) +static void mpol_put_async(struct task_struct *task, struct mempolicy *p) { - enum task_work_notify_mode notify = TWA_RESUME; - if (!atomic_dec_and_test(&p->refcnt)) return;
@@ -333,10 +342,8 @@ void mpol_put_async(struct task_struct *task, struct mempolicy *p) goto out;
init_task_work(&p->w.cb_head, mpol_free_async); - if (task_work_pending(task)) - notify = TWA_SIGNAL; /* free memory in time */
- if (!task_work_add(task, &p->w.cb_head, notify)) + if (!task_work_add(task, &p->w.cb_head, TWA_SIGNAL_NO_IPI)) return; out: kmem_cache_free(policy_cache, p);
Thanks.
| |