Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp770611yba; Thu, 9 May 2019 05:47:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqzP7gZ2grxrO4T3bDIWoZqWcND5M/BWK3eFTY4jdV6HECRIn1pDRTA/62BUuioIa/Oms+cC X-Received: by 2002:a17:902:2702:: with SMTP id c2mr4703867plb.277.1557406062738; Thu, 09 May 2019 05:47:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557406062; cv=none; d=google.com; s=arc-20160816; b=0Yy1aMgMVmxGQGW+On4ieNOhkWEh8pwJGmjwuwv/CLBarQvB1hYrn/hO0Sc8ChtiUB 8GsHnkYcvsF2UkNwWJiHIZG8Pzv3Cy42MW7ShxO9sEf1sW757q02wD6xjOSmJHkWeo1S 9vmiXsgULZ6WY94kkB1o6XYUXzp4WYzPcxqj9cVb5AovnFOWc9GGvEJk6erwuXIESs0M 1a/5jgJduH0KR8LQ1Q7dJAt7fhnnfuS7zDcbUT/y7ZY7Log6mPviAi+wausPix8kpL+p WN5kgn0MIPznRkTJWxHyIBjcmXxXNUeNVbz+d2f8T/9n0z9lmET8YikU+I5w0OLzPeyC d8Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date; bh=+phK1cVXiJnNn5EyClT7CUVOqZ4BhMstBmQ1KciQlp0=; b=YESl7XrN0lcVIAFXnWK3nInbKaUi4Gbmq92X3zMwMHstIRLm9CKk5146yNZ80+0oao H4u6QRoknTMJ6nb4C+VE/smLKXhhDGEiaImHNFK8h1tE5g1zoQq9csDq2t4WyYTApTc9 J5PCb3J890u7mRZHrpreDe2FNneWJs9IANqZGvuV/y8zFHHYu9JUnycXNGONsHS24O+1 o5gXZkoDe03N+lUO+TexFNZSHVTG32qUmXE8IRWPk50VO391GNoaUJu93oSLFPNbdJWY CJwjS7y1uEJg/NG7jFi0ZwOzOmgXAcoLnCzOBHQhZKwSgBX9GnibopHH5qhK4ddgQ/SE Lzqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i7si2863689pgb.597.2019.05.09.05.47.25; Thu, 09 May 2019 05:47:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726557AbfEIMpB (ORCPT + 99 others); Thu, 9 May 2019 08:45:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35480 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726054AbfEIMpA (ORCPT ); Thu, 9 May 2019 08:45:00 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 75C62369D2; Thu, 9 May 2019 12:45:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5FDE64F84; Thu, 9 May 2019 12:45:00 +0000 (UTC) Received: from zmail17.collab.prod.int.phx2.redhat.com (zmail17.collab.prod.int.phx2.redhat.com [10.5.83.19]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 31EFE3FAF4; Thu, 9 May 2019 12:45:00 +0000 (UTC) Date: Thu, 9 May 2019 08:44:57 -0400 (EDT) From: Jan Stancek To: Peter Zijlstra Cc: Will Deacon , Yang Shi , akpm@linux-foundation.org, stable@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, aneesh kumar , npiggin@gmail.com, namit@vmware.com, minchan@kernel.org, Mel Gorman , Jan Stancek Message-ID: <436298752.21855393.1557405897147.JavaMail.zimbra@redhat.com> In-Reply-To: <20190509103813.GP2589@hirez.programming.kicks-ass.net> References: <1557264889-109594-1-git-send-email-yang.shi@linux.alibaba.com> <20190509083726.GA2209@brain-police> <20190509103813.GP2589@hirez.programming.kicks-ass.net> Subject: Re: [PATCH] mm: mmu_gather: remove __tlb_reset_range() for force flush MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [10.40.204.125, 10.4.195.27] Thread-Topic: mmu_gather: remove __tlb_reset_range() for force flush Thread-Index: DI/vebM+Rldg1xz41Sw2XzYn9lA53w== X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 09 May 2019 12:45:00 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > > I don't think we can elide the call __tlb_reset_range() entirely, since I > > think we do want to clear the freed_pXX bits to ensure that we walk the > > range with the smallest mapping granule that we have. Otherwise couldn't we > > have a problem if we hit a PMD that had been cleared, but the TLB > > invalidation for the PTEs that used to be linked below it was still > > pending? > > That's tlb->cleared_p*, and yes agreed. That is, right until some > architecture has level dependent TLBI instructions, at which point we'll > need to have them all set instead of cleared. > > > Perhaps we should just set fullmm if we see that here's a concurrent > > unmapper rather than do a worst-case range invalidation. Do you have a > > feeling > > for often the mm_tlb_flush_nested() triggers in practice? > > Quite a bit for certain workloads I imagine, that was the whole point of > doing it. > > Anyway; am I correct in understanding that the actual problem is that > we've cleared freed_tables and the ARM64 tlb_flush() will then not > invalidate the cache and badness happens? That is my understanding, only last level is flushed, which is not enough. > > Because so far nobody has actually provided a coherent description of > the actual problem we're trying to solve. But I'm thinking something > like the below ought to do. I applied it (and fixed small typo: s/tlb->full_mm/tlb->fullmm/). It fixes the problem for me. > > > diff --git a/mm/mmu_gather.c b/mm/mmu_gather.c > index 99740e1dd273..fe768f8d612e 100644 > --- a/mm/mmu_gather.c > +++ b/mm/mmu_gather.c > @@ -244,15 +244,20 @@ void tlb_finish_mmu(struct mmu_gather *tlb, > unsigned long start, unsigned long end) > { > /* > - * If there are parallel threads are doing PTE changes on same range > - * under non-exclusive lock(e.g., mmap_sem read-side) but defer TLB > - * flush by batching, a thread has stable TLB entry can fail to flush > - * the TLB by observing pte_none|!pte_dirty, for example so flush TLB > - * forcefully if we detect parallel PTE batching threads. > + * Sensible comment goes here.. > */ > - if (mm_tlb_flush_nested(tlb->mm)) { > - __tlb_reset_range(tlb); > - __tlb_adjust_range(tlb, start, end - start); > + if (mm_tlb_flush_nested(tlb->mm) && !tlb->full_mm) { > + /* > + * Since we're can't tell what we actually should have > + * flushed flush everything in the given range. > + */ > + tlb->start = start; > + tlb->end = end; > + tlb->freed_tables = 1; > + tlb->cleared_ptes = 1; > + tlb->cleared_pmds = 1; > + tlb->cleared_puds = 1; > + tlb->cleared_p4ds = 1; > } > > tlb_flush_mmu(tlb); >