Received: by 10.213.65.68 with SMTP id h4csp2883768imn; Mon, 2 Apr 2018 16:14:27 -0700 (PDT) X-Google-Smtp-Source: AIpwx48yrXUPJ4P3YRKNC9AYgUvrJYJuR3jGwW5RXHuQcmPHQxYzu+y7JT3p+CJlHKumAMMbHiC0 X-Received: by 10.98.217.88 with SMTP id s85mr8736872pfg.20.1522710867917; Mon, 02 Apr 2018 16:14:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522710867; cv=none; d=google.com; s=arc-20160816; b=zPT73eS6Ck9Me+mHNuif09RLoSeiXfzSbLG1pR5zy+trG4pvpV+y3cOU84/pLed4Ef jN8JtdImW5XOwcIhpRndDT5rzGtvAOlpn94C2arIeCTeht7+L0LvmeJ2I0G0kOHXkJGg 2w8x5xfjuoJ/IH9/m5d7zfdKQzU/RMa82S9AmqBXspFXevU07puJhOx5bo3f4VoMWc22 8SwsubZrUy2xcdo3HsO/2sE79E8X60juBanzN7Nz+QgxNtTdk5pmk2Hk0fI1LIj2rR9B eQqrfZWA34xyfhJBZNYdtDVQjEL4t2YPzbF8v0N7rwO7ZhdieLdaHYA+YJbJctKNM/+a BXQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=/lULgNx4KttrsSzuzTxHraiIVhRdZKJTbrvGRafjQtM=; b=Vd0SIu/j9DscR8koX2rDsELSL4XY3XNI0f99i1BUEKjxTrmaCRrNobOCnSxx2s5BkB EB0bcNwmp3SVurSsYV4wFjlRrjkkfax9kDo3bjiJDbgzVJUj/ZgDP8765uhZ0oFk2XS7 wSC2/P3AVQIJRHNWvCApV6THgBaMaPzO6t5wUjYOzFgP4wXk2MbOsXsTOc7huqkhVkpn BS3FSERrxY34NavOKBPyBmH6T2uriEprspJGqhE12p0wowjuxblLYLB2nPw15JJ9+n0N BM93CKxDRQjzq+eFGYanUxj7Nr/zhyEJMbmYDpysT+uWeS4UCEcJPUhIMOYjQ+3FgXia 9bFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ob+6A+Yd; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a187si911962pgc.762.2018.04.02.16.14.14; Mon, 02 Apr 2018 16:14:27 -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=@google.com header.s=20161025 header.b=ob+6A+Yd; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754610AbeDBXM0 (ORCPT + 99 others); Mon, 2 Apr 2018 19:12:26 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:45533 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754550AbeDBXMY (ORCPT ); Mon, 2 Apr 2018 19:12:24 -0400 Received: by mail-pl0-f66.google.com with SMTP id v18-v6so4220998ply.12 for ; Mon, 02 Apr 2018 16:12:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=/lULgNx4KttrsSzuzTxHraiIVhRdZKJTbrvGRafjQtM=; b=ob+6A+YdnS1UtgRX17OQ6Ho33iDvwh7p5um7lez9hJuuSUihnNFTe66MSNH9+4GpHi dj+8UqU3KIAiWOMpyJTigBC85suTwha5MLYH3zGe8Un49h2Xv/ovDU3LHrJ1ZySTvwmF AKSQo8pVzVkjMixLqzgODmYsFDSrOkp7tg1hzQeSylU3lWqKCID5FvdS8grMjbQniLi9 HIu6wg6gO+ni/LTfqKAyofzDYQlaBQbDqEZPvsIFvztkvInwLUGQtQoglO/h2wBpOL66 mzo00+kYzfQh/4cjBGyEczqHgF2lo3aq7C5Fq5jn1zRm0JcSAJeh2wXT2ER/BYk1rwh1 QuVg== 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:in-reply-to:message-id :references:user-agent:mime-version; bh=/lULgNx4KttrsSzuzTxHraiIVhRdZKJTbrvGRafjQtM=; b=uZueXABIYnPw9YMwidM3u3+EVRXzYB+OBuVn7z11TmHxsgAID2CGDDu03o7degBXs4 CWVDw6uesTczAUwL0kre8fmJXqd+l11gdIDCENycefdLVxTVK3fbyV+G0Cg9GNG2G8f8 N66S5zfOhfaF52JDeNUqCpHdkTTbdro5XyJWHV6h5CQPQuXapgYjCC6LoVy9R0v5YStr rR7plMpPIevUq97+ISqyNXTQMB/RMcb0AMJlK7IXOry2+pg/S9R2lx7yUbiuFsVzKDIX JOcJXhBul9xFbjcfBz0tLtFZZH4xlt7CagXqU5hpmuseJ25Dx5g/expR63v1Htm9fo8w TEpg== X-Gm-Message-State: AElRT7HSbHi/k1lHKhhfsqRTNcJyBFsayx748wacwTlUumLYQmQUzfu5 ct6CqPDck3T0mhfwZFCeha+bTw== X-Received: by 2002:a17:902:6184:: with SMTP id u4-v6mr11900859plj.390.1522710744094; Mon, 02 Apr 2018 16:12:24 -0700 (PDT) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id j11sm2042819pgc.91.2018.04.02.16.12.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Apr 2018 16:12:23 -0700 (PDT) Date: Mon, 2 Apr 2018 16:12:22 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Laurent Dufour cc: paulmck@linux.vnet.ibm.com, peterz@infradead.org, akpm@linux-foundation.org, kirill@shutemov.name, ak@linux.intel.com, mhocko@kernel.org, dave@stgolabs.net, jack@suse.cz, Matthew Wilcox , benh@kernel.crashing.org, mpe@ellerman.id.au, paulus@samba.org, Thomas Gleixner , Ingo Molnar , hpa@zytor.com, Will Deacon , Sergey Senozhatsky , Andrea Arcangeli , Alexei Starovoitov , kemi.wang@intel.com, sergey.senozhatsky.work@gmail.com, Daniel Jordan , linux-kernel@vger.kernel.org, linux-mm@kvack.org, haren@linux.vnet.ibm.com, khandual@linux.vnet.ibm.com, npiggin@gmail.com, bsingharora@gmail.com, Tim Chen , linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: Re: [PATCH v9 14/24] mm: Introduce __maybe_mkwrite() In-Reply-To: <1520963994-28477-15-git-send-email-ldufour@linux.vnet.ibm.com> Message-ID: References: <1520963994-28477-1-git-send-email-ldufour@linux.vnet.ibm.com> <1520963994-28477-15-git-send-email-ldufour@linux.vnet.ibm.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 13 Mar 2018, Laurent Dufour wrote: > diff --git a/include/linux/mm.h b/include/linux/mm.h > index dfa81a638b7c..a84ddc218bbd 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -684,13 +684,18 @@ void free_compound_page(struct page *page); > * pte_mkwrite. But get_user_pages can cause write faults for mappings > * that do not have writing enabled, when used by access_process_vm. > */ > -static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma) > +static inline pte_t __maybe_mkwrite(pte_t pte, unsigned long vma_flags) > { > - if (likely(vma->vm_flags & VM_WRITE)) > + if (likely(vma_flags & VM_WRITE)) > pte = pte_mkwrite(pte); > return pte; > } > > +static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma) > +{ > + return __maybe_mkwrite(pte, vma->vm_flags); > +} > + > int alloc_set_pte(struct vm_fault *vmf, struct mem_cgroup *memcg, > struct page *page); > int finish_fault(struct vm_fault *vmf); > diff --git a/mm/memory.c b/mm/memory.c > index 0a0a483d9a65..af0338fbc34d 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -2472,7 +2472,7 @@ static inline void wp_page_reuse(struct vm_fault *vmf) > > flush_cache_page(vma, vmf->address, pte_pfn(vmf->orig_pte)); > entry = pte_mkyoung(vmf->orig_pte); > - entry = maybe_mkwrite(pte_mkdirty(entry), vma); > + entry = __maybe_mkwrite(pte_mkdirty(entry), vmf->vma_flags); > if (ptep_set_access_flags(vma, vmf->address, vmf->pte, entry, 1)) > update_mmu_cache(vma, vmf->address, vmf->pte); > pte_unmap_unlock(vmf->pte, vmf->ptl); > @@ -2549,8 +2549,8 @@ static int wp_page_copy(struct vm_fault *vmf) > inc_mm_counter_fast(mm, MM_ANONPAGES); > } > flush_cache_page(vma, vmf->address, pte_pfn(vmf->orig_pte)); > - entry = mk_pte(new_page, vma->vm_page_prot); > - entry = maybe_mkwrite(pte_mkdirty(entry), vma); > + entry = mk_pte(new_page, vmf->vma_page_prot); > + entry = __maybe_mkwrite(pte_mkdirty(entry), vmf->vma_flags); > /* > * Clear the pte entry and flush it first, before updating the > * pte with the new entry. This will avoid a race condition Don't you also need to do this in do_swap_page()? diff --git a/mm/memory.c b/mm/memory.c --- a/mm/memory.c +++ b/mm/memory.c @@ -3067,9 +3067,9 @@ int do_swap_page(struct vm_fault *vmf) inc_mm_counter_fast(vma->vm_mm, MM_ANONPAGES); dec_mm_counter_fast(vma->vm_mm, MM_SWAPENTS); - pte = mk_pte(page, vma->vm_page_prot); + pte = mk_pte(page, vmf->vma_page_prot); if ((vmf->flags & FAULT_FLAG_WRITE) && reuse_swap_page(page, NULL)) { - pte = maybe_mkwrite(pte_mkdirty(pte), vma); + pte = __maybe_mkwrite(pte_mkdirty(pte), vmf->vma_flags); vmf->flags &= ~FAULT_FLAG_WRITE; ret |= VM_FAULT_WRITE; exclusive = RMAP_EXCLUSIVE;