Xen-Devel Archive mirror
 help / color / mirror / Atom feed
From: Henry Wang <xin.wang2@amd.com>
To: Michal Orzel <michal.orzel@amd.com>, <xen-devel@lists.xenproject.org>
Cc: Anthony PERARD <anthony.perard@citrix.com>,
	Juergen Gross <jgross@suse.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>,
	Bertrand Marquis <bertrand.marquis@arm.com>,
	"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>,
	Alec Kwapis <alec.kwapis@medtronic.com>,
	"Daniel P . Smith" <dpsmith@apertussolutions.com>
Subject: Re: [PATCH 1/3] xen/arm/dom0less-build: Alloc magic pages for Dom0less DomUs from hypervisor
Date: Fri, 10 May 2024 15:42:32 +0800	[thread overview]
Message-ID: <d357beeb-6874-4262-8137-8b4145fd64c4@amd.com> (raw)
In-Reply-To: <5d3ead96-5079-4fa3-b5fd-4d9803c251b6@amd.com>

Hi Michal,

Thanks very much for taking a look!

On 5/10/2024 3:37 PM, Michal Orzel wrote:
> Hi Henry,
>
> On 26/04/2024 05:14, Henry Wang wrote:
>> There are use cases (for example using the PV driver) in Dom0less
>> setup that require Dom0less DomUs start immediately with Dom0, but
>> initialize XenStore later after Dom0's successful boot and call to
>> the init-dom0less application.
>>
>> An error message can seen from the init-dom0less application on
>> 1:1 direct-mapped domains:
>> ```
>> Allocating magic pages
>> memory.c:238:d0v0 mfn 0x39000 doesn't belong to d1
>> Error on alloc magic pages
>> ```
>> This is because currently the magic pages for Dom0less DomUs are
>> populated by the init-dom0less app through populate_physmap(), and
>> populate_physmap() automatically assumes gfn == mfn for 1:1 direct
>> mapped domains. This cannot be true for the magic pages that are
>> allocated later from the init-dom0less application executed in Dom0.
>> For domain using statically allocated memory but not 1:1 direct-mapped,
>> similar error "failed to retrieve a reserved page" can be seen as the
>> reserved memory list is empty at that time.
>>
>> To solve above issue, this commit allocates the magic pages for
>> Dom0less DomUs at the domain construction time. The base address/PFN
>> of the magic page region will be noted and communicated to the
>> init-dom0less application in Dom0.
>>
>> Reported-by: Alec Kwapis <alec.kwapis@medtronic.com>
>> Suggested-by: Daniel P. Smith <dpsmith@apertussolutions.com>
>> Signed-off-by: Henry Wang <xin.wang2@amd.com>
>> ---
>>   tools/libs/guest/xg_dom_arm.c |  1 -
>>   xen/arch/arm/dom0less-build.c | 22 ++++++++++++++++++++++
>>   xen/include/public/arch-arm.h |  1 +
>>   3 files changed, 23 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/libs/guest/xg_dom_arm.c b/tools/libs/guest/xg_dom_arm.c
>> index 2fd8ee7ad4..8cc7f27dbb 100644
>> --- a/tools/libs/guest/xg_dom_arm.c
>> +++ b/tools/libs/guest/xg_dom_arm.c
>> @@ -25,7 +25,6 @@
>>   
>>   #include "xg_private.h"
>>   
>> -#define NR_MAGIC_PAGES 4
> Moving only this macro to arch-arm.h while leaving the offsets does not make much sense to me.
> I think they all should be moved. This would also allow init-dom0less.h not to re-define XENSTORE_PFN_OFFSET.

Sounds good. Will do in v2.

>>   #define CONSOLE_PFN_OFFSET 0
>>   #define XENSTORE_PFN_OFFSET 1
>>   #define MEMACCESS_PFN_OFFSET 2
>> diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c
>> index fb63ec6fd1..40dc85c759 100644
>> --- a/xen/arch/arm/dom0less-build.c
>> +++ b/xen/arch/arm/dom0less-build.c
>> @@ -834,11 +834,33 @@ static int __init construct_domU(struct domain *d,
>>   
>>       if ( kinfo.dom0less_feature & DOM0LESS_XENSTORE )
>>       {
>> +        struct page_info *magic_pg;
>> +        mfn_t mfn;
>> +        gfn_t gfn;
>> +
>>           ASSERT(hardware_domain);
>>           rc = alloc_xenstore_evtchn(d);
>>           if ( rc < 0 )
>>               return rc;
>>           d->arch.hvm.params[HVM_PARAM_STORE_PFN] = ~0ULL;
>> +
>> +        d->max_pages += NR_MAGIC_PAGES;
>> +        magic_pg = alloc_domheap_pages(d, get_order_from_pages(NR_MAGIC_PAGES), 0);
> 80 char exceeded

Ooops, I am sorry. Will fix in v2.

>> +        if ( magic_pg == NULL )
>> +            return -ENOMEM;
>> +
>> +        mfn = page_to_mfn(magic_pg);
>> +        if ( !is_domain_direct_mapped(d) )
>> +            gfn = gaddr_to_gfn(GUEST_MAGIC_BASE);
>> +        else
>> +            gfn = gaddr_to_gfn(mfn_to_maddr(mfn));
>> +
>> +        rc = guest_physmap_add_pages(d, gfn, mfn, NR_MAGIC_PAGES);
>> +        if ( rc )
>> +        {
>> +            free_domheap_pages(magic_pg, get_order_from_pages(NR_MAGIC_PAGES));
>> +            return rc;
>> +        }
> Please create a function alloc_magic_pages to encapsulate the above block.

Sure. Will do.

Kind regards,
Henry


  reply	other threads:[~2024-05-10  7:42 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-26  3:14 [PATCH 0/3] Guest magic region allocation for 11 Dom0less domUs - Take two Henry Wang
2024-04-26  3:14 ` [PATCH 1/3] xen/arm/dom0less-build: Alloc magic pages for Dom0less DomUs from hypervisor Henry Wang
2024-04-30  0:27   ` Daniel P. Smith
2024-04-30  2:55     ` Henry Wang
2024-04-30 10:22       ` Daniel P. Smith
2024-05-06  3:13         ` Henry Wang
2024-05-10  7:37   ` Michal Orzel
2024-05-10  7:42     ` Henry Wang [this message]
2024-04-26  3:14 ` [PATCH 2/3] xen/arm, tools: Add a new HVM_PARAM_MAGIC_BASE_PFN key in HVMOP Henry Wang
2024-04-26  6:21   ` Jan Beulich
2024-04-26  6:30     ` Henry Wang
2024-04-26  6:50       ` Jan Beulich
2024-04-26  7:02         ` Henry Wang
2024-04-30  0:31     ` Daniel P. Smith
2024-04-30  2:51       ` Henry Wang
2024-04-30  6:11         ` Jan Beulich
2024-04-30  8:12           ` Henry Wang
2024-04-30  8:51             ` Jan Beulich
2024-04-30  0:35   ` Daniel P. Smith
2024-04-30  1:25     ` Daniel P. Smith
2024-05-02 18:08   ` Stefano Stabellini
2024-05-06  2:01     ` Henry Wang
2024-04-26  3:14 ` [PATCH 3/3] tools/init-dom0less: Avoid hardcoding GUEST_MAGIC_BASE Henry Wang

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=d357beeb-6874-4262-8137-8b4145fd64c4@amd.com \
    --to=xin.wang2@amd.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=alec.kwapis@medtronic.com \
    --cc=anthony.perard@citrix.com \
    --cc=bertrand.marquis@arm.com \
    --cc=dpsmith@apertussolutions.com \
    --cc=jgross@suse.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.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 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 read-only IMAP folder(s) and NNTP newsgroup(s).