diff mbox

[v2,2/8] xen: clean up grant_table.h

Message ID 20170906082632.6494-3-jgross@suse.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jürgen Groß Sept. 6, 2017, 8:26 a.m. UTC
Many definitions can be moved from xen/grant_table.h to
common/grant_table.c now, as they are no longer used in other sources.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 xen/common/grant_table.c      | 81 +++++++++++++++++++++++++++++++++++++++--
 xen/include/xen/grant_table.h | 84 -------------------------------------------
 2 files changed, 79 insertions(+), 86 deletions(-)

Comments

Paul Durrant Sept. 6, 2017, 8:37 a.m. UTC | #1
> -----Original Message-----

> From: Xen-devel [mailto:xen-devel-bounces@lists.xen.org] On Behalf Of

> Juergen Gross

> Sent: 06 September 2017 09:26

> To: xen-devel@lists.xen.org

> Cc: Juergen Gross <jgross@suse.com>; sstabellini@kernel.org; Wei Liu

> <wei.liu2@citrix.com>; George Dunlap <George.Dunlap@citrix.com>;

> Andrew Cooper <Andrew.Cooper3@citrix.com>; Ian Jackson

> <Ian.Jackson@citrix.com>; Tim (Xen.org) <tim@xen.org>;

> jbeulich@suse.com

> Subject: [Xen-devel] [PATCH v2 2/8] xen: clean up grant_table.h

> 

> Many definitions can be moved from xen/grant_table.h to

> common/grant_table.c now, as they are no longer used in other sources.

> 

> Signed-off-by: Juergen Gross <jgross@suse.com>


Reviewed-by: Paul Durrant <paul.durrant@citrix.com>


> ---

>  xen/common/grant_table.c      | 81

> +++++++++++++++++++++++++++++++++++++++--

>  xen/include/xen/grant_table.h | 84 -------------------------------------------

>  2 files changed, 79 insertions(+), 86 deletions(-)

> 

> diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c

> index 4c2e9e40a5..a94dfdda7b 100644

> --- a/xen/common/grant_table.c

> +++ b/xen/common/grant_table.c

> @@ -40,6 +40,42 @@

>  #include <xsm/xsm.h>

>  #include <asm/flushtlb.h>

> 

> +/* Per-domain grant information. */

> +struct grant_table {

> +    /*

> +     * Lock protecting updates to grant table state (version, active

> +     * entry list, etc.)

> +     */

> +    percpu_rwlock_t       lock;

> +    /* Table size. Number of frames shared with guest */

> +    unsigned int          nr_grant_frames;

> +    /* Shared grant table (see include/public/grant_table.h). */

> +    union {

> +        void **shared_raw;

> +        struct grant_entry_v1 **shared_v1;

> +        union grant_entry_v2 **shared_v2;

> +    };

> +    /* Number of grant status frames shared with guest (for version 2) */

> +    unsigned int          nr_status_frames;

> +    /* State grant table (see include/public/grant_table.h). */

> +    grant_status_t       **status;

> +    /* Active grant table. */

> +    struct active_grant_entry **active;

> +    /* Mapping tracking table per vcpu. */

> +    struct grant_mapping **maptrack;

> +    unsigned int          maptrack_limit;

> +    /* Lock protecting the maptrack limit */

> +    spinlock_t            maptrack_lock;

> +    /* The defined versions are 1 and 2.  Set to 0 if we don't know

> +       what version to use yet. */

> +    unsigned              gt_version;

> +};

> +

> +#ifndef DEFAULT_MAX_NR_GRANT_FRAMES /* to allow arch to override

> */

> +/* Default maximum size of a grant table. [POLICY] */

> +#define DEFAULT_MAX_NR_GRANT_FRAMES   32

> +#endif

> +

>  unsigned int __read_mostly max_grant_frames;

>  integer_param("gnttab_max_frames", max_grant_frames);

> 

> @@ -118,6 +154,18 @@ struct grant_mapping {

>      uint32_t pad;           /* round size to a power of 2 */

>  };

> 

> +/* Number of grant table frames. Caller must hold d's grant table lock. */

> +static inline unsigned int nr_grant_frames(const struct grant_table *gt)

> +{

> +    return gt->nr_grant_frames;

> +}

> +

> +/* Number of status grant table frames. Caller must hold d's gr. table lock.*/

> +static inline unsigned int nr_status_frames(const struct grant_table *gt)

> +{

> +    return gt->nr_status_frames;

> +}

> +

>  #define MAPTRACK_PER_PAGE (PAGE_SIZE / sizeof(struct grant_mapping))

>  #define maptrack_entry(t, e) \

>      ((t)->maptrack[(e)/MAPTRACK_PER_PAGE][(e)%MAPTRACK_PER_PAGE])

> @@ -197,7 +245,27 @@ static inline void act_set_gfn(struct

> active_grant_entry *act, gfn_t gfn)

>  #endif

>  }

> 

> -DEFINE_PERCPU_RWLOCK_GLOBAL(grant_rwlock);

> +static DEFINE_PERCPU_RWLOCK_GLOBAL(grant_rwlock);

> +

> +static inline void grant_read_lock(struct grant_table *gt)

> +{

> +    percpu_read_lock(grant_rwlock, &gt->lock);

> +}

> +

> +static inline void grant_read_unlock(struct grant_table *gt)

> +{

> +    percpu_read_unlock(grant_rwlock, &gt->lock);

> +}

> +

> +static inline void grant_write_lock(struct grant_table *gt)

> +{

> +    percpu_write_lock(grant_rwlock, &gt->lock);

> +}

> +

> +static inline void grant_write_unlock(struct grant_table *gt)

> +{

> +    percpu_write_unlock(grant_rwlock, &gt->lock);

> +}

> 

>  static inline void gnttab_flush_tlb(const struct domain *d)

>  {

> @@ -250,6 +318,15 @@ static inline void active_entry_release(struct

> active_grant_entry *act)

>      spin_unlock(&act->lock);

>  }

> 

> +#define GRANT_STATUS_PER_PAGE (PAGE_SIZE / sizeof(grant_status_t))

> +#define GRANT_PER_PAGE (PAGE_SIZE / sizeof(grant_entry_v2_t))

> +/* Number of grant table status entries. Caller must hold d's gr. table lock.*/

> +static inline unsigned int grant_to_status_frames(unsigned int

> grant_frames)

> +{

> +    return (grant_frames * GRANT_PER_PAGE + GRANT_STATUS_PER_PAGE

> - 1) /

> +        GRANT_STATUS_PER_PAGE;

> +}

> +

>  /* Check if the page has been paged out, or needs unsharing.

>     If rc == GNTST_okay, *page contains the page struct with a ref taken.

>     Caller must do put_page(*page).

> @@ -1580,7 +1657,7 @@ gnttab_unpopulate_status_frames(struct domain

> *d, struct grant_table *gt)

>   * Grow the grant table. The caller must hold the grant table's

>   * write lock before calling this function.

>   */

> -int

> +static int

>  gnttab_grow_table(struct domain *d, unsigned int req_nr_frames)

>  {

>      struct grant_table *gt = d->grant_table;

> diff --git a/xen/include/xen/grant_table.h b/xen/include/xen/grant_table.h

> index 43ec6c4d80..43b07e60c5 100644

> --- a/xen/include/xen/grant_table.h

> +++ b/xen/include/xen/grant_table.h

> @@ -29,66 +29,9 @@

>  #include <asm/page.h>

>  #include <asm/grant_table.h>

> 

> -#ifndef DEFAULT_MAX_NR_GRANT_FRAMES /* to allow arch to override */

> -/* Default maximum size of a grant table. [POLICY] */

> -#define DEFAULT_MAX_NR_GRANT_FRAMES   32

> -#endif

>  /* The maximum size of a grant table. */

>  extern unsigned int max_grant_frames;

> 

> -DECLARE_PERCPU_RWLOCK_GLOBAL(grant_rwlock);

> -

> -/* Per-domain grant information. */

> -struct grant_table {

> -    /*

> -     * Lock protecting updates to grant table state (version, active

> -     * entry list, etc.)

> -     */

> -    percpu_rwlock_t       lock;

> -    /* Table size. Number of frames shared with guest */

> -    unsigned int          nr_grant_frames;

> -    /* Shared grant table (see include/public/grant_table.h). */

> -    union {

> -        void **shared_raw;

> -        struct grant_entry_v1 **shared_v1;

> -        union grant_entry_v2 **shared_v2;

> -    };

> -    /* Number of grant status frames shared with guest (for version 2) */

> -    unsigned int          nr_status_frames;

> -    /* State grant table (see include/public/grant_table.h). */

> -    grant_status_t       **status;

> -    /* Active grant table. */

> -    struct active_grant_entry **active;

> -    /* Mapping tracking table per vcpu. */

> -    struct grant_mapping **maptrack;

> -    unsigned int          maptrack_limit;

> -    /* Lock protecting the maptrack limit */

> -    spinlock_t            maptrack_lock;

> -    /* The defined versions are 1 and 2.  Set to 0 if we don't know

> -       what version to use yet. */

> -    unsigned              gt_version;

> -};

> -

> -static inline void grant_read_lock(struct grant_table *gt)

> -{

> -    percpu_read_lock(grant_rwlock, &gt->lock);

> -}

> -

> -static inline void grant_read_unlock(struct grant_table *gt)

> -{

> -    percpu_read_unlock(grant_rwlock, &gt->lock);

> -}

> -

> -static inline void grant_write_lock(struct grant_table *gt)

> -{

> -    percpu_write_lock(grant_rwlock, &gt->lock);

> -}

> -

> -static inline void grant_write_unlock(struct grant_table *gt)

> -{

> -    percpu_write_unlock(grant_rwlock, &gt->lock);

> -}

> -

>  /* Create/destroy per-domain grant table context. */

>  int grant_table_create(

>      struct domain *d);

> @@ -106,33 +49,6 @@ void

>  gnttab_release_mappings(

>      struct domain *d);

> 

> -/* Increase the size of a domain's grant table.

> - * Caller must hold d's grant table write lock.

> - */

> -int

> -gnttab_grow_table(struct domain *d, unsigned int req_nr_frames);

> -

> -/* Number of grant table frames. Caller must hold d's grant table lock. */

> -static inline unsigned int nr_grant_frames(struct grant_table *gt)

> -{

> -    return gt->nr_grant_frames;

> -}

> -

> -/* Number of status grant table frames. Caller must hold d's gr. table lock.*/

> -static inline unsigned int nr_status_frames(struct grant_table *gt)

> -{

> -    return gt->nr_status_frames;

> -}

> -

> -#define GRANT_STATUS_PER_PAGE (PAGE_SIZE / sizeof(grant_status_t))

> -#define GRANT_PER_PAGE (PAGE_SIZE / sizeof(grant_entry_v2_t))

> -/* Number of grant table status entries. Caller must hold d's gr. table lock.*/

> -static inline unsigned int grant_to_status_frames(int grant_frames)

> -{

> -    return (grant_frames * GRANT_PER_PAGE + GRANT_STATUS_PER_PAGE

> - 1) /

> -        GRANT_STATUS_PER_PAGE;

> -}

> -

>  int mem_sharing_gref_to_gfn(struct grant_table *gt, grant_ref_t ref,

>                              gfn_t *gfn, uint16_t *status);

> 

> --

> 2.12.3

> 

> 

> _______________________________________________

> Xen-devel mailing list

> Xen-devel@lists.xen.org

> https://lists.xen.org/xen-devel
Wei Liu Sept. 6, 2017, 10:11 a.m. UTC | #2
On Wed, Sep 06, 2017 at 10:26:26AM +0200, Juergen Gross wrote:
> +struct grant_table {
> +    /*
> +     * Lock protecting updates to grant table state (version, active
> +     * entry list, etc.)
> +     */
> +    percpu_rwlock_t       lock;
> +    /* Table size. Number of frames shared with guest */
> +    unsigned int          nr_grant_frames;
> +    /* Shared grant table (see include/public/grant_table.h). */
> +    union {
> +        void **shared_raw;
> +        struct grant_entry_v1 **shared_v1;
> +        union grant_entry_v2 **shared_v2;
> +    };
> +    /* Number of grant status frames shared with guest (for version 2) */
> +    unsigned int          nr_status_frames;
> +    /* State grant table (see include/public/grant_table.h). */
> +    grant_status_t       **status;
> +    /* Active grant table. */
> +    struct active_grant_entry **active;
> +    /* Mapping tracking table per vcpu. */
> +    struct grant_mapping **maptrack;
> +    unsigned int          maptrack_limit;
> +    /* Lock protecting the maptrack limit */
> +    spinlock_t            maptrack_lock;
> +    /* The defined versions are 1 and 2.  Set to 0 if we don't know
> +       what version to use yet. */

Could you please fix the style of the comment?

Otherwise:
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Jürgen Groß Sept. 6, 2017, 10:12 a.m. UTC | #3
On 06/09/17 12:11, Wei Liu wrote:
> On Wed, Sep 06, 2017 at 10:26:26AM +0200, Juergen Gross wrote:
>> +struct grant_table {
>> +    /*
>> +     * Lock protecting updates to grant table state (version, active
>> +     * entry list, etc.)
>> +     */
>> +    percpu_rwlock_t       lock;
>> +    /* Table size. Number of frames shared with guest */
>> +    unsigned int          nr_grant_frames;
>> +    /* Shared grant table (see include/public/grant_table.h). */
>> +    union {
>> +        void **shared_raw;
>> +        struct grant_entry_v1 **shared_v1;
>> +        union grant_entry_v2 **shared_v2;
>> +    };
>> +    /* Number of grant status frames shared with guest (for version 2) */
>> +    unsigned int          nr_status_frames;
>> +    /* State grant table (see include/public/grant_table.h). */
>> +    grant_status_t       **status;
>> +    /* Active grant table. */
>> +    struct active_grant_entry **active;
>> +    /* Mapping tracking table per vcpu. */
>> +    struct grant_mapping **maptrack;
>> +    unsigned int          maptrack_limit;
>> +    /* Lock protecting the maptrack limit */
>> +    spinlock_t            maptrack_lock;
>> +    /* The defined versions are 1 and 2.  Set to 0 if we don't know
>> +       what version to use yet. */
> 
> Could you please fix the style of the comment?

Okay.


Juergen

> 
> Otherwise:
> Reviewed-by: Wei Liu <wei.liu2@citrix.com>
>
diff mbox

Patch

diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
index 4c2e9e40a5..a94dfdda7b 100644
--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -40,6 +40,42 @@ 
 #include <xsm/xsm.h>
 #include <asm/flushtlb.h>
 
+/* Per-domain grant information. */
+struct grant_table {
+    /*
+     * Lock protecting updates to grant table state (version, active
+     * entry list, etc.)
+     */
+    percpu_rwlock_t       lock;
+    /* Table size. Number of frames shared with guest */
+    unsigned int          nr_grant_frames;
+    /* Shared grant table (see include/public/grant_table.h). */
+    union {
+        void **shared_raw;
+        struct grant_entry_v1 **shared_v1;
+        union grant_entry_v2 **shared_v2;
+    };
+    /* Number of grant status frames shared with guest (for version 2) */
+    unsigned int          nr_status_frames;
+    /* State grant table (see include/public/grant_table.h). */
+    grant_status_t       **status;
+    /* Active grant table. */
+    struct active_grant_entry **active;
+    /* Mapping tracking table per vcpu. */
+    struct grant_mapping **maptrack;
+    unsigned int          maptrack_limit;
+    /* Lock protecting the maptrack limit */
+    spinlock_t            maptrack_lock;
+    /* The defined versions are 1 and 2.  Set to 0 if we don't know
+       what version to use yet. */
+    unsigned              gt_version;
+};
+
+#ifndef DEFAULT_MAX_NR_GRANT_FRAMES /* to allow arch to override */
+/* Default maximum size of a grant table. [POLICY] */
+#define DEFAULT_MAX_NR_GRANT_FRAMES   32
+#endif
+
 unsigned int __read_mostly max_grant_frames;
 integer_param("gnttab_max_frames", max_grant_frames);
 
@@ -118,6 +154,18 @@  struct grant_mapping {
     uint32_t pad;           /* round size to a power of 2 */
 };
 
+/* Number of grant table frames. Caller must hold d's grant table lock. */
+static inline unsigned int nr_grant_frames(const struct grant_table *gt)
+{
+    return gt->nr_grant_frames;
+}
+
+/* Number of status grant table frames. Caller must hold d's gr. table lock.*/
+static inline unsigned int nr_status_frames(const struct grant_table *gt)
+{
+    return gt->nr_status_frames;
+}
+
 #define MAPTRACK_PER_PAGE (PAGE_SIZE / sizeof(struct grant_mapping))
 #define maptrack_entry(t, e) \
     ((t)->maptrack[(e)/MAPTRACK_PER_PAGE][(e)%MAPTRACK_PER_PAGE])
@@ -197,7 +245,27 @@  static inline void act_set_gfn(struct active_grant_entry *act, gfn_t gfn)
 #endif
 }
 
-DEFINE_PERCPU_RWLOCK_GLOBAL(grant_rwlock);
+static DEFINE_PERCPU_RWLOCK_GLOBAL(grant_rwlock);
+
+static inline void grant_read_lock(struct grant_table *gt)
+{
+    percpu_read_lock(grant_rwlock, &gt->lock);
+}
+
+static inline void grant_read_unlock(struct grant_table *gt)
+{
+    percpu_read_unlock(grant_rwlock, &gt->lock);
+}
+
+static inline void grant_write_lock(struct grant_table *gt)
+{
+    percpu_write_lock(grant_rwlock, &gt->lock);
+}
+
+static inline void grant_write_unlock(struct grant_table *gt)
+{
+    percpu_write_unlock(grant_rwlock, &gt->lock);
+}
 
 static inline void gnttab_flush_tlb(const struct domain *d)
 {
@@ -250,6 +318,15 @@  static inline void active_entry_release(struct active_grant_entry *act)
     spin_unlock(&act->lock);
 }
 
+#define GRANT_STATUS_PER_PAGE (PAGE_SIZE / sizeof(grant_status_t))
+#define GRANT_PER_PAGE (PAGE_SIZE / sizeof(grant_entry_v2_t))
+/* Number of grant table status entries. Caller must hold d's gr. table lock.*/
+static inline unsigned int grant_to_status_frames(unsigned int grant_frames)
+{
+    return (grant_frames * GRANT_PER_PAGE + GRANT_STATUS_PER_PAGE - 1) /
+        GRANT_STATUS_PER_PAGE;
+}
+
 /* Check if the page has been paged out, or needs unsharing.
    If rc == GNTST_okay, *page contains the page struct with a ref taken.
    Caller must do put_page(*page).
@@ -1580,7 +1657,7 @@  gnttab_unpopulate_status_frames(struct domain *d, struct grant_table *gt)
  * Grow the grant table. The caller must hold the grant table's
  * write lock before calling this function.
  */
-int
+static int
 gnttab_grow_table(struct domain *d, unsigned int req_nr_frames)
 {
     struct grant_table *gt = d->grant_table;
diff --git a/xen/include/xen/grant_table.h b/xen/include/xen/grant_table.h
index 43ec6c4d80..43b07e60c5 100644
--- a/xen/include/xen/grant_table.h
+++ b/xen/include/xen/grant_table.h
@@ -29,66 +29,9 @@ 
 #include <asm/page.h>
 #include <asm/grant_table.h>
 
-#ifndef DEFAULT_MAX_NR_GRANT_FRAMES /* to allow arch to override */
-/* Default maximum size of a grant table. [POLICY] */
-#define DEFAULT_MAX_NR_GRANT_FRAMES   32
-#endif
 /* The maximum size of a grant table. */
 extern unsigned int max_grant_frames;
 
-DECLARE_PERCPU_RWLOCK_GLOBAL(grant_rwlock);
-
-/* Per-domain grant information. */
-struct grant_table {
-    /*
-     * Lock protecting updates to grant table state (version, active
-     * entry list, etc.)
-     */
-    percpu_rwlock_t       lock;
-    /* Table size. Number of frames shared with guest */
-    unsigned int          nr_grant_frames;
-    /* Shared grant table (see include/public/grant_table.h). */
-    union {
-        void **shared_raw;
-        struct grant_entry_v1 **shared_v1;
-        union grant_entry_v2 **shared_v2;
-    };
-    /* Number of grant status frames shared with guest (for version 2) */
-    unsigned int          nr_status_frames;
-    /* State grant table (see include/public/grant_table.h). */
-    grant_status_t       **status;
-    /* Active grant table. */
-    struct active_grant_entry **active;
-    /* Mapping tracking table per vcpu. */
-    struct grant_mapping **maptrack;
-    unsigned int          maptrack_limit;
-    /* Lock protecting the maptrack limit */
-    spinlock_t            maptrack_lock;
-    /* The defined versions are 1 and 2.  Set to 0 if we don't know
-       what version to use yet. */
-    unsigned              gt_version;
-};
-
-static inline void grant_read_lock(struct grant_table *gt)
-{
-    percpu_read_lock(grant_rwlock, &gt->lock);
-}
-
-static inline void grant_read_unlock(struct grant_table *gt)
-{
-    percpu_read_unlock(grant_rwlock, &gt->lock);
-}
-
-static inline void grant_write_lock(struct grant_table *gt)
-{
-    percpu_write_lock(grant_rwlock, &gt->lock);
-}
-
-static inline void grant_write_unlock(struct grant_table *gt)
-{
-    percpu_write_unlock(grant_rwlock, &gt->lock);
-}
-
 /* Create/destroy per-domain grant table context. */
 int grant_table_create(
     struct domain *d);
@@ -106,33 +49,6 @@  void
 gnttab_release_mappings(
     struct domain *d);
 
-/* Increase the size of a domain's grant table.
- * Caller must hold d's grant table write lock.
- */
-int
-gnttab_grow_table(struct domain *d, unsigned int req_nr_frames);
-
-/* Number of grant table frames. Caller must hold d's grant table lock. */
-static inline unsigned int nr_grant_frames(struct grant_table *gt)
-{
-    return gt->nr_grant_frames;
-}
-
-/* Number of status grant table frames. Caller must hold d's gr. table lock.*/
-static inline unsigned int nr_status_frames(struct grant_table *gt)
-{
-    return gt->nr_status_frames;
-}
-
-#define GRANT_STATUS_PER_PAGE (PAGE_SIZE / sizeof(grant_status_t))
-#define GRANT_PER_PAGE (PAGE_SIZE / sizeof(grant_entry_v2_t))
-/* Number of grant table status entries. Caller must hold d's gr. table lock.*/
-static inline unsigned int grant_to_status_frames(int grant_frames)
-{
-    return (grant_frames * GRANT_PER_PAGE + GRANT_STATUS_PER_PAGE - 1) /
-        GRANT_STATUS_PER_PAGE;
-}
-
 int mem_sharing_gref_to_gfn(struct grant_table *gt, grant_ref_t ref,
                             gfn_t *gfn, uint16_t *status);