All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleksandr Tyshchenko <olekstysh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Cc: Oleksandr Tyshchenko
	<oleksandr_tyshchenko-uRwfk40T5oI@public.gmane.org>,
	Volodymyr Babchuk
	<vlad.babchuk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	will.deacon-5wv7dgnIgG8@public.gmane.org,
	Andrii Anisov
	<andrii.anisov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Oleksandr Andrushchenko
	<andr2000-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	al1img <al1img-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Artem Mygaiev <joculator-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: Re: [RFC PATCH v1] iommu/io-pgtable-arm: Check for leaf entry right after finding it
Date: Mon, 13 Feb 2017 13:07:02 +0200	[thread overview]
Message-ID: <CAPD2p-=TtT9ZHpLu8w9jUdKR5u6JG_BGtz0BDDKejmWS-jQ9WQ@mail.gmail.com> (raw)
In-Reply-To: <1486648600-27457-1-git-send-email-olekstysh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

Hi, all.

Any comments?

On Thu, Feb 9, 2017 at 3:56 PM, Oleksandr Tyshchenko
<olekstysh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> From: Oleksandr Tyshchenko <oleksandr_tyshchenko-uRwfk40T5oI@public.gmane.org>
>
> 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_lpae_init_pte(), i.e. before
> installing new leaf entry at the current level if conditions to do so
> are met (size == block_size).
>
> 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 (size != block_size).
> In that case we continue walking the page table down with wrong pointer
> to the next level.
>
> So, move check from arm_lpae_init_pte() to __arm_lpae_map() in order to
> avoid all cases.
>
> Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko-uRwfk40T5oI@public.gmane.org>
> ---
> I hope that following actions can help to catch it:
> 1. Call iommu_map for a block mapping (e.g. 2M) at some address
>    (e.g. iova 0x80000000 pa 0x80000000).
> 2. Call iommu_map for a page mapping (4k) at some address from
>    the previous mapped region (e.g. iova 0x80008000 pa 0x90000000).
>
> I understand that after iommu_map should be iommu_unmap, but
> different scenarios may occur).
> ---
> ---
>  drivers/iommu/io-pgtable-arm.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c
> index f5c90e1..ebdb82f 100644
> --- a/drivers/iommu/io-pgtable-arm.c
> +++ b/drivers/iommu/io-pgtable-arm.c
> @@ -272,11 +272,7 @@ static int arm_lpae_init_pte(struct arm_lpae_io_pgtable *data,
>         arm_lpae_iopte pte = prot;
>         struct io_pgtable_cfg *cfg = &data->iop.cfg;
>
> -       if (iopte_leaf(*ptep, lvl)) {
> -               /* We require an unmap first */
> -               WARN_ON(!selftest_running);
> -               return -EEXIST;
> -       } else if (iopte_type(*ptep, lvl) == ARM_LPAE_PTE_TYPE_TABLE) {
> +       if (iopte_type(*ptep, lvl) == ARM_LPAE_PTE_TYPE_TABLE) {
>                 /*
>                  * We need to unmap and free the old table before
>                  * overwriting it with a block entry.
> @@ -315,6 +311,13 @@ static int __arm_lpae_map(struct arm_lpae_io_pgtable *data, unsigned long iova,
>         /* Find our entry at the current level */
>         ptep += ARM_LPAE_LVL_IDX(iova, lvl, data);
>
> +       /* Check for already installed leaf entry */
> +       if (iopte_leaf(*ptep, lvl)) {
> +               /* We require an unmap first */
> +               WARN_ON(!selftest_running);
> +               return -EEXIST;
> +       }
> +
>         /* If we can install a leaf entry at this level, then do so */
>         if (size == block_size && (size & cfg->pgsize_bitmap))
>                 return arm_lpae_init_pte(data, iova, paddr, prot, lvl, ptep);
> --
> 2.7.4
>



-- 
Regards,

Oleksandr Tyshchenko

WARNING: multiple messages have this Message-ID (diff)
From: olekstysh@gmail.com (Oleksandr Tyshchenko)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH v1] iommu/io-pgtable-arm: Check for leaf entry right after finding it
Date: Mon, 13 Feb 2017 13:07:02 +0200	[thread overview]
Message-ID: <CAPD2p-=TtT9ZHpLu8w9jUdKR5u6JG_BGtz0BDDKejmWS-jQ9WQ@mail.gmail.com> (raw)
In-Reply-To: <1486648600-27457-1-git-send-email-olekstysh@gmail.com>

Hi, all.

Any comments?

On Thu, Feb 9, 2017 at 3:56 PM, Oleksandr Tyshchenko
<olekstysh@gmail.com> wrote:
> From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
>
> 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_lpae_init_pte(), i.e. before
> installing new leaf entry at the current level if conditions to do so
> are met (size == block_size).
>
> 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 (size != block_size).
> In that case we continue walking the page table down with wrong pointer
> to the next level.
>
> So, move check from arm_lpae_init_pte() to __arm_lpae_map() in order to
> avoid all cases.
>
> Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
> ---
> I hope that following actions can help to catch it:
> 1. Call iommu_map for a block mapping (e.g. 2M) at some address
>    (e.g. iova 0x80000000 pa 0x80000000).
> 2. Call iommu_map for a page mapping (4k) at some address from
>    the previous mapped region (e.g. iova 0x80008000 pa 0x90000000).
>
> I understand that after iommu_map should be iommu_unmap, but
> different scenarios may occur).
> ---
> ---
>  drivers/iommu/io-pgtable-arm.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c
> index f5c90e1..ebdb82f 100644
> --- a/drivers/iommu/io-pgtable-arm.c
> +++ b/drivers/iommu/io-pgtable-arm.c
> @@ -272,11 +272,7 @@ static int arm_lpae_init_pte(struct arm_lpae_io_pgtable *data,
>         arm_lpae_iopte pte = prot;
>         struct io_pgtable_cfg *cfg = &data->iop.cfg;
>
> -       if (iopte_leaf(*ptep, lvl)) {
> -               /* We require an unmap first */
> -               WARN_ON(!selftest_running);
> -               return -EEXIST;
> -       } else if (iopte_type(*ptep, lvl) == ARM_LPAE_PTE_TYPE_TABLE) {
> +       if (iopte_type(*ptep, lvl) == ARM_LPAE_PTE_TYPE_TABLE) {
>                 /*
>                  * We need to unmap and free the old table before
>                  * overwriting it with a block entry.
> @@ -315,6 +311,13 @@ static int __arm_lpae_map(struct arm_lpae_io_pgtable *data, unsigned long iova,
>         /* Find our entry at the current level */
>         ptep += ARM_LPAE_LVL_IDX(iova, lvl, data);
>
> +       /* Check for already installed leaf entry */
> +       if (iopte_leaf(*ptep, lvl)) {
> +               /* We require an unmap first */
> +               WARN_ON(!selftest_running);
> +               return -EEXIST;
> +       }
> +
>         /* If we can install a leaf entry at this level, then do so */
>         if (size == block_size && (size & cfg->pgsize_bitmap))
>                 return arm_lpae_init_pte(data, iova, paddr, prot, lvl, ptep);
> --
> 2.7.4
>



-- 
Regards,

Oleksandr Tyshchenko

  parent reply	other threads:[~2017-02-13 11:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-09 13:56 [RFC PATCH v1] iommu/io-pgtable-arm: Check for leaf entry right after finding it Oleksandr Tyshchenko
2017-02-09 13:56 ` Oleksandr Tyshchenko
     [not found] ` <1486648600-27457-1-git-send-email-olekstysh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-02-13 11:07   ` Oleksandr Tyshchenko [this message]
2017-02-13 11:07     ` Oleksandr Tyshchenko
2017-02-13 11:27     ` Will Deacon
2017-02-13 11:27       ` Will Deacon
     [not found]       ` <20170213112728.GH1512-5wv7dgnIgG8@public.gmane.org>
2017-02-13 11:50         ` Oleksandr Tyshchenko
2017-02-13 11:50           ` Oleksandr Tyshchenko
2017-02-13 12:00           ` Will Deacon
2017-02-13 12:00             ` Will Deacon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPD2p-=TtT9ZHpLu8w9jUdKR5u6JG_BGtz0BDDKejmWS-jQ9WQ@mail.gmail.com' \
    --to=olekstysh-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=al1img-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=andr2000-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=andrii.anisov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=joculator-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=oleksandr_tyshchenko-uRwfk40T5oI@public.gmane.org \
    --cc=vlad.babchuk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=will.deacon-5wv7dgnIgG8@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.