From: "Michał Leszczyński" <michal.leszczynski@cert.pl>
To: "Roger Pau Monné" <roger.pau@citrix.com>
Cc: Julien Grall <julien@xen.org>,
Stefano Stabellini <sstabellini@kernel.org>,
tamas lengyel <tamas.lengyel@intel.com>, Wei Liu <wl@xen.org>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
George Dunlap <george.dunlap@citrix.com>,
luwei kang <luwei.kang@intel.com>,
Jan Beulich <jbeulich@suse.com>,
xen-devel@lists.xenproject.org
Subject: Re: [PATCH v5 06/11] x86/hvm: processor trace interface in HVM
Date: Mon, 6 Jul 2020 12:09:02 +0200 (CEST) [thread overview]
Message-ID: <212702848.20024300.1594030142855.JavaMail.zimbra@cert.pl> (raw)
In-Reply-To: <20200706084234.GB735@Air-de-Roger>
----- 6 lip 2020 o 10:42, Roger Pau Monné roger.pau@citrix.com napisał(a):
> On Sun, Jul 05, 2020 at 08:54:59PM +0200, Michał Leszczyński wrote:
>> From: Michal Leszczynski <michal.leszczynski@cert.pl>
>>
>> Implement necessary changes in common code/HVM to support
>> processor trace features. Define vmtrace_pt_* API and
>> implement trace buffer allocation/deallocation in common
>> code.
>>
>> Signed-off-by: Michal Leszczynski <michal.leszczynski@cert.pl>
>> ---
>> xen/arch/x86/domain.c | 19 +++++++++++++++++++
>> xen/common/domain.c | 19 +++++++++++++++++++
>> xen/include/asm-x86/hvm/hvm.h | 20 ++++++++++++++++++++
>> xen/include/xen/sched.h | 4 ++++
>> 4 files changed, 62 insertions(+)
>>
>> diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
>> index fee6c3931a..79c9794408 100644
>> --- a/xen/arch/x86/domain.c
>> +++ b/xen/arch/x86/domain.c
>> @@ -2199,6 +2199,25 @@ int domain_relinquish_resources(struct domain *d)
>> altp2m_vcpu_disable_ve(v);
>> }
>>
>> + for_each_vcpu ( d, v )
>> + {
>> + unsigned int i;
>> +
>> + if ( !v->vmtrace.pt_buf )
>> + continue;
>> +
>> + for ( i = 0; i < (v->domain->vmtrace_pt_size >> PAGE_SHIFT); i++ )
>> + {
>> + struct page_info *pg = mfn_to_page(
>> + mfn_add(page_to_mfn(v->vmtrace.pt_buf), i));
>> + if ( (pg->count_info & PGC_count_mask) != 1 )
>> + return -EBUSY;
>> + }
>> +
>> + free_domheap_pages(v->vmtrace.pt_buf,
>> + get_order_from_bytes(v->domain->vmtrace_pt_size));
>
> This is racy as a control domain could take a reference between the
> check and the freeing.
>
>> + }
>> +
>> if ( is_pv_domain(d) )
>> {
>> for_each_vcpu ( d, v )
>> diff --git a/xen/common/domain.c b/xen/common/domain.c
>> index 25d3359c5b..f480c4e033 100644
>> --- a/xen/common/domain.c
>> +++ b/xen/common/domain.c
>> @@ -137,6 +137,21 @@ static void vcpu_destroy(struct vcpu *v)
>> free_vcpu_struct(v);
>> }
>>
>> +static int vmtrace_alloc_buffers(struct vcpu *v)
>> +{
>> + struct page_info *pg;
>> + uint64_t size = v->domain->vmtrace_pt_size;
>> +
>> + pg = alloc_domheap_pages(v->domain, get_order_from_bytes(size),
>> + MEMF_no_refcount);
>> +
>> + if ( !pg )
>> + return -ENOMEM;
>> +
>> + v->vmtrace.pt_buf = pg;
>> + return 0;
>> +}
>
> I think we already agreed that you would use the same model as ioreq
> servers, where a reference is taken on allocation and then the pages
> are not explicitly freed on domain destruction and put_page_and_type
> is used. Is there some reason why that model doesn't work in this
> case?
>
> If not, please see hvm_alloc_ioreq_mfn and hvm_free_ioreq_mfn.
>
> Roger.
Ok, I've got it, will do. Thanks for pointing out the examples.
One thing that is confusing to me is that I don't get what is
the meaning of MEMF_no_refcount flag.
In the hvm_{alloc,free}_ioreq_mfn the memory is allocated
explicitly but freed just by putting out the reference, so
I guess it's automatically detected that the refcount dropped to 0
and the page should be freed? If so, why the flag is named "no refcount"?
Best regards,
Michał Leszczyński
CERT Polska
next prev parent reply other threads:[~2020-07-06 10:10 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-05 18:54 [PATCH v5 00/11] Implement support for external IPT monitoring Michał Leszczyński
2020-07-05 18:54 ` [PATCH v5 01/11] memory: batch processing in acquire_resource() Michał Leszczyński
2020-07-05 18:54 ` [PATCH v5 02/11] x86/vmx: add Intel PT MSR definitions Michał Leszczyński
2020-07-05 18:54 ` [PATCH v5 03/11] x86/vmx: add IPT cpu feature Michał Leszczyński
2020-07-05 18:54 ` [PATCH v5 04/11] common: add vmtrace_pt_size domain parameter Michał Leszczyński
2020-07-06 10:13 ` Michał Leszczyński
2020-07-06 10:45 ` Julien Grall
2020-07-05 18:54 ` [PATCH v5 05/11] tools/libxl: add vmtrace_pt_size parameter Michał Leszczyński
2020-07-05 19:02 ` Michał Leszczyński
2020-07-06 10:53 ` Julien Grall
2020-07-05 18:54 ` [PATCH v5 06/11] x86/hvm: processor trace interface in HVM Michał Leszczyński
2020-07-05 19:11 ` Michał Leszczyński
2020-07-06 8:31 ` Jan Beulich
2020-07-06 10:31 ` Michał Leszczyński
2020-07-06 8:42 ` Roger Pau Monné
2020-07-06 10:09 ` Michał Leszczyński [this message]
2020-07-06 14:38 ` Roger Pau Monné
2020-07-05 18:55 ` [PATCH v5 07/11] x86/vmx: implement IPT in VMX Michał Leszczyński
2020-07-05 18:55 ` [PATCH v5 08/11] x86/mm: add vmtrace_buf resource type Michał Leszczyński
2020-07-06 10:28 ` Julien Grall
2020-07-05 18:55 ` [PATCH v5 09/11] x86/domctl: add XEN_DOMCTL_vmtrace_op Michał Leszczyński
2020-07-06 10:31 ` Julien Grall
2020-07-06 10:37 ` Jan Beulich
2020-07-06 10:38 ` Julien Grall
2020-07-06 11:20 ` Jan Beulich
2020-07-05 18:55 ` [PATCH v5 10/11] tools/libxc: add xc_vmtrace_* functions Michał Leszczyński
2020-07-05 18:55 ` [PATCH v5 11/11] tools/proctrace: add proctrace tool Michał Leszczyński
2020-07-05 18:58 ` Michał Leszczyński
2020-07-06 8:33 ` Jan Beulich
2020-07-06 9:47 ` Andrew Cooper
2020-07-06 10:18 ` Michał Leszczyński
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=212702848.20024300.1594030142855.JavaMail.zimbra@cert.pl \
--to=michal.leszczynski@cert.pl \
--cc=andrew.cooper3@citrix.com \
--cc=george.dunlap@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=luwei.kang@intel.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=tamas.lengyel@intel.com \
--cc=wl@xen.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.