From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE6EEC433ED for ; Thu, 1 Apr 2021 16:50:47 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 717F761389 for ; Thu, 1 Apr 2021 16:50:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 717F761389 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=fao7DpY+0baWqpKJdltXDInoKht5/JmXXVoNqFc3B5o=; b=TK28YSoRfYNwTxhl9vLa3xCUt 76VAvQKLjLXEaYmnez1KY3qsFqDuA2OcAYoFZoYe6wNY8zCvvgxFGmOsZ4xkI8aHZmKfNMtGo7Jlb gFzV0Vs8K3ggIVoCXISCfIjpfAaXjjmIBhCEM+DGAd13TWRfIcFny6XMvj2gYVf0U6PgoPbAemfhT DJl/jrtJldUNuqg6wEqAqPJjFM3d0ZA9vNkqd+5YxW9hcxHKrEudKYCyvU/KSnjvamBO/4Yx0Ov8Y eCDjNWqvCP7bFj7WoGubaQx/UJIEdH94ir4zbzag9t/AufQRtgVPZcw7bb3Rl5UXpqQkMaOGxhLqv sXyxa7KTA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lS0Vf-00ANwd-Ux; Thu, 01 Apr 2021 16:49:32 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lS0Ut-00ANkc-Ra for linux-arm-kernel@lists.infradead.org; Thu, 01 Apr 2021 16:48:45 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6738C61389; Thu, 1 Apr 2021 16:48:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617295722; bh=m+QOtK4MBnW2L0WweNAXI08Q1Wjuv41DugP348K1TW8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KS94AAUr/WbiLXrpHLRYc4VWJiMwix2aQ1o6JIJ17PhemR9TIwjtwD7/clEb8GS0x 10aQlthgJR8DPT6EQe8r+DH69DdqWx1yA1qTZLRUxrxA/Mlt8xgSWPtEm5uROVn7Pu eJ18hz8j/aN6DcgkDZt7+Jf975cRFo1Pa1TbgTCIBabCcBC9z5EdLYwgG1w1XdFxYE d39LF7XGXBa5AlqPRRbTqyLuYznr6y2niVDSSSm/DAwkCzk098q9c0+OqfZThd/P0u vrTar44pZxuoxmIEztfv6NpN/8B4ufvHuPh7Xp4f//atqCRQmvElnj47lqJ1MUjZXB u64Er8zWs32oA== From: Will Deacon To: iommu@lists.linux-foundation.org Cc: linux-arm-kernel@lists.infradead.org, Will Deacon , "Isaac J. Manjarres" , Pratik Patel , Robin Murphy , Lu Baolu Subject: [RFC PATCH 6/6] iommu: Accomodate larger pages in iommu_pgsize() 'count' calculation Date: Thu, 1 Apr 2021 17:47:38 +0100 Message-Id: <20210401164738.9513-7-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210401164738.9513-1-will@kernel.org> References: <20210401164738.9513-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210401_174844_121820_731A3B73 X-CRM114-Status: GOOD ( 15.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Extend the calculation of 'count' in iommu_pgsize() so that it takes larger page sizes into consideration and returns a value which will allow a larger page size to be used on the next call. Signed-off-by: Will Deacon --- drivers/iommu/iommu.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index fe186691fc21..0572a4dcd9e2 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2360,9 +2360,9 @@ EXPORT_SYMBOL_GPL(iommu_iova_to_phys); static size_t iommu_pgsize(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t size, size_t *count) { - unsigned int pgsize_idx; + unsigned int pgsize_idx, pgsize_idx_next; unsigned long pgsizes; - size_t pgsize; + size_t offset, pgsize, pgsize_next; phys_addr_t addr_merge = paddr | iova; /* Page sizes supported by the hardware and small enough for @size */ @@ -2378,9 +2378,37 @@ static size_t iommu_pgsize(struct iommu_domain *domain, unsigned long iova, /* Pick the biggest page size remaining */ pgsize_idx = __fls(pgsizes); pgsize = BIT(pgsize_idx); + if (!count) + return pgsize; - if (count) - *count = size >> pgsize_idx; + + /* Find the next biggest support page size, if it exists */ + pgsizes = domain->pgsize_bitmap & ~GENMASK(pgsize_idx, 0); + if (!pgsizes) + goto out_set_count; + + pgsize_idx_next = __ffs(pgsizes); + pgsize_next = BIT(pgsize_idx_next); + + /* + * There's no point trying a bigger page size unless the virtual + * and physical addresses are similarly offset within the larger page. + */ + if ((iova ^ paddr) & (pgsize_next - 1)) + goto out_set_count; + + /* Calculate the offset to the next page size alignment boundary */ + offset = pgsize_next - (addr_merge & (pgsize_next - 1)); + + /* + * If size is big enough to accomodate the larger page, reduce + * the number of smaller pages. + */ + if (offset + pgsize_next <= size) + size = offset; + +out_set_count: + *count = size >> pgsize_idx; return pgsize; } -- 2.31.0.291.g576ba9dcdaf-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel