Message ID | 20230926031245.795759-1-riel@surriel.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1642454vqu; Mon, 25 Sep 2023 20:22:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEUatz3sQAnNnW0LX4xdC62qUUKlKVYd3la9/XurmiNwGqV5SBPRhBdh7Vkqr4rnm4F2NdZ X-Received: by 2002:a05:6a00:399f:b0:68e:3bc7:3101 with SMTP id fi31-20020a056a00399f00b0068e3bc73101mr11042013pfb.2.1695698524348; Mon, 25 Sep 2023 20:22:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695698524; cv=none; d=google.com; s=arc-20160816; b=Sjn/6U/KCrZvH5aXVsji3iiChyAMVH0DXTLlNzQPTBsa0+kGl1EuFsEMYUwxSlRnqQ OtehxbnMpVVr/ej4uQQ/g4cqIu5uQ5XKO+1US2ZzyPPHLJVVNVsFGDvpH+6s+AT2EfZ5 Qs5nQQ9e8gQrSaPCR+goGYkE2knKNgZxm0pH2giuwe6GuqmgoJ/45ke/Vjed4wDwf1ZB d/UR2YKmRInFiQPdGTfb05oZOlbwQoBfmdKtlC8iQQxBwpSbx780Kk3Fo0e3DigAyDWc tR3sdU8DJC1bvKej2Wr0IqvJipSREP3vmlZ5O8XkVe7sQv8w+90fOqDi2+TSorS/roaa XswQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=lo9SBe6E3yZylvB3m0vLKsYs1lYeEqPoJjVl7+P3TSY=; fh=q9SQMO40xEi/EnFYzkYLxDJR2yDm5elEChUbTy2RFH8=; b=r4vscNNmkXfTiU+iEmUXGPdztTtfmiBo73xSlOBHmkSLuXid3voo4mnPhGlz9Rlb9f zK78buGEQbOseqMwpRb2yUSQQCC5MujH4sf9t5ScapdBVpf+khqIXbI1CkEQQATM0+ll t1KUoe5x+WBuyLK0Bh5W57LMKGxnBIpJCW4Rq42NwzqS6tiwNvKgz4QUTTnzK9qyAHsv tpRaG1psmfgb9T2SnZlt6ZR2YRKdWG2fmNbZSWsGyvHMP+Z8BEqGHgKj8MET3HGkpw4x 8Wyc6YiNJDLyiZyDClgIEicbrQElFm4iJ9W6t0UvRTm2TI3WIGf45HE6jm9MqHvyfD4l rVgg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id c5-20020a6566c5000000b005653e3f6d58si4947329pgw.748.2023.09.25.20.22.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 20:22:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 847ED80E06AE; Mon, 25 Sep 2023 20:13:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230299AbjIZDNp (ORCPT <rfc822;pwkd43@gmail.com> + 27 others); Mon, 25 Sep 2023 23:13:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229574AbjIZDNl (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 25 Sep 2023 23:13:41 -0400 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1B439F for <linux-kernel@vger.kernel.org>; Mon, 25 Sep 2023 20:13:33 -0700 (PDT) Received: from imladris.home.surriel.com ([10.0.13.28] helo=imladris.surriel.com) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from <riel@shelob.surriel.com>) id 1qkyVD-00025y-0I; Mon, 25 Sep 2023 23:12:47 -0400 From: riel@surriel.com To: linux-kernel@vger.kernel.org Cc: kernel-team@meta.com, linux-mm@kvack.org, akpm@linux-foundation.org, muchun.song@linux.dev, mike.kravetz@oracle.com, leit@meta.com, willy@infradead.org Subject: [PATCH v4 0/3] hugetlbfs: close race between MADV_DONTNEED and page fault Date: Mon, 25 Sep 2023 23:10:49 -0400 Message-ID: <20230926031245.795759-1-riel@surriel.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: riel@surriel.com X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 25 Sep 2023 20:13:54 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778068271289012259 X-GMAIL-MSGID: 1778068776126148152 |
Series |
hugetlbfs: close race between MADV_DONTNEED and page fault
|
|
Message
Rik van Riel
Sept. 26, 2023, 3:10 a.m. UTC
v4: fix unmap_vmas locking issue pointed out by Mike Kravetz, and resulting lockdep fallout v3: fix compile error w/ lockdep and test case errors with patch 3 v2: fix the locking bug found with the libhugetlbfs tests. Malloc libraries, like jemalloc and tcalloc, take decisions on when to call madvise independently from the code in the main application. This sometimes results in the application page faulting on an address, right after the malloc library has shot down the backing memory with MADV_DONTNEED. Usually this is harmless, because we always have some 4kB pages sitting around to satisfy a page fault. However, with hugetlbfs systems often allocate only the exact number of huge pages that the application wants. Due to TLB batching, hugetlbfs MADV_DONTNEED will free pages outside of any lock taken on the page fault path, which can open up the following race condition: CPU 1 CPU 2 MADV_DONTNEED unmap page shoot down TLB entry page fault fail to allocate a huge page killed with SIGBUS free page Fix that race by extending the hugetlb_vma_lock locking scheme to also cover private hugetlb mappings (with resv_map), and pulling the locking from __unmap_hugepage_final_range into helper functions called from zap_page_range_single. This ensures page faults stay locked out of the MADV_DONTNEED VMA until the huge pages have actually been freed. The third patch in the series is more of an RFC. Using the invalidate_lock instead of the hugetlb_vma_lock greatly simplifies the code, but at the cost of turning a per-VMA lock into a lock per backing hugetlbfs file, which could slow things down when multiple processes are mapping the same hugetlbfs file.