Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp1805145ybj; Sun, 22 Sep 2019 12:18:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwRtdP40W5GkYDffQok/7Fy+1BpPiuyNXNTQNMTLFmSWVhofRZ9WT/t9p99bcYSbGf9hM4m X-Received: by 2002:a50:b501:: with SMTP id y1mr32887072edd.167.1569179932927; Sun, 22 Sep 2019 12:18:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569179932; cv=none; d=google.com; s=arc-20160816; b=Iy7CinvMDB9gPxGlJrbRxaNSmJUbY2hIJKp6VsXDXXCF+PKtDmobkWptHB+li2IVFg 4Phnk4tMGBazVW6JP1cGBPiO2iI1D6W4oUd7cC4CwnbiHjvyBXwFz+OT1+as20bGQRZu uxg6mHqCwvKmpVt+5hErXnb8yCT5wiWYeZDWwXr4Oo/8cA92+4P/LfKQDvJbtViFTn0O ZThXS7MAEcGwYonzZe0sUp2+QemseVvKBy2qkAJItHb+A5nxCaN+iFCUZ8fzeOtk67Y/ QI+6ixKaXRiSzqZBSYj55ywjGL3tQGuV9oNqafLz+iPvh2NeASttMXcUt87YS7qZuL0O pp6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject:dkim-signature; bh=W+8ekTa9bxVsBuWJwU/8AJ+YtRXTgXJvM5aflsiRw9k=; b=DR7ZQwwVT7I3puWR/9W1z89KPzfgbIOjp34zmsB0s+8jPQtrOhIJT8rAUa7JAWz7v+ fpSJ6rGploecBQgPgJgLCbb1/GzeuRPrEEwOceUBmQA7AHa5Tog3WiZJWdXPz3CpffEW rtJ+HxoQ0vcDtQ1wIUUcBlI0sUZijRw+bsDNYivsbFAIN4qG3h4rmum+rre1Ztfn79C6 V4szGSEUF2sKtNGoIm79mXFhC27in8oMtDXk2SVXmy51o15HqWcOhYGgu6BFwbsosURB zRRmXw2UctYEiJBIV5AH4nRGET2u1KiVg8unAQtcwNV3pCTduRO0VLAbX2Uasn19V2FL Aicw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uV1iPiYQ; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r26si5947154edx.61.2019.09.22.12.18.29; Sun, 22 Sep 2019 12:18:52 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uV1iPiYQ; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394177AbfIUNTz (ORCPT + 99 others); Sat, 21 Sep 2019 09:19:55 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:41870 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388184AbfIUNTy (ORCPT ); Sat, 21 Sep 2019 09:19:54 -0400 Received: by mail-pf1-f193.google.com with SMTP id q7so6336711pfh.8 for ; Sat, 21 Sep 2019 06:19:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=W+8ekTa9bxVsBuWJwU/8AJ+YtRXTgXJvM5aflsiRw9k=; b=uV1iPiYQk1e6NbfNJ8We8iK7oluOWL0Hk/ZMhuNR/wjLhXsjJTusXf9UaZmH2Q0smn XtW9GB/AJkWCGsk8XFi4goxBDmeexyzPbU8dolM29bc2w10bdNX1OZ8FHmhb83mBoFfr cZRPBsw6cFySPnUfGpXU2GXwraRqgtPx9YeG6qXrVCBfVp1rL0kqadMOa83zSH7CnTF5 kxholiBotGcFAj8yDqBO/onLZEDfdwRjQ+10a+NS2vlPl5xnim4sOyWVZRvzgcxevPxQ TJn2z6Ny9m282Ymd9CipIPgk7VvugoclMMFIvSxEH4mRjnNi5qQAHyNSAhmuGzuhpJCN me9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=W+8ekTa9bxVsBuWJwU/8AJ+YtRXTgXJvM5aflsiRw9k=; b=IyLri+6pL43whE+zncDY6Y7wyHiYt3JL8UnjSLzQs4HIIgfVPaVcCF+yAb9c71SCBh WkRsNeZbyaoVEi8QoEPGPqgVY9boNIg2GyCuLd6h2WnWRvxxeyikixtyWSVDKyr1OFAq 0ytoGRlfot1wYTAYaxl1Pfj3C1uCHhES3HNdUCl0Wn9tFCO5SqzAwEc3yHpU97bOihZV z0wQ0VxMPB9C0RkOLumXm3KJ+WXKn62ipdorGXzdHXx7JeBncVsZrhEVuf21e/aZyvPY EbVr0BKx0AlmOWh305jeT7Pek1L/NQnEu+rcH1shLshqlqDUTgTJI+19otlfIbT9CKrj Y52Q== X-Gm-Message-State: APjAAAUveIKBpy3bVptWZbAYQyWMLmGXvSw+K+m1/a/i+yOWjQpk1Ba8 f06F5Etphj/cHVs9uw6B638= X-Received: by 2002:a17:90a:3387:: with SMTP id n7mr10004663pjb.26.1569071993741; Sat, 21 Sep 2019 06:19:53 -0700 (PDT) Received: from [0.0.0.0] (104.129.187.94.16clouds.com. [104.129.187.94]) by smtp.gmail.com with ESMTPSA id d76sm7941194pfd.185.2019.09.21.06.19.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Sep 2019 06:19:52 -0700 (PDT) Subject: Re: [PATCH v7 3/3] mm: fix double page fault on arm64 if PTE_AF is cleared To: Matthew Wilcox , Jia He Cc: 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?SsOpcsO0bWUgR2xpc3Nl?= , Ralph Campbell , Kaly Xin , nd@arm.com References: <20190920135437.25622-1-justin.he@arm.com> <20190920135437.25622-4-justin.he@arm.com> <20190920155300.GC15392@bombadil.infradead.org> From: Jia He Message-ID: Date: Sat, 21 Sep 2019 21:19:34 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20190920155300.GC15392@bombadil.infradead.org> Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [On behalf of justin.he@arm.com] Hi Matthew On 2019/9/20 23:53, 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. We could also go with returning a > vm_fault_t, but that would be more complex than needed today, I think. Ok, will change the return type to bool as you suggested. Thanks --- Cheers, Justin (Jia He)