From patchwork Thu Oct 11 03:52:45 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: 10635685 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 584EB16B1 for ; Thu, 11 Oct 2018 03:53:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E210289D1 for ; Thu, 11 Oct 2018 03:53:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3258028AEC; Thu, 11 Oct 2018 03:53:33 +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 A4CCE289D1 for ; Thu, 11 Oct 2018 03:53:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CC036B000D; Wed, 10 Oct 2018 23:53:31 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 69F716B000E; Wed, 10 Oct 2018 23:53:31 -0400 (EDT) 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 568866B0010; Wed, 10 Oct 2018 23:53:31 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by kanga.kvack.org (Postfix) with ESMTP id 29AC26B000D for ; Wed, 10 Oct 2018 23:53:31 -0400 (EDT) Received: by mail-oi1-f200.google.com with SMTP id b202-v6so5067409oii.23 for ; Wed, 10 Oct 2018 20:53:31 -0700 (PDT) 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:message-id; bh=erpUhTjrlOHe8YWeZ/WIaSisNtCNGo4aCs0IlsOK7WY=; b=fVAbxK6eWMCgKAxkz0itH1uSPBSFjVhWYA6yf3agga5ZtcKK0TQAOtGtfH4wIRNFfK rejM7zUzCi+UhhB5su9gwZuQZMtaS3lG1KocQvHCFZhUcaswkV2j0eI6SO3UXx5n/kHa iVCXG+HRSvL5c86g3+VTQj52s+w2j8f+2c4X6YSd9+BHepjW0ngbx03JBnwXwd52ir6x KZSh4OkOFiGn9LCAsm0La+qpYmmG84ucAJo/WApLtzEN+jzvIaTnb0zg2mHrfkEflpDE qOpemWhRjLahNgoRlOkrjzQC6MKvHYKkbTDoYV6MAmrWAOitRWQU5b5hCbfEFkQf0gDW myPQ== 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: ABuFfohlfQ5CswYQG0R4QzoCiWL+fGnbentugsQ+VrzDa88C5goewp+M kyYW0j88HO4mVKnp3mVxxcfKJRPJocwEhUG+DhPQCGhssz8DQX9NKL7xMEhEmkCs9P6Dv4SFqXK iuQu7+yC/V2uQehNEs28FVt8Tzqjut20H/Ulejbv6ZwWH5owbQwhV2y1lN58xjdTMZw== X-Received: by 2002:a9d:5b66:: with SMTP id e35mr22338372otj.206.1539230010856; Wed, 10 Oct 2018 20:53:30 -0700 (PDT) X-Google-Smtp-Source: ACcGV614/wUS5PrBM0lblxKiOav2hY9dKxgV7zlyRctLVntN5xrZQ4rIeU+QfJTuoCvBjaohbHvX X-Received: by 2002:a9d:5b66:: with SMTP id e35mr22338356otj.206.1539230010128; Wed, 10 Oct 2018 20:53:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539230010; cv=none; d=google.com; s=arc-20160816; b=GWyya5deMWBHNmh1qvWgtEe0PVPEgsUcAP7xL0MGqVFEc/leJfZw+V7ZYw3VtcxTLP 1eKNJ50E+OM1nEL6pjGJE0I6yuGqFPCanmMEWay9JYoL4NuCnU4CaeApo7a6+KslgVCu eI/CPPGfaUJXVnt2mq95i41fsIv79JuTUDFdZRYWi4FFvBf1KGSp5npH1/ByOD4WO3h0 gQD0eCVvj/cmlKdI3PGVNxo2FVIRZWN/A3Qe2nJRBmXnyRMTv8fb4v/HC3/80oBt7SBh cdD7S5VJsz1qPegnBlIU2gx+F4dl9G5GW4AR4VZSeN17bRpPoz+6I0e36RbVMJP7fw1j aKhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:references:in-reply-to:date:subject:cc:to:from; bh=erpUhTjrlOHe8YWeZ/WIaSisNtCNGo4aCs0IlsOK7WY=; b=PUw0MyUv1qxrGbB4KfoLH+uKSf1VpKLOexqqIA7qwhcbDG+ypT+Mv+Q0Uibd5NBP4l IaY6OREl/ulTP81gNxtUDH92k8ZONZb0GPkiPm3tQnZnPD8FmzK624K+A3H8VYyNmWHi kUfKDRoWnMzlo3xk8npQkYajhwU4K/kHqz5DgSI4SobfktWHVJBxskFPRfdZuaNdB/tY 8fIrnmJfpNmV2FYD6BTNMsUWoz0HFDaPQtCp2AuMykQ1/Vj6SAnjHRl7z2WFnPLccc0z DMTxa+GUXcBW/QBdf7r9LYzELNh9wXF26JJYy54dJTdJ9Y2INRTJatIAe5qmf7SFa2VP fkeQ== 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 s14si12780997ote.50.2018.10.10.20.53.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Oct 2018 20:53:30 -0700 (PDT) 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 (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w9B3mt8v118932 for ; Wed, 10 Oct 2018 23:53:29 -0400 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0a-001b2d01.pphosted.com with ESMTP id 2n1tdg18nt-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 10 Oct 2018 23:53:29 -0400 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 10 Oct 2018 21:53:28 -0600 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) 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, 10 Oct 2018 21:53:24 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w9B3rN9a50659548 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 10 Oct 2018 20:53:23 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 983367806A; Wed, 10 Oct 2018 21:53:23 -0600 (MDT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 40C9578066; Wed, 10 Oct 2018 21:53:21 -0600 (MDT) Received: from skywalker.ibmuc.com (unknown [9.85.73.187]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 10 Oct 2018 21:53:20 -0600 (MDT) From: "Aneesh Kumar K.V" To: akpm@linux-foundation.org, mpe@ellerman.id.au, benh@kernel.crashing.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, "Aneesh Kumar K.V" Subject: [PATCH 3/5] arch/powerpc/mm: Nest MMU workaround for mprotect/autonuma RW upgrade. Date: Thu, 11 Oct 2018 09:22:45 +0530 X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181011035247.30687-1-aneesh.kumar@linux.ibm.com> References: <20181011035247.30687-1-aneesh.kumar@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18101103-0012-0000-0000-000016C609D0 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009857; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000268; SDB=6.01100919; UDB=6.00569641; IPR=6.00880964; MB=3.00023702; MTD=3.00000008; XFM=3.00000015; UTC=2018-10-11 03:53:27 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18101103-0013-0000-0000-000054B62FB5 Message-Id: <20181011035247.30687-4-aneesh.kumar@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-10-11_01:,, 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=837 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810110036 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 and autonuma 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/mm/pgtable-book3s64.c | 34 ++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h index f108e2ce7f64..c55468eaedc7 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h @@ -1324,6 +1324,24 @@ static inline const 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 Read or Write upgrade of pte. + */ +static inline bool is_pte_upgrade(unsigned long old_val, unsigned long new_val) +{ + if ((!(old_val & _PAGE_READ)) && (new_val & _PAGE_READ)) + return true; + + 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/mm/pgtable-book3s64.c b/arch/powerpc/mm/pgtable-book3s64.c index 43e99e1d947b..43f71125249b 100644 --- a/arch/powerpc/mm/pgtable-book3s64.c +++ b/arch/powerpc/mm/pgtable-book3s64.c @@ -481,3 +481,37 @@ 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) +{ + 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_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); +} +EXPORT_SYMBOL(ptep_modify_prot_commit);