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=-6.4 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FSL_HELO_FAKE,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 192C5C2D0E4 for ; Fri, 20 Nov 2020 15:55:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 98AC222464 for ; Fri, 20 Nov 2020 15:55:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nQ8Gix8W" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 98AC222464 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 00D9C6B006E; Fri, 20 Nov 2020 10:55:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ED9B86B0070; Fri, 20 Nov 2020 10:55:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA1D46B0071; Fri, 20 Nov 2020 10:55:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A9D6A6B006E for ; Fri, 20 Nov 2020 10:55:19 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 59AA41EE6 for ; Fri, 20 Nov 2020 15:55:19 +0000 (UTC) X-FDA: 77505245958.15.table51_00012842734c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 2D9881814B0C7 for ; Fri, 20 Nov 2020 15:55:19 +0000 (UTC) X-HE-Tag: table51_00012842734c X-Filterd-Recvd-Size: 5197 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Fri, 20 Nov 2020 15:55:18 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id b63so8211422pfg.12 for ; Fri, 20 Nov 2020 07:55:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=mH0XWTPw1aDZdBTH/G0qziz2DLxku/Ckk+DQq/83avE=; b=nQ8Gix8WRyqbKUlkh4PixmhfzCCdN6Vp1oepEYKR1kSzb0c9NFHOT/nOqiemkWOXmc ouxU3ZBc4u58gBkwswnza3mAVLFvjxHgsX31Et3extwahWtmKpiqNIu2KKpIhCOIg/mt vBUXuPdJEmhSbV+yN2v5TFjxZpim0OVTR16hEkvV2Nrz3Q3igRSvZNjgrHW+CAU0zW9W d4h/rwZSnIPvpumibKFp/DN9gzoYRg5h65NjqUJekm18Nec8Tl4SPu4HI+p2YFQcNYV+ UAQ9XJKpX4a4LaCSu22juQDRUm1s8tzoP4XzyhKyOqXyO6iNn/6VVDR27RzxllLrXeda iCBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=mH0XWTPw1aDZdBTH/G0qziz2DLxku/Ckk+DQq/83avE=; b=DFRWxxUuFR1Pu6beL4kq9CctMaENzDJGYcA8bE+d2GtACY7b4PdyqTyzLXcxc8aZxF jWNrU0ELMBTFBBRuqMjmA98IbJV4U9LDyxoZ0uWnlDAWtYAQ7c5V7E1sebYZwJj5U/7J ev5cn8WWa5Qeg1yBdAEXqyKOSntxDmSdx0h1i5YFuoWndFvDJ0wU7lnw2Ij5CXvo5aKd ezqToIE9IlCCOkuwtnBRp1Jza5os6gTeG0GyTI9hKSawtGOBeaBdLT8cKHuIFzLQxcV4 ZdBbsVaPxJwuqm4OELC8Be27QwTLsIYOHw7PeeENPT5//q8LIdCnm/InL7+7IMWTPLoE P2dA== X-Gm-Message-State: AOAM533XplZn6zJ10Kfy/A4DLkYwIhQmqTbI4HgFv9ngQIzaG+PrJZw2 NaTl5WxeneLAgiMA2JBuEdY= X-Google-Smtp-Source: ABdhPJzY/UZC1PpZ/zzTDc+GgXIRIMMltQQy7bU5UOZcHAdIY6OkOzwMpFDnmqnHJ2Oa1mRfWmjHGw== X-Received: by 2002:a63:e20:: with SMTP id d32mr5040393pgl.94.1605887717816; Fri, 20 Nov 2020 07:55:17 -0800 (PST) Received: from google.com ([2620:15c:211:201:7220:84ff:fe09:5e58]) by smtp.gmail.com with ESMTPSA id x12sm4088482pjr.51.2020.11.20.07.55.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2020 07:55:16 -0800 (PST) Date: Fri, 20 Nov 2020 07:55:14 -0800 From: Minchan Kim To: Peter Zijlstra Cc: Will Deacon , linux-kernel@vger.kernel.org, kernel-team@android.com, Catalin Marinas , Yu Zhao , Linus Torvalds , Anshuman Khandual , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 4/6] mm: proc: Invalidate TLB after clearing soft-dirty page state Message-ID: <20201120155514.GA3377168@google.com> References: <20201120143557.6715-1-will@kernel.org> <20201120143557.6715-5-will@kernel.org> <20201120150023.GH3040@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201120150023.GH3040@hirez.programming.kicks-ass.net> 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 Fri, Nov 20, 2020 at 04:00:23PM +0100, Peter Zijlstra wrote: > On Fri, Nov 20, 2020 at 02:35:55PM +0000, Will Deacon wrote: > > Since commit 0758cd830494 ("asm-generic/tlb: avoid potential double flush"), > > TLB invalidation is elided in tlb_finish_mmu() if no entries were batched > > via the tlb_remove_*() functions. Consequently, the page-table modifications > > performed by clear_refs_write() in response to a write to > > /proc//clear_refs do not perform TLB invalidation. Although this is > > fine when simply aging the ptes, in the case of clearing the "soft-dirty" > > state we can end up with entries where pte_write() is false, yet a > > writable mapping remains in the TLB. > > > > Fix this by calling tlb_remove_tlb_entry() for each entry being > > write-protected when cleating soft-dirty. > > > > > @@ -1053,6 +1054,7 @@ static inline void clear_soft_dirty(struct vm_area_struct *vma, > > ptent = pte_wrprotect(old_pte); > > ptent = pte_clear_soft_dirty(ptent); > > ptep_modify_prot_commit(vma, addr, pte, old_pte, ptent); > > + tlb_remove_tlb_entry(tlb, pte, addr); > > } else if (is_swap_pte(ptent)) { > > ptent = pte_swp_clear_soft_dirty(ptent); > > set_pte_at(vma->vm_mm, addr, pte, ptent); > > Oh! > > Yesterday when you had me look at this code; I figured the sane thing > to do was to make it look more like mprotect(). > > Why did you chose to make it work with mmu_gather instead? I'll grant > you that it's probably the smaller patch, but I still think it's weird > to use mmu_gather here. I agree. The reason why clear_refs_write used the gather API was [1] and seems like to overkill to me. We could just do like [inc|dec]_tlb_flush_pending with flush_tlb_mm at right before dec_tlb_flush_pending instead of gather. thought? [1] b3a81d0841a95, mm: fix KSM data corruption