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 X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D666C4320A for ; Wed, 28 Jul 2021 04:04:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A2B6260D07 for ; Wed, 28 Jul 2021 04:04:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A2B6260D07 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 0154A8D0001; Wed, 28 Jul 2021 00:04:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F077D6B005D; Wed, 28 Jul 2021 00:04:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF60F8D0001; Wed, 28 Jul 2021 00:04:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0019.hostedemail.com [216.40.44.19]) by kanga.kvack.org (Postfix) with ESMTP id C31786B0036 for ; Wed, 28 Jul 2021 00:04:23 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 5CBD320412 for ; Wed, 28 Jul 2021 04:04:23 +0000 (UTC) X-FDA: 78410654406.03.D6E4A8C Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by imf24.hostedemail.com (Postfix) with ESMTP id 45627B0038C3 for ; Wed, 28 Jul 2021 04:04:22 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id mt6so3224442pjb.1 for ; Tue, 27 Jul 2021 21:04:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Btfk1u4wYAEJ1JPHSnp+79fE/Z+lkoWUjorje3TDib8=; b=QvYmeosTm1xNtdIH2Um5jkPjS8DNjlxHPDVK1JGrxPEGZ5IeY5GeXQBsUygtX9Xu7d 1UftAb3jV0ph4tAQHvuq+ZN90fJvJC7xy0aqiBdsv22Whb30yiiCITJkbmWODMM8NP0z g6xA5fnbetPqa8wg8lNX4kiSxd4BBoPuFSQOpuFtub3U1yEHtN0f3HyiqbDic89lgQWD F4F92tJWGrOZ4sMZoC6g/XBPa+4Ez+XlU2wiorvGYrlxhbqkRTKKrqoXYndj3kBgI9Ca fxchpke7+h8A9rrvbHqYnYUdqZkQTR+204gpIiN2u4NNGnHXi+FtYoIjIsG7wl0AfAak cyJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Btfk1u4wYAEJ1JPHSnp+79fE/Z+lkoWUjorje3TDib8=; b=qME56LD89l7W8UAjLAcc3cNRC7OvSMcZaDffuPI2+kejonlbGr+wampE+hJ0OqOsvc 1ig0aDDdX64/FIgUliPi55OsrUMmiwg6my979MkVEdL3OQs0Q1in7eEo5YTBtJcLeHkH rPhcvNl8oL+bTmk6wem273oKg7jEBgxvoIiHmx9xdQNr1mBppDrbX3n4O+tLmy/CbyYs e5Mqz2U/LwXN8XjTpr+sGO+BEe4sco2jPqVnucbwbPnXUWo+YtKGUg1ROI3FhZwpjDDz oWww+Ihnf8nZ1G7NLkXf2tIX8WwpUwkrlSaYJOLRP10kD4uhwtSYsQ9BpDHwmzMPfeWW aRMg== X-Gm-Message-State: AOAM532qew6xLr+/nlkm0ef1SngS5ewDkXyZ8yFg6+P+O9uUBkz57VIh 7iVecYzpNc8v+jCc7plPGI7cVrfaSpM+IlAqwWltPw== X-Google-Smtp-Source: ABdhPJwEhkeM1mmwO19L8ixbUhxtXf9ohgyUP3+rnpJvGdjSmRksQaaldFhuG7IFEZGB+ZDKL39ysLb8bMFXMz06xp4= X-Received: by 2002:a17:90a:4894:: with SMTP id b20mr6624100pjh.13.1627445060944; Tue, 27 Jul 2021 21:04:20 -0700 (PDT) MIME-Version: 1.0 References: <20210710002441.167759-1-mike.kravetz@oracle.com> <22abb0f0-ce85-3567-3bfd-74dd1450c14f@oracle.com> In-Reply-To: <22abb0f0-ce85-3567-3bfd-74dd1450c14f@oracle.com> From: Muchun Song Date: Wed, 28 Jul 2021 12:03:42 +0800 Message-ID: Subject: Re: [PATCH 0/3] hugetlb: fix potential ref counting races To: Mike Kravetz Cc: Linux Memory Management List , LKML , Michal Hocko , Oscar Salvador , David Hildenbrand , Matthew Wilcox , Naoya Horiguchi , Mina Almasry , Andrew Morton Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 45627B0038C3 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=QvYmeosT; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf24.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.42 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-Stat-Signature: xhehwmno9zqgc3ejyt3jkaoggadskze1 X-HE-Tag: 1627445062-769764 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: On Wed, Jul 28, 2021 at 7:41 AM Mike Kravetz wrote: > > Any additional comments on these patches/this approach? > > The first patch addressing this issue actually went into the 5.14 merge > window as commit 7118fc2906e2 ("hugetlb: address ref count racing in > prep_compound_gigantic_page"). > > All this code is very tricky and subtle. It addresses potential issues > discovered by code analysis. I do not believe the races have ever been > experienced in practice. If anyone has suggestions for a simpler or > alternative approach, I would love to hear them. Hi Mike, I agree with you that this code is very tricky and subtle. I have looked at this patch set. For me, I cannot figure out a better solution for this race. -- Thanks, Muchun > -- > Mike Kravetz > > > On 7/9/21 5:24 PM, Mike Kravetz wrote: > > When Muchun Song brought up a potential issue with hugetlb ref counting[1], > > I started looking closer at the code. hugetlbfs is the only code with it's > > own specialized compound page destructor and taking special action when ref > > counts drop to zero. Potential races happen in this unique handling of ref > > counts. The following patches address these races when creating and > > destroying hugetlb pages. > > > > These potential races have likely existed since the creation of > > hugetlbfs. They certainly have been around for more than 10 years. > > However, I am unaware of anyone actually hitting these races. It is > > VERY unlikely than anyone will actually hit these races, but they do > > exist. > > > > I could not think of an easy (or difficult) way to force these races. > > Therefore, testing consisted of adding code to randomly increase ref > > counts in strategic places. In this way, I was able to exercise all the > > race handling code paths. > > > > [1] https://lore.kernel.org/linux-mm/CAMZfGtVMn3daKrJwZMaVOGOaJU+B4dS--x_oPmGQMD=c=QNGEg@mail.gmail.com/ > > > > Mike Kravetz (3): > > hugetlb: simplify prep_compound_gigantic_page ref count racing code > > hugetlb: drop ref count earlier after page allocation > > hugetlb: before freeing hugetlb page set dtor to appropriate value > > > > mm/hugetlb.c | 137 ++++++++++++++++++++++++++++++++++++++------------- > > 1 file changed, 104 insertions(+), 33 deletions(-) > >