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 D630BC433FE for ; Fri, 21 Oct 2022 23:32:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6FC5B8E0002; Fri, 21 Oct 2022 19:32:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6ACB38E0001; Fri, 21 Oct 2022 19:32:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59B298E0002; Fri, 21 Oct 2022 19:32:15 -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 4C2518E0001 for ; Fri, 21 Oct 2022 19:32:15 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 02DB2120904 for ; Fri, 21 Oct 2022 23:32:14 +0000 (UTC) X-FDA: 80046557430.08.EF5EA6A Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf15.hostedemail.com (Postfix) with ESMTP id AC50EA0039 for ; Fri, 21 Oct 2022 23:32:13 +0000 (UTC) Received: from imladris.surriel.com ([96.67.55.152]) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1om1Ul-0002Ll-0V; Fri, 21 Oct 2022 19:32:07 -0400 Message-ID: <3de4bb41badd79953df5af72827279e897344791.camel@surriel.com> Subject: Re: [PATCH] hugetlb: don't delete vma_lock in hugetlb MADV_DONTNEED processing From: Rik van Riel To: Mike Kravetz , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Naoya Horiguchi , David Hildenbrand , Axel Rasmussen , Mina Almasry , Peter Xu , Vlastimil Babka , Matthew Wilcox , Andrew Morton , Wei Chen , stable@vger.kernel.org Date: Fri, 21 Oct 2022 19:32:06 -0400 In-Reply-To: <20221021230722.370587-1-mike.kravetz@oracle.com> References: <20221021230722.370587-1-mike.kravetz@oracle.com> Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-BltVCMQR0UYFZX5Kjqch" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=none (imf15.hostedemail.com: domain of riel@shelob.surriel.com has no SPF policy when checking 96.67.55.147) smtp.mailfrom=riel@shelob.surriel.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666395133; a=rsa-sha256; cv=none; b=xR5aDXky5CE1v1H3sR04MaENbntz721gU1WCbgTbh1aw6Gcn807muLhmVQMOwiy7znIZ1e 8sTRVMuDEPGZUnOIgb/o97rVnRlnDL2pKkzj6vTBf1MogRag+X8f4x0fIDSDtifleeogRQ EVHUPScvDyRz3Hz/6oHuBYDrdKUFy/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666395133; h=from:from:sender: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: in-reply-to:in-reply-to:references:references; bh=YN+/plI89rtxRvLM6ifRnxDuM/DF7h/b4aojfT/Tm+U=; b=as+LS/Zem4K1iovHZKLuB3F85HVdlWbEWq1+TN8R22hulOqD9FDM7SQ9TUKmy0o3eTaDnr 6QmiM73JxEQeJuCLVR8IHKnoQJrF11afEijcNwg6QIkaGzn/HDuIltM7rOTC+Y9opGOcSE 1iYuSr/8udIEVfywjVrZ42JbYKlp8wM= X-Rspamd-Queue-Id: AC50EA0039 Authentication-Results: imf15.hostedemail.com; dkim=none; spf=none (imf15.hostedemail.com: domain of riel@shelob.surriel.com has no SPF policy when checking 96.67.55.147) smtp.mailfrom=riel@shelob.surriel.com; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam09 X-Stat-Signature: hw65am6a9qnknuhxh97hspercgg39915 X-HE-Tag: 1666395133-560585 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: --=-BltVCMQR0UYFZX5Kjqch Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, 2022-10-21 at 16:07 -0700, Mike Kravetz wrote: > madvise(MADV_DONTNEED) ends up calling zap_page_range() to clear the > page tables associated with the address range.=C2=A0 For hugetlb vmas, > zap_page_range will call __unmap_hugepage_range_final.=C2=A0 However, > __unmap_hugepage_range_final assumes the passed vma is about to be > removed and deletes the vma_lock to prevent pmd sharing as the vma is > on the way out.=C2=A0 In the case of madvise(MADV_DONTNEED) the vma > remains, > but the missing vma_lock prevents pmd sharing and could potentially > lead to issues with truncation/fault races. >=20 > This issue was originally reported here [1] as a BUG triggered in > page_try_dup_anon_rmap.=C2=A0 Prior to the introduction of the hugetlb > vma_lock, __unmap_hugepage_range_final cleared the VM_MAYSHARE flag > to > prevent pmd sharing.=C2=A0 Subsequent faults on this vma were confused as > VM_MAYSHARE indicates a sharable vma, but was not set so page_mapping > was not set in new pages added to the page table.=C2=A0 This resulted in > pages that appeared anonymous in a VM_SHARED vma and triggered the > BUG. >=20 > Create a new routine clear_hugetlb_page_range() that can be called > from > madvise(MADV_DONTNEED) for hugetlb vmas.=C2=A0 It has the same setup as > zap_page_range, but does not delete the vma_lock. >=20 Reviewed-by: Rik van Riel --=20 All Rights Reversed. --=-BltVCMQR0UYFZX5Kjqch Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEKR73pCCtJ5Xj3yADznnekoTE3oMFAmNTK/YACgkQznnekoTE 3oO1ewf7BRz85x843rfqU2bU6WR23hUrg1J5DkgmUU8YM+g6MSRoAy4aNMr01e8G myXy05UuZzLNL1wfW3N3qomU+iTVlYjHAzV8a4g6P63sCzejdwAFMEOXUoKtqQYk KzZueG9xhh+ael0APQlQ3JaU4p2UQ7nF2JSjLUJcUt9wE/t8gkOxYHg5MmkrkEgl tmuVrQ4WmxkM7GLwbKJB+38lmQSbj1UNx4RZWDIG5k6VISoCRsH0XR2JitS5hYw8 OmWsU/iAs/zxXewjmSM0fHeDO2tutLo0S634GYBTfrMOZ3+TtEvakYy94LINEVKZ J61B5PFjcwmYGJ4e4Q0rqmCKTPlc1w== =nIj+ -----END PGP SIGNATURE----- --=-BltVCMQR0UYFZX5Kjqch--