From patchwork Thu Oct 11 03:52:47 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: 10635689 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 3E75F16B1 for ; Thu, 11 Oct 2018 03:53:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 249A9289D1 for ; Thu, 11 Oct 2018 03:53:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1831A28AEC; Thu, 11 Oct 2018 03:53:41 +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 87E49289D1 for ; Thu, 11 Oct 2018 03:53:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1246A6B0266; Wed, 10 Oct 2018 23:53:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0D2DA6B026A; Wed, 10 Oct 2018 23:53:39 -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 EDE316B026B; Wed, 10 Oct 2018 23:53:38 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) by kanga.kvack.org (Postfix) with ESMTP id C1C716B0266 for ; Wed, 10 Oct 2018 23:53:38 -0400 (EDT) Received: by mail-ot1-f71.google.com with SMTP id f95so5343183otb.19 for ; Wed, 10 Oct 2018 20:53:38 -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=UojY1cP+L+xFR6PxNBp2ZjUl6WQPxA+nR9Ke97N5LoA=; b=IDCtokZ9a1Ipk9zEZOoGZydXLY54S0pGavFyrIBfpyyBaEMj9H7yS6BbhZetRkztaH IwncXGQGFTKvUcbTVzHswLl9hRskBcG6qdX0MiSlG1MUqgwmuSoNvC+177GV6xDCZ4Td 2wYd0tT3mWrq0lCicIEFeTG21BwF8B3fDr1nvl/pEX/eZcmjD0RsgLpe2TE0cAVqBJnY gkQvB1Lpy1ndgcq7Z6FsI6rDMeJodMHR7p92nrPAcuN5F2+wxEuo2JR+Ww96JxBZ1tJz f8Xgx+JKg/BkeHEPmgYGL2lqva3Wp6QYW9FMic2r16pjoVUlkN+yKSvb2G6auEIuqz4J fJ7A== 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: ABuFfohv31QNNiCDeTfAvgJFwByDOUPZ1RoHtXo0qNqyiwvK/7FhMJGz YC4PxRVMs+aoZYYG9uyVD9nvaSNVzKLlhr3Ju3DWN5XQnOf0pVBLy7yrpOphxK8WPumvXSHqy4W 9yyvTueODE7mPc8QtQkVV4L+myIBP1wPa4U2sZfWIOuqglM1+MBcCHatuYM6tRcr2Kw== X-Received: by 2002:a9d:2a44:: with SMTP id t62mr20763848ota.321.1539230018515; Wed, 10 Oct 2018 20:53:38 -0700 (PDT) X-Google-Smtp-Source: ACcGV603TyJA5PiAMB96WYlTLrYfUMYvH0W9N8rPdCk0U9TXpzEeN9Bt/M7r09l1lXte1HCm7N9d X-Received: by 2002:a9d:2a44:: with SMTP id t62mr20763830ota.321.1539230017740; Wed, 10 Oct 2018 20:53:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539230017; cv=none; d=google.com; s=arc-20160816; b=RuI2Y+101+FRz473VrSpxEcKBbVcpnU21lpA6bx17DfpMFIgYJbf/KHH0W7V9sajUL Rv9k2UP9YVWss0lvXrD8q9BTeey8mYiCSwl0TBVw/kw/HYVYRV+TEb1UPFWa1k9lSlUJ EpzcWJr0OrdqDzlI7eZFitvrvEqaedOkZn7Yfb6QEpXtGQU7Z2xvFtYiorALZETuXV8j wGIQYL6kpyT5cDBxBFb1sdQ1xTwz+wNEacC6jv8ryxofQmkqlqiVBf7vOAoq4Zk55PWi q+ZbOw4WqpcKnKjBuiEG2ITqN0y8kx4Mv/K7m3x4/dNS7kWv3rFkL1ZBgpxmZP5stMtJ 0Gdw== 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=UojY1cP+L+xFR6PxNBp2ZjUl6WQPxA+nR9Ke97N5LoA=; b=K20DpY/IU382hwjOFSv8Wr2qM3dW33lh8+3ySg/Qnm+CTVgrN6A8e8TsfPNlmz6Unv MNxpkJH1f4vncNEFqE3iClDisufY9taHLsJ+MAL2XgDZP3Q03n80yTelfz/R0EWF/faD 1IO8IxQPrYXYTmDlm0cEbP/WJjkT7Okl3/fe7s5yCimdrdedqMbbFVdKs4CN2G4d/J7b y2G5LdcLEnMvh9kcH+mBz7hK0PWrPXAK8PinFi63BU4DdFhuuOFa0xpiorfSZDyXdWqs bL41q07BrpXyYpmDL9Kp/Sd3BKqDUrc6gzNI/WFKs5LaIeCahcgNjzcO/LuVTE608hl/ hM2A== 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 s3si5177643oth.284.2018.10.10.20.53.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Oct 2018 20:53:37 -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 (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w9B3mweo011721 for ; Wed, 10 Oct 2018 23:53:37 -0400 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0a-001b2d01.pphosted.com with ESMTP id 2n1xxmg465-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 10 Oct 2018 23:53:36 -0400 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 10 Oct 2018 21:53:36 -0600 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) 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, 10 Oct 2018 21:53:32 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w9B3rV611900912 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 10 Oct 2018 20:53:31 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9285C7805C; Wed, 10 Oct 2018 21:53:31 -0600 (MDT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2BC6A7806A; Wed, 10 Oct 2018 21:53:29 -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:28 -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 5/5] arch/powerpc/mm/hugetlb: NestMMU workaround for hugetlb mprotect RW upgrade Date: Thu, 11 Oct 2018 09:22:47 +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-0020-0000-0000-00000E76A6E8 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:34 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18101103-0021-0000-0000-00006354F454 Message-Id: <20181011035247.30687-6-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=536 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") Signed-off-by: Aneesh Kumar K.V --- arch/powerpc/include/asm/book3s/64/hugetlb.h | 8 +++++ arch/powerpc/include/asm/hugetlb.h | 2 +- arch/powerpc/mm/hugetlbpage.c | 35 ++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/include/asm/book3s/64/hugetlb.h b/arch/powerpc/include/asm/book3s/64/hugetlb.h index 5b0177733994..a12bde29a5f0 100644 --- a/arch/powerpc/include/asm/book3s/64/hugetlb.h +++ b/arch/powerpc/include/asm/book3s/64/hugetlb.h @@ -42,4 +42,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/include/asm/hugetlb.h b/arch/powerpc/include/asm/hugetlb.h index 2d00cc530083..60c1d37e446a 100644 --- a/arch/powerpc/include/asm/hugetlb.h +++ b/arch/powerpc/include/asm/hugetlb.h @@ -4,7 +4,6 @@ #ifdef CONFIG_HUGETLB_PAGE #include -#include extern struct kmem_cache *hugepte_cache; @@ -176,6 +175,7 @@ static inline void arch_clear_hugepage_flags(struct page *page) { } +#include #else /* ! CONFIG_HUGETLB_PAGE */ static inline void flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr) diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c index a7226ed9cae6..8b098bedaff5 100644 --- a/arch/powerpc/mm/hugetlbpage.c +++ b/arch/powerpc/mm/hugetlbpage.c @@ -913,3 +913,38 @@ 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) +{ + 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_hugetlb_page(vma, addr); + + set_huge_pte_at(vma->vm_mm, addr, ptep, pte); +} +EXPORT_SYMBOL(huge_ptep_modify_prot_commit); +#endif