All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chao Peng <chao.p.peng@linux.intel.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: keir@xen.org, Ian.Campbell@citrix.com,
	stefano.stabellini@eu.citrix.com, George.Dunlap@eu.citrix.com,
	andrew.cooper3@citrix.com, Ian.Jackson@eu.citrix.com,
	xen-devel@lists.xen.org, dgdegra@tycho.nsa.gov
Subject: Re: [PATCH v18 04/10] x86: detect and initialize Cache Monitoring Technology feature
Date: Wed, 1 Oct 2014 18:49:23 +0800	[thread overview]
Message-ID: <20141001104923.GB7360@pengc-linux> (raw)
In-Reply-To: <542AC88E020000780003B14C@mail.emea.novell.com>

On Tue, Sep 30, 2014 at 02:13:18PM +0100, Jan Beulich wrote:
> >>> On 30.09.14 at 12:49, <chao.p.peng@linux.intel.com> wrote:
> > --- /dev/null
> > +++ b/xen/arch/x86/psr.c
> > @@ -0,0 +1,114 @@
> > +/*
> > + * pqos.c: Platform Shared Resource related service for guest.
> 
> Stale filename.

Good catch, thanks.

> 
> > +static void __init parse_psr_param(char *s)
> > +{
> > +    char *ss, *val_str;
> > +
> > +    do {
> > +        ss = strchr(s, ',');
> > +        if ( ss )
> > +            *ss = '\0';
> > +
> > +        val_str = strchr(s, ':');
> > +        if ( val_str )
> > +            *val_str++ = '\0';
> > +
> > +        if ( !strcmp(s, "cmt") && ( !val_str || parse_bool(val_str) == 1 ) )
> > +            opt_psr |= PSR_CMT;
> 
> Do you really mean to ignore e.g. "psr=cmt:xyz"?

Yes, CMT is disabled silently for such case. But I feel comfortable to
add some msg like this:
    if ( parse_bool(val_str) == -1 )
        printk("PSR: unknown cmt value: %s - CMT disabled!\n", val_str);

> 
> > +static void __init init_psr_cmt(unsigned int rmid_max)
> > +{
> > +    unsigned int eax, ebx, ecx, edx;
> > +    unsigned int rmid;
> > +
> > +    if ( !boot_cpu_has(X86_FEATURE_CMT) )
> > +        return;
> > +
> > +    cpuid_count(0xf, 0, &eax, &ebx, &ecx, &edx);
> > +    if ( !edx )
> > +        return;
> > +
> > +    psr_cmt = xzalloc(struct psr_cmt);
> > +    if ( !psr_cmt )
> > +        return;
> > +
> > +    psr_cmt->features = edx;
> > +    psr_cmt->rmid_mask = ~(~0ull << get_count_order(ebx));
> > +    psr_cmt->rmid_max = min(rmid_max, ebx);
> 
> The value written here gets replaced further down without taking
> the value computed here into account - that's likely not what you
> want. The two rmid_max values being recorded are kind of
> confusing anyway - do you really need both at some point (other
> than here)?

This is actually a good catch. The line below should be:
psr_cmt->rmid_max = min(psr_cmt->rmid_max, psr_cmt->l3.rmid_max);

> 
> > +
> > +    if ( psr_cmt->features & PSR_RESOURCE_TYPE_L3 )
> > +    {
> > +        cpuid_count(0xf, 1, &eax, &ebx, &ecx, &edx);
> > +        psr_cmt->l3.upscaling_factor = ebx;
> > +        psr_cmt->l3.rmid_max = ecx;
> > +        psr_cmt->l3.features = edx;
> > +    }
> > +
> > +    psr_cmt->rmid_max = min(rmid_max, psr_cmt->l3.rmid_max);
> > +    psr_cmt->rmid_to_dom = xmalloc_array(domid_t, psr_cmt->rmid_max + 1);
> 
> This still degenerates to allocating zero bytes (and then corrupting
> memory) when psr_cmt->rmid_max is 0xffffffff. At the very least
> use 1UL as addend.

Indeed, xmalloc will not return NULL as we expected for such case.
Then the following can be picked up again:
    BUG_ON(pqosm->rmid_max < 0xffffffff);

> 
> > +static int __init init_psr(void)
> > +{
> > +    if ( opt_psr & PSR_CMT && opt_rmid_max )
> 
> Please parenthesize the &.
> 
> > --- a/xen/arch/x86/setup.c
> > +++ b/xen/arch/x86/setup.c
> > @@ -49,6 +49,7 @@
> >  #include <xen/cpu.h>
> >  #include <asm/nmi.h>
> >  #include <asm/alternative.h>
> > +#include <asm/psr.h>
> 
> Why?
> 
> > +struct psr_cmt {
> > +    unsigned long rmid_mask;
> 
> When in patch 7 finally this field gets used for something it is to mask
> a value read from an MSR. Hence its type should be uint64_t. And
> of course it would have helped if the field got added there rather
> than here (perhaps also for the l3 field below).

Will change rmid_mask to uint64_t and move it to .c file. But will leave
l3 field here as it's needed for sysctl.c.

Chao
> 
> > +    unsigned int rmid_max;
> > +    unsigned int features;
> > +    domid_t *rmid_to_dom;
> > +    struct psr_cmt_l3 l3;
> > +};
> 
> Jan
> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel

  reply	other threads:[~2014-10-01 10:49 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-30 10:49 [PATCH v18 00/10] enable Cache Monitoring Technology (CMT) feature Chao Peng
2014-09-30 10:49 ` [PATCH v18 01/10] x86: add generic resource (e.g. MSR) access hypercall Chao Peng
2014-09-30 11:00   ` Andrew Cooper
2014-09-30 11:08     ` Andrew Cooper
2014-09-30 12:15       ` Jan Beulich
2014-09-30 12:12   ` Jan Beulich
2014-10-01 10:04     ` Chao Peng
2014-10-01 10:33       ` Jan Beulich
2014-10-02 10:26         ` Chao Peng
2014-09-30 10:49 ` [PATCH v18 02/10] xsm: add resource operation related xsm policy Chao Peng
2014-09-30 10:49 ` [PATCH v18 03/10] tools: provide interface for generic resource access Chao Peng
2014-09-30 10:49 ` [PATCH v18 04/10] x86: detect and initialize Cache Monitoring Technology feature Chao Peng
2014-09-30 13:13   ` Jan Beulich
2014-10-01 10:49     ` Chao Peng [this message]
2014-09-30 10:49 ` [PATCH v18 05/10] x86: dynamically attach/detach CMT service for a guest Chao Peng
2014-09-30 10:49 ` [PATCH v18 06/10] x86: collect global CMT information Chao Peng
2014-09-30 13:20   ` Jan Beulich
2014-09-30 10:49 ` [PATCH v18 07/10] x86: enable CMT for each domain RMID Chao Peng
2014-09-30 10:49 ` [PATCH v18 08/10] x86: add CMT related MSRs in allowed list Chao Peng
2014-09-30 13:26   ` Jan Beulich
2014-10-01 10:59     ` Chao Peng
2014-10-01 11:17       ` Jan Beulich
2014-10-02 10:27         ` Chao Peng
2014-10-06 14:01     ` Chao Peng
2014-10-06 14:06       ` Andrew Cooper
2014-10-06 14:23         ` Chao Peng
2014-10-08  7:58         ` Chao Peng
2014-09-30 10:49 ` [PATCH v18 09/10] xsm: add CMT related xsm policies Chao Peng
2014-09-30 10:49 ` [PATCH v18 10/10] tools: CMDs and APIs for Cache Monitoring Technology Chao Peng
2014-10-02 14:57   ` Konrad Rzeszutek Wilk
2014-10-02 16:49     ` Wei Liu

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=20141001104923.GB7360@pengc-linux \
    --to=chao.p.peng@linux.intel.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=dgdegra@tycho.nsa.gov \
    --cc=keir@xen.org \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xen.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.