Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4633805imu; Tue, 18 Dec 2018 19:48:41 -0800 (PST) X-Google-Smtp-Source: AFSGD/VVKKsoZht7rZ37BGXQP9z/t/A8LOGzXbWVKyvrqUynfHYeCFwNnKzUbeIAHz6Z4ainJjFX X-Received: by 2002:a63:9a09:: with SMTP id o9mr17341517pge.94.1545191321084; Tue, 18 Dec 2018 19:48:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545191321; cv=none; d=google.com; s=arc-20160816; b=wqr9sL3mRL207okkxrSpCwN9SR/wReOTcCkuJq6ZZDq93ldwaDyUs1NwbNRAW0PBRE NzD9546TmlU1gYNLW+P+RjRFkcxKYxI3t3LXYkAVY1jFQK+oKytMnOHFNr270ZB3JMNz rMvHFl/DTlJMJfaL49hMfa3VLkcS26u/SmlOa8LYMy4L1O0V7KYuy2IjBWb8jnKRpu3J A72DXxVs15AOQYOztcyzECDBpG9hBJnqYisDW83oWwiBAi5R4B5T9SSh+nC9Xprnx4Id cR0qUU8r349tXtrGB2vEszCoF9RmmJ1etnZDKj2PpGxwhyhly99XG6Sp1t2LHI/Li2bR 6Q7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:subject:cc:to:from; bh=7xyo4vCoOybUS2MnbDGpne2N6gyF4Htl7wmMPJPOt5g=; b=riJ3JctdpQ4K84pZWLMMR55LwNPxU8yDVfOQGWxh4XgnxCmt7civElCZ0WScpYJpt2 Fjh2N5aO+IkdfIFVebiWgE0IgcnkO7PKBQy0OrYkoUGk8LVaGtDnWi690tttLJI7N+o/ 9LjRHTApikdGt5BbddaQNWObz/hvxfkjtLFtDYHadcHEkq6rYt4/CNa2bF5wIB3wdw54 DDUSmEw5giiceYdlTOu4157SQbBdaV3gOIZ4CFwNagsmxI+cYc0bii1OlqYFg7n0eGDn 49yoVoUqArzZas1lkW2I+WEMBaJZkZAlCYf3s7B3QuiutwonI/sZTWCQmmHCWYjjE3RX wT5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10si14648470plh.307.2018.12.18.19.48.25; Tue, 18 Dec 2018 19:48:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727541AbeLSDlV (ORCPT + 99 others); Tue, 18 Dec 2018 22:41:21 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:36346 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726537AbeLSDlU (ORCPT ); Tue, 18 Dec 2018 22:41:20 -0500 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wBJ3dMoT040269 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 mx0b-001b2d01.pphosted.com with ESMTP id 2pfbj4p0f0-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 Content-Transfer-Encoding: 8bit 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); /* -- 2.19.2