From patchwork Thu Nov 11 09:50:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Imbrenda X-Patchwork-Id: 12614507 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10836C433F5 for ; Thu, 11 Nov 2021 09:50:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A19DE611AD for ; Thu, 11 Nov 2021 09:50:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A19DE611AD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 348056B0096; Thu, 11 Nov 2021 04:50:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F7C36B0098; Thu, 11 Nov 2021 04:50:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BFAC6B009A; Thu, 11 Nov 2021 04:50:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0234.hostedemail.com [216.40.44.234]) by kanga.kvack.org (Postfix) with ESMTP id 0DF266B0096 for ; Thu, 11 Nov 2021 04:50:38 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id CAF8D82FFF for ; Thu, 11 Nov 2021 09:50:37 +0000 (UTC) X-FDA: 78796179714.13.A09822C Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf16.hostedemail.com (Postfix) with ESMTP id 3358BF000090 for ; Thu, 11 Nov 2021 09:50:27 +0000 (UTC) Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1AB9IS7Z021006; Thu, 11 Nov 2021 09:50:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=FSi8nF5wttF33E9wgVxGAZhKsV5pV7mXAM/JTrIWIiw=; b=sES0q8W/tjRlpDAi+C9NI5dLSv3V8Krdto3gEi4eJNKt3x0PVTH01Hqdw85aUgY7gUf5 vP/W/3pjo/b1JbbUOwsPdqfRQ8G5VByJdkRfzB/VfXlqi5NxEOx/cc3S3HPiwnXPgfXU go0G3IEj+wBtcJ7W9o0T1gQwQSfH8dB5KjHymbCvzIszkDkPCAKiNbJjEofdjQGQtZoe +dmhN9iy4yO/7cpP6OqtOHbxu0BosfIGKQVArewqIS7nn8ouLyaGs6ZnVW0YcjZaXZzn 6prUe0OQk3cPp6v0JivSc1v7tqqLb6brj68ARBrz6rjmCikKGMQBz+mbBnhViHB51Hpk fQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3c90e80pcw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Nov 2021 09:50:27 +0000 Received: from m0098416.ppops.net (m0098416.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 1AB9lpbf004875; Thu, 11 Nov 2021 09:50:27 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0b-001b2d01.pphosted.com with ESMTP id 3c90e80pc4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Nov 2021 09:50:27 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 1AB9mqPx020080; Thu, 11 Nov 2021 09:50:25 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma03ams.nl.ibm.com with ESMTP id 3c5hbaur9p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Nov 2021 09:50:25 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1AB9oKcI41353644 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Nov 2021 09:50:20 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 101544C04A; Thu, 11 Nov 2021 09:50:20 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D23E24C064; Thu, 11 Nov 2021 09:50:18 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.11.147]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 11 Nov 2021 09:50:18 +0000 (GMT) From: Claudio Imbrenda To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: thuth@redhat.com, frankja@linux.ibm.com, borntraeger@de.ibm.com, Ulrich.Weigand@de.ibm.com, heiko.carstens@de.ibm.com, david@redhat.com, ultrachin@163.com, akpm@linux-foundation.org, vbabka@suse.cz, brookxu.cn@gmail.com, xiaoggchen@tencent.com, linuszeng@tencent.com, yihuilu@tencent.com, mhocko@suse.com, daniel.m.jordan@oracle.com, axboe@kernel.dk, legion@kernel.org, peterz@infradead.org, aarcange@redhat.com, christian@brauner.io, ebiederm@xmission.com, tglx@linutronix.de Subject: [RFC v1 1/4] exit: add arch mmput hook in exit_mm Date: Thu, 11 Nov 2021 10:50:05 +0100 Message-Id: <20211111095008.264412-3-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211111095008.264412-1-imbrenda@linux.ibm.com> References: <20211111095008.264412-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: bwRiliviVrvAScIBWTLvzmJnAaPO8Fsb X-Proofpoint-ORIG-GUID: 14pCVOk4SHyEK6qP3Tb520e2M6mm0Di6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-11_02,2021-11-08_02,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 mlxlogscore=855 impostorscore=0 malwarescore=0 lowpriorityscore=0 spamscore=0 mlxscore=0 adultscore=0 priorityscore=1501 suspectscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111110056 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 3358BF000090 X-Stat-Signature: 31bzj34efg58tabeok5rp4orogngi787 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b="sES0q8W/"; spf=pass (imf16.hostedemail.com: domain of imbrenda@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=imbrenda@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com X-HE-Tag: 1636624227-868881 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: This simple patch adds a hook for the mmput in exit_mm. This allows archs to perform the mmput in custom ways if desired (e.g. asynchronously) No functional change intended. Signed-off-by: Claudio Imbrenda --- include/asm-generic/mmu_context.h | 4 ++++ kernel/exit.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/asm-generic/mmu_context.h b/include/asm-generic/mmu_context.h index 91727065bacb..900931a6a105 100644 --- a/include/asm-generic/mmu_context.h +++ b/include/asm-generic/mmu_context.h @@ -73,4 +73,8 @@ static inline void deactivate_mm(struct task_struct *tsk, } #endif +#ifndef arch_exit_mm_mmput +#define arch_exit_mm_mmput mmput +#endif + #endif /* __ASM_GENERIC_MMU_CONTEXT_H */ diff --git a/kernel/exit.c b/kernel/exit.c index f702a6a63686..6eb1fdcc434e 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -504,7 +504,7 @@ static void exit_mm(void) task_unlock(current); mmap_read_unlock(mm); mm_update_next_owner(mm); - mmput(mm); + arch_exit_mm_mmput(mm); if (test_thread_flag(TIF_MEMDIE)) exit_oom_victim(); } From patchwork Thu Nov 11 09:50:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Imbrenda X-Patchwork-Id: 12614517 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAFB0C433EF for ; Thu, 11 Nov 2021 09:50:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5DAA3611AD for ; Thu, 11 Nov 2021 09:50:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5DAA3611AD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 8E9596B009C; Thu, 11 Nov 2021 04:50:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 611806B00A0; Thu, 11 Nov 2021 04:50:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45CEA6B009A; Thu, 11 Nov 2021 04:50:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0246.hostedemail.com [216.40.44.246]) by kanga.kvack.org (Postfix) with ESMTP id 167026B00A0 for ; Thu, 11 Nov 2021 04:50:42 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C81AF83E8A for ; Thu, 11 Nov 2021 09:50:41 +0000 (UTC) X-FDA: 78796179882.13.D72D800 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf28.hostedemail.com (Postfix) with ESMTP id 48F2990000AD for ; Thu, 11 Nov 2021 09:50:41 +0000 (UTC) Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1AB9gqiA023254; Thu, 11 Nov 2021 09:50:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=bKdhg9Gb6K7KpjmSeWRokfTQvQTvpxc1xwEDUvD3EfA=; b=ekaqFmvqo3LJBdmkfUcOrdH5GH83fPERilRix/c0CTGsvOPx1tYWI8mrFH2n1FvmPkav hPU3eDd5K3F3SrHf13JH1NbvNSA6IdkPeWrTidiMEO14XNEfZZFCXyfb8o69mYvZkdRA AIk1GddbxiRqwV5YVNR60+RyNDeAZ9Jhli5r0xHqTh0zInF/oSb1QsCsZpmYKj/XiDd5 aXct30h/GVpoDoVhNTiTmwA2MgsAtGkOTqwcIE68sj35/emFa6+JpoMDpLy29jrUbVf7 DmGXnyDxBW30ws/l5T6EVd9cG8RbfjZHHhFAYb5Oob72/IhocQvIC0gdlJnVksmd9/Oz 8Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3c90sp85d9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Nov 2021 09:50:30 +0000 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 1AB9gpXL023206; Thu, 11 Nov 2021 09:50:29 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3c90sp85cb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Nov 2021 09:50:29 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 1AB9n9u4027421; Thu, 11 Nov 2021 09:50:26 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma04ams.nl.ibm.com with ESMTP id 3c5hbauqrk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Nov 2021 09:50:26 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1AB9hbWU46334262 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Nov 2021 09:43:37 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5FA504C046; Thu, 11 Nov 2021 09:50:21 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 254FF4C05A; Thu, 11 Nov 2021 09:50:20 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.11.147]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 11 Nov 2021 09:50:20 +0000 (GMT) From: Claudio Imbrenda To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: thuth@redhat.com, frankja@linux.ibm.com, borntraeger@de.ibm.com, Ulrich.Weigand@de.ibm.com, heiko.carstens@de.ibm.com, david@redhat.com, ultrachin@163.com, akpm@linux-foundation.org, vbabka@suse.cz, brookxu.cn@gmail.com, xiaoggchen@tencent.com, linuszeng@tencent.com, yihuilu@tencent.com, mhocko@suse.com, daniel.m.jordan@oracle.com, axboe@kernel.dk, legion@kernel.org, peterz@infradead.org, aarcange@redhat.com, christian@brauner.io, ebiederm@xmission.com, tglx@linutronix.de Subject: [RFC v1 2/4] kernel/fork.c: implement new process_mmput_async syscall Date: Thu, 11 Nov 2021 10:50:06 +0100 Message-Id: <20211111095008.264412-4-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211111095008.264412-1-imbrenda@linux.ibm.com> References: <20211111095008.264412-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: wo1ZC9ZfZPI0gR0GLIm88cmTflN3RQqr X-Proofpoint-ORIG-GUID: KWan9gBZ8_nmYld4DZ6voFMR-T6Tknlq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-11_02,2021-11-08_02,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 adultscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 mlxscore=0 spamscore=0 mlxlogscore=944 clxscore=1015 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111110056 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 48F2990000AD X-Stat-Signature: fsnz6n5xubbz3gqi3xgjmfbowc571eo5 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=ekaqFmvq; spf=pass (imf28.hostedemail.com: domain of imbrenda@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=imbrenda@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com X-HE-Tag: 1636624241-648572 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: The goal of this new syscall is to be able to asynchronously free the mm of a dying process. This is especially useful for processes that use huge amounts of memory (e.g. databases or KVM guests). The process is allowed to terminate immediately, while its mm is cleaned/reclaimed asynchronously. A separate process needs use the process_mmput_async syscall to attach itself to the mm of a running target process. The process will then sleep until the last user of the target mm has gone. When the last user of the mm has gone, instead of synchronously free the mm, the attached process is awoken. The syscall will then continue and clean up the target mm. This solution has the advantage that the cleanup of the target mm can happen both be asynchronous and properly accounted for (e.g. cgroups). Tested on s390x. A separate patch will actually wire up the syscall. Signed-off-by: Claudio Imbrenda --- include/linux/mm_types.h | 1 + kernel/fork.c | 103 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 102 insertions(+), 2 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index bb8c6f5f19bc..adc62cba3e91 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -631,6 +631,7 @@ struct mm_struct { atomic_long_t hugetlb_usage; #endif struct work_struct async_put_work; + struct task_struct *mmput_async_task; #ifdef CONFIG_IOMMU_SUPPORT u32 pasid; diff --git a/kernel/fork.c b/kernel/fork.c index 5de23f3e08bf..0da39b76005c 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1062,6 +1062,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p, #endif mm_init_uprobes_state(mm); hugetlb_count_init(mm); + mm->mmput_async_task = NULL; if (current->mm) { mm->flags = current->mm->flags & MMF_INIT_MASK; @@ -1130,7 +1131,12 @@ void mmput(struct mm_struct *mm) { might_sleep(); - if (atomic_dec_and_test(&mm->mm_users)) + if (!atomic_dec_and_test(&mm->mm_users)) + return; + + if (READ_ONCE(mm->mmput_async_task)) + wake_up_process(mm->mmput_async_task); + else __mmput(mm); } EXPORT_SYMBOL_GPL(mmput); @@ -1146,7 +1152,12 @@ static void mmput_async_fn(struct work_struct *work) void mmput_async(struct mm_struct *mm) { - if (atomic_dec_and_test(&mm->mm_users)) { + if (!atomic_dec_and_test(&mm->mm_users)) + return; + + if (READ_ONCE(mm->mmput_async_task)) { + wake_up_process(mm->mmput_async_task); + } else { INIT_WORK(&mm->async_put_work, mmput_async_fn); schedule_work(&mm->async_put_work); } @@ -3191,3 +3202,91 @@ int sysctl_max_threads(struct ctl_table *table, int write, return 0; } + +SYSCALL_DEFINE2(process_mmput_async, int, pidfd, unsigned int, flags) +{ +#ifdef CONFIG_MMU + struct mm_struct *mm = NULL; + struct task_struct *task; + unsigned int tmp; + struct pid *pid; + + if (flags) + return -EINVAL; + + pid = pidfd_get_pid(pidfd, &tmp); + if (IS_ERR(pid)) + return PTR_ERR(pid); + + task = get_pid_task(pid, PIDTYPE_TGID); + /* The PID is not needed once we have the tast_struct */ + put_pid(pid); + if (!task) + return -ESRCH; + + /* + * The struct_mm is guaranteed to be there as long as we are holding + * a reference to the task_struct. This also guarantees that we + * will not race with mmput, since we are now holding one additional + * reference. + */ + if (mmget_not_zero(task->mm)) + mm = task->mm; + /* The task_struct is not needed once we have the mm_struct */ + put_task_struct(task); + /* If the target process no longer has an mm, there is nothing we can do. */ + if (!mm) + return -ENXIO; + + /* Use TASK_IDLE instead of TASK_UNINTERRUPTIBLE to avoid stall notifications. */ + set_current_state(TASK_IDLE); + /* + * Return an error if another task had already set itself as async + * cleanup for the target mm. + */ + if (cmpxchg(&mm->mmput_async_task, NULL, current) != NULL) { + set_current_state(TASK_RUNNING); + return -EEXIST; + } + + /* + * The target mm now has an extra reference to current. + * Is this useless? + */ + get_task_struct(current); + /* + * We will now do mmput, and we no longer have a reference to the + * task; we need mmgrab to be able to reference the mm_struct even + * after its last user is gone. + */ + mmgrab(mm); + /* + * If the target mm has been discarded after we got its reference, + * then we are holding the last reference to it, and doing mmput + * here will cause us to be schedulable again. + */ + mmput(mm); + + /* + * Go to sleep; we are set to TASK_IDLE, so nothing will wake us up + * except an explicit wake_up_process from mmput. + */ + schedule(); + + /* Put the extra reference taken above */ + put_task_struct(current); + + /* Should this be a warning instead? */ + if (atomic_read(&mm->mm_users)) + panic("mm_users not 0 but trying to __mmput anyway!"); + + /* Do the actual work */ + __mmput(mm); + /* And put the extra reference taken above */ + mmdrop(mm); + + return 0; +#else + return -ENOSYS; +#endif /* CONFIG_MMU */ +} From patchwork Thu Nov 11 09:50:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Imbrenda X-Patchwork-Id: 12614515 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 515AFC433EF for ; Thu, 11 Nov 2021 09:50:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D29F961152 for ; Thu, 11 Nov 2021 09:50:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D29F961152 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 6938B6B009A; Thu, 11 Nov 2021 04:50:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3AEDC6B009F; Thu, 11 Nov 2021 04:50:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE00B6B009A; Thu, 11 Nov 2021 04:50:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0049.hostedemail.com [216.40.44.49]) by kanga.kvack.org (Postfix) with ESMTP id C2EF16B009D for ; Thu, 11 Nov 2021 04:50:41 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8249B82FFF for ; Thu, 11 Nov 2021 09:50:41 +0000 (UTC) X-FDA: 78796179882.10.820DC5D Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf03.hostedemail.com (Postfix) with ESMTP id 5C3D530000AC for ; Thu, 11 Nov 2021 09:50:32 +0000 (UTC) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1AB9hsIP010326; Thu, 11 Nov 2021 09:50:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=xxd1gYnGnuLUzdYjZpHEdzhiOxRoDQl3TblHLAxYn0w=; b=pk+01Nx2owzE+rr8I+sp+hRiWrP8AvTWl3qNLrQhaFGM3JMRrIw+Mdan+PpSno1MEH7a nGX9W5QkYLwxPUKbpJXXJFmW70tadvgYHy+GvR4BD2bnH5ryl2Vwc6oBuAT6vJ0jKXzd gU3wWQgogDLR8N89WLYot/QntO6DwtlsRs7EVVKWJYONnmP5EBpSPSHZZNY/l9ak8PvJ qBYmTf57v3o27PB2nTW+RA+Q0zhqZSMg3q/JcuNo3b6bJS8/CsUqb1gu5fu7+oXVJAAP /q9d0XRG5QemiMQPIZxXWY30kOtrJhdemmF2R8BghU8fTlziWookuwq9J4L51F2HMScd LA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3c90t4r337-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Nov 2021 09:50:30 +0000 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 1AB9jDJk016101; Thu, 11 Nov 2021 09:50:30 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 3c90t4r32h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Nov 2021 09:50:30 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 1AB9mpgj016615; Thu, 11 Nov 2021 09:50:27 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma06ams.nl.ibm.com with ESMTP id 3c5gyk3vrv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Nov 2021 09:50:27 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1AB9hfF559965944 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Nov 2021 09:43:41 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A14E74C040; Thu, 11 Nov 2021 09:50:22 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 77A224C05A; Thu, 11 Nov 2021 09:50:21 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.11.147]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 11 Nov 2021 09:50:21 +0000 (GMT) From: Claudio Imbrenda To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: thuth@redhat.com, frankja@linux.ibm.com, borntraeger@de.ibm.com, Ulrich.Weigand@de.ibm.com, heiko.carstens@de.ibm.com, david@redhat.com, ultrachin@163.com, akpm@linux-foundation.org, vbabka@suse.cz, brookxu.cn@gmail.com, xiaoggchen@tencent.com, linuszeng@tencent.com, yihuilu@tencent.com, mhocko@suse.com, daniel.m.jordan@oracle.com, axboe@kernel.dk, legion@kernel.org, peterz@infradead.org, aarcange@redhat.com, christian@brauner.io, ebiederm@xmission.com, tglx@linutronix.de Subject: [RFC v1 3/4] mm: wire up the process_mmput_async syscall Date: Thu, 11 Nov 2021 10:50:07 +0100 Message-Id: <20211111095008.264412-5-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211111095008.264412-1-imbrenda@linux.ibm.com> References: <20211111095008.264412-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: _hl2XRplxyqsMBE5ybW60qxgt44LFywM X-Proofpoint-GUID: w8Uuk7VwYqRZto6iYF5TCI0Em3wLqK1f X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-11_02,2021-11-08_02,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 clxscore=1015 suspectscore=0 malwarescore=0 phishscore=0 mlxscore=0 impostorscore=0 bulkscore=0 mlxlogscore=829 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111110056 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 5C3D530000AC X-Stat-Signature: xme6iuim5rg5j8bwuf5wt44nhygk1dr6 Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=pk+01Nx2; spf=pass (imf03.hostedemail.com: domain of imbrenda@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=imbrenda@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com X-HE-Tag: 1636624232-606630 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: Wire up the process_mmput_async syscall. Signed-off-by: Claudio Imbrenda --- arch/alpha/kernel/syscalls/syscall.tbl | 2 ++ arch/arm/tools/syscall.tbl | 1 + arch/arm64/include/asm/unistd.h | 2 +- arch/arm64/include/asm/unistd32.h | 2 ++ arch/ia64/kernel/syscalls/syscall.tbl | 2 ++ arch/m68k/kernel/syscalls/syscall.tbl | 2 ++ arch/microblaze/kernel/syscalls/syscall.tbl | 2 ++ arch/mips/kernel/syscalls/syscall_n32.tbl | 2 ++ arch/mips/kernel/syscalls/syscall_n64.tbl | 2 ++ arch/mips/kernel/syscalls/syscall_o32.tbl | 2 ++ arch/parisc/kernel/syscalls/syscall.tbl | 2 ++ arch/powerpc/kernel/syscalls/syscall.tbl | 2 ++ arch/s390/kernel/syscalls/syscall.tbl | 2 ++ arch/sh/kernel/syscalls/syscall.tbl | 2 ++ arch/sparc/kernel/syscalls/syscall.tbl | 2 ++ arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + arch/xtensa/kernel/syscalls/syscall.tbl | 2 ++ include/linux/syscalls.h | 1 + include/uapi/asm-generic/unistd.h | 5 ++++- kernel/sys_ni.c | 1 + 21 files changed, 38 insertions(+), 2 deletions(-) diff --git a/arch/alpha/kernel/syscalls/syscall.tbl b/arch/alpha/kernel/syscalls/syscall.tbl index e4a041cd5715..2ec84b67534e 100644 --- a/arch/alpha/kernel/syscalls/syscall.tbl +++ b/arch/alpha/kernel/syscalls/syscall.tbl @@ -488,3 +488,5 @@ 556 common landlock_restrict_self sys_landlock_restrict_self # 557 reserved for memfd_secret 558 common process_mrelease sys_process_mrelease +# 559 reserved for futex_waitv +560 common process_mmput_async sys_process_mmput_async diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl index 543100151f2b..8aee1a20f4d5 100644 --- a/arch/arm/tools/syscall.tbl +++ b/arch/arm/tools/syscall.tbl @@ -463,3 +463,4 @@ # 447 reserved for memfd_secret 448 common process_mrelease sys_process_mrelease 449 common futex_waitv sys_futex_waitv +450 common process_mmput_async sys_process_mmput_async diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h index 6bdb5f5db438..4e65da3445c7 100644 --- a/arch/arm64/include/asm/unistd.h +++ b/arch/arm64/include/asm/unistd.h @@ -38,7 +38,7 @@ #define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5) #define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800) -#define __NR_compat_syscalls 450 +#define __NR_compat_syscalls 451 #endif #define __ARCH_WANT_SYS_CLONE diff --git a/arch/arm64/include/asm/unistd32.h b/arch/arm64/include/asm/unistd32.h index 41ea1195e44b..e3b75a2896d2 100644 --- a/arch/arm64/include/asm/unistd32.h +++ b/arch/arm64/include/asm/unistd32.h @@ -905,6 +905,8 @@ __SYSCALL(__NR_landlock_restrict_self, sys_landlock_restrict_self) __SYSCALL(__NR_process_mrelease, sys_process_mrelease) #define __NR_futex_waitv 449 __SYSCALL(__NR_futex_waitv, sys_futex_waitv) +#define __NR_process_mmput_async 450 +__SYSCALL(__NR_process_mmput_async, sys_process_mmput_async) /* * Please add new compat syscalls above this comment and update diff --git a/arch/ia64/kernel/syscalls/syscall.tbl b/arch/ia64/kernel/syscalls/syscall.tbl index 6fea1844fb95..c1e454342e94 100644 --- a/arch/ia64/kernel/syscalls/syscall.tbl +++ b/arch/ia64/kernel/syscalls/syscall.tbl @@ -369,3 +369,5 @@ 446 common landlock_restrict_self sys_landlock_restrict_self # 447 reserved for memfd_secret 448 common process_mrelease sys_process_mrelease +# 449 reserved for futex_waitv +450 common process_mmput_async sys_process_mmput_async diff --git a/arch/m68k/kernel/syscalls/syscall.tbl b/arch/m68k/kernel/syscalls/syscall.tbl index 7976dff8f879..b89bcb3b50d0 100644 --- a/arch/m68k/kernel/syscalls/syscall.tbl +++ b/arch/m68k/kernel/syscalls/syscall.tbl @@ -448,3 +448,5 @@ 446 common landlock_restrict_self sys_landlock_restrict_self # 447 reserved for memfd_secret 448 common process_mrelease sys_process_mrelease +# 449 reserved for futex_waitv +450 common process_mmput_async sys_process_mmput_async diff --git a/arch/microblaze/kernel/syscalls/syscall.tbl b/arch/microblaze/kernel/syscalls/syscall.tbl index 6b0e11362bd2..cf4df3a9f95d 100644 --- a/arch/microblaze/kernel/syscalls/syscall.tbl +++ b/arch/microblaze/kernel/syscalls/syscall.tbl @@ -454,3 +454,5 @@ 446 common landlock_restrict_self sys_landlock_restrict_self # 447 reserved for memfd_secret 448 common process_mrelease sys_process_mrelease +# 449 reserved for futex_waitv +450 common process_mmput_async sys_process_mmput_async diff --git a/arch/mips/kernel/syscalls/syscall_n32.tbl b/arch/mips/kernel/syscalls/syscall_n32.tbl index 70e32de2bcaa..6374c2acc370 100644 --- a/arch/mips/kernel/syscalls/syscall_n32.tbl +++ b/arch/mips/kernel/syscalls/syscall_n32.tbl @@ -387,3 +387,5 @@ 446 n32 landlock_restrict_self sys_landlock_restrict_self # 447 reserved for memfd_secret 448 n32 process_mrelease sys_process_mrelease +# 449 reserved for futex_waitv +450 common process_mmput_async sys_process_mmput_async diff --git a/arch/mips/kernel/syscalls/syscall_n64.tbl b/arch/mips/kernel/syscalls/syscall_n64.tbl index 1ca7bc337932..f7d336bcdcad 100644 --- a/arch/mips/kernel/syscalls/syscall_n64.tbl +++ b/arch/mips/kernel/syscalls/syscall_n64.tbl @@ -363,3 +363,5 @@ 446 n64 landlock_restrict_self sys_landlock_restrict_self # 447 reserved for memfd_secret 448 n64 process_mrelease sys_process_mrelease +# 449 reserved for futex_waitv +450 common process_mmput_async sys_process_mmput_async diff --git a/arch/mips/kernel/syscalls/syscall_o32.tbl b/arch/mips/kernel/syscalls/syscall_o32.tbl index a61c35edaa74..1b4572b4c0f4 100644 --- a/arch/mips/kernel/syscalls/syscall_o32.tbl +++ b/arch/mips/kernel/syscalls/syscall_o32.tbl @@ -436,3 +436,5 @@ 446 o32 landlock_restrict_self sys_landlock_restrict_self # 447 reserved for memfd_secret 448 o32 process_mrelease sys_process_mrelease +# 449 reserved for futex_waitv +450 common process_mmput_async sys_process_mmput_async diff --git a/arch/parisc/kernel/syscalls/syscall.tbl b/arch/parisc/kernel/syscalls/syscall.tbl index bf751e0732b7..58fca00dd2c4 100644 --- a/arch/parisc/kernel/syscalls/syscall.tbl +++ b/arch/parisc/kernel/syscalls/syscall.tbl @@ -446,3 +446,5 @@ 446 common landlock_restrict_self sys_landlock_restrict_self # 447 reserved for memfd_secret 448 common process_mrelease sys_process_mrelease +# 449 reserved for futex_waitv +450 common process_mmput_async sys_process_mmput_async diff --git a/arch/powerpc/kernel/syscalls/syscall.tbl b/arch/powerpc/kernel/syscalls/syscall.tbl index 7bef917cc84e..9c62f9ca307f 100644 --- a/arch/powerpc/kernel/syscalls/syscall.tbl +++ b/arch/powerpc/kernel/syscalls/syscall.tbl @@ -528,3 +528,5 @@ 446 common landlock_restrict_self sys_landlock_restrict_self # 447 reserved for memfd_secret 448 common process_mrelease sys_process_mrelease +# 449 reserved for futex_waitv +450 common process_mmput_async sys_process_mmput_async diff --git a/arch/s390/kernel/syscalls/syscall.tbl b/arch/s390/kernel/syscalls/syscall.tbl index df5261e5cfe1..aa6b50367a8b 100644 --- a/arch/s390/kernel/syscalls/syscall.tbl +++ b/arch/s390/kernel/syscalls/syscall.tbl @@ -451,3 +451,5 @@ 446 common landlock_restrict_self sys_landlock_restrict_self sys_landlock_restrict_self # 447 reserved for memfd_secret 448 common process_mrelease sys_process_mrelease sys_process_mrelease +# 449 reserved for futex_waitv +450 common process_mmput_async sys_process_mmput_async sys_process_mmput_async diff --git a/arch/sh/kernel/syscalls/syscall.tbl b/arch/sh/kernel/syscalls/syscall.tbl index 208f131659c5..372122390fa2 100644 --- a/arch/sh/kernel/syscalls/syscall.tbl +++ b/arch/sh/kernel/syscalls/syscall.tbl @@ -451,3 +451,5 @@ 446 common landlock_restrict_self sys_landlock_restrict_self # 447 reserved for memfd_secret 448 common process_mrelease sys_process_mrelease +# 449 reserved for futex_waitv +450 common process_mmput_async sys_process_mmput_async diff --git a/arch/sparc/kernel/syscalls/syscall.tbl b/arch/sparc/kernel/syscalls/syscall.tbl index c37764dc764d..5c1448ead433 100644 --- a/arch/sparc/kernel/syscalls/syscall.tbl +++ b/arch/sparc/kernel/syscalls/syscall.tbl @@ -494,3 +494,5 @@ 446 common landlock_restrict_self sys_landlock_restrict_self # 447 reserved for memfd_secret 448 common process_mrelease sys_process_mrelease +# 449 reserved for futex_waitv +450 common process_mmput_async sys_process_mmput_async diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl index 7e25543693de..ad034bc349ec 100644 --- a/arch/x86/entry/syscalls/syscall_32.tbl +++ b/arch/x86/entry/syscalls/syscall_32.tbl @@ -454,3 +454,4 @@ 447 i386 memfd_secret sys_memfd_secret 448 i386 process_mrelease sys_process_mrelease 449 i386 futex_waitv sys_futex_waitv +450 i386 process_mmput_async sys_process_mmput_async diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl index fe8f8dd157b4..df659c967932 100644 --- a/arch/x86/entry/syscalls/syscall_64.tbl +++ b/arch/x86/entry/syscalls/syscall_64.tbl @@ -371,6 +371,7 @@ 447 common memfd_secret sys_memfd_secret 448 common process_mrelease sys_process_mrelease 449 common futex_waitv sys_futex_waitv +450 common process_mmput_async sys_process_mmput_async # # Due to a historical design error, certain syscalls are numbered differently diff --git a/arch/xtensa/kernel/syscalls/syscall.tbl b/arch/xtensa/kernel/syscalls/syscall.tbl index 104b327f8ac9..7534f2969af6 100644 --- a/arch/xtensa/kernel/syscalls/syscall.tbl +++ b/arch/xtensa/kernel/syscalls/syscall.tbl @@ -419,3 +419,5 @@ 446 common landlock_restrict_self sys_landlock_restrict_self # 447 reserved for memfd_secret 448 common process_mrelease sys_process_mrelease +# 449 reserved for futex_waitv +450 common process_mmput_async sys_process_mmput_async diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 528a478dbda8..e416f6f8a4b8 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -920,6 +920,7 @@ asmlinkage long sys_mincore(unsigned long start, size_t len, asmlinkage long sys_madvise(unsigned long start, size_t len, int behavior); asmlinkage long sys_process_madvise(int pidfd, const struct iovec __user *vec, size_t vlen, int behavior, unsigned int flags); +asmlinkage long sys_process_mmput_async(int pidfd, unsigned int flags); asmlinkage long sys_process_mrelease(int pidfd, unsigned int flags); asmlinkage long sys_remap_file_pages(unsigned long start, unsigned long size, unsigned long prot, unsigned long pgoff, diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h index 4557a8b6086f..bf6b9c3e4957 100644 --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -883,8 +883,11 @@ __SYSCALL(__NR_process_mrelease, sys_process_mrelease) #define __NR_futex_waitv 449 __SYSCALL(__NR_futex_waitv, sys_futex_waitv) +#define __NR_process_mmput_async 450 +__SYSCALL(__NR_process_mmput_async, sys_process_mmput_async) + #undef __NR_syscalls -#define __NR_syscalls 450 +#define __NR_syscalls 451 /* * 32 bit systems traditionally used different diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c index d1944258cfc0..0b69802a3d62 100644 --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c @@ -290,6 +290,7 @@ COND_SYSCALL(munlockall); COND_SYSCALL(mincore); COND_SYSCALL(madvise); COND_SYSCALL(process_madvise); +COND_SYSCALL(process_mmput_async); COND_SYSCALL(process_mrelease); COND_SYSCALL(remap_file_pages); COND_SYSCALL(mbind); From patchwork Thu Nov 11 09:50:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Imbrenda X-Patchwork-Id: 12614509 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D0B3C433EF for ; Thu, 11 Nov 2021 09:50:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1034E61107 for ; Thu, 11 Nov 2021 09:50:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1034E61107 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id A00426B0098; Thu, 11 Nov 2021 04:50:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9899B6B009A; Thu, 11 Nov 2021 04:50:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B3366B009B; Thu, 11 Nov 2021 04:50:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0187.hostedemail.com [216.40.44.187]) by kanga.kvack.org (Postfix) with ESMTP id 6DDF76B0098 for ; Thu, 11 Nov 2021 04:50:39 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 2533182FF5 for ; Thu, 11 Nov 2021 09:50:39 +0000 (UTC) X-FDA: 78796179756.27.40BFCE6 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf17.hostedemail.com (Postfix) with ESMTP id AAA3BF000136 for ; Thu, 11 Nov 2021 09:50:38 +0000 (UTC) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1AB8hchF015946; Thu, 11 Nov 2021 09:50:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=9yzO3BN01R+xwzrsYOarJeAaAZRR7/sSADKUU1/AwUU=; b=Yl4IkLQNpU6cT1gSgFFV6IAdZVQrcTtnIFH5kKUQlEnhSvo43hIMII+rQQXAbvmFgs6U 6/HM5mvAkv0qcelGhlsRBZiMScPoN/KbG2m3acmmEUOwseqlehFkGza/EDOUTbvMPZSJ GQiCvVHFYCMGwOMVe30zmi13ohNxiSGQl0PLrWU6kXNxaOAkJqpJXyIAhLtxtL6H8WlE 9WxN5wcmYtVL0iGmumqRxDVN8QMQn9A2sY+CKYMCPuoUlqPyK9YusvAf/Bmo53PulagS pffpwXxsl4tbv1ZjD+e5h99ii/CuWPmbWn/aEq3PK7n0oQhp5DeUPXRrMgjLGOxDaYJO MA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3c8ywvskb4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Nov 2021 09:50:31 +0000 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 1AB9Gt3v000675; Thu, 11 Nov 2021 09:50:31 GMT Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 3c8ywvska3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Nov 2021 09:50:31 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 1AB9nJmM003941; Thu, 11 Nov 2021 09:50:29 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma03fra.de.ibm.com with ESMTP id 3c5hbasbxr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Nov 2021 09:50:29 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1AB9oOxx51052872 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Nov 2021 09:50:24 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D8E9A4C05C; Thu, 11 Nov 2021 09:50:23 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B7A734C066; Thu, 11 Nov 2021 09:50:22 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.11.147]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 11 Nov 2021 09:50:22 +0000 (GMT) From: Claudio Imbrenda To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: thuth@redhat.com, frankja@linux.ibm.com, borntraeger@de.ibm.com, Ulrich.Weigand@de.ibm.com, heiko.carstens@de.ibm.com, david@redhat.com, ultrachin@163.com, akpm@linux-foundation.org, vbabka@suse.cz, brookxu.cn@gmail.com, xiaoggchen@tencent.com, linuszeng@tencent.com, yihuilu@tencent.com, mhocko@suse.com, daniel.m.jordan@oracle.com, axboe@kernel.dk, legion@kernel.org, peterz@infradead.org, aarcange@redhat.com, christian@brauner.io, ebiederm@xmission.com, tglx@linutronix.de Subject: [RFC v1 4/4] kernel/fork.c: process_mmput_async: stop OOM while freeing memory Date: Thu, 11 Nov 2021 10:50:08 +0100 Message-Id: <20211111095008.264412-6-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211111095008.264412-1-imbrenda@linux.ibm.com> References: <20211111095008.264412-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: B7S9vjvRQblh7Daa7g2JMtqFHEdIVmw4 X-Proofpoint-ORIG-GUID: JJjGFKWaQASuTc3y7iLoJeuCTRReAybx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-11_02,2021-11-08_02,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 malwarescore=0 mlxlogscore=999 impostorscore=0 mlxscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 clxscore=1015 priorityscore=1501 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111110056 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: AAA3BF000136 X-Stat-Signature: pjiqcwxx5ftu98ggunwjbtkxfsini89w Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=Yl4IkLQN; spf=pass (imf17.hostedemail.com: domain of imbrenda@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=imbrenda@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com X-HE-Tag: 1636624238-386176 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: This patch implements a simple OOM notifier to stop the OOM killer while a mm is being reclaimed asynchronously using the process_mmput_async syscall. Tested on s390x. Signed-off-by: Claudio Imbrenda --- kernel/fork.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/kernel/fork.c b/kernel/fork.c index 0da39b76005c..7279209eb69c 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -118,6 +118,11 @@ */ #define MAX_THREADS FUTEX_TID_MASK +/* + * Priority for the OOM notifier used in process_mmput_async + */ +#define PROCESS_MMPUT_ASYNC_OOM_NOTIFY_PRIORITY 70 + /* * Protected counters by write_lock_irq(&tasklist_lock) */ @@ -3203,13 +3208,27 @@ int sysctl_max_threads(struct ctl_table *table, int write, return 0; } +/* Prevent the OOM from being triggered while we are cleaning up asynchronously */ +static int mmput_async_oom_notifier(struct notifier_block *nb, unsigned long dummy, void *parm) +{ + /* + * We cannot know the speed at which pages are being freed, so we + * fake it and say it's at least one. This is already enough to + * stop the OOM killer. + */ + *(unsigned long *)parm += PAGE_SIZE; + return NOTIFY_OK; +} + SYSCALL_DEFINE2(process_mmput_async, int, pidfd, unsigned int, flags) { #ifdef CONFIG_MMU + struct notifier_block oom_nb; struct mm_struct *mm = NULL; struct task_struct *task; unsigned int tmp; struct pid *pid; + int r; if (flags) return -EINVAL; @@ -3280,8 +3299,17 @@ SYSCALL_DEFINE2(process_mmput_async, int, pidfd, unsigned int, flags) if (atomic_read(&mm->mm_users)) panic("mm_users not 0 but trying to __mmput anyway!"); + /* + * Register an OOM notifier, to stop the OOM while we are + * asynchronously freeing the mm. + */ + oom_nb.priority = PROCESS_MMPUT_ASYNC_OOM_NOTIFY_PRIORITY; + oom_nb.notifier_call = mmput_async_oom_notifier; + r = register_oom_notifier(&oom_nb); /* Do the actual work */ __mmput(mm); + if (!r) + unregister_oom_notifier(&oom_nb); /* And put the extra reference taken above */ mmdrop(mm);