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 75583C5478C for ; Tue, 27 Feb 2024 20:26:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB3DD280018; Tue, 27 Feb 2024 15:26:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E6378280001; Tue, 27 Feb 2024 15:26:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0652280018; Tue, 27 Feb 2024 15:26:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id BCBD9280001 for ; Tue, 27 Feb 2024 15:26:03 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 61BADA0BDC for ; Tue, 27 Feb 2024 20:26:03 +0000 (UTC) X-FDA: 81838715406.05.5BEC683 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 3483F140009 for ; Tue, 27 Feb 2024 20:26:00 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=M01Ikin9; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of alex.williamson@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=alex.williamson@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709065561; 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=V0dqgsQBzDVDbcTQxvGX6bkpULdbIHr8RjTGbZCAKO0=; b=ycbR3L9cOeZ8tppX/jtmloPnvpKmwUiuNEt+NlulofRsh16hO4TYAZDx5GwlYwErbNrlWY gaIOFO4a3i4kie/50IQwFQuQGLmE1QKfVHmsUGWv8R9aCq5NoXHCVxQZiYY/N5GqYwoZRO VBMH3L9TQ6JIlDSDFUzI+CuYWU3hgqU= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=M01Ikin9; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of alex.williamson@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=alex.williamson@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709065561; a=rsa-sha256; cv=none; b=XuxVd2DkZ7B6bvJpMy9J03EonvCOjWssO0rLM8c8nGK+GLzthf1xKd6BHRCXzz//TQalNn h3J8Y/tARq8gWo+EHYesjq5sCgh2BVzCKCld+GbB7psjRlXqNaWSazHVjZ7Kx551R4OIY6 WDpaY3hG1fl0yBb+FGoNyTOn3m/uw3Y= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709065560; h=from:from: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=V0dqgsQBzDVDbcTQxvGX6bkpULdbIHr8RjTGbZCAKO0=; b=M01Ikin94XnApMYxnLaYsojqhzfEq+WEuyCxb7JiUA4C7+k86Vf/C7sww+IKnFwSOTNORE QGhwfIxxNXXyHQobwlY+WpXvq8cDH1zprshw4m9y1u8vnTt3U+DCKzOg2ztHlHCiem8Kgn FQI9Li/f0duCpaEnDOA+4lQuIp+GdkE= Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-395-xaOPWepsN8Cb-Pqy02v_aQ-1; Tue, 27 Feb 2024 15:25:59 -0500 X-MC-Unique: xaOPWepsN8Cb-Pqy02v_aQ-1 Received: by mail-io1-f70.google.com with SMTP id ca18e2360f4ac-7c495649efdso465504639f.2 for ; Tue, 27 Feb 2024 12:25:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709065558; x=1709670358; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+h7qK8aFxtDvDR5hE75ZYRCW8UfQrEkELzJmQTxV4sw=; b=CBQmQt1ntFlF+BFJAgtRb405fUUjOOY+eIM92OR2kSem/pumBGS+YJO8bOGMD268Wo 9i/rlTCDsSyxOW5dJgFAUBhiks+9lID3GKsaJdB1rbtN8p3tqv/xVtBfQCJigKMFYC6h tN0bPWzRm2Bte4A0aZMkAkaLe7jN8janbMsprzTLgvvDlhfJXUBLAepOQ5+qhaWyXKq1 v4DMEMj1AlhGFiOKfGpps4mFQ2ki6NGGZRjWzOtJw0Jio6Z1St6zPw/AwM72eHlALWOm KFgjadWtV9xnqP+vEY7Fu4cDUu4BmclHlWh8EuPPZv/K4P+XCoykWeRU++q944zYbtLG wDzQ== X-Forwarded-Encrypted: i=1; AJvYcCUBsJkwp4I+CwJ0ERo5fyiDrZgRVUeVYTPyV1WKlcEI4+aag7cQaiFOUGZ6gZfxBWQrD5FUUihcGtk3q/5PMiY9fMw= X-Gm-Message-State: AOJu0Ywr3IWZp8CNlXzUK8mycLFspu94jYJa/EcS4TgDVp5lk+9v9eOW Ro6YI22bJ2+0HIu0ENLYNwHWhZWWu5xoET4T9Kv31diBOvEgW2xLVz6Dl02Ds9Zr6R2zXN9+VAn iGLSwcl+iVXc/xIeoE/c9AjW77Zcsq/eArp2Ta6Hf8mlJNzxq X-Received: by 2002:a5d:87c3:0:b0:7c7:f47b:79f8 with SMTP id q3-20020a5d87c3000000b007c7f47b79f8mr897091ios.11.1709065558447; Tue, 27 Feb 2024 12:25:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IHHci+23CQB98NMLlChr+k6ZWKSdNDJpBGejQs+zKcJAxWU9Z7kPda1p4il3PKo54WX87BWJQ== X-Received: by 2002:a5d:87c3:0:b0:7c7:f47b:79f8 with SMTP id q3-20020a5d87c3000000b007c7f47b79f8mr897080ios.11.1709065558190; Tue, 27 Feb 2024 12:25:58 -0800 (PST) Received: from redhat.com ([38.15.36.11]) by smtp.gmail.com with ESMTPSA id r25-20020a056602235900b007c7de4a670esm684477iot.6.2024.02.27.12.25.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 12:25:57 -0800 (PST) Date: Tue, 27 Feb 2024 13:25:56 -0700 From: Alex Williamson To: David Hildenbrand Cc: Yisheng Xie , akpm@linux-foundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] vfio/type1: unpin PageReserved page Message-ID: <20240227132556.17e87767.alex.williamson@redhat.com> In-Reply-To: References: <20240226160106.24222-1-ethan.xys@linux.alibaba.com> <20240226091438.1fc37957.alex.williamson@redhat.com> <20240226103238.75ad4b24.alex.williamson@redhat.com> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-redhat-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Stat-Signature: 4fd7hod7j3gb3ruihewsxuwxwdmrsz6c X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3483F140009 X-HE-Tag: 1709065560-809637 X-HE-Meta: U2FsdGVkX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ozO482LhzvHPLBQ/dZEgzBJwJimoCPj8beYl/p5sqlC0QMfNTIKa7VJ+950RrRoH9bhBVpeznPZ/C0Jo10Q2DXkJg4Q665SEcUQxtYxru7ZtFR2dUfrgtyIb4tEfiiCEi39rOemm86h0AleiemjCKg3bs/PuRbf7TJMJkQeL1Br/+3T7bOYZMaGzgOVlB7O6IGGZi1N5rSQ6vDfG9AoKqXREN4a/LEDK5pK4TxxecrAJXz/hzA+dHi1OgbbDhZtBmn2lXeNBe/F/tETvBD9ESlMhVHY89q503WqOhJwuA== 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: On Tue, 27 Feb 2024 11:27:08 +0100 David Hildenbrand wrote: > On 26.02.24 18:32, Alex Williamson wrote: > > On Tue, 27 Feb 2024 01:14:54 +0800 > > Yisheng Xie wrote: > > =20 > >> =E5=9C=A8 2024/2/27 00:14, Alex Williamson =E5=86=99=E9=81=93: =20 > >>> On Tue, 27 Feb 2024 00:01:06 +0800 > >>> Yisheng Xie wrote: > >>> =20 > >>>> 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 =20 > >>> = ^^^^^^^^ > >>> > >>> Does this issue reproduce on mainline? Thanks, =20 > >> > >> 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. =20 > >=20 > > 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, =20 >=20 > This commit, to be precise: >=20 > commit 873aefb376bbc0ed1dd2381ea1d6ec88106fdbd4 > Author: Alex Williamson > Date: Mon Aug 29 21:05:40 2022 -0600 >=20 > vfio/type1: Unpin zero pages > =20 > There's currently a reference count leak on the zero page. We incre= ment > the reference via pin_user_pages_remote(), but the page is later han= dled > as an invalid/reserved page, therefore it's not accounted against th= e > user and not unpinned by our put_pfn(). > =20 > Introducing special zero page handling in put_pfn() would resolve th= e > leak, but without accounting of the zero page, a single user could > still create enough mappings to generate a reference count overflow. > =20 > The zero page is always resident, so for our purposes there's no rea= son > to keep it pinned. Therefore, add a loop to walk pages returned fro= m > pin_user_pages_remote() and unpin any zero pages. >=20 >=20 > BUT >=20 > in the meantime, we also have >=20 > commit c8070b78751955e59b42457b974bea4a4fe00187 > Author: David Howells > Date: Fri May 26 22:41:40 2023 +0100 >=20 > mm: Don't pin ZERO_PAGE in pin_user_pages() > =20 > Make pin_user_pages*() leave a ZERO_PAGE unpinned if it extracts a p= ointer > to it from the page tables and make unpin_user_page*() corresponding= ly > ignore a ZERO_PAGE when unpinning. We don't want to risk overrunnin= g a > zero page's refcount as we're only allowed ~2 million pins on it - > something that userspace can conceivably trigger. > =20 > Add a pair of functions to test whether a page or a folio is a ZERO_= PAGE. >=20 >=20 > So the unpin_user_page_* won't do anything with the shared zeropage. >=20 > (likely, we could revert 873aefb376bbc0ed1dd2381ea1d6ec88106fdbd4) Yes, according to the commit log it seems like the unpin is now just wasted work since v6.5. Thanks! Alex