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 85823C54E49 for ; Wed, 28 Feb 2024 11:35:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F38686B0096; Wed, 28 Feb 2024 06:35:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EC1CE6B009C; Wed, 28 Feb 2024 06:35:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D88C46B009D; Wed, 28 Feb 2024 06:35:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C58336B0096 for ; Wed, 28 Feb 2024 06:35:22 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 71346160F22 for ; Wed, 28 Feb 2024 11:35:22 +0000 (UTC) X-FDA: 81841006884.02.E5F36F8 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by imf23.hostedemail.com (Postfix) with ESMTP id D60AD14000E for ; Wed, 28 Feb 2024 11:35:18 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=LPVjUYL3; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf23.hostedemail.com: domain of ethan.xys@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=ethan.xys@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709120120; 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=ZHu3CCtC5tTmDrHwG9sD4yIzMC6+Q14Tg7eRIc+2je8=; b=OtJUIPap930o2ODOFceioxCuXIntZmQXxY0KKVnuTgtSyiPh6ET63idzA5jqmmjqGGfHT9 tEUcoFyvWKGsMU5XdOik3xopX31MXLz47fClUr4jf8WOPU42YodYcT18aqlJERqXwe4IQT DL2i1V555FRfYML25K0N8j3ILmmUdwo= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=LPVjUYL3; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf23.hostedemail.com: domain of ethan.xys@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=ethan.xys@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709120120; a=rsa-sha256; cv=none; b=N8TyPRfkKJLZHwERassU7pOTZVZlaApPT4g4kxyHJDQ8AaM7azE9UNbmlVtp17YUWCoseh E5pgzNEE3/RBlQUokxSMJiRS6y9v7h8P9ntWTtqEY+Xkh83HnAFXlAd8uyotKVSd6joDiW 5SXm6lO8CmtAkAsh/jdg9pFR3a83zU4= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1709120115; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=ZHu3CCtC5tTmDrHwG9sD4yIzMC6+Q14Tg7eRIc+2je8=; b=LPVjUYL3cGooiqYveJ8ROgLw4wJi4eB7UQ7KOlXRhgSQ3OhL1W6w6vzsMDcT3pMcHucicc2vtcQFEy/zpu4mD0cu63opcTrgLGhW+wVsOInSo6hU2IIaS0JlhpohMYc9qWoTOuxMS8P7K59XT0YmDc3nH9huW5oLvrKdgB/puuE= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R971e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=ethan.xys@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0W1PkVY5_1709120113; Received: from 30.221.98.53(mailfrom:ethan.xys@linux.alibaba.com fp:SMTPD_---0W1PkVY5_1709120113) by smtp.aliyun-inc.com; Wed, 28 Feb 2024 19:35:14 +0800 Message-ID: <4ec89335-917a-4ea5-b38b-5cea6476d9a1@linux.alibaba.com> Date: Wed, 28 Feb 2024 19:35:12 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] vfio/type1: unpin PageReserved page To: David Hildenbrand , Alex Williamson , akpm@linux-foundation.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20240226160106.24222-1-ethan.xys@linux.alibaba.com> <20240226091438.1fc37957.alex.williamson@redhat.com> <20240226103238.75ad4b24.alex.williamson@redhat.com> From: Yisheng Xie In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: D60AD14000E X-Stat-Signature: fwb6s9uua8zhsquggji95394ecj5buyy X-Rspam-User: X-HE-Tag: 1709120118-648669 X-HE-Meta: U2FsdGVkX1/j18np+j1EJHzv6IuJQzODrXVrbK+cP2+QniLPc9AxmY91TG81oMMmkw1xWzMoF48XbKRTDfPZey5zcxB/9kb3HiiZUDJ5HrxTJRBUlrUgjl+107VHhIXaq2szovGWe36bJnMjBnQ4YQg+fVNAuCN+4GJXHJYTGenXIUMxU8SdTOG1fIuUXT/pv5Neqck5mF9g5CKM5eE2Ot6Q7itg5fjeN6GemrM77zquLqJiHmIL9hIY8D4u7eapZUeqD+tXfWszSo2rRNKXSKRCsAIOKQSHis9NxP5Lpi1mdrOWhFU94eJbxIRjpHzR0Qkgw4dIaGwuaHCQ1GQvclaUpZHPQKeFYEh2aSDA9XbKSk95MCODnkmnGCs89R0Q7CG6Ntn2XbPbcKHPFmps65OBFHJJHwSCP67xPY4nxNleyQW5vVa+X8wXuJveWXSNweNiOxh5yGhfQB1ga2jS2QtvpPjGKOUAI0WBWiQqqwBjfiDejvPJnvl3H+Eci6Lvgohm1WzskY7pkxb7A0p7s5V2kbJpl4IPSwUf719bh5S1Gay2nGG1T70SUDbI9JlsR5GJk6LipXOkNhee9Xp+CzF4kN9h393yjcAQxu7X/PI27kRwIu7AlTuWJCfkG6NoWMle/prziDy20YtLQk8QZ8+JwtI3b+Z6aXWYtzzwJIh2mXhyE3NakHzjmoClDuTpa+MiLWQJjyrbo7M5zTqrc3NgvQQbiI/y52e2Hn77mbGEGQeO0gAXsi74Mttt+hXfxgPfYKH/legywoVl1I4HcReRK/FwVWFxtBhJHvTavm/knuppIO/sYVC+IS8KwKgehLbiCLtTDBF943UcleX2cFzpoMOT6+BO7NzsGCRwzRawhAOfCf5R7OcBM9aC4MqH8Mj9nYcnqIShJwpnH/c9ncg1gV0QNSZN 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: 在 2024/2/27 18:27, David Hildenbrand 写道: > On 26.02.24 18:32, Alex Williamson wrote: >> On Tue, 27 Feb 2024 01:14:54 +0800 >> Yisheng Xie wrote: >> >>> 在 2024/2/27 00:14, Alex Williamson 写道: >>>> On Tue, 27 Feb 2024 00:01:06 +0800 >>>> Yisheng Xie  wrote: >>>>> We meet a warning as following: >>>>>    WARNING: CPU: 99 PID: 1766859 at mm/gup.c:209 >>>>> try_grab_page.part.0+0xe8/0x1b0 >>>>>    CPU: 99 PID: 1766859 Comm: qemu-kvm Kdump: loaded Tainted: GOE  >>>>> 5.10.134-008.2.x86_64 #1 >>>> ^^^^^^^^ >>>> >>>> Does this issue reproduce on mainline?  Thanks, >>> >>> I have check the code of mainline, the logical seems the same as my >>> version. >>> >>> so I think it can reproduce if i understand correctly. >> >> I obviously can't speak to what's in your 5.10.134-008.2 kernel, but I >> do know there's a very similar issue resolved in v6.0 mainline and >> included in v5.10.146 of the stable tree.  Please test.  Thanks, > > This commit, to be precise: > > commit 873aefb376bbc0ed1dd2381ea1d6ec88106fdbd4 > Author: Alex Williamson > Date:   Mon Aug 29 21:05:40 2022 -0600 > >     vfio/type1: Unpin zero pages >         There's currently a reference count leak on the zero page.  We > increment >     the reference via pin_user_pages_remote(), but the page is later > handled >     as an invalid/reserved page, therefore it's not accounted against the >     user and not unpinned by our put_pfn(). >         Introducing special zero page handling in put_pfn() would > resolve the >     leak, but without accounting of the zero page, a single user could >     still create enough mappings to generate a reference count overflow. >         The zero page is always resident, so for our purposes there's > no reason >     to keep it pinned.  Therefore, add a loop to walk pages returned from >     pin_user_pages_remote() and unpin any zero pages. > > > BUT > > in the meantime, we also have > > commit c8070b78751955e59b42457b974bea4a4fe00187 > Author: David Howells > Date:   Fri May 26 22:41:40 2023 +0100 > >     mm: Don't pin ZERO_PAGE in pin_user_pages() >         Make pin_user_pages*() leave a ZERO_PAGE unpinned if it > extracts a pointer >     to it from the page tables and make unpin_user_page*() > correspondingly >     ignore a ZERO_PAGE when unpinning.  We don't want to risk > overrunning a >     zero page's refcount as we're only allowed ~2 million pins on it - >     something that userspace can conceivably trigger. >         Add a pair of functions to test whether a page or a folio is a > ZERO_PAGE. > > > So the unpin_user_page_* won't do anything with the shared zeropage. > > (likely, we could revert 873aefb376bbc0ed1dd2381ea1d6ec88106fdbd4) Thanks for your detail info. BTW, do we need handle all of the pagereserved page?