Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3436463rwi; Fri, 21 Oct 2022 16:45:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5b2Rk7ZZqkogZNtm52cUUKNjLze9fizx7hahdbAbhZnDmNveRHDWjWab4SO5Gt/Dr8VSOW X-Received: by 2002:a17:90a:17eb:b0:212:8210:c92e with SMTP id q98-20020a17090a17eb00b002128210c92emr11157418pja.62.1666395900768; Fri, 21 Oct 2022 16:45:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666395900; cv=none; d=google.com; s=arc-20160816; b=Ccq1NBPuExC7bycje4BjtnQJRPVSXR0nQcOCSWPB82GxGTw/9yF1PFqFtKnhUQXALN YXdfCB0zGUBWvTlgrKxpjxdelMa/Ep5qsb54smWAhBdycoOz3Vo5eAK8dDbgj53wR2YO nKK8FO1EoRe491hKnVoe5GVnmjc82wjzvpji/2ljG6bzBGfNRnwZg2myaKWdo+3S3L4e HZWBaZnNmJ1rJ3Ji/5JjHrOGd030gFHsExjKkGt7u/+XU4c022SNRxYgFWrGY6oDP7Np PGvtdlPco7wCDvaoRmGtEHxNDDtRO8xIYbIKteffbsIjewdh6yBM6PI5zR4yUU/BI+8o DGjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id; bh=YN+/plI89rtxRvLM6ifRnxDuM/DF7h/b4aojfT/Tm+U=; b=X25To+C/fCnqRYBAnC9vx8ZrreFaEFzgJyjBSPIFP49/JOxLXq2GmRETe6r2rwg1fz htpHqkJeWgmcnTayy7LoG15leIAFj/cqDTJYYAffep0BCqHo8gBLob2X28y0ibV2tS1S rBw/XxCkC6ImmblmFqMtSMEptxT/PF/1h7B2dtK2zcmHvZgDQIpkhd5VAtqcOtvdmDKi zNJRQc1BKFDO585lQIfWlSEmXhKLNwzvADiNpZC0K2yK0X610unLmKMl2CNU3iHGZ04O j3iflTHg9z3ScRBfGAzi8XMAMdPtGyT22YmzhjxblVuT9J/e02itq8DBANOge4zRt8QB M8fA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j8-20020a056a00130800b00561898445bdsi28061906pfu.273.2022.10.21.16.44.48; Fri, 21 Oct 2022 16:45:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229615AbiJUXcR (ORCPT + 99 others); Fri, 21 Oct 2022 19:32:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbiJUXcO (ORCPT ); Fri, 21 Oct 2022 19:32:14 -0400 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E101F2AB117 for ; Fri, 21 Oct 2022 16:32:13 -0700 (PDT) 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 Sender: riel@shelob.surriel.com X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-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--