From patchwork Wed Nov 28 14:34:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 10702771 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1FDC3109C for ; Wed, 28 Nov 2018 14:35:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EEA32BA49 for ; Wed, 28 Nov 2018 14:35:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 019862C886; Wed, 28 Nov 2018 14:35:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D4612BA49 for ; Wed, 28 Nov 2018 14:35:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 430B76B4D70; Wed, 28 Nov 2018 09:35:05 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 390916B4D71; Wed, 28 Nov 2018 09:35:05 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 209E66B4D72; Wed, 28 Nov 2018 09:35:05 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id CA88C6B4D70 for ; Wed, 28 Nov 2018 09:35:04 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id h10so26355271plk.12 for ; Wed, 28 Nov 2018 06:35:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:in-reply-to:references:mime-version :content-transfer-encoding:message-id; bh=XXs0HWX7O3OqoiMqHYgrHcBzm2Mr5gIkOEH19IHZkc0=; b=BNKBJjmJsC8XI3MqKtRuTrkR/F3rv5ZBn0MNwKEJZYXM30iFXxR5+jpIra5cjumI39 93a6I+XEemxuK/8KWNemeMcMg/D4yY6RkqA0FfSYV3XT2QKHLe7ZR7RBjJzewvRGncoq JF5EKbEXClZc3xWT2nvhQejuqeus0ajEHivUn9dj4/tZUAh6dB38UmESoyiUWerihJGu JFaUFKkLCZgiBapsK5fGTXjYJUl2xA1AUY4OtZ+nM6Fdag4BnWkiWkwYLb+4HYyqCs/t qeKQw/rcBzAKPV+/OphiXn8nAD5k1JkHCL8azXm+ILpaGUZDPj3NCLSCOrGgMwfraVwt Zr6A== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com X-Gm-Message-State: AA+aEWYB8aKfbpKuCEgYb81c/hrEgmoqxgxSGpa/9qsQk4Vbi20Gy7tp wtTz1BK/KNArOYk4LK/9MS7RfT7Iu+8j0EqB8aLiFmwI6qq7bxGh5iyhD2CS11DHfcucel9a5St oBKmhUpEptfDVVc6bnIWU9tyEJd1xfxIMiNpaDdbkuZrFnFpB5B1M94l1IvDgUqrmgg== X-Received: by 2002:a17:902:a411:: with SMTP id p17mr36653788plq.292.1543415704431; Wed, 28 Nov 2018 06:35:04 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xf7tU1wUb2PUOFzLBh2pyPlT3MhU/uXE3zVJHtc8miwQNWHxccE7Bu49W/AWAHe+xQ6Zh0 X-Received: by 2002:a17:902:a411:: with SMTP id p17mr36653705plq.292.1543415703149; Wed, 28 Nov 2018 06:35:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543415703; cv=none; d=google.com; s=arc-20160816; b=lkqY6rATyT/ZlfA3oq/9NeJjiWeUFmxEO+PeEex/oSZ/gZQcNg1PDTUhgcNA597++D kkYGbeJ9jZcUXi+D6QCOQQyELPW2v2n9kgryD2hWyf9szL2FXIM1y2q7zSair5EIBl1P Ez5lg/sVTE+zC9ZDPYTJuzhcWYQLw+E0JYR1fDmE6IFjp/xUhDottq2KwlLqkf6vAe+t x/gsflpy0/flu2sJC/gYkkgh6cG9I7AkdKu9IYkCnTZsmrV2Hmi4tUHrH0qjpdiRAO6z sCNCQa/0cPtFXb+cydaYUvfiJd3Q2nl7ubTR6T9iVR4ljQHSJ8tJabo5uvFI0dMcWoKH LVjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:content-transfer-encoding:mime-version:references :in-reply-to:date:subject:cc:to:from; bh=XXs0HWX7O3OqoiMqHYgrHcBzm2Mr5gIkOEH19IHZkc0=; b=qP7sYTeeV4SUtvuvVEH5P2VTaEckeX6g3dXdHPrPctuApHZE+dLraNqylrj04z/m9M NXHaG+wq76KrWBjq3poyjOUsA08sSdpeEtHiXrw4BHyuNIkgdxFlOHvWg5tqDuDL5qD+ X8gJ9RjS3NGGcgOzkYXZB9WyQkrhKBVpJk0ku3yZAUO/pmyVu8BDhZxiJWakgeV3lxzu CYYGkwloEZT++a1/iS+oH8mF4IWGTJeMA25YCZwzG3u9VN3LfsCdkqMpMYPD3sFg07cS e3pPPeT9+aMr2+I9m5KgG6iBN6xjUIaBqVk64NITi9wNcIgiBUqSQ2Vin9x/Xo89dQhY h0fA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com. [148.163.156.1]) by mx.google.com with ESMTPS id p3-v6si7542229pld.119.2018.11.28.06.35.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Nov 2018 06:35:03 -0800 (PST) Received-SPF: pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) client-ip=148.163.156.1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wASEYJJv008335 for ; Wed, 28 Nov 2018 09:35:02 -0500 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0a-001b2d01.pphosted.com with ESMTP id 2p1tve6316-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 28 Nov 2018 09:35:01 -0500 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 28 Nov 2018 14:35:01 -0000 Received: from b03cxnp08028.gho.boulder.ibm.com (9.17.130.20) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 28 Nov 2018 14:34:57 -0000 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wASEYuQV16646388 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 28 Nov 2018 14:34:56 GMT Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 462056E04E; Wed, 28 Nov 2018 14:34:56 +0000 (GMT) Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3E1526E05B; Wed, 28 Nov 2018 14:34:53 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.85.87.253]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 28 Nov 2018 14:34:52 +0000 (GMT) From: "Aneesh Kumar K.V" To: akpm@linux-foundation.org, mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, "Aneesh Kumar K.V" Subject: [PATCH V2 1/5] mm: Update ptep_modify_prot_start/commit to take vm_area_struct as arg Date: Wed, 28 Nov 2018 20:04:34 +0530 X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181128143438.29458-1-aneesh.kumar@linux.ibm.com> References: <20181128143438.29458-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18112814-0020-0000-0000-00000E918F65 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010137; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000270; SDB=6.01124008; UDB=6.00583546; IPR=6.00904138; MB=3.00024366; MTD=3.00000008; XFM=3.00000015; UTC=2018-11-28 14:34:59 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18112814-0021-0000-0000-000063DE30D5 Message-Id: <20181128143438.29458-2-aneesh.kumar@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-28_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=805 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811280129 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: X-Virus-Scanned: ClamAV using ClamSMTP Some architecture may want to call flush_tlb_range from these helpers. Signed-off-by: Aneesh Kumar K.V --- arch/s390/include/asm/pgtable.h | 4 ++-- arch/s390/mm/pgtable.c | 6 ++++-- arch/x86/include/asm/paravirt.h | 7 +++++-- fs/proc/task_mmu.c | 4 ++-- include/asm-generic/pgtable.h | 8 ++++---- mm/memory.c | 4 ++-- mm/mprotect.c | 4 ++-- 7 files changed, 21 insertions(+), 16 deletions(-) diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h index 063732414dfb..5d730199e37b 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -1069,8 +1069,8 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm, } #define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION -pte_t ptep_modify_prot_start(struct mm_struct *, unsigned long, pte_t *); -void ptep_modify_prot_commit(struct mm_struct *, unsigned long, pte_t *, pte_t); +pte_t ptep_modify_prot_start(struct vm_area_struct *, unsigned long, pte_t *); +void ptep_modify_prot_commit(struct vm_area_struct *, unsigned long, pte_t *, pte_t); #define __HAVE_ARCH_PTEP_CLEAR_FLUSH static inline pte_t ptep_clear_flush(struct vm_area_struct *vma, diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c index f2cc7da473e4..29c0a21cd34a 100644 --- a/arch/s390/mm/pgtable.c +++ b/arch/s390/mm/pgtable.c @@ -301,12 +301,13 @@ pte_t ptep_xchg_lazy(struct mm_struct *mm, unsigned long addr, } EXPORT_SYMBOL(ptep_xchg_lazy); -pte_t ptep_modify_prot_start(struct mm_struct *mm, unsigned long addr, +pte_t ptep_modify_prot_start(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) { pgste_t pgste; pte_t old; int nodat; + struct mm_struct *mm = vma->vm_mm; preempt_disable(); pgste = ptep_xchg_start(mm, addr, ptep); @@ -320,10 +321,11 @@ pte_t ptep_modify_prot_start(struct mm_struct *mm, unsigned long addr, } EXPORT_SYMBOL(ptep_modify_prot_start); -void ptep_modify_prot_commit(struct mm_struct *mm, unsigned long addr, +void ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t pte) { pgste_t pgste; + struct mm_struct *mm = vma->vm_mm; if (!MACHINE_HAS_NX) pte_val(pte) &= ~_PAGE_NOEXEC; diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h index 4bf42f9e4eea..1154f154025d 100644 --- a/arch/x86/include/asm/paravirt.h +++ b/arch/x86/include/asm/paravirt.h @@ -417,19 +417,22 @@ static inline pgdval_t pgd_val(pgd_t pgd) } #define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION -static inline pte_t ptep_modify_prot_start(struct mm_struct *mm, unsigned long addr, +static inline pte_t ptep_modify_prot_start(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) { pteval_t ret; + struct mm_struct *mm = vma->vm_mm; ret = PVOP_CALL3(pteval_t, mmu.ptep_modify_prot_start, mm, addr, ptep); return (pte_t) { .pte = ret }; } -static inline void ptep_modify_prot_commit(struct mm_struct *mm, unsigned long addr, +static inline void ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t pte) { + struct mm_struct *mm = vma->vm_mm; + if (sizeof(pteval_t) > sizeof(long)) /* 5 arg words */ pv_ops.mmu.ptep_modify_prot_commit(mm, addr, ptep, pte); diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 47c3764c469b..9952d7185170 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -940,10 +940,10 @@ static inline void clear_soft_dirty(struct vm_area_struct *vma, pte_t ptent = *pte; if (pte_present(ptent)) { - ptent = ptep_modify_prot_start(vma->vm_mm, addr, pte); + ptent = ptep_modify_prot_start(vma, addr, pte); ptent = pte_wrprotect(ptent); ptent = pte_clear_soft_dirty(ptent); - ptep_modify_prot_commit(vma->vm_mm, addr, pte, ptent); + ptep_modify_prot_commit(vma, addr, pte, ptent); } else if (is_swap_pte(ptent)) { ptent = pte_swp_clear_soft_dirty(ptent); set_pte_at(vma->vm_mm, addr, pte, ptent); diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h index 359fb935ded6..c9897dcc46c4 100644 --- a/include/asm-generic/pgtable.h +++ b/include/asm-generic/pgtable.h @@ -606,22 +606,22 @@ static inline void __ptep_modify_prot_commit(struct mm_struct *mm, * queue the update to be done at some later time. The update must be * actually committed before the pte lock is released, however. */ -static inline pte_t ptep_modify_prot_start(struct mm_struct *mm, +static inline pte_t ptep_modify_prot_start(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) { - return __ptep_modify_prot_start(mm, addr, ptep); + return __ptep_modify_prot_start(vma->vm_mm, addr, ptep); } /* * Commit an update to a pte, leaving any hardware-controlled bits in * the PTE unmodified. */ -static inline void ptep_modify_prot_commit(struct mm_struct *mm, +static inline void ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t pte) { - __ptep_modify_prot_commit(mm, addr, ptep, pte); + __ptep_modify_prot_commit(vma->vm_mm, addr, ptep, pte); } #endif /* __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION */ #endif /* CONFIG_MMU */ diff --git a/mm/memory.c b/mm/memory.c index 4ad2d293ddc2..d36b0eaa7862 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3588,12 +3588,12 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) * Make it present again, Depending on how arch implementes non * accessible ptes, some can allow access by kernel mode. */ - pte = ptep_modify_prot_start(vma->vm_mm, vmf->address, vmf->pte); + pte = ptep_modify_prot_start(vma, vmf->address, vmf->pte); pte = pte_modify(pte, vma->vm_page_prot); pte = pte_mkyoung(pte); if (was_writable) pte = pte_mkwrite(pte); - ptep_modify_prot_commit(vma->vm_mm, vmf->address, vmf->pte, pte); + ptep_modify_prot_commit(vma, vmf->address, vmf->pte, pte); update_mmu_cache(vma, vmf->address, vmf->pte); page = vm_normal_page(vma, vmf->address, pte); diff --git a/mm/mprotect.c b/mm/mprotect.c index 6d331620b9e5..a301d4c83d3c 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -110,7 +110,7 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, continue; } - ptent = ptep_modify_prot_start(mm, addr, pte); + ptent = ptep_modify_prot_start(vma, addr, pte); ptent = pte_modify(ptent, newprot); if (preserve_write) ptent = pte_mk_savedwrite(ptent); @@ -121,7 +121,7 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, !(vma->vm_flags & VM_SOFTDIRTY))) { ptent = pte_mkwrite(ptent); } - ptep_modify_prot_commit(mm, addr, pte, ptent); + ptep_modify_prot_commit(vma, addr, pte, ptent); pages++; } else if (IS_ENABLED(CONFIG_MIGRATION)) { swp_entry_t entry = pte_to_swp_entry(oldpte); From patchwork Wed Nov 28 14:34:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 10702773 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3CA2F17D5 for ; Wed, 28 Nov 2018 14:35:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C35A2BA49 for ; Wed, 28 Nov 2018 14:35:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 205042CA44; Wed, 28 Nov 2018 14:35:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 783312BA49 for ; Wed, 28 Nov 2018 14:35:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 456E86B4D71; Wed, 28 Nov 2018 09:35:12 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3DF2C6B4D72; Wed, 28 Nov 2018 09:35:12 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 258E76B4D73; Wed, 28 Nov 2018 09:35:12 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id C01646B4D71 for ; Wed, 28 Nov 2018 09:35:11 -0500 (EST) Received: by mail-ed1-f69.google.com with SMTP id w15so12593941edl.21 for ; Wed, 28 Nov 2018 06:35:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:in-reply-to:references:mime-version :content-transfer-encoding:message-id; bh=PPuEcGxXRMGPERhMUAv3wDuKToxo1vLycOYU8n2g+7Y=; b=Z05hhY7XQdHjQxuJSWK4JHf+w3h7EWM3txf4n7tj2BqUU/kDIEx1t/48AuC7iMRtzz ++v5z/Fajrf4/eBBYK2tUIvSS23CcB0Oy3/00nlnyktLHusyIWnBbjMG0Hrvzj9Ug3W5 sm2XgsNQsqj3DwlcSjJmZbfZmsqY/Wske5G48cWWNzn0kCvuROleBS6vsh6BkRqjWsSQ Xp2Yrv7CN432I8ZNxPwByYReYTyU/uwNw4DRhuW3T8j6yp2dRy2kYDOtwDl5BIYUzzvv DejJpU21LvWZlR6Nm7YZ3RQwifCgawrr8X05GzTmZY9kMELEEew8wXwEVJ6ucCBZCuRH LRmw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com X-Gm-Message-State: AA+aEWYRRGWZItW7VLCvVzclhJSoEFI73r+B1bhme/ax58qTVgMPMtJw MsvfrDa6MXTa4szYa+JjMh5qaxtfNvzyC0/6vH8UVqoa2hn62+6rsc0bfTUlE/YoBW0XRHHawTU iVPEJLC3nXjv/irUNXs6hb2pa+9du3Dk5gIqxRJOfhQldGtLdyGynTUBiuAKLmqMpeQ== X-Received: by 2002:a50:f10b:: with SMTP id w11mr31734687edl.0.1543415711275; Wed, 28 Nov 2018 06:35:11 -0800 (PST) X-Google-Smtp-Source: AFSGD/VxzC44f9YvEr6QcNvGzfTmvVjbArZWe4sE+H6FJuW1DekZjrNBfoN+KdG3/VSZvM+Oqs3h X-Received: by 2002:a50:f10b:: with SMTP id w11mr31734594edl.0.1543415709775; Wed, 28 Nov 2018 06:35:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543415709; cv=none; d=google.com; s=arc-20160816; b=ZuFp41E07eHCiE3QF89Vln7NCWSsMgTBdc8qrAbVlQuQ8WqtNjV8xzLolZis0vxj50 r/MDniXK1jvfpD+v7EoZmg7/ItirXbQ18NooZMmRdzV5wS68uTbO7O2To1YYglkDtzkb bkwH1CblUnLwphbYm+SE1pcfKVqXsWJZtmym0OPgz9jnIvGFsIzKNkoJcK+ALkJ3lnkG qhTRIk2D50EeJWVnGzB4sCWKB2tH4ZWnRrTRvbr1UaqoHzivFjhP2Nv7QgBq5zNNC6xD r8ZkwFHY0YZ56+nPtn1VU8p08JTPqn7vvVOhU3zMzkYndZLyCKWxAIcJES3Ik/Et0K5E ipxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:content-transfer-encoding:mime-version:references :in-reply-to:date:subject:cc:to:from; bh=PPuEcGxXRMGPERhMUAv3wDuKToxo1vLycOYU8n2g+7Y=; b=RA386QGltFrQA3LJPs8U5KRTo2m6ynyIlQIboDBphsPYHtGqqKvse0aOR9dn19qwbr +1YtlgkRQFsRTKGZmktNx0w/IGN0DvoapQPsTbeLq5eqaKld5uqesmDNoLcQK0rNPREW 3n6RNmmSzw++NhQlDhxyhpRz9lFYXPkbvHUJkeQvF5PENgUZgNv2lMu7UV6SxckgMbsd oz/ZAlqqYoM1pCBtxnyDkXFXuP5qmlnZcHOtZYbTaKsYaC6DQ40iTxvys0tueHqsnO9t vPTMHMAhawliPQm+yILUhzgUa8cqAx8jHf6i4Jd9bPYOjMqGRO3HgGkw7xvfSaqlrfWp dmXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com. [148.163.158.5]) by mx.google.com with ESMTPS id f10si904532edb.244.2018.11.28.06.35.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Nov 2018 06:35:09 -0800 (PST) Received-SPF: pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) client-ip=148.163.158.5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wASEYGJ2001383 for ; Wed, 28 Nov 2018 09:35:08 -0500 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0a-001b2d01.pphosted.com with ESMTP id 2p1v29jpqe-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 28 Nov 2018 09:35:07 -0500 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 28 Nov 2018 14:35:06 -0000 Received: from b03cxnp08028.gho.boulder.ibm.com (9.17.130.20) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 28 Nov 2018 14:35:04 -0000 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wASEZ3v07929986 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 28 Nov 2018 14:35:03 GMT Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2E3F76E04C; Wed, 28 Nov 2018 14:35:03 +0000 (GMT) Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0E32C6E05D; Wed, 28 Nov 2018 14:34:57 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.85.87.253]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 28 Nov 2018 14:34:57 +0000 (GMT) From: "Aneesh Kumar K.V" To: akpm@linux-foundation.org, mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, "Aneesh Kumar K.V" Subject: [PATCH V2 2/5] mm: update ptep_modify_prot_commit to take old pte value as arg Date: Wed, 28 Nov 2018 20:04:35 +0530 X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181128143438.29458-1-aneesh.kumar@linux.ibm.com> References: <20181128143438.29458-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18112814-0012-0000-0000-000016E1501C X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010137; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000270; SDB=6.01124008; UDB=6.00583546; IPR=6.00904137; MB=3.00024366; MTD=3.00000008; XFM=3.00000015; UTC=2018-11-28 14:35:06 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18112814-0013-0000-0000-000055440C34 Message-Id: <20181128143438.29458-3-aneesh.kumar@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-28_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=750 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811280129 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: X-Virus-Scanned: ClamAV using ClamSMTP Architectures like ppc64 requires to do a conditional tlb flush based on the old and new value of pte. Enable that by passing old pte value as the arg. Signed-off-by: Aneesh Kumar K.V --- arch/s390/include/asm/pgtable.h | 3 ++- arch/s390/mm/pgtable.c | 2 +- arch/x86/include/asm/paravirt.h | 2 +- fs/proc/task_mmu.c | 8 +++++--- include/asm-generic/pgtable.h | 2 +- mm/memory.c | 8 ++++---- mm/mprotect.c | 6 +++--- 7 files changed, 17 insertions(+), 14 deletions(-) diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h index 5d730199e37b..76dc344edb8c 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -1070,7 +1070,8 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm, #define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION pte_t ptep_modify_prot_start(struct vm_area_struct *, unsigned long, pte_t *); -void ptep_modify_prot_commit(struct vm_area_struct *, unsigned long, pte_t *, pte_t); +void ptep_modify_prot_commit(struct vm_area_struct *, unsigned long, + pte_t *, pte_t, pte_t); #define __HAVE_ARCH_PTEP_CLEAR_FLUSH static inline pte_t ptep_clear_flush(struct vm_area_struct *vma, diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c index 29c0a21cd34a..b283b92722cc 100644 --- a/arch/s390/mm/pgtable.c +++ b/arch/s390/mm/pgtable.c @@ -322,7 +322,7 @@ pte_t ptep_modify_prot_start(struct vm_area_struct *vma, unsigned long addr, EXPORT_SYMBOL(ptep_modify_prot_start); void ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr, - pte_t *ptep, pte_t pte) + pte_t *ptep, pte_t old_pte, pte_t pte) { pgste_t pgste; struct mm_struct *mm = vma->vm_mm; diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h index 1154f154025d..0d75a4f60500 100644 --- a/arch/x86/include/asm/paravirt.h +++ b/arch/x86/include/asm/paravirt.h @@ -429,7 +429,7 @@ static inline pte_t ptep_modify_prot_start(struct vm_area_struct *vma, unsigned } static inline void ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr, - pte_t *ptep, pte_t pte) + pte_t *ptep, pte_t old_pte, pte_t pte) { struct mm_struct *mm = vma->vm_mm; diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 9952d7185170..8d62891d38a8 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -940,10 +940,12 @@ static inline void clear_soft_dirty(struct vm_area_struct *vma, pte_t ptent = *pte; if (pte_present(ptent)) { - ptent = ptep_modify_prot_start(vma, addr, pte); - ptent = pte_wrprotect(ptent); + pte_t old_pte; + + old_pte = ptep_modify_prot_start(vma, addr, pte); + ptent = pte_wrprotect(old_pte); ptent = pte_clear_soft_dirty(ptent); - ptep_modify_prot_commit(vma, addr, pte, ptent); + ptep_modify_prot_commit(vma, addr, pte, old_pte, ptent); } else if (is_swap_pte(ptent)) { ptent = pte_swp_clear_soft_dirty(ptent); set_pte_at(vma->vm_mm, addr, pte, ptent); diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h index c9897dcc46c4..37039e918f17 100644 --- a/include/asm-generic/pgtable.h +++ b/include/asm-generic/pgtable.h @@ -619,7 +619,7 @@ static inline pte_t ptep_modify_prot_start(struct vm_area_struct *vma, */ static inline void ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr, - pte_t *ptep, pte_t pte) + pte_t *ptep, pte_t old_pte, pte_t pte) { __ptep_modify_prot_commit(vma->vm_mm, addr, ptep, pte); } diff --git a/mm/memory.c b/mm/memory.c index d36b0eaa7862..4f3ddaedc764 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3568,7 +3568,7 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) int last_cpupid; int target_nid; bool migrated = false; - pte_t pte; + pte_t pte, old_pte; bool was_writable = pte_savedwrite(vmf->orig_pte); int flags = 0; @@ -3588,12 +3588,12 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) * Make it present again, Depending on how arch implementes non * accessible ptes, some can allow access by kernel mode. */ - pte = ptep_modify_prot_start(vma, vmf->address, vmf->pte); - pte = pte_modify(pte, vma->vm_page_prot); + old_pte = ptep_modify_prot_start(vma, vmf->address, vmf->pte); + pte = pte_modify(old_pte, vma->vm_page_prot); pte = pte_mkyoung(pte); if (was_writable) pte = pte_mkwrite(pte); - ptep_modify_prot_commit(vma, vmf->address, vmf->pte, pte); + ptep_modify_prot_commit(vma, vmf->address, vmf->pte, old_pte, pte); update_mmu_cache(vma, vmf->address, vmf->pte); page = vm_normal_page(vma, vmf->address, pte); diff --git a/mm/mprotect.c b/mm/mprotect.c index a301d4c83d3c..1b46b1b1248d 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -110,8 +110,8 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, continue; } - ptent = ptep_modify_prot_start(vma, addr, pte); - ptent = pte_modify(ptent, newprot); + oldpte = ptep_modify_prot_start(vma, addr, pte); + ptent = pte_modify(oldpte, newprot); if (preserve_write) ptent = pte_mk_savedwrite(ptent); @@ -121,7 +121,7 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, !(vma->vm_flags & VM_SOFTDIRTY))) { ptent = pte_mkwrite(ptent); } - ptep_modify_prot_commit(vma, addr, pte, ptent); + ptep_modify_prot_commit(vma, addr, pte, oldpte, ptent); pages++; } else if (IS_ENABLED(CONFIG_MIGRATION)) { swp_entry_t entry = pte_to_swp_entry(oldpte); From patchwork Wed Nov 28 14:34:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 10702775 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F251A109C for ; Wed, 28 Nov 2018 14:35:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E30ED2C886 for ; Wed, 28 Nov 2018 14:35:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6FCA2CC6D; Wed, 28 Nov 2018 14:35:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42F002C886 for ; Wed, 28 Nov 2018 14:35:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 122CA6B4D73; Wed, 28 Nov 2018 09:35:18 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0A9D76B4D74; Wed, 28 Nov 2018 09:35:18 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E636D6B4D75; Wed, 28 Nov 2018 09:35:17 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id 863F46B4D73 for ; Wed, 28 Nov 2018 09:35:17 -0500 (EST) Received: by mail-ed1-f71.google.com with SMTP id w15so12594072edl.21 for ; Wed, 28 Nov 2018 06:35:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:in-reply-to:references:mime-version :content-transfer-encoding:message-id; bh=FxbEqkKsrYhgBkWlbs5Nw+OPNaONAnQJPU/YYtWIDxg=; b=NHXq5jJzBFfn7bcUjwvTAFWj3oRqxRZRcb4VEb+PtwzqgKJcmrT8vvfDmvuPfqulQE kXzG25X27UGL21O8q9a3uDpT5D+u9WW+XVxBT50o2Q9tD1HZFhi3+Or1KXjICHwLCOJD R5mLXuklzSTVffsAN76Z7BfAhHGsl1rox/3E8xD8j9hssnc/Ul/lGyzmAvIBKTzmmPsM Mavyiu00sabeNIHDUw6g5TjaGAPR49MhxfHdhTG4Pwj7FqHs8t4Sgm8XcOKOJM9fwXO+ s1IpX/pMxU4J84jS8TLaevYEiJRgV53sc0jyzjCnhfnlm14taup2sP9St+E/At3wfjJG JiHQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com X-Gm-Message-State: AA+aEWYFifa8hbUNexIqE3CYSVoWSF7cB4ku1d6NpKRpKrtYD5lPHUCd TC+WU2+o3PpWOxIowy6uTpTPC46rAuNU1FbjcXP3yNItiit87K5CNGjQnR9jdC6xw5XZnjByxV9 1Q7KtDBHMuLmu8EWJs54mCIUZfMe+d31a7SxpJFvjYlKNWo+ShCycQr3c8U9+PwCYIQ== X-Received: by 2002:a50:f284:: with SMTP id f4mr30338717edm.77.1543415717037; Wed, 28 Nov 2018 06:35:17 -0800 (PST) X-Google-Smtp-Source: AFSGD/X1nYN7gD/Kn8Cl7L3yTMFMeF2uKFWAJvg5I1SzJE+8SskwhVlfYkJ5JhGDLeLjkbPBYGGQ X-Received: by 2002:a50:f284:: with SMTP id f4mr30338623edm.77.1543415715433; Wed, 28 Nov 2018 06:35:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543415715; cv=none; d=google.com; s=arc-20160816; b=np0MDkutDEFsmtiEmEzITtYHYLkmW+nH3BA2Junoq/OQqdNjaEx5K3NlmOOo6quC0o eQsJFkWoGiV4RliOHVTRGSBj4Osq5xyuZgDmlSQdT5uAqUDVhb5GFttbUiAVMIeMlk/8 AkvpMC0FpliqGWNQLBHC9XNRmVNHPMffectGvVJ9gB0wU8qjfVPd+w3IF7DnkMa+Eepc fyDTksZ6UFUhq6tPffP2TijuqJsJmcldt8ATqXwj7/SzVDeGg6m256z1S+1agfu2mUcf OD9oKpXlU0m4uxRCcZ2IQ7l9SYjNyjv8mOanbAy6Zm7lisR0EPaOS+iAULsu2uPF6GKe 0zKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:content-transfer-encoding:mime-version:references :in-reply-to:date:subject:cc:to:from; bh=FxbEqkKsrYhgBkWlbs5Nw+OPNaONAnQJPU/YYtWIDxg=; b=hMM++EWe2004IRRipnBhQOKGFsXCyyZDfy7N/5PQCS3z8MGtoewuvJddhqi/Oujwoz Aui8wt2Dl9vcKKg0AMS050iG4OTizlCjOp+Dl60MJwAAVM7YR8VhhHqZGAxLkJPkpPfs wywFxMk4+7VQ/07nuL+bYrvfiaFGe5MqwjUjVHxos4F1Lb8t2GqKaTT9aXohKs7l3TDs Yrox11zOJ8KMsTU/RJ4y95IBeryU4y1Q7+dwFKaMJLrDEaPgSzcjaycjyhUnAHG+8mP9 qqDMYPWuSwvbTBsNZ3tYgD2SuaeTeheGGbc5NzEyJ4v9ly+XjsKZPz02HBNCmYLCwqtJ ndOw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com. [148.163.158.5]) by mx.google.com with ESMTPS id v16si539468edq.63.2018.11.28.06.35.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Nov 2018 06:35:15 -0800 (PST) Received-SPF: pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) client-ip=148.163.158.5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com 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 wASEYQkt156564 for ; Wed, 28 Nov 2018 09:35:13 -0500 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0b-001b2d01.pphosted.com with ESMTP id 2p1u9avak8-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 28 Nov 2018 09:35:13 -0500 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 28 Nov 2018 14:35:12 -0000 Received: from b03cxnp08028.gho.boulder.ibm.com (9.17.130.20) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 28 Nov 2018 14:35:09 -0000 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wASEZ8jH9699448 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 28 Nov 2018 14:35:08 GMT Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F41366E06B; Wed, 28 Nov 2018 14:35:07 +0000 (GMT) Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E0E746E053; Wed, 28 Nov 2018 14:35:04 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.85.87.253]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 28 Nov 2018 14:35:04 +0000 (GMT) From: "Aneesh Kumar K.V" To: akpm@linux-foundation.org, mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, "Aneesh Kumar K.V" Subject: [PATCH V2 3/5] arch/powerpc/mm: Nest MMU workaround for mprotect RW upgrade. Date: Wed, 28 Nov 2018 20:04:36 +0530 X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181128143438.29458-1-aneesh.kumar@linux.ibm.com> References: <20181128143438.29458-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18112814-0016-0000-0000-0000095C37AC X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010137; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000270; SDB=6.01124008; UDB=6.00583546; IPR=6.00904137; MB=3.00024366; MTD=3.00000008; XFM=3.00000015; UTC=2018-11-28 14:35:10 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18112814-0017-0000-0000-000041381589 Message-Id: <20181128143438.29458-4-aneesh.kumar@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-28_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=840 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811280129 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: X-Virus-Scanned: ClamAV using ClamSMTP NestMMU requires us to mark the pte invalid and flush the tlb when we do a RW upgrade of pte. We fixed a variant of this in the fault path in commit Fixes: bd5050e38aec ("powerpc/mm/radix: Change pte relax sequence to handle nest MMU hang") Do the same for mprotect upgrades. Hugetlb is handled in the next patch. Signed-off-by: Aneesh Kumar K.V --- arch/powerpc/include/asm/book3s/64/pgtable.h | 18 +++++++++++++ arch/powerpc/include/asm/book3s/64/radix.h | 4 +++ arch/powerpc/mm/pgtable-book3s64.c | 27 ++++++++++++++++++++ arch/powerpc/mm/pgtable-radix.c | 18 +++++++++++++ 4 files changed, 67 insertions(+) diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h index 2e6ada28da64..92eaea164700 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h @@ -1314,6 +1314,24 @@ static inline int pud_pfn(pud_t pud) BUILD_BUG(); return 0; } +#define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION +pte_t ptep_modify_prot_start(struct vm_area_struct *, unsigned long, pte_t *); +void ptep_modify_prot_commit(struct vm_area_struct *, unsigned long, + pte_t *, pte_t, pte_t); + +/* + * Returns true for a R -> RW upgrade of pte + */ +static inline bool is_pte_rw_upgrade(unsigned long old_val, unsigned long new_val) +{ + if (!(old_val & _PAGE_READ)) + return false; + + if ((!(old_val & _PAGE_WRITE)) && (new_val & _PAGE_WRITE)) + return true; + + return false; +} #endif /* __ASSEMBLY__ */ #endif /* _ASM_POWERPC_BOOK3S_64_PGTABLE_H_ */ diff --git a/arch/powerpc/include/asm/book3s/64/radix.h b/arch/powerpc/include/asm/book3s/64/radix.h index 7d1a3d1543fc..5ab134eeed20 100644 --- a/arch/powerpc/include/asm/book3s/64/radix.h +++ b/arch/powerpc/include/asm/book3s/64/radix.h @@ -127,6 +127,10 @@ extern void radix__ptep_set_access_flags(struct vm_area_struct *vma, pte_t *ptep pte_t entry, unsigned long address, int psize); +extern void radix__ptep_modify_prot_commit(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, + pte_t old_pte, pte_t pte); + static inline unsigned long __radix_pte_update(pte_t *ptep, unsigned long clr, unsigned long set) { diff --git a/arch/powerpc/mm/pgtable-book3s64.c b/arch/powerpc/mm/pgtable-book3s64.c index 9f93c9f985c5..3d126353b11e 100644 --- a/arch/powerpc/mm/pgtable-book3s64.c +++ b/arch/powerpc/mm/pgtable-book3s64.c @@ -482,3 +482,30 @@ void arch_report_meminfo(struct seq_file *m) atomic_long_read(&direct_pages_count[MMU_PAGE_1G]) << 20); } #endif /* CONFIG_PROC_FS */ + +pte_t ptep_modify_prot_start(struct vm_area_struct *vma, unsigned long addr, + pte_t *ptep) +{ + unsigned long pte_val; + + /* + * Clear the _PAGE_PRESENT so that no hardware parallel update is + * possible. Also keep the pte_present true so that we don't take + * wrong fault. + */ + pte_val = pte_update(vma->vm_mm, addr, ptep, _PAGE_PRESENT, _PAGE_INVALID, 0); + + return __pte(pte_val); + +} +EXPORT_SYMBOL(ptep_modify_prot_start); + +void ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr, + pte_t *ptep, pte_t old_pte, pte_t pte) +{ + if (radix_enabled()) + return radix__ptep_modify_prot_commit(vma, addr, + ptep, old_pte, pte); + set_pte_at(vma->vm_mm, addr, ptep, pte); +} +EXPORT_SYMBOL(ptep_modify_prot_commit); diff --git a/arch/powerpc/mm/pgtable-radix.c b/arch/powerpc/mm/pgtable-radix.c index 931156069a81..14938186df5b 100644 --- a/arch/powerpc/mm/pgtable-radix.c +++ b/arch/powerpc/mm/pgtable-radix.c @@ -1063,3 +1063,21 @@ void radix__ptep_set_access_flags(struct vm_area_struct *vma, pte_t *ptep, } /* See ptesync comment in radix__set_pte_at */ } + +void radix__ptep_modify_prot_commit(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, + pte_t old_pte, pte_t pte) +{ + struct mm_struct *mm = vma->vm_mm; + + /* + * To avoid NMMU hang while relaxing access we need to flush the tlb before + * we set the new value. We need to do this only for radix, because hash + * translation does flush when updating the linux pte. + */ + if (is_pte_rw_upgrade(pte_val(old_pte), pte_val(pte)) && + (atomic_read(&mm->context.copros) > 0)) + flush_tlb_page(vma, addr); + + set_pte_at(mm, addr, ptep, pte); +} From patchwork Wed Nov 28 14:34:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 10702777 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A69C517D5 for ; Wed, 28 Nov 2018 14:35:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9766D2CC97 for ; Wed, 28 Nov 2018 14:35:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B7B62CC99; Wed, 28 Nov 2018 14:35:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 170502CC97 for ; Wed, 28 Nov 2018 14:35:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 519406B4D74; Wed, 28 Nov 2018 09:35:19 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4A0CE6B4D75; Wed, 28 Nov 2018 09:35:19 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F5CC6B4D76; Wed, 28 Nov 2018 09:35:19 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by kanga.kvack.org (Postfix) with ESMTP id E1E876B4D74 for ; Wed, 28 Nov 2018 09:35:18 -0500 (EST) Received: by mail-pf1-f200.google.com with SMTP id t72so10097210pfi.21 for ; Wed, 28 Nov 2018 06:35:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:in-reply-to:references:mime-version :content-transfer-encoding:message-id; bh=0CHtk93zjxSBfH1sgMDcjD34yWO3RG5hYpBQIy+BXGY=; b=nk+KntJt9r3upZx5T5vQZKu7HRq/WdOLsg/xlpzpiW1828XkuNwF5ASY7N9tBY43G/ u3zzAV5eLWW7tVsHbHUf5yb6KyLJd+0L2lroMwE0CEmVJU2ybGdg+e8kUKc9UvGHNnVW +fqtAYy9p/bXIyLNmjbO49b3I/iNxHsmT06lqIOdeKlXk5DpG05Sbu1LjR9fdkZXmGu0 OSfRG2N+C+nw3kacY/0rwP17vx7aAXpDomE09k2HTcJQSQSCKtESoo1mVjGsXEz7lWFq 80XaxCslSF11xLpfAQxbPneO8VgeX+GEL7LD1o6mNjkXyLjN5rl0zDZlfxChojAjZ+vy fBGA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com X-Gm-Message-State: AA+aEWY7Ffwo6WJB84uVMTsXdTeOi+mykR+qz4M3xEkLx3xXDuPF99HE BiaeLm7imQdaB5agldV5sXLntUMwqN4QrvH1xv5+U2SPD7rZ8UZSizhk9M6sZUeAAlRdUShp4Lc 7zM0QBWQ7hb5TxW4mCFvl2SPg4oHafjjGQ3b4BXnBy8VThQL9yfhrhww0YG7RiX6dig== X-Received: by 2002:a62:34c6:: with SMTP id b189mr30657914pfa.229.1543415718542; Wed, 28 Nov 2018 06:35:18 -0800 (PST) X-Google-Smtp-Source: AFSGD/W+27cswDeRNIasUeLO4N5LAvdRDT/baWTo2ParHOT/gh3U+UMVsnV9NznzIUowf67syns9 X-Received: by 2002:a62:34c6:: with SMTP id b189mr30657867pfa.229.1543415717851; Wed, 28 Nov 2018 06:35:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543415717; cv=none; d=google.com; s=arc-20160816; b=e3lpOVNWcY+65BeKbz4egtt+55Rw6YQIIuFmQeWNrar80Vj3tEFlupYrUQHzK762aE Ruw8pMc3i8GedLyt2bK308Y4tZWVlpoGyVqOSq4OLB3jwJ/1T6TciPkHAEGuZNk+28y1 Q8A21kVDzoyKtD8rbdxzh5SKGg7WoiN28QNwhIO+E/UATP5Z778K8ucN/PvX4kJsswQV yBHJlqbcADc7X54xxecr1njGQodC/Q8tv9EhP7SCYVzT0klAzpwVztzo8IifkkUP/qxy EUsLnP/LKM3TUx/LIg302208P6nfnmXx7loaIO4OWQWwDzr0OhEfHTAf0sNQp+ojwvnd u6qQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:content-transfer-encoding:mime-version:references :in-reply-to:date:subject:cc:to:from; bh=0CHtk93zjxSBfH1sgMDcjD34yWO3RG5hYpBQIy+BXGY=; b=0kFxI5k+Rk5sYAJlBe5CZjbe0LE9srizPhCS41twWbYmronRExTUiGl4gNDBQpK3/n HlLpw3zaD140sw2mugRy80aZyWoLtPqsPplbr5AmJNJt16o5L5LIGo38q8edRZjdHUAR k+I5spErH77RQS+7XX/rexd1vN4si28GsNAseDYH6gM7xwmFwG5W3Ewm8+Doj8dOqlUU is1SiBclV+kq2rB5LYQmTpppoJtGG+MWh306c0xz78E9Kfo/+rqC5so4stvCEocvZolw IsWv02d99Rdnn0uT+D+ciEyRro9T7fbMqtO1smGzYLKC/R0b7nWrAkSyJ8PXwkV8G1uL KaPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com. [148.163.156.1]) by mx.google.com with ESMTPS id q64si7446000pga.280.2018.11.28.06.35.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Nov 2018 06:35:17 -0800 (PST) Received-SPF: pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) client-ip=148.163.156.1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wASEYIjF126475 for ; Wed, 28 Nov 2018 09:35:17 -0500 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0a-001b2d01.pphosted.com with ESMTP id 2p1t4qfsg3-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 28 Nov 2018 09:35:17 -0500 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 28 Nov 2018 14:35:16 -0000 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 28 Nov 2018 14:35:13 -0000 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wASEZCEA23462128 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 28 Nov 2018 14:35:12 GMT Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AD7376E056; Wed, 28 Nov 2018 14:35:12 +0000 (GMT) Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9D0EE6E054; Wed, 28 Nov 2018 14:35:09 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.85.87.253]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 28 Nov 2018 14:35:09 +0000 (GMT) From: "Aneesh Kumar K.V" To: akpm@linux-foundation.org, mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, "Aneesh Kumar K.V" Subject: [PATCH V2 4/5] mm/hugetlb: Add prot_modify_start/commit sequence for hugetlb update Date: Wed, 28 Nov 2018 20:04:37 +0530 X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181128143438.29458-1-aneesh.kumar@linux.ibm.com> References: <20181128143438.29458-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18112814-0016-0000-0000-0000095C37AF X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010137; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000270; SDB=6.01124008; UDB=6.00583546; IPR=6.00904137; MB=3.00024366; MTD=3.00000008; XFM=3.00000015; UTC=2018-11-28 14:35:15 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18112814-0017-0000-0000-000041381595 Message-Id: <20181128143438.29458-5-aneesh.kumar@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-28_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=981 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811280129 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: X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Aneesh Kumar K.V --- include/linux/hugetlb.h | 18 ++++++++++++++++++ mm/hugetlb.c | 8 +++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 087fd5f48c91..e2a3b0c854eb 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -543,6 +543,24 @@ static inline void set_huge_swap_pte_at(struct mm_struct *mm, unsigned long addr set_huge_pte_at(mm, addr, ptep, pte); } #endif + +#ifndef huge_ptep_modify_prot_start +static inline pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep) +{ + return huge_ptep_get_and_clear(vma->vm_mm, addr, ptep); +} +#endif + +#ifndef huge_ptep_modify_prot_commit +static inline void huge_ptep_modify_prot_commit(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, + pte_t old_pte, pte_t pte) +{ + set_huge_pte_at(vma->vm_mm, addr, ptep, pte); +} +#endif + #else /* CONFIG_HUGETLB_PAGE */ struct hstate {}; #define alloc_huge_page(v, a, r) NULL diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 7f2a28ab46d5..e5f5cda14f28 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4388,10 +4388,12 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma, continue; } if (!huge_pte_none(pte)) { - pte = huge_ptep_get_and_clear(mm, address, ptep); - pte = pte_mkhuge(huge_pte_modify(pte, newprot)); + pte_t old_pte; + + old_pte = huge_ptep_modify_prot_start(vma, address, ptep); + pte = pte_mkhuge(huge_pte_modify(old_pte, newprot)); pte = arch_make_huge_pte(pte, vma, NULL, 0); - set_huge_pte_at(mm, address, ptep, pte); + huge_ptep_modify_prot_commit(vma, address, ptep, old_pte, pte); pages++; } spin_unlock(ptl); From patchwork Wed Nov 28 14:34:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 10702779 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E37017D5 for ; Wed, 28 Nov 2018 14:35:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C6DD2BA49 for ; Wed, 28 Nov 2018 14:35:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 407E12CA44; Wed, 28 Nov 2018 14:35:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE84A2BA49 for ; Wed, 28 Nov 2018 14:35:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5167C6B4D77; Wed, 28 Nov 2018 09:35:26 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4A41B6B4D78; Wed, 28 Nov 2018 09:35:26 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F5D86B4D79; Wed, 28 Nov 2018 09:35:26 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id C19426B4D77 for ; Wed, 28 Nov 2018 09:35:25 -0500 (EST) Received: by mail-ed1-f70.google.com with SMTP id k58so12602074eda.20 for ; Wed, 28 Nov 2018 06:35:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:in-reply-to:references:mime-version :content-transfer-encoding:message-id; bh=+S8tKiP0FohuXyrbbEpzzlPlbCsW78x5v6nFajfoAQo=; b=NwmO0Svqd4u0mHVpQqhV3BcpEjD8n1a2qTcQaJt21h+bAQS469KGNX9wsAvbGbmM1G 3GJU0G5+eeMRKeX3RO0lRKrUKdlFDvo15W30HQsWtfse9T4OpJ1JI6wtR22lTwEZC+wn xMhKnnJ+2u9N+9yPuOazQu6esAzTykVUn7B4Ct1mBbLmCtiCTUIp80kO0RwlE/P1KgDM kUizqmZlm3bMzErS6n3ybMAaEwkfh9W1ThhD/7LKQGQfHIHxFRD+St+W44HtTex5hIho 0iO9YJMtQ6YtSxUcPj1/+RXln/+MXT3XzHlgUqYA4bGzonQ/YM5ucIozWkyJfgwTWlG/ NkZA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com X-Gm-Message-State: AA+aEWYEvBq7ScPAM7tO3tUXZa6zag5Frv+a6Woz19EfPm3A9XZmg0zt eC5IOtmCSaaPDpf6uOOVOVg61zOFEsDe93YDrwJ9EusTjNWpeDgKSLMCmqR1eYmrSuaNIx0bH1g kX2Vc6yV0kEdVplMrJZD7DlEqWoVUUXaqpOwWarmf9RdK175BvG0yS4VJTIt7BX875Q== X-Received: by 2002:a50:a726:: with SMTP id h35mr13315602edc.192.1543415725296; Wed, 28 Nov 2018 06:35:25 -0800 (PST) X-Google-Smtp-Source: AFSGD/Va6jK9dQ9N4SzwW/WTF2MaysKHPM68GPOE5ijHoF1yeGXNHq12f+aFVZ+hu09RRi8hIfi7 X-Received: by 2002:a50:a726:: with SMTP id h35mr13315530edc.192.1543415724345; Wed, 28 Nov 2018 06:35:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543415724; cv=none; d=google.com; s=arc-20160816; b=px0yFu2YsjRrrJ5ajnssX7/EaVAr9P7MDp+b9BbSFSh5+LuQKbuaAWtBrpNkCFF1pa pXrnxb4WC3vtzWU9wySIykxIWN5g/RwfKMkAu12EMewqV57nx57ISJvCCkfwKN2V90zq dUc+lWu6WYPzcfjtQrKLBza0+o3O+WKXggUth1urXM3hWNkj7ookm9ATwOZxrNo2jqlj nc/rDIv0xFRA3nWzdz0zLXdKLq2ZYoqb1GdbFDJeNtcYF6CB1V79iJ6GmouF0cLrZXbL jJRj1Wr629V0LWJkEDBzhoHvM5MaiHh3EexrQ9BdqTryah1Lh2vDMlFNh7xHOSooBdEi NPCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:content-transfer-encoding:mime-version:references :in-reply-to:date:subject:cc:to:from; bh=+S8tKiP0FohuXyrbbEpzzlPlbCsW78x5v6nFajfoAQo=; b=0S1XHi7wwWHB4f/PccO0sJ0BKOik9LYd/0J0OmVPvv4fWcSfnkpPX6Z4upu0nChCpA hCap74SPpTFXVgC8wV4cEcqBHq6Yx9pszTis8zHkgqWqwRcnjxsrqZx9AYLQUXEqP9Ct OD7M4DvlfLphMIbtIkixonnrI5TNsoTzgTYqDMOfVVYG0dXMxfNHyYZDJEybzO0wXmF5 42EDMeUrjtnPR8JlIWN5av+i82dYvL0DWa6TNZOMVUEZ8OIjJB1v1TZGUkY4fHaFvIwR ywL+fs197K/VMrg24Fs6xVQ/YoOP49963T3OslMZbI+rioRWmEid4Cq7CGlxNGOQil73 Av1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com. [148.163.158.5]) by mx.google.com with ESMTPS id j6-v6si1158524ejf.66.2018.11.28.06.35.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Nov 2018 06:35:24 -0800 (PST) Received-SPF: pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) client-ip=148.163.158.5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wASEYNRw001195 for ; Wed, 28 Nov 2018 09:35:22 -0500 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0b-001b2d01.pphosted.com with ESMTP id 2p1v1qarkd-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 28 Nov 2018 09:35:22 -0500 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 28 Nov 2018 14:35:21 -0000 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 28 Nov 2018 14:35:18 -0000 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wASEZHNg20512924 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 28 Nov 2018 14:35:17 GMT Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1BC656E058; Wed, 28 Nov 2018 14:35:17 +0000 (GMT) Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 552996E053; Wed, 28 Nov 2018 14:35:14 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.85.87.253]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 28 Nov 2018 14:35:13 +0000 (GMT) From: "Aneesh Kumar K.V" To: akpm@linux-foundation.org, mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, "Aneesh Kumar K.V" Subject: [PATCH V2 5/5] arch/powerpc/mm/hugetlb: NestMMU workaround for hugetlb mprotect RW upgrade Date: Wed, 28 Nov 2018 20:04:38 +0530 X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181128143438.29458-1-aneesh.kumar@linux.ibm.com> References: <20181128143438.29458-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18112814-8235-0000-0000-00000E2FC527 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010137; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000270; SDB=6.01124008; UDB=6.00583546; IPR=6.00904138; MB=3.00024366; MTD=3.00000008; XFM=3.00000015; UTC=2018-11-28 14:35:19 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18112814-8236-0000-0000-000043843E47 Message-Id: <20181128143438.29458-6-aneesh.kumar@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-28_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=583 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811280129 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: X-Virus-Scanned: ClamAV using ClamSMTP NestMMU requires us to mark the pte invalid and flush the tlb when we do a RW upgrade of pte. We fixed a variant of this in the fault path in commit Fixes: bd5050e38aec ("powerpc/mm/radix: Change pte relax sequence to handle nest MMU hang") Signed-off-by: Aneesh Kumar K.V --- arch/powerpc/include/asm/book3s/64/hugetlb.h | 12 ++++++++ arch/powerpc/mm/hugetlbpage-radix.c | 17 ++++++++++++ arch/powerpc/mm/hugetlbpage.c | 29 ++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/arch/powerpc/include/asm/book3s/64/hugetlb.h b/arch/powerpc/include/asm/book3s/64/hugetlb.h index 5b0177733994..66c1e4f88d65 100644 --- a/arch/powerpc/include/asm/book3s/64/hugetlb.h +++ b/arch/powerpc/include/asm/book3s/64/hugetlb.h @@ -13,6 +13,10 @@ radix__hugetlb_get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags); +extern void radix__huge_ptep_modify_prot_commit(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, + pte_t old_pte, pte_t pte); + static inline int hstate_get_psize(struct hstate *hstate) { unsigned long shift; @@ -42,4 +46,12 @@ static inline bool gigantic_page_supported(void) /* hugepd entry valid bit */ #define HUGEPD_VAL_BITS (0x8000000000000000UL) +#define huge_ptep_modify_prot_start huge_ptep_modify_prot_start +extern pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep); + +#define huge_ptep_modify_prot_commit huge_ptep_modify_prot_commit +extern void huge_ptep_modify_prot_commit(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, + pte_t old_pte, pte_t new_pte); #endif diff --git a/arch/powerpc/mm/hugetlbpage-radix.c b/arch/powerpc/mm/hugetlbpage-radix.c index 2486bee0f93e..1f77d71e7708 100644 --- a/arch/powerpc/mm/hugetlbpage-radix.c +++ b/arch/powerpc/mm/hugetlbpage-radix.c @@ -90,3 +90,20 @@ radix__hugetlb_get_unmapped_area(struct file *file, unsigned long addr, return vm_unmapped_area(&info); } + +void radix__huge_ptep_modify_prot_commit(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, + pte_t old_pte, pte_t pte) +{ + struct mm_struct *mm = vma->vm_mm; + + /* + * To avoid NMMU hang while relaxing access we need to flush the tlb before + * we set the new value. + */ + if (is_pte_rw_upgrade(pte_val(old_pte), pte_val(pte)) && + (atomic_read(&mm->context.copros) > 0)) + flush_hugetlb_page(vma, addr); + + set_huge_pte_at(vma->vm_mm, addr, ptep, pte); +} diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c index 8cf035e68378..39d33a3d0dc6 100644 --- a/arch/powerpc/mm/hugetlbpage.c +++ b/arch/powerpc/mm/hugetlbpage.c @@ -912,3 +912,32 @@ int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr, return 1; } + +#ifdef CONFIG_PPC_BOOK3S_64 +pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep) +{ + unsigned long pte_val; + /* + * Clear the _PAGE_PRESENT so that no hardware parallel update is + * possible. Also keep the pte_present true so that we don't take + * wrong fault. + */ + pte_val = pte_update(vma->vm_mm, addr, ptep, + _PAGE_PRESENT, _PAGE_INVALID, 1); + + return __pte(pte_val); +} +EXPORT_SYMBOL(huge_ptep_modify_prot_start); + +void huge_ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr, + pte_t *ptep, pte_t old_pte, pte_t pte) +{ + + if (radix_enabled()) + return radix__huge_ptep_modify_prot_commit(vma, addr, ptep, + old_pte, pte); + set_huge_pte_at(vma->vm_mm, addr, ptep, pte); +} +EXPORT_SYMBOL(huge_ptep_modify_prot_commit); +#endif