qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Auger Eric <eric.auger@redhat.com>
To: Yan Zhao <yan.y.zhao@intel.com>, pbonzini@redhat.com
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v3] memory: warning on out of scope notification
Date: Mon, 24 Jun 2019 12:11:11 +0200	[thread overview]
Message-ID: <bcdc42ec-e60c-5048-da04-8122032f4a09@redhat.com> (raw)
In-Reply-To: <1561365559-10235-1-git-send-email-yan.y.zhao@intel.com>

Hi Yan,

On 6/24/19 10:39 AM, Yan Zhao wrote:
> if an entry has parts out of scope of notifier's range, print warning
> message.
> 
> Out of scope mapping/unmapping would cause problem, as in below case:
> 
> 1. initially there are two notifiers with ranges
> 0-0xfedfffff, 0xfef00000-0xffffffffffffffff,
> IOVAs from 0x3c000000 - 0x3c1fffff is in shadow page table.
> 
> 2. in vfio, memory_region_register_iommu_notifier() is followed by
> memory_region_iommu_replay(), which will first call address space
> unmap,
> and walk and add back all entries in vtd shadow page table. e.g.
> (1) for notifier 0-0xfedfffff,
>     IOVAs from 0 - 0xffffffff get unmapped,
>     and IOVAs from 0x3c000000 - 0x3c1fffff get mapped
> (2) for notifier 0xfef00000-0xffffffffffffffff
>     IOVAs from 0 - 0x7fffffffff get unmapped,
>     but IOVAs from 0x3c000000 - 0x3c1fffff cannot get mapped back.
> 
> Cc: Auger Eric <eric.auger@redhat.com>
> Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
> 
> ---
> v3:
> refined code style and message format
> 
> v2:
> 1. added a local variable entry_end (Auger Eric)
> 2. using PRIx64 as format for address range in warning message
> (Auger Eric)
> ---
>  memory.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/memory.c b/memory.c
> index 0a089a7..c7154ab 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -1937,13 +1937,13 @@ void memory_region_notify_one(IOMMUNotifier *notifier,
>                                IOMMUTLBEntry *entry)
>  {
>      IOMMUNotifierFlag request_flags;
> +    hwaddr entry_end = entry->iova + entry->addr_mask;
>  
>      /*
>       * Skip the notification if the notification does not overlap
>       * with registered range.
>       */
> -    if (notifier->start > entry->iova + entry->addr_mask ||
> -        notifier->end < entry->iova) {
> +    if (notifier->start > entry_end || notifier->end < entry->iova) {
>          return;
>      }
>  
> @@ -1953,6 +1953,15 @@ void memory_region_notify_one(IOMMUNotifier *notifier,
>          request_flags = IOMMU_NOTIFIER_UNMAP;
>      }
>  
> +    if (entry->iova < notifier->start || entry_end > notifier->end) {
> +        warn_report("%s IOMMUTLBEntry 0x%" PRIx64 " - 0x%" PRIx64
> +                " outside of notifier scope 0x%" PRIx64 " - 0x%" PRIx64,
> +                (request_flags == IOMMU_NOTIFIER_MAP) ?
> +                "Mapping" : "Unmapping",
> +                entry->iova, entry->iova + entry->addr_mask,
entry_end as well.

Then shouldn't we assert in that case?

Thanks

Eric
> +                notifier->start, notifier->end);
> +    }
> +
>      if (notifier->notifier_flags & request_flags) {
>          notifier->notify(notifier, entry);
>      }
> 


  reply	other threads:[~2019-06-24 10:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-24  8:26 [Qemu-devel] [PATCH v2] memory: warning on out of scope notification Yan Zhao
2019-06-24  8:39 ` [Qemu-devel] [PATCH v3] " Yan Zhao
2019-06-24 10:11   ` Auger Eric [this message]
2019-06-25  3:04     ` Yan Zhao

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=bcdc42ec-e60c-5048-da04-8122032f4a09@redhat.com \
    --to=eric.auger@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=yan.y.zhao@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).