From patchwork Wed Dec 19 03:40: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: 10736749 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 247A913B5 for ; Wed, 19 Dec 2018 03:41:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 144A62B250 for ; Wed, 19 Dec 2018 03:41:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 089CD2B254; Wed, 19 Dec 2018 03:41: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 88B922B250 for ; Wed, 19 Dec 2018 03:41:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A38938E000E; Tue, 18 Dec 2018 22:41:20 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9E78C8E0001; Tue, 18 Dec 2018 22:41:20 -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 8B0308E000E; Tue, 18 Dec 2018 22:41:20 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id 4AF118E0001 for ; Tue, 18 Dec 2018 22:41:20 -0500 (EST) Received: by mail-pl1-f200.google.com with SMTP id b24so13566301pls.11 for ; Tue, 18 Dec 2018 19:41:20 -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=7xyo4vCoOybUS2MnbDGpne2N6gyF4Htl7wmMPJPOt5g=; b=eVnQvFe/FVFqw3a/ExY2Ei996Cj4r4/S89oZwPl8bLoqtFx1k/9cv/An/gppbykmJ7 nfd9vLD10QDixBCKW8nG8Ijpky0aelYkEy8uUL+rB/iQhbvGB4eu74l3COr1bLV9busR snW+A3/ClFeCU9TWVL86XcxfPy0707R1k36Qkr72/ByfXxeWJcmu2PY4ZULrLfJAmGFh HslAfhI9DoLaiDSPXOVap963OErBbFexPQ5PwmrIbFjH763wB2l5EyPDGiFafI59OzdJ dr4iz/2vvx3NW77DOlWMhQqozNtyoIO2l14K3PAeZEoPhg0s+l8o1DWNsnrhvGiaF0cQ wUlQ== 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+aEWboTxw3/AA0UlI0H3boIsFlLWJs85xPUIAZohTTzKytjcZvaHtB r7zndvwB1sNs/kr+abbH5Q668zIbOvLqq4QulNCx1TGP0VpyPh/Lsdz5se24xIBmJQ41Lvok8lW Qlw3WnUq1m6Ov3ydCf+2Mg6qwS3fHYCevxATNOYLNUDjufmuUL6Acf1crN3BS8BHvjw== X-Received: by 2002:a17:902:7896:: with SMTP id q22mr19085809pll.280.1545190879984; Tue, 18 Dec 2018 19:41:19 -0800 (PST) X-Google-Smtp-Source: AFSGD/VXd6nEOogJCRLKlDoEHT9V1egvYqxRIvvhhVKQpvQAfuykr0Fx4SHZycUc0xZsgZr6tcz8 X-Received: by 2002:a17:902:7896:: with SMTP id q22mr19085791pll.280.1545190879235; Tue, 18 Dec 2018 19:41:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545190879; cv=none; d=google.com; s=arc-20160816; b=JqDCBUTz5XuckS/bs7E47qnJLL4S+xhl1OwIVFWP1i+gGRVvl8rqjd28m6vXbB6qms oaSw2FLunvWk7Aj+dpreuCD3Ux4PyZT3dXltAx2WR8eAk15CU+ZdRjcXzM7BZnqsInYG uU/79qDo2lPe06LLg4xFlmQeuSrvvAfplWQ7i0RtlVav4Ic8vnMLcNZeNO+VSKdzdr2M kfmMLFmWEpUraQGjc03oX+LIilI288zwitvAlpFFZo8ShSL6LFJjVueCQRaINVE8Zug7 UYAk18LmwciEMxNg4a5wytrDQzhQK39LlPBBKo/RaAJJmq2XO/yaIXXZYXR9oTE4hOsC y97Q== 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=7xyo4vCoOybUS2MnbDGpne2N6gyF4Htl7wmMPJPOt5g=; b=q+qI+xgJKqf3YutrE5BITRbJQ+kR5w3H/qAa3wuMPK030KAFU+43YSEPaHmhoaYOTV bWyt0dvSNMHyPCMU0JbO8LpIT8whGpt8qmO/gB76LeljeqR4gv12nt7GJwK4h/8VG+5m 2cuznsMFyDqLhKxHwjx+hGH2DUJ87K1YKeC8dp88Yk2crYbs8PNMWaJtFj2UozyhqeyM T9EMkrVqYzpZdWk35MJHct8ALDUHosIUNto398S8t7U9R/LQoDNsgC2qPEBHxki6a+Ko zBzgSwceVbwLUwK2lHiVC71nhhf72aef3DfiGd+57U8Ek+xEvu7Tq8RKAff2P/Hd9zwD dPjQ== 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 q5si14807989pgg.204.2018.12.18.19.41.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Dec 2018 19:41:19 -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 wBJ3dSNv050626 for ; Tue, 18 Dec 2018 22:41:18 -0500 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0a-001b2d01.pphosted.com with ESMTP id 2pf988awga-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 18 Dec 2018 22:41:18 -0500 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 19 Dec 2018 03:41:17 -0000 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 19 Dec 2018 03:41:14 -0000 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 wBJ3fD4q26017958 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 19 Dec 2018 03:41:13 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 105267805F; Wed, 19 Dec 2018 03:41:13 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 50D357805E; Wed, 19 Dec 2018 03:41:09 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.85.71.103]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 19 Dec 2018 03:41:09 +0000 (GMT) From: "Aneesh Kumar K.V" To: akpm@linux-foundation.org, Michal Hocko , Alexey Kardashevskiy , mpe@ellerman.id.au, paulus@samba.org, David Gibson Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, "Aneesh Kumar K.V" Subject: [PATCH V5 3/3] powerpc/mm/iommu: Allow large IOMMU page size only for hugetlb backing Date: Wed, 19 Dec 2018 09:10:47 +0530 X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181219034047.16305-1-aneesh.kumar@linux.ibm.com> References: <20181219034047.16305-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18121903-0004-0000-0000-000014C46FB2 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010246; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000271; SDB=6.01133803; UDB=6.00589449; IPR=6.00913978; MB=3.00024741; MTD=3.00000008; XFM=3.00000015; UTC=2018-12-19 03:41:16 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18121903-0005-0000-0000-000089E8D883 Message-Id: <20181219034047.16305-4-aneesh.kumar@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-12-19_02:,, 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812190029 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 THP pages can get split during different code paths. An incremented reference count do imply we will not split the compound page. But the pmd entry can be converted to level 4 pte entries. Keep the code simpler by allowing large IOMMU page size only if the guest ram is backed by hugetlb pages. Signed-off-by: Aneesh Kumar K.V --- arch/powerpc/mm/mmu_context_iommu.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/arch/powerpc/mm/mmu_context_iommu.c b/arch/powerpc/mm/mmu_context_iommu.c index 1d5161f93ce6..0741d905ed04 100644 --- a/arch/powerpc/mm/mmu_context_iommu.c +++ b/arch/powerpc/mm/mmu_context_iommu.c @@ -95,8 +95,6 @@ long mm_iommu_get(struct mm_struct *mm, unsigned long ua, unsigned long entries, struct mm_iommu_table_group_mem_t *mem; long i, ret = 0, locked_entries = 0; unsigned int pageshift; - unsigned long flags; - unsigned long cur_ua; mutex_lock(&mem_list_mutex); @@ -159,23 +157,15 @@ long mm_iommu_get(struct mm_struct *mm, unsigned long ua, unsigned long entries, pageshift = PAGE_SHIFT; for (i = 0; i < entries; ++i) { struct page *page = mem->hpages[i]; - cur_ua = ua + (i << PAGE_SHIFT); - if (mem->pageshift > PAGE_SHIFT && PageCompound(page)) { - pte_t *pte; + /* + * Allow to use larger than 64k IOMMU pages. Only do that + * if we are backed by hugetlb. + */ + if ((mem->pageshift > PAGE_SHIFT) && PageHuge(page)) { struct page *head = compound_head(page); - unsigned int compshift = compound_order(head); - unsigned int pteshift; - - local_irq_save(flags); /* disables as well */ - pte = find_linux_pte(mm->pgd, cur_ua, NULL, &pteshift); - - /* Double check it is still the same pinned page */ - if (pte && pte_page(*pte) == head && - pteshift == compshift + PAGE_SHIFT) - pageshift = max_t(unsigned int, pteshift, - PAGE_SHIFT); - local_irq_restore(flags); + + pageshift = compound_order(head) + PAGE_SHIFT; } mem->pageshift = min(mem->pageshift, pageshift); /*