xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Daniel De Graaf <dgdegra@tycho.nsa.gov>
To: Jan Beulich <JBeulich@suse.com>
Cc: Keir Fraser <keir@xen.org>,
	Ian Campbell <ian.campbell@citrix.com>, Tim Deegan <tim@xen.org>,
	xen-devel@lists.xen.org,
	Stefano Stabellini <stefano.stabellini@citrix.com>,
	Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
	Xiantao Zhang <xiantao.zhang@intel.com>
Subject: Re: [PATCH 1/6] xen: use domid check in is_hardware_domain
Date: Wed, 05 Mar 2014 10:25:51 -0500	[thread overview]
Message-ID: <531741FF.1000509@tycho.nsa.gov> (raw)
In-Reply-To: <5316FB0E02000078001211A9@nat28.tlf.novell.com>

On 03/05/2014 04:23 AM, Jan Beulich wrote:
>>>> On 04.03.14 at 23:51, Daniel De Graaf <dgdegra@tycho.nsa.gov> wrote:
>> The hardware domain manages devices for PCI pass-through to driver
>> domains or can act as a driver domain itself, depending on the desired
>> degree of disaggregation.  It is also the domain managing devices that
>> do not support pass-through: PCI configuration space access, parsing the
>> hardware ACPI tables and system power or machine check events.  This is
>> the only domain where is_hardware_domain() is true.  The return of
>> is_control_domain() is false for this domain.
>
> "s/is/may be/" ?

I had intended this sentence to describe the model, where the return is
always false. However, I agree with the change to avoid confusion that
the two is_*_domain() functions are exclusive.

>> --- a/xen/arch/x86/domain.c
>> +++ b/xen/arch/x86/domain.c
>> @@ -1505,7 +1505,7 @@ void context_switch(struct vcpu *prev, struct vcpu *next)
>>           }
>>
>>           set_cpuid_faulting(is_pv_vcpu(next) &&
>> -                           (next->domain->domain_id != 0));
>> +                           !is_control_domain(next->domain));
>
> I can't see why the hardware domain (which can't be migrated)
> should be prevented from seeing the real CPUID values. It's
> less obvious whether a control domain should always see real
> values. Hence if you think the latter should be the case (as the
> change above shows), I think you should check for both cases
> here.

Agreed, the hardware domain also needs to be checked for here. The
reason the control domain is present is that it needs to see real
CPUID values in order to set CPUID policy for guests based on the
real hardware values.

>> --- a/xen/arch/x86/traps.c
>> +++ b/xen/arch/x86/traps.c
>> @@ -738,7 +738,7 @@ void pv_cpuid(struct cpu_user_regs *regs)
>>       c = regs->ecx;
>>       d = regs->edx;
>>
>> -    if ( current->domain->domain_id != 0 )
>> +    if ( !is_control_domain(current->domain) )
>
> The same consideration applies here then, obviously.
>
>> --- a/xen/common/domain.c
>> +++ b/xen/common/domain.c
>> @@ -242,7 +242,7 @@ struct domain *domain_create(
>>       else if ( domcr_flags & DOMCRF_pvh )
>>           d->guest_type = guest_type_pvh;
>>
>> -    if ( domid == 0 )
>> +    if ( is_hardware_domain(d) )
>>       {
>>           d->is_pinned = opt_dom0_vcpus_pin;
>>           d->disable_migrate = 1;
>> @@ -267,10 +267,10 @@ struct domain *domain_create(
>>           d->is_paused_by_controller = 1;
>>           atomic_inc(&d->pause_count);
>>
>> -        if ( domid )
>> -            d->nr_pirqs = nr_static_irqs + extra_domU_irqs;
>> -        else
>> +        if ( is_hardware_domain(d) )
>>               d->nr_pirqs = nr_static_irqs + extra_dom0_irqs;
>> +        else
>> +            d->nr_pirqs = nr_static_irqs + extra_domU_irqs;
>
> I'd prefer the if/else cases to remain as they are - makes the patch
> smaller, and fits better with the (weak) model of using the if branch
> for the common case and the else one for the special one (outside
> of error handling of course).

OK. I prefer to avoid the if (!foo) bar; else baz; construct where
possible, but common case first is a good reason to use it.

>> --- a/xen/common/xenoprof.c
>> +++ b/xen/common/xenoprof.c
>> @@ -603,7 +603,7 @@ static int xenoprof_op_init(XEN_GUEST_HANDLE_PARAM(void) arg)
>>
>>       xenoprof_init.is_primary =
>>           ((xenoprof_primary_profiler == d) ||
>> -         ((xenoprof_primary_profiler == NULL) && (d->domain_id == 0)));
>> +         ((xenoprof_primary_profiler == NULL) && is_control_domain(d)));
>
> Do you really consider profiling a control domain property? This is
> even more so questionable without knowing whether you checked
> that there are no issues with all of the sudden there perhaps
> being more than one domain eligible for becoming the primary
> profiler - the oprofile code isn't in that good a shape to be certain
> without explicit checking.
>
> Jan

I don't directly consider profiling to be a control domain property, but
I also don't consider it a hardware domain property, and it does need to
be restricted in some way. I could make a separate patch changing the
condition to use an XSM hook, only setting xenoprof_primary_profiler if
the domain is allowed the XEN__PRIVPROFILE permission, but this still
could cause multiple domains to be eligible.

 From my cursory examination when I made this change, the first domain to
try becoming the primary profiler will succeed and be assigned to
xenoprof_primary_profiler. Later domains will not be considered since the
primary will already be set.

One thing I had not considered that may be a problem: if the profiling
domain is shut down without calling XENOPROF_shutdown, it will not be
possible to use profiling this boot unless the struct domain* is reused.
This may then become a security issue because an arbitrary domain is
now the primary profiler, although the XSM policy should prevent any
actions by a domain not permitted to use the profiling hypercalls.
Using is_hardware_domain here avoids that problem (as the hardware domain
may never shut down or be destroyed), so that may be the simplest
solution until a better model of who is responsible for profiling is
presented.

-- 
Daniel De Graaf
National Security Agency

  reply	other threads:[~2014-03-05 15:25 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-04 22:51 [PATCH 0/6] xen: Hardware domain support Daniel De Graaf
2014-03-04 22:51 ` [PATCH 1/6] xen: use domid check in is_hardware_domain Daniel De Graaf
2014-03-05  3:44   ` Julien Grall
2014-03-05  9:23   ` Jan Beulich
2014-03-05 15:25     ` Daniel De Graaf [this message]
2014-03-05 15:45       ` Jan Beulich
2014-03-05 21:23         ` Daniel De Graaf
2014-03-11 13:10       ` Ian Campbell
2014-03-04 22:51 ` [PATCH 2/6] xen/iommu: Move dom0 setup code out of __init Daniel De Graaf
2014-03-05  9:56   ` Jan Beulich
2014-03-05 22:25     ` Daniel De Graaf
2014-03-06  9:53       ` Jan Beulich
2014-03-04 22:51 ` [PATCH 3/6] xen: prevent 0 from being used as a dynamic domid Daniel De Graaf
2014-03-04 22:51 ` [PATCH 4/6] xen: Allow hardare domain != dom0 Daniel De Graaf
2014-03-05  3:50   ` Julien Grall
2014-03-05 23:04     ` Daniel De Graaf
2014-03-05 10:04   ` Jan Beulich
2014-03-05 23:04     ` Daniel De Graaf
2014-03-06  9:54       ` Jan Beulich
2014-03-04 22:51 ` [PATCH 5/6] tools/libxl: Allow dom0 to be destroyed Daniel De Graaf
2014-03-05 10:07   ` Jan Beulich
2014-03-05 12:02   ` Ian Jackson
2014-03-05 22:36     ` Daniel De Graaf
2014-03-10 16:45       ` Ian Jackson
2014-03-12 14:27         ` Daniel De Graaf
2014-03-13 17:17           ` Ian Jackson
2014-03-13 17:41             ` Daniel De Graaf
2014-03-14 14:32               ` Ian Jackson
2014-03-04 22:51 ` [PATCH 6/6] xenstored: add --master-domid to support domain builder Daniel De Graaf
2014-03-10 12:14   ` Ian Jackson
2014-03-04 23:32 ` Domain Builder Daniel De Graaf

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=531741FF.1000509@tycho.nsa.gov \
    --to=dgdegra@tycho.nsa.gov \
    --cc=JBeulich@suse.com \
    --cc=ian.campbell@citrix.com \
    --cc=keir@xen.org \
    --cc=stefano.stabellini@citrix.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xen.org \
    --cc=xiantao.zhang@intel.com \
    /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).