From patchwork Thu Feb 16 13:52:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 9577225 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4FBB8600F6 for ; Thu, 16 Feb 2017 13:53:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46051285A2 for ; Thu, 16 Feb 2017 13:53:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3AED7285DD; Thu, 16 Feb 2017 13:53:12 +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=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B45A8285A2 for ; Thu, 16 Feb 2017 13:53:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=z7vY1rHfmBHiwWPI8LJBQVMBfd/Z+9asCJM3ksrNQWo=; b=d+f xOPUyuUVEr6nxiBi7RLx3ri3Tkl3uUCe8ajpuG/kCufMWe7DLx/wEf6rd5zKQ4Nf8IbBz5tN71N88 KmimrbaK66uQIZfkI31ccbsUjQw1Ua0RFN46yQcVAQzdKo8S8sDZVsec6E1hVj08Lndn0UK9OUkQN xOJQyVDbnLJ2Mb033ytjsry1DQCuu14DTJuBd29zykGZTQ7hn49kDI6Ybau8KeCwoCxNBIASxxzR3 VGcYisbv5OtrKsBfYHfWDtXjBEKBbIUzN1lKHoVODpTOWOSm0tqYHg3RFQjzAa9ppsEBI0V0S990j 8yCnJy9lg5bGFRF1tMYw/YQa3q9foNQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ceMUg-000266-Lb; Thu, 16 Feb 2017 13:53:10 +0000 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ceMUU-0001Vu-Kl for linux-arm-kernel@lists.infradead.org; Thu, 16 Feb 2017 13:53:06 +0000 Received: by mail-wr0-x241.google.com with SMTP id i10so2146739wrb.0 for ; Thu, 16 Feb 2017 05:52:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=oczCgrIflGRoYb7u2ZAH1HvG2ArTwiLaRD5tjAxb1PA=; b=QDuJs47FQUtiYwLzjQmD0QbJ2NIMpwGK0qGAZIatfrMpUiy6MacBBHa+tcGqgCPqQo 9bSY7TwFG9NtBv87TPTmQgmFuNzW+MWyN85u9H7WIEtHzd3dU7srGHqdzbkMmmIFyPR+ WaeETjpnKTecO7AI8ZDTgXtVo7D+yAs7ZSmzlm3L6yxJp9dPI1CPETA9iB1dxh6a55lp W9R6YZjMMFcKc8NBmy/K0DOR2ZB0YNZV4ff585K37ndUmMxUNaChl5adT7SnAK7i/mAh sdMuoGub0nRGAKj+Im2fid7NAqr9e9pZLCpbFuClIKUQssZLcaxB1UdFsIHt1ly/Gwi5 dcSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=oczCgrIflGRoYb7u2ZAH1HvG2ArTwiLaRD5tjAxb1PA=; b=NiqE2OeJavNGKlrlY/c5sE1eFdtwORfm9t/9vhArtJDs32UKwGozfp0n+V24x89cAb DC8M3TwOtNobPdMM2e6iDRWoembjgp2Xg9O8MuAQ9XvzmaOXRzfMKRoh7nO/tccyDXZ7 cmrHAykfdx9xjRJ8u+30nTHJIBeKukUJmzBkjL8L2FyIFqDemPO6wbmCFTYrhBQaHfbV 38/SBHF/mMqSo6EnOPrARSZ7h11lPAlfxo/ZWAz6R/MG70PVYUaKZjhbnCUm4xjM73f1 ztbwz6dF/QRcvuhXMN0oNmFhJBKCMSIid6vEhVO8UY0q8eRX1T5VGRevbWd+RhPygCJa jMDQ== X-Gm-Message-State: AMke39mH1paxaGuh5LcfKIv2i6DZ2JLjD3Sl2sbHin80JoEqF0+Km8hdTHFGwyjz1i1rPA== X-Received: by 10.223.173.40 with SMTP id p37mr2559394wrc.136.1487253156348; Thu, 16 Feb 2017 05:52:36 -0800 (PST) Received: from otyshchenko.kyiv.epam.com (ll-74.141.223.85.sovam.net.ua. [85.223.141.74]) by smtp.gmail.com with ESMTPSA id o2sm293899wmb.28.2017.02.16.05.52.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Feb 2017 05:52:35 -0800 (PST) From: Oleksandr Tyshchenko To: linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org Subject: [RFC PATCH v1] iommu/io-pgtable-arm-v7s: Check for leaf entry right after finding it Date: Thu, 16 Feb 2017 15:52:17 +0200 Message-Id: <1487253137-13792-1-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170216_055259_019284_783C3F78 X-CRM114-Status: GOOD ( 14.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Oleksandr Tyshchenko , vlad.babchuk@gmail.com, joro@8bytes.org, will.deacon@arm.com, andrii.anisov@gmail.com, andr2000@gmail.com, al1img@gmail.com, robin.murphy@arm.com, joculator@gmail.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Oleksandr Tyshchenko Do a check for already installed leaf entry at the current level before performing any actions when trying to map. This check is already present in arm_v7s_init_pte(), i.e. before installing new leaf entry at the current level if conditions to do so are met (num_entries > 0). But, this might be insufficient in case when we have already installed block mapping at this level and it is not time to install new leaf entry (num_entries == 0). In that case we continue walking the page table down with wrong pointer to the next level. So, move check from arm_v7s_init_pte() to __arm_v7s_map() in order to avoid all cases. Signed-off-by: Oleksandr Tyshchenko --- This patch does similar things as the patch I have pushed a week ago for long-descriptor format [1]. The reason why this patch is RFC is because I am not sure I did the right thing and I even didn't test it. [1] https://lists.linuxfoundation.org/pipermail/iommu/2017-February/020411.html --- --- drivers/iommu/io-pgtable-arm-v7s.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c index f50e51c..7f7594b 100644 --- a/drivers/iommu/io-pgtable-arm-v7s.c +++ b/drivers/iommu/io-pgtable-arm-v7s.c @@ -364,10 +364,6 @@ static int arm_v7s_init_pte(struct arm_v7s_io_pgtable *data, if (WARN_ON(__arm_v7s_unmap(data, iova + i * sz, sz, lvl, tblp) != sz)) return -EINVAL; - } else if (ptep[i]) { - /* We require an unmap first */ - WARN_ON(!selftest_running); - return -EEXIST; } pte |= ARM_V7S_PTE_TYPE_PAGE; @@ -392,11 +388,20 @@ static int __arm_v7s_map(struct arm_v7s_io_pgtable *data, unsigned long iova, { struct io_pgtable_cfg *cfg = &data->iop.cfg; arm_v7s_iopte pte, *cptep; - int num_entries = size >> ARM_V7S_LVL_SHIFT(lvl); + int i = 0, num_entries = size >> ARM_V7S_LVL_SHIFT(lvl); /* Find our entry at the current level */ ptep += ARM_V7S_LVL_IDX(iova, lvl); + /* Check for already installed leaf entry */ + do { + if (ptep[i] && !ARM_V7S_PTE_IS_TABLE(ptep[i], lvl)) { + /* We require an unmap first */ + WARN_ON(!selftest_running); + return -EEXIST; + } + } while (++i < num_entries); + /* If we can install a leaf entry at this level, then do so */ if (num_entries) return arm_v7s_init_pte(data, iova, paddr, prot,