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 *);