All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Orzel <michal.orzel@amd.com>
To: Luca Fancellu <luca.fancellu@arm.com>, <xen-devel@lists.xenproject.org>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>,
	Bertrand Marquis <bertrand.marquis@arm.com>,
	"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>
Subject: Re: [PATCH 03/11] xen/arm: Introduce a generic way to access memory bank structures
Date: Tue, 19 Mar 2024 14:10:08 +0100	[thread overview]
Message-ID: <73dbf297-31ed-4cf1-b081-c6f82c234de8@amd.com> (raw)
In-Reply-To: <20240312130331.78418-4-luca.fancellu@arm.com>

Hi Luca,

On 12/03/2024 14:03, Luca Fancellu wrote:
> 
> 
> Currently the 'stuct meminfo' is defining a static defined array of
> 'struct membank' of NR_MEM_BANKS elements, some feature like
> shared memory don't require such amount of memory allocation but
> might want to reuse existing code to manipulate this kind of
> structure that is just as 'struct meminfo' but less bulky.
> 
> For this reason introduce a generic way to access this kind of
> structure using a new stucture 'struct membanks', which implements
s/stucture/structure

> all the fields needed by a structure related to memory banks
> without the need to specify at build time the size of the
> 'struct membank' array.
Might be beneficial here to mention the use of FAM.

> 
> Modify 'struct meminfo' to implement the field related to the new
> introduced structure, given the change all usage of this structure
> are updated in this way:
>  - code accessing bootinfo.{mem,reserved_mem,acpi} field now uses
>    3 new introduced static inline helpers to access the new field
>    of 'struct meminfo' named 'common'.
>  - code accessing 'struct kernel_info *' member 'mem' now use the
>    new introduced macro 'kernel_info_get_mem(...)' to access the
>    new field of 'struct meminfo' named 'common'.
> 
> Constify pointers where needed.
> 
> Suggested-by: Julien Grall <julien@xen.org>
> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
> ---
>  xen/arch/arm/acpi/domain_build.c        |   6 +-
>  xen/arch/arm/arm32/mmu/mm.c             |  44 +++++-----
>  xen/arch/arm/arm64/mmu/mm.c             |   2 +-
>  xen/arch/arm/bootfdt.c                  |  27 +++---
>  xen/arch/arm/dom0less-build.c           |  18 ++--
>  xen/arch/arm/domain_build.c             | 106 +++++++++++++-----------
>  xen/arch/arm/efi/efi-boot.h             |   8 +-
>  xen/arch/arm/efi/efi-dom0.c             |  13 +--
>  xen/arch/arm/include/asm/domain_build.h |   2 +-
>  xen/arch/arm/include/asm/kernel.h       |   9 ++
>  xen/arch/arm/include/asm/setup.h        |  40 ++++++++-
>  xen/arch/arm/include/asm/static-shmem.h |   4 +-
>  xen/arch/arm/kernel.c                   |  12 +--
>  xen/arch/arm/setup.c                    |  58 +++++++------
>  xen/arch/arm/static-memory.c            |  27 +++---
>  xen/arch/arm/static-shmem.c             |  34 ++++----
>  16 files changed, 243 insertions(+), 167 deletions(-)
Lots of mechanical changes but in general I like this approach.
I'd like other maintainers to share their opinion.

[...]

> @@ -1157,10 +1163,12 @@ int __init make_hypervisor_node(struct domain *d,
>      }
>      else
>      {
> -        ext_regions = xzalloc(struct meminfo);
> +        ext_regions = (struct membanks *)xzalloc(struct meminfo);
You're making assumption that struct membanks is the first member of meminfo but there's no sanity check.
Why not xzalloc_flex_struct()?

>          if ( !ext_regions )
>              return -ENOMEM;

[...]
> diff --git a/xen/arch/arm/include/asm/kernel.h b/xen/arch/arm/include/asm/kernel.h
> index 0a23e86c2d37..d28b843c01a9 100644
> --- a/xen/arch/arm/include/asm/kernel.h
> +++ b/xen/arch/arm/include/asm/kernel.h
> @@ -78,6 +78,15 @@ struct kernel_info {
>      };
>  };
> 
> +#define kernel_info_get_mem(kinfo) \
> +    (&(kinfo)->mem.common)
Why this is a macro but for bootinfo you use static inline helpers?

> +
> +#define KERNEL_INFO_INIT \
NIT: in most places we prefer \ to be aligned (the same apply to other places)

> +{ \
> +    .mem.common.max_banks = NR_MEM_BANKS, \
> +    .shm_mem.common.max_banks = NR_MEM_BANKS, \
> +}
> +
>  /*
>   * Probe the kernel to detemine its type and select a loader.
>   *
> diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.h
> index d15a88d2e0d1..a3e1dc8fdb6c 100644
> --- a/xen/arch/arm/include/asm/setup.h
> +++ b/xen/arch/arm/include/asm/setup.h
> @@ -56,8 +56,14 @@ struct membank {
>  #endif
>  };
> 
> -struct meminfo {
> +struct membanks {
>      unsigned int nr_banks;
> +    unsigned int max_banks;
> +    struct membank bank[];
> +};
> +
> +struct meminfo {
> +    struct membanks common;
You were supposed to make sure there is no extra padding here. I don't see any check in this patch.
I'd at least do sth like:
BUILD_BUG_ON((offsetof(struct membanks, bank)) != (offsetof(struct meminfo, bank)));

~Michal


  reply	other threads:[~2024-03-19 13:10 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-12 13:03 [PATCH 00/11] Static shared memory followup v2 - pt1 Luca Fancellu
2024-03-12 13:03 ` [PATCH 01/11] xen/arm: remove stale addr_cells/size_cells in assign_shared_memory Luca Fancellu
2024-03-12 13:03 ` [PATCH 02/11] xen/arm: avoid repetitive checking in process_shm_node Luca Fancellu
2024-03-19 10:57   ` Michal Orzel
2024-03-12 13:03 ` [PATCH 03/11] xen/arm: Introduce a generic way to access memory bank structures Luca Fancellu
2024-03-19 13:10   ` Michal Orzel [this message]
2024-03-19 13:30     ` Luca Fancellu
2024-03-20  9:30     ` Julien Grall
2024-03-12 13:03 ` [PATCH 04/11] xen/arm: Conditional compilation of kernel_info.shm_mem member Luca Fancellu
2024-03-19 14:58   ` Michal Orzel
2024-04-04  9:27     ` Luca Fancellu
2024-04-04  9:33       ` Michal Orzel
2024-03-12 13:03 ` [PATCH 05/11] xen/arm: Introduce helper for static memory pages Luca Fancellu
2024-03-20 10:41   ` Michal Orzel
2024-03-12 13:03 ` [PATCH 06/11] xen/arm: Avoid code duplication in find_unallocated_memory Luca Fancellu
2024-03-20 10:57   ` Michal Orzel
2024-03-20 14:53     ` Luca Fancellu
2024-03-21  9:02       ` Michal Orzel
2024-03-12 13:03 ` [PATCH 07/11] xen/arm: Avoid code duplication in check_reserved_regions_overlap Luca Fancellu
2024-03-12 13:03 ` [PATCH 08/11] xen/arm: Reduce struct membank size on static shared memory Luca Fancellu
2024-03-22 10:30   ` Michal Orzel
2024-04-04  9:33     ` Luca Fancellu
2024-04-04 11:19       ` Michal Orzel
2024-03-12 13:03 ` [PATCH 09/11] xen/arm: remove shm holes for extended regions Luca Fancellu
2024-03-22 15:09   ` Michal Orzel
2024-03-22 20:11     ` Luca Fancellu
2024-03-12 13:03 ` [PATCH 10/11] xen/arm: fix duplicate /reserved-memory node in Dom0 Luca Fancellu
2024-03-25  8:09   ` Michal Orzel
2024-03-12 13:03 ` [PATCH 11/11] xen/arm: List static shared memory regions as /memory nodes Luca Fancellu
2024-03-25  8:58   ` Michal Orzel
2024-03-26 14:19     ` Luca Fancellu
2024-03-27  8:27       ` Michal Orzel

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=73dbf297-31ed-4cf1-b081-c6f82c234de8@amd.com \
    --to=michal.orzel@amd.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=bertrand.marquis@arm.com \
    --cc=julien@xen.org \
    --cc=luca.fancellu@arm.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.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.