From patchwork Wed Jan 16 08:50:35 2019 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: 10765529 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 9CBBD13B5 for ; Wed, 16 Jan 2019 08:51:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C4CC2D46B for ; Wed, 16 Jan 2019 08:51:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F4272D44A; Wed, 16 Jan 2019 08:51:27 +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 E677E2D46B for ; Wed, 16 Jan 2019 08:51:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E57878E0008; Wed, 16 Jan 2019 03:51:24 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E055D8E0002; Wed, 16 Jan 2019 03:51:24 -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 CCE0E8E0008; Wed, 16 Jan 2019 03:51:24 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id 8EA9F8E0002 for ; Wed, 16 Jan 2019 03:51:24 -0500 (EST) Received: by mail-pf1-f197.google.com with SMTP id 74so4141013pfk.12 for ; Wed, 16 Jan 2019 00:51:24 -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=xgU05ra4xRm4loD62apxjh4pH3L+B4iDXCDdAfMly1I=; b=hD8TI8F6vzZeyxYFmWBux6GUReJA2C6uHPuSKMFlDkh7ZM8os0oG9GsF0uMCm02M7M 4wOcghsObbwaTidkBazc8zFmrURPDt56aYwFBmPe+ErO1wH7RxjIgK0/kUeqNyXmY9bj Yr98ZItuvvof91GPC3PmNvFlzEJc5KaWvkTg7tR7YKX2bq4+02cS30iXGyWKZn4+TmHZ Z9iKaI4PF0rLtoNPClF9iTgszKZqsc+OmJfpUpeAYsV5drtRBtrSrZoN9Hxrp9Pdm98+ cAh+oyDOXH3RpIsgL1NDCRsY3VLQ8nlRjMwPKbuXrPcpKFBYR2H/XYaMn6Lt8xDssB2L 7SXg== 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: AJcUukduFQEn/9H81IB+nyImjAFw1/4XMVcLzl156lpcVC31g4B79ea6 iLouT1ioBNRzPkDSlfYqgfgfZdi/NYi/RkdFBeSo0+hX7LrT3DWO1vNLPBOoCLC0TOBT9+93Cal NWpBTC/K8Y9kRjd74Yo17XTypoM7VC9TmmIZPl2X6O6gLPQBo0TymD37cxhLCVuWPeg== X-Received: by 2002:a62:5884:: with SMTP id m126mr8608934pfb.177.1547628684239; Wed, 16 Jan 2019 00:51:24 -0800 (PST) X-Google-Smtp-Source: ALg8bN47sY+nHaP9FtwDROIxe0RBdi6N+DrdUBRj8O62EHlBw3CfYqeAQTX6QDC8pWhnMlzeOwn0 X-Received: by 2002:a62:5884:: with SMTP id m126mr8608886pfb.177.1547628683369; Wed, 16 Jan 2019 00:51:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547628683; cv=none; d=google.com; s=arc-20160816; b=gr7Dg9tR1b6HwAjDS22gyMbDzILr6Ub1ntGo1Xlwhp8TP39SeKnf8vroCroiLXKyC/ wOHaudtzExe9l/BJ78F18Em4YMNaKVOu0G61nkuaXjS0qMnb/YTGWeU7cDVJkz9W99oI yhDaAfyp4UKAJkHWacuvEKceoGMchyQmsmG4A0oLygE/kPD5SjdaZr8LMtgm1lDHYT4c m8tog50yPvNNXe8Z6DSwK26ASiXU8ie5IB/bzfHSipUgLfCMnyCJzzz03u/n5ncM6m38 qMGYlp8MUFXlxaQVhY3aa12472USeo/cAqQsmxQaG1IZZINldMRQaT46+o0166kJsK90 80rw== 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=xgU05ra4xRm4loD62apxjh4pH3L+B4iDXCDdAfMly1I=; b=ztblZg2JMHU78Id8MLDwqIKgtMLiajaXIEfD4x0Ah8FASB9FLJlPGGFB93OogSbByc 8BkUtynysZapMkTdxDKzRhiIXcjWHnF2W3pDz9BlqNOPj9lvKAQO3NO3N20C/PA2dnHw aBmjjyjW13fC9S9LbIdJ/IIsF66uCJzx6Lk1bh/paVTv7/+MJ5W3+vv+jRQY3oj9wk/V L3K8eRRoqmmTamKc0aFD3DXuWIwCY/AA+x7z344Sry6TEdNPPFOLwVH43QkwHqgtRDbo T8yC8pjlgmYJ3RKBmfSgGcAH/tNnbTpm9jB9bwRMly9+Sj5Pcpy5+e+O/1qPHy2CxwZu 7I3A== 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 h96si6039863plb.230.2019.01.16.00.51.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jan 2019 00:51:23 -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 (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id x0G8mn7Q078089 for ; Wed, 16 Jan 2019 03:51:22 -0500 Received: from e11.ny.us.ibm.com (e11.ny.us.ibm.com [129.33.205.201]) by mx0a-001b2d01.pphosted.com with ESMTP id 2q1xdcs3ba-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 16 Jan 2019 03:51:22 -0500 Received: from localhost by e11.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 16 Jan 2019 08:51:21 -0000 Received: from b01cxnp23034.gho.pok.ibm.com (9.57.198.29) by e11.ny.us.ibm.com (146.89.104.198) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 16 Jan 2019 08:51:17 -0000 Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x0G8pGBH21299290 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 16 Jan 2019 08:51:16 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8014E12405C; Wed, 16 Jan 2019 08:51:16 +0000 (GMT) Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4538F124052; Wed, 16 Jan 2019 08:51:14 +0000 (GMT) Received: from skywalker.in.ibm.com (unknown [9.124.31.92]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 16 Jan 2019 08:51:14 +0000 (GMT) From: "Aneesh Kumar K.V" To: npiggin@gmail.com, benh@kernel.crashing.org, paulus@samba.org, mpe@ellerman.id.au, akpm@linux-foundation.org, x86@kernel.org Cc: linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, "Aneesh Kumar K.V" Subject: [PATCH V5 5/5] arch/powerpc/mm/hugetlb: NestMMU workaround for hugetlb mprotect RW upgrade Date: Wed, 16 Jan 2019 14:20:35 +0530 X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190116085035.29729-1-aneesh.kumar@linux.ibm.com> References: <20190116085035.29729-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 19011608-2213-0000-0000-0000033E30AA X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010416; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000274; SDB=6.01147213; UDB=6.00597570; IPR=6.00927509; MB=3.00025150; MTD=3.00000008; XFM=3.00000015; UTC=2019-01-16 08:51:20 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19011608-2214-0000-0000-00005CFD9593 Message-Id: <20190116085035.29729-6-aneesh.kumar@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-01-16_04:,, 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=503 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901160075 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 Reviewed-by: Michael Ellerman --- arch/powerpc/include/asm/book3s/64/hugetlb.h | 12 ++++++++++ arch/powerpc/mm/hugetlbpage-hash64.c | 25 ++++++++++++++++++++ arch/powerpc/mm/hugetlbpage-radix.c | 17 +++++++++++++ 3 files changed, 54 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-hash64.c b/arch/powerpc/mm/hugetlbpage-hash64.c index 2e6a8f9345d3..367ce3a4a503 100644 --- a/arch/powerpc/mm/hugetlbpage-hash64.c +++ b/arch/powerpc/mm/hugetlbpage-hash64.c @@ -121,3 +121,28 @@ int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid, *ptep = __pte(new_pte & ~H_PAGE_BUSY); return 0; } + +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); +} + +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); +} diff --git a/arch/powerpc/mm/hugetlbpage-radix.c b/arch/powerpc/mm/hugetlbpage-radix.c index 2486bee0f93e..11d9ea28a816 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)) + radix__flush_hugetlb_page(vma, addr); + + set_huge_pte_at(vma->vm_mm, addr, ptep, pte); +}