Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp6914527ybe; Wed, 18 Sep 2019 11:07:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwfAq73yHgg8F5S00rqOBjfiEfCJobgPSlqaML4zryzhJIuFSO9aCl/DLYjsVOjwMSSQsd3 X-Received: by 2002:a50:9625:: with SMTP id y34mr11560284eda.72.1568830040292; Wed, 18 Sep 2019 11:07:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568830040; cv=none; d=google.com; s=arc-20160816; b=Dyfz8hyEuaw1CiECDfjZT90XlgVuyeXoRwmdnLWhFwMbAPM08Qp0pT4vPrY2xRHF7j yvSxbhBx+UUqgm47980l1m8w8NhnFUyC/9ropH1BClJWLi66UwwdujvnkumxtyrL8l/3 OJHE26VsPoKo8B/19DDf1VRwRzVcwc4wnyq30DWO4xo1t+ZtJcuDvK5smwlXySR0W5n5 /AOUKszJcKkXDm9BQPy5XbcieyYRfqSF+RcX2c/pnk41+jFGMJMnSgXX4V2KLD3feFmd LX+z77d3mEEZR1fuMxZyxWNwv0lgUKyj5/vuFTuoySi1vRYZrWODC/E4u00zi6NZl3xw OuuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=oY230vJDS4ob/y9rR8lf0HJdEJi58AaHZkomAMyFhXw=; b=mk1R+OwcOEbV6xGSSY8A2InYwEMOdfdUNu7hTMoB7A6n6w8lSDVzNM39YEvt4SZGms A/3TvuLYZXjzJrPObp7fG/ZGQ05Tl7nesvtQaRZozbVIqUT5ZNW2jPBJ/Ki3DCK1vCeH OEQROBzFM1mnP2haWSQ1wiDFxy0gs/7kVtn0yrXZuA3vs5VfHsT4PoMBgEka41kh7qkI PhmES6bNSESEx07BL/+asqVmoOvlpsjudR4E2FtcbucvRgzwvruUnAyUQ8c9K5REq1pE ot4H51YchHdtVeIaH6kJWtka3SnKYGMP/6oz7eVRbJfkS2Bp0ki0NN668gtFm1q+8Pd4 dXZg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m5si3148560ejj.286.2019.09.18.11.06.32; Wed, 18 Sep 2019 11:07:20 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729768AbfIRSAk (ORCPT + 99 others); Wed, 18 Sep 2019 14:00:40 -0400 Received: from foss.arm.com ([217.140.110.172]:46294 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727000AbfIRSAk (ORCPT ); Wed, 18 Sep 2019 14:00:40 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 547971000; Wed, 18 Sep 2019 11:00:39 -0700 (PDT) Received: from iMac.local (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 58E363F59C; Wed, 18 Sep 2019 11:00:36 -0700 (PDT) Date: Wed, 18 Sep 2019 19:00:30 +0100 From: Catalin Marinas To: "Kirill A. Shutemov" Cc: Jia He , Will Deacon , Mark Rutland , James Morse , Marc Zyngier , Matthew Wilcox , "Kirill A. Shutemov" , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Suzuki Poulose , Punit Agrawal , Anshuman Khandual , Jun Yao , Alex Van Brunt , Robin Murphy , Thomas Gleixner , Andrew Morton , =?iso-8859-1?B?Suly9G1l?= Glisse , Ralph Campbell , hejianet@gmail.com, Kaly Xin Subject: Re: [PATCH v4 3/3] mm: fix double page fault on arm64 if PTE_AF is cleared Message-ID: <20190918180029.GB20601@iMac.local> References: <20190918131914.38081-1-justin.he@arm.com> <20190918131914.38081-4-justin.he@arm.com> <20190918140027.ckj32xnryyyesc23@box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190918140027.ckj32xnryyyesc23@box> User-Agent: Mutt/1.11.1 (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 18, 2019 at 05:00:27PM +0300, Kirill A. Shutemov wrote: > On Wed, Sep 18, 2019 at 09:19:14PM +0800, Jia He wrote: > > @@ -2152,20 +2163,34 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo > > */ > > if (unlikely(!src)) { > > void *kaddr = kmap_atomic(dst); > > - void __user *uaddr = (void __user *)(va & PAGE_MASK); > > + void __user *uaddr = (void __user *)(addr & PAGE_MASK); > > + pte_t entry; > > > > /* > > * This really shouldn't fail, because the page is there > > * in the page tables. But it might just be unreadable, > > * in which case we just give up and fill the result with > > - * zeroes. > > + * zeroes. On architectures with software "accessed" bits, > > + * we would take a double page fault here, so mark it > > + * accessed here. > > */ > > + if (arch_faults_on_old_pte() && !pte_young(vmf->orig_pte)) { > > + spin_lock(vmf->ptl); > > + if (likely(pte_same(*vmf->pte, vmf->orig_pte))) { > > + entry = pte_mkyoung(vmf->orig_pte); > > + if (ptep_set_access_flags(vma, addr, > > + vmf->pte, entry, 0)) > > + update_mmu_cache(vma, addr, vmf->pte); > > + } > > I don't follow. > > So if pte has changed under you, you don't set the accessed bit, but never > the less copy from the user. > > What makes you think it will not trigger the same problem? > > I think we need to make cow_user_page() fail in this case and caller -- > wp_page_copy() -- return zero. If the fault was solved by other thread, we > are fine. If not userspace would re-fault on the same address and we will > handle the fault from the second attempt. It would be nice to clarify the semantics of this function and do as you suggest but the current comment is slightly confusing: /* * If the source page was a PFN mapping, we don't have * a "struct page" for it. We do a best-effort copy by * just copying from the original user address. If that * fails, we just zero-fill it. Live with it. */ Would any user-space rely on getting a zero-filled page here instead of a recursive fault? -- Catalin