[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <404735fb-023d-df37-e88e-8b05981bc1d5@bytedance.com>
Date: Mon, 14 Nov 2022 17:24:52 +0800
From: Zhongkun He <hezhongkun.hzk@...edance.com>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: corbet@....net, mhocko@...e.com, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, linux-api@...r.kernel.org,
linux-doc@...r.kernel.org
Subject: Re: [External] Re: [PATCH v2] mm: add new syscall
pidfd_set_mempolicy().
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.
Powered by blists - more mailing lists