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=-20.9 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FSL_HELO_FAKE, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham 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 44655C2D0E4 for ; Fri, 20 Nov 2020 19:53:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ADA9D2245B for ; Fri, 20 Nov 2020 19:53:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rnN1fS4z" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ADA9D2245B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 192246B0036; Fri, 20 Nov 2020 14:53:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 13FE16B005C; Fri, 20 Nov 2020 14:53:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 055526B005D; Fri, 20 Nov 2020 14:53:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id C83F26B0036 for ; Fri, 20 Nov 2020 14:53:14 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 7679E1F08 for ; Fri, 20 Nov 2020 19:53:14 +0000 (UTC) X-FDA: 77505845508.07.light67_5b0de902734e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id 5D0C018020C2E for ; Fri, 20 Nov 2020 19:53:14 +0000 (UTC) X-HE-Tag: light67_5b0de902734e X-Filterd-Recvd-Size: 5617 Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Fri, 20 Nov 2020 19:53:13 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id m9so11130142iox.10 for ; Fri, 20 Nov 2020 11:53:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=GxnkL7sBSNoqYoJigqom0+XD1YVRiqS6FwGLG7iJAO4=; b=rnN1fS4zx8lj60uqorsVrI3/bKsdKEpgfxSOWN01UgyAtOLtDXXzTzcw82y7Zwm2jj 4t69K1Pf6kMgoVoH25M4P/QarFk9kkw/yUl2Nc1RM9B97YcnzYowzkrgorLOT0hmE+7f HTZq8pNl9P7i4UdG5dqVikedfi4RgHQtz6AmwvgDvnZQDB5l/TR24hX0yfZQDxFxbffz kEU+8CqQYPWFwmcqTeTQ+qh3f7CTXFHID/R5BPF3kkZJr1QgRO9bQz1x6jFnrN9oExvB Z+bOFim2X686YNJFfO8IQZfgMBjjNc8Zcr2SyO5Md8SRJTBcmk5UTqRMS4boS0ewTmJI dcQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=GxnkL7sBSNoqYoJigqom0+XD1YVRiqS6FwGLG7iJAO4=; b=Bw4EhJ3XWAa2USjZ50tmcCGn8M/NJFNyDb5VNZQfB8/gZEj9+7Vy1CHD3kogE6Hs3s qpAkccqYcog2uQI57qx8V0ZHMLUYc5t8nSyoJsjRS7nlB3w4diJYz+QDPtZqXNAcs4jM ASsrMqGm1LauXb829Ze+4wpdTtdgKT5XZ1MI+TqG44ZzNP0mZzTTafmRoesq6A3eKb4Z aI4J6Zeow8dHyGBX5xSwGGz+xnJT3AAqNde6A74Z2HePto8mO+UOW3jKT13WYTezVb7Y 4XNvSW/07nM8h8iuyFXM03SL0kKXMFBPSuwJP60NUR0DSRFxwlc0cbPumOuB6bIY38pM 0wVg== X-Gm-Message-State: AOAM532TUHB97zZhQRn7pnuNOiHzz2enL23R65gKbjTiHUzqo+M9sh4u TfTqg+3mSc7Wf13x3cv3+IBSFoc7RvITlDwb X-Google-Smtp-Source: ABdhPJxSffGKpVjywoxuXIvCRu/AM8DhpUH1m+P2eYdFRYvfM6wAc7GXcabZRhXBoGj9LwhZ0yGeZQ== X-Received: by 2002:a02:90ca:: with SMTP id c10mr21200448jag.115.1605901993088; Fri, 20 Nov 2020 11:53:13 -0800 (PST) Received: from google.com ([2620:15c:183:200:7220:84ff:fe09:2d90]) by smtp.gmail.com with ESMTPSA id k26sm1937993iom.32.2020.11.20.11.53.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2020 11:53:12 -0800 (PST) Date: Fri, 20 Nov 2020 12:53:08 -0700 From: Yu Zhao To: Will Deacon Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, Catalin Marinas , Minchan Kim , Peter Zijlstra , Linus Torvalds , Anshuman Khandual , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, stable@vger.kernel.org Subject: Re: [PATCH 1/6] arm64: pgtable: Fix pte_accessible() Message-ID: <20201120195308.GA1303870@google.com> References: <20201120143557.6715-1-will@kernel.org> <20201120143557.6715-2-will@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201120143557.6715-2-will@kernel.org> 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 02:35:52PM +0000, Will Deacon wrote: > pte_accessible() is used by ptep_clear_flush() to figure out whether TLB > invalidation is necessary when unmapping pages for reclaim. Although our > implementation is correct according to the architecture, returning true > only for valid, young ptes in the absence of racing page-table > modifications, this is in fact flawed due to lazy invalidation of old > ptes in ptep_clear_flush_young() where we elide the expensive DSB > instruction for completing the TLB invalidation. > > Rather than penalise the aging path, adjust pte_accessible() to return > true for any valid pte, even if the access flag is cleared. The chance of a system hitting reclaim is proportional to how long it's been running, and that of having mapped but yet to be accessed PTEs is reciprocal, so to speak. I don't reboot my devices everyday, and therefore: Acked-by: Yu Zhao > Cc: > Fixes: 76c714be0e5e ("arm64: pgtable: implement pte_accessible()") > Reported-by: Yu Zhao > Signed-off-by: Will Deacon > --- > arch/arm64/include/asm/pgtable.h | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h > index 4ff12a7adcfd..1bdf51f01e73 100644 > --- a/arch/arm64/include/asm/pgtable.h > +++ b/arch/arm64/include/asm/pgtable.h > @@ -115,8 +115,6 @@ extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)]; > #define pte_valid(pte) (!!(pte_val(pte) & PTE_VALID)) > #define pte_valid_not_user(pte) \ > ((pte_val(pte) & (PTE_VALID | PTE_USER)) == PTE_VALID) > -#define pte_valid_young(pte) \ > - ((pte_val(pte) & (PTE_VALID | PTE_AF)) == (PTE_VALID | PTE_AF)) > #define pte_valid_user(pte) \ > ((pte_val(pte) & (PTE_VALID | PTE_USER)) == (PTE_VALID | PTE_USER)) > > @@ -126,7 +124,7 @@ extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)]; > * remapped as PROT_NONE but are yet to be flushed from the TLB. > */ > #define pte_accessible(mm, pte) \ > - (mm_tlb_flush_pending(mm) ? pte_present(pte) : pte_valid_young(pte)) > + (mm_tlb_flush_pending(mm) ? pte_present(pte) : pte_valid(pte)) > > /* > * p??_access_permitted() is true for valid user mappings (subject to the > -- > 2.29.2.454.gaff20da3a2-goog >