Received: by 10.213.65.68 with SMTP id h4csp890471imn; Wed, 4 Apr 2018 08:58:46 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/LgsJZUUYBOBDxfoAXT1x9KFR3flIj0/iT2lgC5uqWkAcULf8OUgAbyDgJ3kw+MQHcvwdO X-Received: by 10.101.99.149 with SMTP id h21mr12526687pgv.345.1522857526068; Wed, 04 Apr 2018 08:58:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522857526; cv=none; d=google.com; s=arc-20160816; b=LhEOo2b3P39hNbQsjwHzN3d2PumUG98gy5wbou8NKPCrHWhKNBWdEVu2j/nbIJ5EuR i9mP2WT/6cXzEKEGt0gnHbwu9Nck7gixiC61BoFNMfnHj1MLbAY2beIgvn2qCKl+2p7V 9EGKDxVCkWjQj1RRdU2SoVCrnkokWY0yuoald4MkH42/mYsrDgdioJP5gINX7z6ruPIr bkcEtMw3Qb3l0odM231QNdqbx3hFmoeGRrwyvW7QMkXcs5J3qFthEo4IzWezxjEMJTnL qMwmH3WfveW+w0nVhWrv2c2FbZHaIFAq34cRnQ0wQ25GI3Fdl/mC2RuxDy5/4hv9PEiX kQ6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date:from :references:cc:to:subject:arc-authentication-results; bh=ZjfgkbVWBd3sMcMe034zFqarhEpYtlOae/Z/2ohjPu8=; b=aeLMJozm1Id1z14GXHhEWocu0Z2gPJf4MNWwItXyvzbMhgq3qVfgCGeMy4x6o+K9Ti r2n22kaRFmXqHAhEdBeiUJRyv5Akn4Yvm0Ue8kXW5yCwhGp2MNaFixY7nL67gJmSbPPK KEZRNFKxftMU+DqfEpwIXQSqqzB9Wyb1aWoR9qzcZyjzcjiebXcSIiANcCDzYwp5fIoT nYVr+vlC62YuMj62YiJbJEyG2OJ6Eh1X2za8fivr+PtqckmXtCaqZIN86zWx0stPpICA tUjOTIBSclhtf15wQ21oS2Ar14W2jnsNqx4uuitUh7IGosiTulOfIEQTznyYpB4QTgMH Lzjg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o1-v6si3326379plb.459.2018.04.04.08.58.32; Wed, 04 Apr 2018 08:58:46 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752084AbeDDP5C (ORCPT + 99 others); Wed, 4 Apr 2018 11:57:02 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:42846 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751780AbeDDP5A (ORCPT ); Wed, 4 Apr 2018 11:57:00 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w34Fu2R5044753 for ; Wed, 4 Apr 2018 11:57:00 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0b-001b2d01.pphosted.com with ESMTP id 2h50g3v6p6-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Wed, 04 Apr 2018 11:56:58 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 4 Apr 2018 16:56:56 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 4 Apr 2018 16:56:49 +0100 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w34FumOp57278616; Wed, 4 Apr 2018 15:56:48 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1F15D42042; Wed, 4 Apr 2018 16:48:39 +0100 (BST) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 022444203F; Wed, 4 Apr 2018 16:48:37 +0100 (BST) Received: from [9.145.59.61] (unknown [9.145.59.61]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 4 Apr 2018 16:48:36 +0100 (BST) Subject: Re: [PATCH v9 14/24] mm: Introduce __maybe_mkwrite() To: David Rientjes 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 References: <1520963994-28477-1-git-send-email-ldufour@linux.vnet.ibm.com> <1520963994-28477-15-git-send-email-ldufour@linux.vnet.ibm.com> From: Laurent Dufour Date: Wed, 4 Apr 2018 17:56:46 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 18040415-0008-0000-0000-000004E6B65F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18040415-0009-0000-0000-00001E79C683 Message-Id: <403a5d84-99f9-d1a5-0c75-38b0d4cc1637@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-04-04_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1804040161 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/04/2018 01:12, David Rientjes wrote: > 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()? Indeed I'll drop this patch as all the changes are now done in the patch 11 "mm: Cache some VMA fields in the vm_fault structure" where, as you suggested, maybe_mkwrite() is now getting passed the vm_flags value directly. > 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; >