From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A4AEC433FE for ; Mon, 14 Nov 2022 09:25:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD1506B0072; Mon, 14 Nov 2022 04:25:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B650B6B0073; Mon, 14 Nov 2022 04:25:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A22E86B0074; Mon, 14 Nov 2022 04:25:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9053F6B0072 for ; Mon, 14 Nov 2022 04:25:00 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5DCB2120DBF for ; Mon, 14 Nov 2022 09:25:00 +0000 (UTC) X-FDA: 80131513560.04.F314CE9 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by imf08.hostedemail.com (Postfix) with ESMTP id 1004C16000B for ; Mon, 14 Nov 2022 09:24:58 +0000 (UTC) Received: by mail-pj1-f53.google.com with SMTP id l22-20020a17090a3f1600b00212fbbcfb78so13196319pjc.3 for ; Mon, 14 Nov 2022 01:24:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=2148sqylEkmjswFsMWG1hvqqLaO0xyf1SiCUhyBRhaQ=; b=wDmXeMBBM5jSJ/rpe94OT8vmZBocQzSOc2asE4+zf3/rv3ent4zKaT8mtg8PyjCFU5 2RUzEpAC+0zcOMEnW/et/WDcoJYvUN3Uvq9sskGvYTdlE6Pn39zd81tE9UNAfHBNEtx4 avQW9asTBmZiES1iB7Ux0C/jRhSnPPEPtLujUGby6LtECk1fjNAXPHIErxjf/S2/CqD7 xoJHNK/933wBWaLG6toe5+DU8eAEIVkxat/mjG+0jU/ZSCn76zQR+CX6SLIDT6wLeAhg E+WK5T3IsQI62HF7yVJSqeyH9SWca57H0s5Zj38EUCAlKgbXpujmmr4YSUotKeezKjS6 FM3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=2148sqylEkmjswFsMWG1hvqqLaO0xyf1SiCUhyBRhaQ=; b=ALgLqLbuhclzN0t+vfwASwn9kv2kOJ2NYHquKN1Dpo0ZBH1VQqdGd8sjU6oFzbsejO oV9aAPKZFlWBQiiJIIkjLOLY41N6B2Uxj1zbbAoduhb94ROsWzyqZL2xGY8Cfdz/WQXV sy8U0XIF6A3H53zRJqz7J/zzMUAm0xdipaHRabOjjV79uJ+r4PGAW4Xmmfz70kldOTbN ubvSveYSLsMBV+HLi0gQHdvkX5znP308Bg83ux728DOjPtmpSNcusFkJ9HfUrr7jGde6 9N3SPyr5UOkajWB81f97tokBchk2wD8C1RvuSQW7prLaIADJgIYzhrhK7MXk6CAifQ++ AGig== X-Gm-Message-State: ANoB5pmx1bHZ1f3ovK9iNtricyg46FCQDFtmQpCYvHLiVfTFWHWrw0YF kABv+1TTiTCINNivNBUEmad+zA== X-Google-Smtp-Source: AA0mqf4JWvsDijQPfo/kXXptsIS2yyDPC0lc7dAS8Ff3VNNyq4RT1WTyw4YINmHAKX/obSA93DCkqA== X-Received: by 2002:a17:90a:6d8f:b0:214:2ee7:3dc with SMTP id a15-20020a17090a6d8f00b002142ee703dcmr12797742pjk.105.1668417897845; Mon, 14 Nov 2022 01:24:57 -0800 (PST) Received: from [10.68.76.92] ([139.177.225.245]) by smtp.gmail.com with ESMTPSA id h13-20020a170902f54d00b00176b3c9693esm6852376plf.299.2022.11.14.01.24.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Nov 2022 01:24:57 -0800 (PST) Message-ID: <404735fb-023d-df37-e88e-8b05981bc1d5@bytedance.com> Date: Mon, 14 Nov 2022 17:24:52 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [External] Re: [PATCH v2] mm: add new syscall pidfd_set_mempolicy(). To: Andrew Morton Cc: corbet@lwn.net, mhocko@suse.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org References: <20221111084051.2121029-1-hezhongkun.hzk@bytedance.com> <20221111112732.30e1696bcd0d5b711c188a9a@linux-foundation.org> From: Zhongkun He In-Reply-To: <20221111112732.30e1696bcd0d5b711c188a9a@linux-foundation.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668417900; a=rsa-sha256; cv=none; b=TDQT7TawrIwoQjK6Ro0lAxCfXL503C9TIP2mCxTbPnsM1BzVp34RSTgb4zw2hFtvCsOqmk y/Fo+wG0NDl9cadVuicIeMntkH138NGvIW5N591PV8WuNpbNikkNOFfC3b3SjrVi970oEY 8PZWAcMoipZhcsAkbMzrlb/ig1zlDTU= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=wDmXeMBB; spf=pass (imf08.hostedemail.com: domain of hezhongkun.hzk@bytedance.com designates 209.85.216.53 as permitted sender) smtp.mailfrom=hezhongkun.hzk@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668417900; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2148sqylEkmjswFsMWG1hvqqLaO0xyf1SiCUhyBRhaQ=; b=Xf9nr0B0bPkSH6dZyc/znTVGRRGh8H7n5A6OBJRgivoiaURTBYiqhdEizNdJxU1hOd+c5i 4hfPs1TnExZ4uNMKWv+uZWtpyVEebmw3MjjhMNf+ZrrkxFOZDtqy1j0VbfUNcTVyQHSIb2 by9yo+DnbENTaacwbSVzfuo6OP7Jrbg= X-Stat-Signature: 39b5s66rc381kb6ae4sta15ogzkpq438 X-Rspamd-Queue-Id: 1004C16000B Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=wDmXeMBB; spf=pass (imf08.hostedemail.com: domain of hezhongkun.hzk@bytedance.com designates 209.85.216.53 as permitted sender) smtp.mailfrom=hezhongkun.hzk@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1668417898-736086 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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.