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