qemu-arm.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Auger Eric <eric.auger@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>,
	qemu-arm@nongnu.org, qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Richard Henderson" <rth@twiddle.net>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	patches@linaro.org
Subject: Re: [Qemu-devel] [PATCH 01/27] memory.h: Improve IOMMU related documentation
Date: Tue, 22 May 2018 13:40:53 +0200	[thread overview]
Message-ID: <50b9fbd0-5571-a83f-1ae5-b44b1f7828a9@redhat.com> (raw)
In-Reply-To: <20180521140402.23318-2-peter.maydell@linaro.org>

Hi Peter,

On 05/21/2018 04:03 PM, Peter Maydell wrote:
> Add more detail to the documentation for memory_region_init_iommu()
> and other IOMMU-related functions and data structures.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Auger <eric.auger@redhat.com>

Thanks

Eric
> ---
> v2->v3 changes:
>  * minor wording tweaks per Eric's review
>  * moved the bit about requirements to notify out from the translate
>    method docs to the top level class doc comment
>  * added description of flags argument and in particular that it's
>    just an optimization and callers can pass IOMMU_NONE to get the
>    full permissions
> v1 -> v2 changes:
>  * documented replay method
>  * added note about wanting RCU or big qemu lock while calling
>    translate
> ---
>  include/exec/memory.h | 105 ++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 95 insertions(+), 10 deletions(-)
> 
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index 4fa1227f13..cce355d2d8 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -194,29 +194,100 @@ enum IOMMUMemoryRegionAttr {
>      IOMMU_ATTR_SPAPR_TCE_FD
>  };
>  
> +/**
> + * IOMMUMemoryRegionClass:
> + *
> + * All IOMMU implementations need to subclass TYPE_IOMMU_MEMORY_REGION
> + * and provide an implementation of at least the @translate method here
> + * to handle requests to the memory region. Other methods are optional.
> + *
> + * The IOMMU implementation must use the IOMMU notifier infrastructure
> + * to report whenever mappings are changed, by calling
> + * memory_region_notify_iommu() (or, if necessary, by calling
> + * memory_region_notify_one() for each registered notifier).
> + */
>  typedef struct IOMMUMemoryRegionClass {
>      /* private */
>      struct DeviceClass parent_class;
>  
>      /*
> -     * Return a TLB entry that contains a given address. Flag should
> -     * be the access permission of this translation operation. We can
> -     * set flag to IOMMU_NONE to mean that we don't need any
> -     * read/write permission checks, like, when for region replay.
> +     * Return a TLB entry that contains a given address.
> +     *
> +     * The IOMMUAccessFlags indicated via @flag are optional and may
> +     * be specified as IOMMU_NONE to indicate that the caller needs
> +     * the full translation information for both reads and writes. If
> +     * the access flags are specified then the IOMMU implementation
> +     * may use this as an optimization, to stop doing a page table
> +     * walk as soon as it knows that the requested permissions are not
> +     * allowed. If IOMMU_NONE is passed then the IOMMU must do the
> +     * full page table walk and report the permissions in the returned
> +     * IOMMUTLBEntry. (Note that this implies that an IOMMU may not
> +     * return different mappings for reads and writes.)
> +     *
> +     * The returned information remains valid while the caller is
> +     * holding the big QEMU lock or is inside an RCU critical section;
> +     * if the caller wishes to cache the mapping beyond that it must
> +     * register an IOMMU notifier so it can invalidate its cached
> +     * information when the IOMMU mapping changes.
> +     *
> +     * @iommu: the IOMMUMemoryRegion
> +     * @hwaddr: address to be translated within the memory region
> +     * @flag: requested access permissions
>       */
>      IOMMUTLBEntry (*translate)(IOMMUMemoryRegion *iommu, hwaddr addr,
>                                 IOMMUAccessFlags flag);
> -    /* Returns minimum supported page size */
> +    /* Returns minimum supported page size in bytes.
> +     * If this method is not provided then the minimum is assumed to
> +     * be TARGET_PAGE_SIZE.
> +     *
> +     * @iommu: the IOMMUMemoryRegion
> +     */
>      uint64_t (*get_min_page_size)(IOMMUMemoryRegion *iommu);
> -    /* Called when IOMMU Notifier flag changed */
> +    /* Called when IOMMU Notifier flag changes (ie when the set of
> +     * events which IOMMU users are requesting notification for changes).
> +     * Optional method -- need not be provided if the IOMMU does not
> +     * need to know exactly which events must be notified.
> +     *
> +     * @iommu: the IOMMUMemoryRegion
> +     * @old_flags: events which previously needed to be notified
> +     * @new_flags: events which now need to be notified
> +     */
>      void (*notify_flag_changed)(IOMMUMemoryRegion *iommu,
>                                  IOMMUNotifierFlag old_flags,
>                                  IOMMUNotifierFlag new_flags);
> -    /* Set this up to provide customized IOMMU replay function */
> +    /* Called to handle memory_region_iommu_replay().
> +     *
> +     * The default implementation of memory_region_iommu_replay() is to
> +     * call the IOMMU translate method for every page in the address space
> +     * with flag == IOMMU_NONE and then call the notifier if translate
> +     * returns a valid mapping. If this method is implemented then it
> +     * overrides the default behaviour, and must provide the full semantics
> +     * of memory_region_iommu_replay(), by calling @notifier for every
> +     * translation present in the IOMMU.
> +     *
> +     * Optional method -- an IOMMU only needs to provide this method
> +     * if the default is inefficient or produces undesirable side effects.
> +     *
> +     * Note: this is not related to record-and-replay functionality.
> +     */
>      void (*replay)(IOMMUMemoryRegion *iommu, IOMMUNotifier *notifier);
>  
> -    /* Get IOMMU misc attributes */
> -    int (*get_attr)(IOMMUMemoryRegion *iommu, enum IOMMUMemoryRegionAttr,
> +    /* Get IOMMU misc attributes. This is an optional method that
> +     * can be used to allow users of the IOMMU to get implementation-specific
> +     * information. The IOMMU implements this method to handle calls
> +     * by IOMMU users to memory_region_iommu_get_attr() by filling in
> +     * the arbitrary data pointer for any IOMMUMemoryRegionAttr values that
> +     * the IOMMU supports. If the method is unimplemented then
> +     * memory_region_iommu_get_attr() will always return -EINVAL.
> +     *
> +     * @iommu: the IOMMUMemoryRegion
> +     * @attr: attribute being queried
> +     * @data: memory to fill in with the attribute data
> +     *
> +     * Returns 0 on success, or a negative errno; in particular
> +     * returns -EINVAL for unrecognized or unimplemented attribute types.
> +     */
> +    int (*get_attr)(IOMMUMemoryRegion *iommu, enum IOMMUMemoryRegionAttr attr,
>                      void *data);
>  } IOMMUMemoryRegionClass;
>  
> @@ -705,6 +776,14 @@ static inline void memory_region_init_reservation(MemoryRegion *mr,
>   * An IOMMU region translates addresses and forwards accesses to a target
>   * memory region.
>   *
> + * The IOMMU implementation must define a subclass of TYPE_IOMMU_MEMORY_REGION.
> + * @_iommu_mr should be a pointer to enough memory for an instance of
> + * that subclass, @instance_size is the size of that subclass, and
> + * @mrtypename is its name. This function will initialize @_iommu_mr as an
> + * instance of the subclass, and its methods will then be called to handle
> + * accesses to the memory region. See the documentation of
> + * #IOMMUMemoryRegionClass for further details.
> + *
>   * @_iommu_mr: the #IOMMUMemoryRegion to be initialized
>   * @instance_size: the IOMMUMemoryRegion subclass instance size
>   * @mrtypename: the type name of the #IOMMUMemoryRegion
> @@ -953,6 +1032,8 @@ void memory_region_register_iommu_notifier(MemoryRegion *mr,
>   * a notifier with the minimum page granularity returned by
>   * mr->iommu_ops->get_page_size().
>   *
> + * Note: this is not related to record-and-replay functionality.
> + *
>   * @iommu_mr: the memory region to observe
>   * @n: the notifier to which to replay iommu mappings
>   */
> @@ -962,6 +1043,8 @@ void memory_region_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier *n);
>   * memory_region_iommu_replay_all: replay existing IOMMU translations
>   * to all the notifiers registered.
>   *
> + * Note: this is not related to record-and-replay functionality.
> + *
>   * @iommu_mr: the memory region to observe
>   */
>  void memory_region_iommu_replay_all(IOMMUMemoryRegion *iommu_mr);
> @@ -981,7 +1064,9 @@ void memory_region_unregister_iommu_notifier(MemoryRegion *mr,
>   * memory_region_iommu_get_attr: return an IOMMU attr if get_attr() is
>   * defined on the IOMMU.
>   *
> - * Returns 0 if succeded, error code otherwise.
> + * Returns 0 on success, or a negative errno otherwise. In particular,
> + * -EINVAL indicates that the IOMMU does not support the requested
> + * attribute.
>   *
>   * @iommu_mr: the memory region
>   * @attr: the requested attribute
> 

  parent reply	other threads:[~2018-05-22 11:40 UTC|newest]

Thread overview: 114+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-21 14:03 [PATCH 00/27] iommu: support txattrs, support TCG execution, implement TZ MPC Peter Maydell
2018-05-21 14:03 ` [PATCH 01/27] memory.h: Improve IOMMU related documentation Peter Maydell
2018-05-21 19:46   ` Richard Henderson
2018-05-22  9:16   ` Alex Bennée
2018-05-22 11:40   ` Auger Eric [this message]
2018-05-21 14:03 ` [PATCH 02/27] Make tb_invalidate_phys_addr() take a MemTxAttrs argument Peter Maydell
2018-05-21 23:54   ` Richard Henderson
2018-05-22  9:21   ` Alex Bennée
2018-05-21 14:03 ` [PATCH 03/27] Make address_space_translate{,_cached}() " Peter Maydell
2018-05-22 10:49   ` Alex Bennée
2018-05-22 16:12   ` Richard Henderson
2018-05-21 14:03 ` [PATCH 04/27] Make address_space_map() " Peter Maydell
2018-05-22 10:49   ` Alex Bennée
2018-05-22 16:13   ` Richard Henderson
2018-05-21 14:03 ` [PATCH 05/27] Make address_space_access_valid() " Peter Maydell
2018-05-22 10:50   ` Alex Bennée
2018-05-22 16:14   ` Richard Henderson
2018-05-21 14:03 ` [PATCH 06/27] Make flatview_extend_translation() " Peter Maydell
2018-05-22 10:56   ` Alex Bennée
2018-05-22 16:15   ` Richard Henderson
2018-05-21 14:03 ` [PATCH 07/27] Make memory_region_access_valid() " Peter Maydell
2018-05-22 10:57   ` Alex Bennée
2018-05-22 16:17   ` Richard Henderson
2018-05-21 14:03 ` [PATCH 08/27] Make MemoryRegion valid.accepts callback " Peter Maydell
2018-05-22 10:58   ` Alex Bennée
2018-05-22 16:20   ` Richard Henderson
2018-05-21 14:03 ` [PATCH 09/27] Make flatview_access_valid() " Peter Maydell
2018-05-22 10:58   ` Alex Bennée
2018-05-22 16:33   ` Richard Henderson
2018-05-22 16:37     ` Peter Maydell
2018-05-21 14:03 ` [PATCH 10/27] Make flatview_translate() " Peter Maydell
2018-05-22 10:58   ` Alex Bennée
2018-05-22 16:33   ` Richard Henderson
2018-05-21 14:03 ` [PATCH 11/27] Make address_space_get_iotlb_entry() " Peter Maydell
2018-05-22 11:00   ` Alex Bennée
2018-05-22 17:29   ` Richard Henderson
2018-05-21 14:03 ` [PATCH 12/27] Make flatview_do_translate() " Peter Maydell
2018-05-22 11:00   ` Alex Bennée
2018-05-22 17:29   ` Richard Henderson
2018-05-21 14:03 ` [PATCH 13/27] Make address_space_translate_iommu " Peter Maydell
2018-05-22 11:00   ` Alex Bennée
2018-05-22 17:30   ` Richard Henderson
2018-05-21 14:03 ` [PATCH 14/27] iommu: Add IOMMU index concept to IOMMU API Peter Maydell
2018-05-22  3:03   ` [Qemu-devel] " Peter Xu
2018-05-22  8:40     ` Peter Maydell
2018-05-22 11:02       ` Peter Xu
2018-05-22 11:11         ` Peter Maydell
2018-05-23  1:06           ` Peter Xu
2018-05-23 11:47             ` Peter Maydell
2018-05-24  6:23               ` Peter Xu
2018-05-24 10:54                 ` Peter Maydell
2018-05-25  2:50                   ` Peter Xu
2018-05-25  9:27                   ` Auger Eric
2018-05-25  9:34                     ` Peter Maydell
2018-05-22 12:58   ` Auger Eric
2018-05-22 13:22     ` Peter Maydell
2018-05-22 14:11       ` Auger Eric
2018-05-22 14:19         ` Peter Maydell
2018-05-22 14:22           ` Auger Eric
2018-05-22 17:42   ` Richard Henderson
2018-05-22 17:51     ` Peter Maydell
2018-05-22 17:52       ` Richard Henderson
2018-05-21 14:03 ` [PATCH 15/27] iommu: Add IOMMU index argument to notifier APIs Peter Maydell
2018-05-22 17:45   ` Richard Henderson
2018-05-23  9:08   ` Alex Bennée
2018-06-04 13:03     ` Peter Maydell
2018-06-04 15:09       ` Alex Bennée
2018-06-04 15:23         ` Peter Maydell
2018-05-24 15:29   ` [Qemu-devel] " Auger Eric
2018-05-24 17:03     ` Peter Maydell
2018-05-24 19:13       ` Auger Eric
2018-05-21 14:03 ` [PATCH 16/27] iommu: Add IOMMU index argument to translate method Peter Maydell
2018-05-22 18:06   ` Richard Henderson
2018-05-23  9:11   ` Alex Bennée
2018-05-21 14:03 ` [PATCH 17/27] exec.c: Handle IOMMUs in address_space_translate_for_iotlb() Peter Maydell
2018-05-23  9:51   ` Alex Bennée
2018-05-23 11:52     ` Peter Maydell
2018-05-24 19:54     ` [Qemu-devel] " Auger Eric
2018-05-25  8:52       ` Peter Maydell
2018-05-25  9:50         ` Auger Eric
2018-05-25  9:59           ` Peter Maydell
2018-05-21 14:03 ` [PATCH 18/27] hw/misc/tz-mpc.c: Implement the Arm TrustZone Memory Protection Controller Peter Maydell
2018-05-22 11:30   ` [Qemu-devel] " Auger Eric
2018-05-22 11:56     ` Peter Maydell
2018-05-22 12:23       ` Auger Eric
2018-05-23 10:41   ` Alex Bennée
2018-05-21 14:03 ` [PATCH 19/27] hw/misc/tz-mpc.c: Implement registers Peter Maydell
2018-05-23 10:44   ` Alex Bennée
2018-05-21 14:03 ` [PATCH 20/27] hw/misc/tz-mpc.c: Implement correct blocked-access behaviour Peter Maydell
2018-05-23 10:49   ` Alex Bennée
2018-05-23 11:54     ` Peter Maydell
2018-05-21 14:03 ` [PATCH 21/27] hw/misc/tz_mpc.c: Honour the BLK_LUT settings in translate Peter Maydell
2018-05-21 14:03 ` [PATCH 22/27] vmstate.h: Provide VMSTATE_BOOL_SUB_ARRAY Peter Maydell
2018-05-23 11:01   ` Alex Bennée
2018-05-21 14:03 ` [PATCH 23/27] hw/core/or-irq: Support more than 16 inputs to an OR gate Peter Maydell
2018-05-21 14:34   ` Paolo Bonzini
2018-05-21 15:02     ` Peter Maydell
2018-05-30 16:59       ` [Qemu-devel] " Paolo Bonzini
2018-05-30 17:35         ` Peter Maydell
2018-05-31 10:21           ` Paolo Bonzini
2018-05-31 10:50             ` Peter Maydell
2018-05-31 11:50               ` Paolo Bonzini
2018-05-31 11:59                 ` Peter Maydell
2018-05-21 14:03 ` [PATCH 24/27] hw/misc/iotkit-secctl.c: Implement SECMPCINTSTATUS Peter Maydell
2018-05-21 14:04 ` [PATCH 25/27] hw/arm/iotkit: Instantiate MPC Peter Maydell
2018-05-23 11:38   ` Alex Bennée
2018-05-21 14:04 ` [PATCH 26/27] hw/arm/iotkit: Wire up MPC interrupt lines Peter Maydell
2018-05-23 11:39   ` Alex Bennée
2018-05-21 14:04 ` [PATCH 27/27] hw/arm/mps2-tz.c: Instantiate MPCs Peter Maydell
2018-05-23 11:41   ` Alex Bennée
2018-05-21 15:10 ` [Qemu-devel] [PATCH 00/27] iommu: support txattrs, support TCG execution, implement TZ MPC no-reply
2018-05-30 16:58 ` Paolo Bonzini
2018-05-31  9:54   ` Peter Maydell
2018-05-31 13:37     ` Peter Maydell

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=50b9fbd0-5571-a83f-1ae5-b44b1f7828a9@redhat.com \
    --to=eric.auger@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=patches@linaro.org \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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).