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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AC83C00140 for ; Fri, 5 Aug 2022 23:14:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241578AbiHEXN5 (ORCPT ); Fri, 5 Aug 2022 19:13:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241449AbiHEXNy (ORCPT ); Fri, 5 Aug 2022 19:13:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7F5135589 for ; Fri, 5 Aug 2022 16:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659741231; 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: in-reply-to:in-reply-to:references:references; bh=CQ0tUUX9dSdS4JRTC1zPGHaQM3Hc6bp+ASxYzjmtUmQ=; b=E555HY3/Kht+Je+3fgfn9tVF44MH7avovwzM2VCN4BOZg5jU82FXTSTEXZugdZYPVj5y/3 1obQXpjJ79DJ5XJiMKTNcaDEVFBZh6jq1QWny9UlxBUHqJfq8KzYDcOAwU4bEr3s0SM6di xlTj8kHW016iJpBtQRjtTyGGTAjoQno= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-590-sW-jUhTwMg-UXYrGQwbwag-1; Fri, 05 Aug 2022 19:13:50 -0400 X-MC-Unique: sW-jUhTwMg-UXYrGQwbwag-1 Received: by mail-qt1-f197.google.com with SMTP id a8-20020a05622a064800b00342240a9fccso2805949qtb.18 for ; Fri, 05 Aug 2022 16:13:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=CQ0tUUX9dSdS4JRTC1zPGHaQM3Hc6bp+ASxYzjmtUmQ=; b=Mi+qj8AMOhHIkdL3ZFPkpQvfos/JyMjIRgH6kC1RpC4z7Fb7NDnEHXJKPtD+eUhDtk ipaRHP6tdcNN9kZgSjXQ76xb5wQV+b5F8POSEhH5L8Q1MBufc+9rlcL05+vozUI2AbzY WI2MREN+1PSmwrLbNIelJZPjB9q4V38+c0cpSL6/xSFwaGxn7a4Xz9sa/mV+8V+VzqQI hGkNuEYkbiaXw2oBCT0FN68fEe5nga4GzP/4K+UcXruSUqGEUWGhFeXVnap1uOVSHZYx 0s+7J4Uum2T/1nkCn3XgqAiOHVj/9gkvJz9LxnwSAeFvR5an5wOHLI20rLbcniKfZIHn AoXg== X-Gm-Message-State: ACgBeo3fOzIGxNmaWRUsFH/j2wPYREZMijkdManf4L4mNDy4mFAXBWdh ZIGQmVSTfORw568OrkDIixzVTOQiHtbeSfDQHQDu2cZoe78AKJEfivBbxK5SIi4nxNKmg5QZ3vN CAp+B4F4J3ai8pKdaMXozcnqY X-Received: by 2002:a05:620a:b86:b0:6b8:d74e:1e08 with SMTP id k6-20020a05620a0b8600b006b8d74e1e08mr6881001qkh.166.1659741229905; Fri, 05 Aug 2022 16:13:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR7vQnU94QQncO9wXjydH0biWvfzN2On2lgdFWzew+raRRdFz5zCSICz/EgkRwetHoifGyaVTQ== X-Received: by 2002:a05:620a:b86:b0:6b8:d74e:1e08 with SMTP id k6-20020a05620a0b8600b006b8d74e1e08mr6880984qkh.166.1659741229647; Fri, 05 Aug 2022 16:13:49 -0700 (PDT) Received: from xz-m1.local (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id r11-20020ac87eeb000000b0031f286f868dsm3289067qtc.92.2022.08.05.16.13.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 16:13:49 -0700 (PDT) Date: Fri, 5 Aug 2022 19:13:47 -0400 From: Peter Xu To: Mike Kravetz Cc: David Hildenbrand , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Muchun Song , Peter Feiner , "Kirill A . Shutemov" , stable@vger.kernel.org Subject: Re: [PATCH v1 1/2] mm/hugetlb: fix hugetlb not supporting write-notify Message-ID: References: <20220805110329.80540-1-david@redhat.com> <20220805110329.80540-2-david@redhat.com> <73050e64-e40f-0c94-be96-316d1e8d5f3b@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 05, 2022 at 01:48:35PM -0700, Mike Kravetz wrote: > On 08/05/22 20:57, David Hildenbrand wrote: > > On 05.08.22 20:33, Mike Kravetz wrote: > > > On 08/05/22 20:25, David Hildenbrand wrote: > > >> On 05.08.22 20:23, Mike Kravetz wrote: > > >>> On 08/05/22 14:14, Peter Xu wrote: > > >>>> On Fri, Aug 05, 2022 at 01:03:28PM +0200, David Hildenbrand wrote: > > >>>>> diff --git a/mm/mmap.c b/mm/mmap.c > > >>>>> index 61e6135c54ef..462a6b0344ac 100644 > > >>>>> --- a/mm/mmap.c > > >>>>> +++ b/mm/mmap.c > > >>>>> @@ -1683,6 +1683,13 @@ int vma_wants_writenotify(struct vm_area_struct *vma, pgprot_t vm_page_prot) > > >>>>> if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED))) > > >>>>> return 0; > > >>>>> > > >>>>> + /* > > >>>>> + * Hugetlb does not require/support writenotify; especially, it does not > > >>>>> + * support softdirty tracking. > > >>>>> + */ > > >>>>> + if (is_vm_hugetlb_page(vma)) > > >>>>> + return 0; > > >>>> > > >>>> I'm kind of confused here.. you seems to be fixing up soft-dirty for > > >>>> hugetlb but here it's explicitly forbidden. > > >>>> > > >>>> Could you explain a bit more on why this patch is needed if (assume > > >>>> there'll be a working) patch 2 being provided? > > >>>> > > >>> > > >>> No comments on the patch, but ... > > >>> > > >>> Since it required little thought, I ran the test program on next-20220802 and > > >>> was surprised that the issue did not recreate. Even added a simple printk > > >>> to make sure we were getting into vma_wants_writenotify with a hugetlb vma. > > >>> We were. > > >> > > >> > > >> ... does your config have CONFIG_MEM_SOFT_DIRTY enabled? > > >> > > > > > > No, Duh! > > > > > > FYI - Some time back, I started looking at adding soft dirty support for > > > hugetlb mappings. I did not finish that work. But, I seem to recall > > > places where code was operating on hugetlb mappings when perhaps it should > > > not. > > > > > > Perhaps, it would also be good to just disable soft dirty for hugetlb at > > > the source? > > > > I thought about that as well. But I came to the conclusion that without > > patch #2, hugetlb VMAs cannot possibly support write-notify, so there is > > no need to bother in vma_wants_writenotify() at all. > > > > The "root" would be places where we clear VM_SOFTDIRTY. That should only > > be fs/proc/task_mmu.c:clear_refs_write() IIRC. > > > > So I don't particularly care, I consider this patch a bit cleaner and > > more generic, but I can adjust clear_refs_write() instead of there is a > > preference. > > > > After a closer look, I agree that this may be the simplest/cleanest way to > proceed. I was going to suggest that you note hugetlb does not support > softdirty, but see you did in the comment. > > Acked-by: Mike Kravetz Filtering out hugetlbfs in vma_wants_writenotify() is still a bit hard to follow to me, since it's not clear why hugetlbfs never wants writenotify. If it's only about soft-dirty, we could have added the hugetlbfs check into vma_soft_dirty_enabled(), then I think it'll achieve the same thing and much clearer - with the soft-dirty check constantly returning false for it, hugetlbfs shared vmas should have vma_wants_writenotify() naturally return 0 already. For the long term - shouldn't we just enable soft-dirty for hugetlbfs? I remember Mike used to have that in todo. Since we've got patch 2 already, I feel like that's really much close (is the only missing piece the clear refs write part? or maybe some more that I didn't notice). Then patch 1 (or IMHO equivalant check in vma_soft_dirty_enabled(), but maybe in stable trees we don't have vma_soft_dirty_enabled then it's exactly patch 1) can be a stable-only backport just to avoid the bug from triggering. Thanks, -- Peter Xu