From patchwork Mon Dec 9 13:25:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13899768 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 86E37E77180 for ; Mon, 9 Dec 2024 13:26:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2FEB46B043E; Mon, 9 Dec 2024 08:26:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AE078D0058; Mon, 9 Dec 2024 08:26:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D99F6B0440; Mon, 9 Dec 2024 08:26:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E16FB6B043E for ; Mon, 9 Dec 2024 08:26:03 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9530116040C for ; Mon, 9 Dec 2024 13:26:03 +0000 (UTC) X-FDA: 82875492336.20.FB3AB9F Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf10.hostedemail.com (Postfix) with ESMTP id BF397C0010 for ; Mon, 9 Dec 2024 13:25:50 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=ruanjinjie@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733750750; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EukFf2fzHXOLFufYAuQeaGOZYaQLk4Tb/e4HfEnCOZA=; b=wzZMsu0XZuLETB0nJQcck4jCWk6RFexlu89IES/8+qQX8Kg2AObyihvKVFNmXYmy4fwfLS kUsHNk35Hx/tJuV9PQHHFaEfBgmOrAFQyL5GBVnXcgsVIezfwCa4/djR7fHVGiU5DRNSVY XS5sVw81S4tIohix1HgSxS0xkAvmSXM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733750750; a=rsa-sha256; cv=none; b=wW6WVZIgk4AlU0gHXBw/ls9XS9ibUO2lnByHIWd7xdXnumLC36pUmBUQnNZLuZvBcb+g4P T3JeaGO7vXDdZOH9GwHR6ThVB9gjwzl5fNmYi68RwLR1FnTez0QquYbgxYM+KMZ9LmwPoz cCy93vYskOAWKMDzo3tmxsqT0NgHjGE= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=ruanjinjie@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Y6MxM4KTbzgZ7S; Mon, 9 Dec 2024 21:23:03 +0800 (CST) Received: from kwepemg200008.china.huawei.com (unknown [7.202.181.35]) by mail.maildlp.com (Postfix) with ESMTPS id CC659180102; Mon, 9 Dec 2024 21:25:55 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemg200008.china.huawei.com (7.202.181.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 9 Dec 2024 21:25:55 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , Subject: [PATCH 1/2] userfaultfd: handle dup_userfaultfd() NULL check inline Date: Mon, 9 Dec 2024 21:25:48 +0800 Message-ID: <20241209132549.2878604-2-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241209132549.2878604-1-ruanjinjie@huawei.com> References: <20241209132549.2878604-1-ruanjinjie@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemg200008.china.huawei.com (7.202.181.35) X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: BF397C0010 X-Stat-Signature: emffy398n9npr1r4o5r3s7dkarq7c8x1 X-Rspam-User: X-HE-Tag: 1733750750-558728 X-HE-Meta: U2FsdGVkX19VCpyD5e2c1Vj0DCpvtkhCMIxD78abdFsplMwN8p3EtfalideMVwf4F325VY4pcRf9+7C9IBZNFWhegI9OK4MLxlzGOoR8SCDLKA0qd2Zm/DBctJHBr3EUU5u8NS9VxZLDaNMn7QE8fSSVDbS/S1SxQxotoDq7rz3fc8GOEjX0l2ucskeY2nVwphF5e4gVhI0BaJ53xEVfQnR/DucQ3yAjEzoxpED460ibA8z8YryYhaJIpo8HpLttNAvBrDMXDqk7EXfcuKb7K65isoUW4/NoiFC7rR9LGIFJChi3KinBgJ4uzVEPl4ETJvADOLV8fi7/L+n7/U2zxvF0w/VrHN1OyaedDzq1pOo89SANOLUcmCe5orVbPIXIfa2l7l3dPJmSA/wsUUAEBrZ7GDSQcBUN7hkhHDG1eMTfnH3AfiPG8/EpNb64FEvCkLo1Gpg1VYjGXxNp8usio68833RN6Jfdf8nDvo/Vz+rSyAhI4vG87L9VSWV4DqqgyLiLHFdeZC9/4yKHdmMGNXpsB6H86wv0bEpZ+CpWlESw6JOwsScNtYvF+Hf6VSbhB26davHSLB6AEpac7jgXId4uyXAxyP8w+liiWKG4XhFuG367BlUsQ0GleZuWRnsTH8WtrdRnttQiMJLFFGddEzkTpslBR5LNmrE84lRh1DDg/cVGS8ZMKeGg2mNF/E72fm+DrlkClZuFAJ44B6PhwDFW+Zx+UocWz9YzMJE4bYEGPOkDovRTKztBPO0OnxPUHNlm0WItq/RbPG/JVXvhRfO7RqDl3lGU69Mpi9S69qmHZea/C9exbJsI5iLpiEguQiPf15Ev8sagU9Vde6yrk/0xVB6hunvaGEl9zFG4wIPNoHndKfXReFQrYqTalb3JxWTYzZ/cIkv68vVnHb/BGz9CqoU/eIamc7uBMlmM6KLnfZ6gwJBMZeZxlHj8nshMcS+UpeiU35RiaO8e4b2 Twtu4yE+ +h8xz4oQfdmxIX3b2fCRGXBimg7ZjP6210Sc51JrxyHqt1NwCmCdlo+YOxElx8Jkj5t5cwauMW/YN6aFEvlA/H70ZmZ0tLElDATCmIVNwRYhiXHfOMIIDEpniqeS0rbYiAqTMplP4acKqh0wLrT8DNtyzc0m/LURU7l5fAu27VvB+Kf+wKn4yVMBv/OMKNSBrRt07 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: List-Subscribe: List-Unsubscribe: Make the NULL check for vma's userfaultfd ctx inline, so we can avoid the function call overhead if the ctx is NULL. Signed-off-by: Jinjie Ruan --- fs/userfaultfd.c | 5 +---- include/linux/userfaultfd_k.h | 11 ++++++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 7c0bd0b55f88..7e551c234832 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -615,15 +615,12 @@ static void userfaultfd_event_complete(struct userfaultfd_ctx *ctx, __remove_wait_queue(&ctx->event_wqh, &ewq->wq); } -int dup_userfaultfd(struct vm_area_struct *vma, struct list_head *fcs) +int __dup_userfaultfd(struct vm_area_struct *vma, struct list_head *fcs) { struct userfaultfd_ctx *ctx = NULL, *octx; struct userfaultfd_fork_ctx *fctx; octx = vma->vm_userfaultfd_ctx.ctx; - if (!octx) - return 0; - if (!(octx->features & UFFD_FEATURE_EVENT_FORK)) { userfaultfd_reset_ctx(vma); return 0; diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h index cb40f1a1d081..06b47104aa1a 100644 --- a/include/linux/userfaultfd_k.h +++ b/include/linux/userfaultfd_k.h @@ -247,7 +247,16 @@ static inline bool vma_can_userfault(struct vm_area_struct *vma, vma_is_shmem(vma); } -extern int dup_userfaultfd(struct vm_area_struct *, struct list_head *); +int __dup_userfaultfd(struct vm_area_struct *, struct list_head *); +static inline int dup_userfaultfd(struct vm_area_struct *vma, + struct list_head *fcs) +{ + if (likely(!vma->vm_userfaultfd_ctx.ctx)) + return 0; + + return __dup_userfaultfd(vma, fcs); +} + extern void dup_userfaultfd_complete(struct list_head *); void dup_userfaultfd_fail(struct list_head *); From patchwork Mon Dec 9 13:25:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13899767 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 7382BE7717D for ; Mon, 9 Dec 2024 13:26:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 41AE36B043D; Mon, 9 Dec 2024 08:26:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BC2C8D0059; Mon, 9 Dec 2024 08:26:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 261AA8D0058; Mon, 9 Dec 2024 08:26:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 05DE76B043D for ; Mon, 9 Dec 2024 08:26:02 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9F3CA12024A for ; Mon, 9 Dec 2024 13:26:02 +0000 (UTC) X-FDA: 82875493386.16.8CC1A91 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf19.hostedemail.com (Postfix) with ESMTP id 3BE871A000D for ; Mon, 9 Dec 2024 13:25:37 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf19.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=ruanjinjie@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733750751; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oqnQIHI2YMQJ3EkVHBMVinxR6ND7w0RifOrNGdS9aRY=; b=LdJ2ZeeDZOxOywwSVULuVUD73PjF+k7QfhXYLqwOVAIIqWAH2tpsggNDc61hXYDuHzRWqa LNxzSu0HzB+2MoWIzJCsy5e45oTANQohjlih3MlHxYhkO3ozgCpkV6E2qmQF1QUH72/Nc1 Vifgecp10pn+5YFNmgWYVZj5VDBCNZI= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf19.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=ruanjinjie@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733750751; a=rsa-sha256; cv=none; b=6K254vKzUjLCXInBnmUt56Pi66M//IpskKmCD+NhJ/DzSVECdlCgmDoO8vJTMK8sgna+IB E+iEnJ3jUr3c7eWZK7rJNwgmmrCABHqqGQIeXQs9TbDu+e65hH9F338AImTpfHWmRG9PFe DiM846O+6ofhi9/xdIz7Hir5vIkLm1k= Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Y6N0R2QZwz1JDvw; Mon, 9 Dec 2024 21:25:43 +0800 (CST) Received: from kwepemg200008.china.huawei.com (unknown [7.202.181.35]) by mail.maildlp.com (Postfix) with ESMTPS id 6AC0A14011D; Mon, 9 Dec 2024 21:25:56 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemg200008.china.huawei.com (7.202.181.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 9 Dec 2024 21:25:55 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , Subject: [PATCH 2/2] mm, rmap: handle anon_vma_fork() NULL check inline Date: Mon, 9 Dec 2024 21:25:49 +0800 Message-ID: <20241209132549.2878604-3-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241209132549.2878604-1-ruanjinjie@huawei.com> References: <20241209132549.2878604-1-ruanjinjie@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemg200008.china.huawei.com (7.202.181.35) X-Rspamd-Queue-Id: 3BE871A000D X-Stat-Signature: tybzghibdwhkpfuukku551fr4pptsdpz X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1733750737-808931 X-HE-Meta: U2FsdGVkX1/TKRR3Zr8nmmNUyMMjOAPbXf/gU6U6hOzipevIZdCxl8rqSKCafIlGfcVbvTyBu3Q/67QpEsbiPgXvbG4Zdi3UvXDZuYODcGZ27IPau7Zum3v78ie3vUBVbQb09cRAi5grnWd/dxCIjFDOE6j9xvknwhOXMPo8cuEcs4pmAPvJDl/2Xq9iGCCZYfKP1HQu38uaAosH6Fqqk+lD72EJUhFjVNtmH807SRvJwTWR/bBINSJ0TAq/UdQSaK7KWNbrC8JgCufUv7gfh2ovOcOxXNHbcOQpKV+OLKrBw1Cy1Kjskj5AU/3lBogbngujtrk6HqUxeglcMBe72JtARkJmSe1Kw9ZFh0NkjqEV8UVk1OzfQswsIAXIJiWg4KNJxqYwBmjRvylzCwd6gmBkZbA3WPAAKkqOFJlxSoDr3v/H4jNI/0aYFvzpTvSz6Otl6DRZvk6tWH8gx3NMMCwGi40db82J6AeZLR8Lu3uqK7ErfwU4Pl15eN7TjSRpOHXF/dUaFwqRi+Bpd2dkABH6caj7irFkNpUfWwtiAIBz7d3f7Oz7McrLEQfD5KgsD3XUDQk6o8ZjWptlKZvsJSbfGi6BCLYYfX4xZLzbzOgJg1oR2PRWGlHJ1e/WaQQ0Gi5NMrQSGiQgsmW9tZuuo9/dkS+LSQdrjL/1mt3jLZUtqworLmE1XcuwCRKD8SOKcZXADKWDyNhBLLaFOpVUPA1DS4Js7FxOUvsjwfkYHDjMWr3fkAS6WlNdqYaMyMzzKZe8zDhx6oI89I0uoCajwF1BIu4/9Wt5adtI3FycFOQhQl2fPxHMhXalPeis9Wy/qTQbduMSmJ44BjYTvGvphtGarcT8rGwOyJVOtr3V10t2NaRz5P6Y/D9oJI2o0iifwe0UjPSDLcJHg+q+YC44WQ/ra/Tf+McuPpiCcIO4iZigXLwkBO+uZQYsWMcC7zaHWk9rcM4B28GzaEAaDcE V1YM0/+A RnZJ2qHMg+kvnC928mug98F0bA52qhIUNL3myNxvQ01Ymf/sPgP3KRxnZ9+ZJnE7GZPqiYeqyTEoUBqRnKmoeWnlnow6pAxnoNnm4vEDULIv+S6PXqhwPjEI+yJhHAVNjqV89jfKzKhV+T7uiOATOs9TnF8D9v6/qYoYx/gTpjz7KEf97JgHwIjl2Va0/EirOVBlL 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: List-Subscribe: List-Unsubscribe: Check the anon_vma of pvma inline so we can avoid the function call overhead if the anon_vma is NULL. Signed-off-by: Jinjie Ruan --- include/linux/rmap.h | 12 +++++++++++- mm/rmap.c | 6 +----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 683a04088f3f..9ddba9b23a1c 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -154,7 +154,17 @@ void anon_vma_init(void); /* create anon_vma_cachep */ int __anon_vma_prepare(struct vm_area_struct *); void unlink_anon_vmas(struct vm_area_struct *); int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *); -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *); + +int __anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *); +static inline int anon_vma_fork(struct vm_area_struct *vma, + struct vm_area_struct *pvma) +{ + /* Don't bother if the parent process has no anon_vma here. */ + if (!pvma->anon_vma) + return 0; + + return __anon_vma_fork(vma, pvma); +} static inline int anon_vma_prepare(struct vm_area_struct *vma) { diff --git a/mm/rmap.c b/mm/rmap.c index c6c4d4ea29a7..06e9b68447c2 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -331,16 +331,12 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src) * the corresponding VMA in the parent process is attached to. * Returns 0 on success, non-zero on failure. */ -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma) +int __anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma) { struct anon_vma_chain *avc; struct anon_vma *anon_vma; int error; - /* Don't bother if the parent process has no anon_vma here. */ - if (!pvma->anon_vma) - return 0; - /* Drop inherited anon_vma, we'll reuse existing or allocate new. */ vma->anon_vma = NULL;