Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp121542pxb; Mon, 2 Nov 2020 16:02:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJwL/Kyg9E2szzxttH9Nuwn7Pe7tHCMntrctck99+2Mi0ep57Q5j/TXTxXs01h6ut/BDipzn X-Received: by 2002:a50:8745:: with SMTP id 5mr18867105edv.49.1604361758724; Mon, 02 Nov 2020 16:02:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604361758; cv=none; d=google.com; s=arc-20160816; b=vB+tzI3FQjL889TmavOnty06oAzlLXF4jVPwngH8YnXqylKIIDN38wFLcR45HgojYf y+noG/wkvnuehQSquKu8HBFmjl/G9AtxmmxElp+0LmkhuTHCOc4twwNoVC+y/pIJVsh1 Mpcfl1nrmIXTG1JbfLIPbjk80B/MIDx2VCkTYGjWHPzfJuDaJXirMb7fbJam+9VZYoq7 O6jlgW+MV6yAHROB5RmbFlmBTkS3T2+Gjjk35C0wVndYM1wD8wXfOa2d1d/EtJIVlBjJ z/EsiZkC42X9cfOIL9nBXkdFWWA69UKAnauK6gI5Veu3q2e1G6ofxhBIx1FOXj2OGXVg bkPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:dkim-signature:dkim-signature:date; bh=EUc8ouU+wBbKL35b1Wz4H1oFm1iThH4UiokAYDkphtI=; b=ac0eNyFjV1CD5Te2B80MC5L6vF2oJB2hhWdWDBROlKRk9PepB3hf8axp9jvW46/Vy4 ifzna7wSJEyMZ1MSHPoCIwNggX+TvFTruK3rZYPyprxovoxywmB3eeC/mgIW7ArkxysS M5zmggY3NJsberSl4DFU1k+plCHPL30c5qiYHky702ZfiWu5oYZht6KN27Z4DzKd416b wf5s6VSh2HQ/JVc8zHBh3hRYGCG1JYgk7kMtDbuk8M+ROxbTvfQcE46fnlXohrs+dMJh nl7kT0gecrMfGEWuFZDz+IGEaltyidbADg/hP1+rOYWfjZDVAAnlh5vkTEgSMY2Gw5TP SnjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mUjJO30z; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="myFbIB/R"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b1si5980459edy.451.2020.11.02.16.02.15; Mon, 02 Nov 2020 16:02:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mUjJO30z; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="myFbIB/R"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727002AbgKBX6e (ORCPT + 99 others); Mon, 2 Nov 2020 18:58:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbgKBX6e (ORCPT ); Mon, 2 Nov 2020 18:58:34 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DD18C0617A6 for ; Mon, 2 Nov 2020 15:58:34 -0800 (PST) Date: Tue, 3 Nov 2020 00:58:31 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1604361512; 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; bh=EUc8ouU+wBbKL35b1Wz4H1oFm1iThH4UiokAYDkphtI=; b=mUjJO30zHIraTb9wkx4VJj8y4oSR6Q5RciQVCCSg/3nHP9zRU6cX8hE29ULf8MyV9miP1z Z631a4hPVaBBxRxXnvsTFH4bIRIZ4K/rfD0Q5TDvB4vrBBhtHOgWszuZHNSdB+9DSpq/cb APTLh3dMUUwDHH0irMGnfnxYGu3zf4CYL0ESe1+DxKgwWqsWy7zWwk92rWLdrPIYdnvyw7 86RR0dlXh4wxsW70k0dr1yWc7bvqDhZLl/tj4knWJ0G42jhvY1BalIqSPxBbmXk5mvnbPp 1ZnicxPBHRL+9Abof6uK7XOhifXeV+7BJCUXmEi4X7vGBHYt/9xJXIpp89IkXw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1604361512; 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; bh=EUc8ouU+wBbKL35b1Wz4H1oFm1iThH4UiokAYDkphtI=; b=myFbIB/Rg7QAUo0gPSmUmACCtS8QYcTO2Hfc4GSxOC9/ctr4bUEMxBvtKoyZbIP1UVxw9V 9D2mOHVkrEAgJUAA== From: "Ahmed S. Darwish" To: Jason Gunthorpe Cc: linux-kernel@vger.kernel.org, Peter Xu , Linus Torvalds , Andrea Arcangeli , Andrew Morton , "Aneesh Kumar K.V" , Christoph Hellwig , Hugh Dickins , Jan Kara , Jann Horn , John Hubbard , Kirill Shutemov , Kirill Tkhai , Leon Romanovsky , Linux-MM , Michal Hocko , Oleg Nesterov , Peter Zijlstra , Ingo Molnar , Will Deacon , Thomas Gleixner , Sebastian Siewior Subject: Re: [PATCH v2 2/2] mm: prevent gup_fast from racing with COW during fork Message-ID: <20201102235831.GA52235@lx-t490> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2-v2-dfe9ecdb6c74+2066-gup_fork_jgg@nvidia.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 30, 2020 at 11:46:21AM -0300, Jason Gunthorpe wrote: ... > diff --git a/mm/memory.c b/mm/memory.c > index c48f8df6e50268..294c2c3c4fe00d 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -1171,6 +1171,12 @@ copy_page_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma) > mmu_notifier_range_init(&range, MMU_NOTIFY_PROTECTION_PAGE, > 0, src_vma, src_mm, addr, end); > mmu_notifier_invalidate_range_start(&range); > + /* > + * The read side doesn't spin, it goes to the mmap_lock, so the > + * raw version is used to avoid disabling preemption here > + */ > + mmap_assert_write_locked(src_mm); > + raw_write_seqcount_t_begin(&src_mm->write_protect_seq); > } > Please, s/raw_write_seqcount_t_begin()/raw_write_seqcount_begin()/g. For plain seqcount_t, it's the same, while still respecting the seqlock.h API boundaries. Let's make the comment also a bit more clear (IMHO, "lockdep" needs to be mentioned somewhere): /* * Disabling preemption is not needed for the write side, as * the read side doesn't spin, but goes to the mmap_lock. * * Use the raw variant of the seqcount_t write API to avoid * lockdep complaining about preemptibility. */ mmap_assert_write_locked(src_mm); raw_write_seqcount_t_begin(&src_mm->write_protect_seq); > ret = 0; > @@ -1187,8 +1193,10 @@ copy_page_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma) > } > } while (dst_pgd++, src_pgd++, addr = next, addr != end); > > - if (is_cow) > + if (is_cow) { > + raw_write_seqcount_t_end(&src_mm->write_protect_seq); ditto. s/raw_write_seqcount_t_end()/raw_write_seqcount_end()/g > mmu_notifier_invalidate_range_end(&range); > + } > return ret; > } > Thanks, -- Ahmed S. Darwish Linutronix GmbH