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 7E870C282EC for ; Mon, 10 Mar 2025 06:40:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5E3F7280002; Mon, 10 Mar 2025 02:40:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 59307280001; Mon, 10 Mar 2025 02:40:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48384280002; Mon, 10 Mar 2025 02:40:45 -0400 (EDT) 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 2A952280001 for ; Mon, 10 Mar 2025 02:40:45 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D0372C0A8A for ; Mon, 10 Mar 2025 06:40:46 +0000 (UTC) X-FDA: 83204693292.09.42E870D Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf09.hostedemail.com (Postfix) with ESMTP id 6CF7E140008 for ; Mon, 10 Mar 2025 06:40:43 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of tujinjiang@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=tujinjiang@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=1741588845; 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; bh=y6TGCE2HQMQDPA35kYiXYdXpz+FFjAyoCKNDJ44TV4s=; b=I3/B5gkEMGJNSVR1Uf0iitvuFzHUz6QcJX5tdmHA8SCsIudeN291IC5ZGhxvjZTPBUrZws ezIsqUIf1KqKaxHW7PNnLi+eC+OvQuHSP5b7hlur6+bkvvWn9C+NgoSYi4TG247DKw1lz5 Ip1gmK+QQIr00EDdS5MbqMtMeMeqL+Q= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of tujinjiang@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=tujinjiang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741588845; a=rsa-sha256; cv=none; b=rFWC7huASB/abynePSBH99hMQaYn08w3LAVyhLEhg6vfw6FCs2FmkGGeSBxawYWD47d0na Aji1P+9JAcBBSVS0KHbjwPIthSofHoW6GY1exxXxpm/PZTsQtNKZLAUaD4krYI9GGsS7Id bNMVkz6r9xx+WqDpohyo3Z+qou7lBqg= Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4ZB6c1755bz2SSkG; Mon, 10 Mar 2025 14:36:17 +0800 (CST) Received: from kwepemo200002.china.huawei.com (unknown [7.202.195.209]) by mail.maildlp.com (Postfix) with ESMTPS id C31841A0188; Mon, 10 Mar 2025 14:40:36 +0800 (CST) Received: from [10.174.179.13] (10.174.179.13) by kwepemo200002.china.huawei.com (7.202.195.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 10 Mar 2025 14:40:35 +0800 Message-ID: Date: Mon, 10 Mar 2025 14:40:35 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: Using userfaultfd with KVM's async page fault handling causes processes to hung waiting for mmap_lock to be released To: Peter Xu , jimsiak CC: , , , , References: <79375b71-db2e-3e66-346b-254c90d915e2@cslab.ece.ntua.gr> <20250307072133.3522652-1-tujinjiang@huawei.com> <46ac83f7-d3e0-b667-7352-d853938c9fc9@huawei.com> From: Jinjiang Tu In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.13] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemo200002.china.huawei.com (7.202.195.209) X-Stat-Signature: egeba8znc9g1xzxi7bu4qt8awx3euy75 X-Rspam-User: X-Rspamd-Queue-Id: 6CF7E140008 X-Rspamd-Server: rspam01 X-HE-Tag: 1741588843-510442 X-HE-Meta: U2FsdGVkX1/jqbeir3ssv+eJyP1QuEOpjSj1i5fOTTNc5eKzY++bMgLqW6wBFeqqwyujzEifcByO8uf48PhcHHl5SZfUC75bDrj2uujwQ5Mosx201BNXAWiHZK89llhor4Wlc405hEmGfXGoJORXf6VNDU3vdbITLzUsWkdfjIa51tMK6vPoDC1y3qbDc/f907fFA19sHOKhBpwoWJWfJmARJzzNLF1XHZH5UDPfoL/Jgdv3kMMDVYfxshoD2RrorAMdF25/lk9qimld0hDv1vs/OmESKtAPx58Ak7lM0SMgBG36gmUpPYO7bnrIs5s124E4/1Fh5IYsmsvB9i7Hs/fo+oJOPI1bjph/Z8h9ZUuTZlfFRp1FLfp6nHNIhYzArlGrRBZhKuqU8Xkw3QD4SVPRIgCibkVGEYwVexB9RslNvfX7pGo2r5Ye0x56P/9A+4RdtVUKSv/jePv0FOclRdnWqFavEh5OmXAEuG23TpyXqB00L27N6ZygwO1RQDYIHYgXdH4jtXDLMBOlYxeVjT0fsa5gbTQFdMmQljwNy+7ajRGRX4v9rF0hh+mhLi8dY3Tuo+ycUKNFSVHMW/OeQ2VQqs0aI93eRSvfcdeIjZpL2D27jwX5ebm7afMKJGBl/p2wHwqSbPTS6APzplivJjy2vpFxZXXVZ46+Zt0IOSI2YmpsDtmlHWwE23m+1MULPmoPE0ZH9D6wbsXxpbeQLh1+qbk1rwngjfb5dpZaysYCN7FqZCFB4FbeazE80iUAuM++Uizcvqb6vkXWqkWDgRquek9brdAf/059/rRkmFHzMgGoP/qtO3Q+j8+eLHBdHFcAiJ3vARjenpaU0v0olTMhZW3PeAOxAAl6TCeH1MtUtKoFwXHTld63O+sefWOcpPuTN4sf+NNPqpPs6RqXu5ucTL4VoQMAUs7UFz3vvDxZXc+JTNMXeaf2frKUlUAoVV1eHRyI+e3Uu6qd2Z8 ac9zzpIn iKRlXi8FX91zR0pmR7IPrgwI4ODhSNFxi1yCjQy9s6/GwCNLogU4iDwdgBqztYvRG6HYaTS6yhkyyVskztYcCFkbrzMlQAzxq+Cxk6DnXET493TCs2vk1O4helPDf/Gqe956EUYm0M3SoRhBA4B7OrHqBiwe3FEAnT6xlthWWFzhDAvr8GN4GKssHeNIqHjmZs2NVR0svVynlB8OJ9GlOnO0eH9Z7KfM6GDzGlVDreUO/WE5X6qkJq7KJLus2200FV06wkhzBE7+2oRg6o7xt/+9DiOJ5RD3/3xbGJlcOwA7ZDYrvSX8auLA/Gg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 在 2025/3/8 6:41, Peter Xu 写道: > On Fri, Mar 07, 2025 at 03:11:09PM +0200, jimsiak wrote: >> Hi, >> >> From my side, I managed to avoid the freezing of processes with the >> following change in function userfaultfd_release() in file fs/userfaultfd.c >> (https://elixir.bootlin.com/linux/v5.13/source/fs/userfaultfd.c#L842): >> >> I moved the following command from line 851: >> WRITE_ONCE(ctx->released, true); >> (https://elixir.bootlin.com/linux/v5.13/source/fs/userfaultfd.c#L851) >> >> to line 905, that is exactly before the functions returns 0. >> >> That simple workaround worked for my use case but I am far from sure that is >> a correct/sufficient fix for the problem at hand. > Updating the field after userfaultfd_ctx_put() might mean UAF, afaict. > > Maybe it's possible to remove ctx->released but only rely on the mmap write > lock. However that'll need some closer look and more thoughts. > > To me, the more straightforward way to fix it is to use the patch I > mentioned in the other email: > > https://lore.kernel.org/all/ZLmT3BfcmltfFvbq@x1n/ > > Or does it mean it didn't work at all? This patch works for me. mlock() syscall calls GUP with FOLL_UNLOCKABLE and allows to release mmap lock and retry. But other GUP call without FOLL_UNLOCKABLE will return VM_FAULT_SIGBUS, is it a regression for the below commit? commit 656710a60e3693911bee3a355d2f2bbae3faba33 Author: Andrea Arcangeli Date: Fri Sep 8 16:12:42 2017 -0700 userfaultfd: non-cooperative: closing the uffd without triggering SIGBUS > > Thanks, >