[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v6 5/7] init-dom0less: allocate xenstore page is not already allocated


  • To: "Stabellini, Stefano" <stefano.stabellini@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: "Orzel, Michal" <Michal.Orzel@xxxxxxx>
  • Date: Fri, 7 Feb 2025 11:36:28 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CWdJfgw9MbL7LVHWuxihk+rZ3qJXHnriM9WwmEMx+PE=; b=pXX0v5eW+bg2cOIzUQch2db8ALvZIuv6+BW4qWszRyTVo0pTeHk2PRp3Dw2FwwRO7DTLEsJwq50zX9Qve5ob08jaU0r+0OKKJ+wN86U/tqQCHU4HZZ+qRhh0LEdTHltCxKvX+H1xDNrZuCAdJW79d0F+pAy5LGeMcxaLFlQA5Dr9/wDS8XuVV5SJlnyjH6X/U2wIxREijiQ9vLwmJgkwAIvkyitn+Q/bsiLTUF+w5+XomSQogokLB0azLY8qJ7VJfTtkWLdXBqPQcd8EHn8DCEtlvN1WK2WVBmHu26YTnYfM8iiy8GAg1IdvWzKIFmcUVIBX+GN1R/fAo9VdmfXyzg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=c7RExT4qDpz6VeARAAkpgRdhsWtI+rl3Y9AyFGWwz7O00E3VrOIGsYk7uJXt6crZIk+VIXpTGspqWZPrfZMihzOgf6KkVXKPHJs4YRWVt09c9ZI9jTtkaQxIHDiLL6d+QSEfXk7P3EGLrUKZeHc2PeX/I8RLjelZCP6Rdzbi4zws3vY0OzJXN7TpYQNpaxiPk+smzRd8DRn9qIieawio5KaE6A1XZ3+jwUfhHPvJDnmOzihURWAAXriyc+e+Xrabm+KQ0dKwTvvitycGruaScP+fLL0OK5eDG0htH8sYPiKr1GTxKrlJX/p3YlA4TmMLTtq31uY7aBAKnxYfstfZvA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com;
  • Cc: "sstabellini@xxxxxxxxxx" <sstabellini@xxxxxxxxxx>, "bertrand.marquis@xxxxxxx" <bertrand.marquis@xxxxxxx>, "julien@xxxxxxx" <julien@xxxxxxx>, "Volodymyr_Babchuk@xxxxxxxx" <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Fri, 07 Feb 2025 11:36:39 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHbeQMlExRkfeH0QUWanXHTtrhJ6LM7twWA
  • Thread-topic: [PATCH v6 5/7] init-dom0less: allocate xenstore page is not already allocated

NIT: commit title: s/is/if/

On 07/02/2025 02:53, Stefano Stabellini wrote:
> We check if the xenstore page is already allocated. If yes, there is
> nothing to do. If no, we proceed allocating it.
The commit message lacks justification which is to support old 
unpatched/unfixed kernels.

> 
> Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxx>
> ---
> Changes in v6:
> - remove double blank lines
> 
>  tools/helpers/init-dom0less.c | 53 +++++++++++++++++++++++++++++++++--
>  1 file changed, 50 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/helpers/init-dom0less.c b/tools/helpers/init-dom0less.c
> index 2b51965fa7..78c59ec5e7 100644
> --- a/tools/helpers/init-dom0less.c
> +++ b/tools/helpers/init-dom0less.c
> @@ -16,8 +16,34 @@
>  
>  #include "init-dom-json.h"
>  
> +#define XENSTORE_PFN_OFFSET 1
>  #define STR_MAX_LENGTH 128
>  
> +static int alloc_xs_page(struct xc_interface_core *xch,
> +                         libxl_dominfo *info,
> +                         uint64_t *xenstore_pfn)
> +{
> +    int rc;
> +    const xen_pfn_t base = GUEST_MAGIC_BASE >> XC_PAGE_SHIFT;
> +    xen_pfn_t p2m = (GUEST_MAGIC_BASE >> XC_PAGE_SHIFT) + 
> XENSTORE_PFN_OFFSET;
base already contains shifted value so why not use it?

> +
> +    rc = xc_domain_setmaxmem(xch, info->domid,
> +                             info->max_memkb + (XC_PAGE_SIZE/1024));
> +    if (rc < 0)
> +        return rc;
> +
> +    rc = xc_domain_populate_physmap_exact(xch, info->domid, 1, 0, 0, &p2m);
> +    if (rc < 0)
> +        return rc;
> +
> +    *xenstore_pfn = base + XENSTORE_PFN_OFFSET;
> +    rc = xc_clear_domain_page(xch, info->domid, *xenstore_pfn);
> +    if (rc < 0)
> +        return rc;
> +
> +    return 0;
> +}
> +
>  static int get_xs_page(struct xc_interface_core *xch, libxl_dominfo *info,
>                         uint64_t *xenstore_pfn)
>  {
> @@ -233,9 +259,30 @@ static int init_domain(struct xs_handle *xsh,
>          return 0;
>  
>      /* Get xenstore page */
> -    if (get_xs_page(xch, info, &xenstore_pfn) != 0) {
> -        printf("Error on getting xenstore page\n");
> -        return 1;
> +    if (get_xs_page(xch, info, &xenstore_pfn) != 0 || xenstore_pfn == ~0ULL) 
> {
If get_xs_page() returns != 0, then something is wrong and we definitiely 
should not try
to allocate a page. The only reason the script should allocate a page is if 
xenstore_pfn is
invalid i.e. ~0ULL or not set i.e. 0. At this point we already validated that 
guest is xenstore enhanced
so the only possibility is ~0ULL. So the code should be:

if (get_xs_page(xch, info, &xenstore_pfn) != 0) {
    return 1;
}

if (xenstore_pfn == ~0ULL) {
...

Other than that:
Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>

~Michal

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.