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=-2.3 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 DF75EC49ED7 for ; Fri, 20 Sep 2019 17:00:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 88C87207FC for ; Fri, 20 Sep 2019 17:00:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="2OJhJbUb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 88C87207FC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DC9E86B0003; Fri, 20 Sep 2019 13:00:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D7A806B0005; Fri, 20 Sep 2019 13:00:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1A266B0006; Fri, 20 Sep 2019 13:00:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0108.hostedemail.com [216.40.44.108]) by kanga.kvack.org (Postfix) with ESMTP id 997EC6B0003 for ; Fri, 20 Sep 2019 13:00:34 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 32E2E180AD804 for ; Fri, 20 Sep 2019 17:00:34 +0000 (UTC) X-FDA: 75955912788.23.linen21_79436028b620f X-HE-Tag: linen21_79436028b620f X-Filterd-Recvd-Size: 5681 Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Fri, 20 Sep 2019 17:00:33 +0000 (UTC) Received: by mail-ed1-f66.google.com with SMTP id v38so7132443edm.7 for ; Fri, 20 Sep 2019 10:00:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=CoI9aEF1VTiw5Xhyqba7lfuNeKaTTzmcsltHbdSRkHo=; b=2OJhJbUbpQmn+x3xQD0IdUL9dWYC/YbYOg+H5Rw3+hLXeib7Fw/NkPDuWjgbqZRyhH UhmCvyDveVppNSNLWGUKKRYDph/8hy+GnlI9BVJWv0qh74USl2ktYfyjzTL8u4DiloGy HnmblWT8RimK7hpAAi8c6P5HsIihYVZ8Je0xC3YEpMKV9Yetl1W5YiYuZ+6wOC/Uh2Kr VZ1PH7IUzV63vSz619E375gvI6LfJ7yVXe1yfFLtVhvs0ek4tvLZGZloHPwyM+S9/UZ9 gi+hz7IU0w427OYGIpgdEyH0pB9IaeIh59t9zYXHgLMoCPNUG9Oyu/8Emo7f+Ps51Xut LF9w== 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:user-agent; bh=CoI9aEF1VTiw5Xhyqba7lfuNeKaTTzmcsltHbdSRkHo=; b=dr18DseOew9RYfo1f/y76bFvPv4xIxZdqm2wJ/KSDelCNDJ5SYCXdRRfTaVVdM042k 7kom+KI2FfbFOT4aDAvfJCrKAx4z8SABGLSvgolh7uKpe3sE9oTLOL9ZLL/aUcmZjQcG HOLNPkNhjsoZjFN9eceYZUtJxbYUkgCZbZ1zf2U0k8nfP7yThxXASZMFBB3PXwbHJ9D9 ll8tEaMmgZTffPGB0Gg+zIJVYj+44gUEYpa8IKBlJSDbKYhyr61iziumohXZ8neFG0qs Z/TNhu7zBn7hLxCu3MAvrLt5YFmmcby83wdX5sWm1e1jPV3Tv5ukb5ypZka44KxY0/rw fJHw== X-Gm-Message-State: APjAAAXZRPu79feo/MSTIc8z8DcR8jJKKmEojwJEWjx5KNl8a8EtnUKa 23KEGRuJngNR02LWSqohFYdanA== X-Google-Smtp-Source: APXvYqxVUZ2ch3TYcwVRBpaEIcvJMThHoIdj+VR77186UorLBRy6kohaNp2UxH3nVDesW7lAnd7TZg== X-Received: by 2002:a17:906:5c49:: with SMTP id c9mr20265396ejr.78.1568998831579; Fri, 20 Sep 2019 10:00:31 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id jr18sm285103ejb.89.2019.09.20.10.00.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Sep 2019 10:00:30 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id DB3CE10140A; Fri, 20 Sep 2019 20:00:30 +0300 (+03) Date: Fri, 20 Sep 2019 20:00:30 +0300 From: "Kirill A. Shutemov" To: Matthew Wilcox Cc: Jia He , Catalin Marinas , Will Deacon , Mark Rutland , James Morse , Marc Zyngier , "Kirill A. Shutemov" , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Suzuki Poulose , Punit Agrawal , Anshuman Khandual , Alex Van Brunt , Robin Murphy , Thomas Gleixner , Andrew Morton , =?utf-8?B?SsOpcsO0bWU=?= Glisse , Ralph Campbell , hejianet@gmail.com, Kaly Xin , nd@arm.com Subject: Re: [PATCH v7 3/3] mm: fix double page fault on arm64 if PTE_AF is cleared Message-ID: <20190920170030.bpse5rlpjodbiv62@box> References: <20190920135437.25622-1-justin.he@arm.com> <20190920135437.25622-4-justin.he@arm.com> <20190920155300.GC15392@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190920155300.GC15392@bombadil.infradead.org> User-Agent: NeoMutt/20180716 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, Sep 20, 2019 at 08:53:00AM -0700, Matthew Wilcox wrote: > On Fri, Sep 20, 2019 at 09:54:37PM +0800, Jia He wrote: > > -static inline void cow_user_page(struct page *dst, struct page *src, unsigned long va, struct vm_area_struct *vma) > > +static inline int cow_user_page(struct page *dst, struct page *src, > > + struct vm_fault *vmf) > > { > > Can we talk about the return type here? > > > + } else { > > + /* Other thread has already handled the fault > > + * and we don't need to do anything. If it's > > + * not the case, the fault will be triggered > > + * again on the same address. > > + */ > > + pte_unmap_unlock(vmf->pte, vmf->ptl); > > + return -1; > ... > > + return 0; > > } > > So -1 for "try again" and 0 for "succeeded". > > > + if (cow_user_page(new_page, old_page, vmf)) { > > Then we use it like a bool. But it's kind of backwards from a bool because > false is success. > > > + /* COW failed, if the fault was solved by other, > > + * it's fine. If not, userspace would re-fault on > > + * the same address and we will handle the fault > > + * from the second attempt. > > + */ > > + put_page(new_page); > > + if (old_page) > > + put_page(old_page); > > + return 0; > > And we don't use the return value; in fact we invert it. > > Would this make more sense: > > static inline bool cow_user_page(struct page *dst, struct page *src, > struct vm_fault *vmf) > ... > pte_unmap_unlock(vmf->pte, vmf->ptl); > return false; > ... > return true; > ... > if (!cow_user_page(new_page, old_page, vmf)) { > > That reads more sensibly for me. I like this idea too. -- Kirill A. Shutemov