From: Paul Durrant <Paul.Durrant@citrix.com>
To: 'Jan Beulich' <JBeulich@suse.com>,
Alexandru Isaila <aisaila@bitdefender.com>
Cc: Kevin Tian <kevin.tian@intel.com>,
"sstabellini@kernel.org" <sstabellini@kernel.org>,
Wei Liu <wei.liu2@citrix.com>,
"suravee.suthikulpanit@amd.com" <suravee.suthikulpanit@amd.com>,
Andrew Cooper <Andrew.Cooper3@citrix.com>,
"Tim (Xen.org)" <tim@xen.org>,
George Dunlap <George.Dunlap@citrix.com>,
"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>,
"jun.nakajima@intel.com" <jun.nakajima@intel.com>,
Ian Jackson <Ian.Jackson@citrix.com>,
"boris.ostrovsky@oracle.com" <boris.ostrovsky@oracle.com>
Subject: Re: [PATCH v4 3/3] x86/hvm: Implement hvmemul_write() using real mappings
Date: Wed, 20 Sep 2017 14:37:19 +0000 [thread overview]
Message-ID: <82f83b3a47804e089cad42bd998c6005@AMSPEX02CL03.citrite.net> (raw)
In-Reply-To: <59C27A12020000780017D6AD@prv-mh.provo.novell.com>
> -----Original Message-----
> From: Jan Beulich [mailto:JBeulich@suse.com]
> Sent: 20 September 2017 13:24
> To: Alexandru Isaila <aisaila@bitdefender.com>
> Cc: suravee.suthikulpanit@amd.com; Andrew Cooper
> <Andrew.Cooper3@citrix.com>; Paul Durrant <Paul.Durrant@citrix.com>;
> Wei Liu <wei.liu2@citrix.com>; George Dunlap <George.Dunlap@citrix.com>;
> Ian Jackson <Ian.Jackson@citrix.com>; jun.nakajima@intel.com; Kevin Tian
> <kevin.tian@intel.com>; sstabellini@kernel.org; xen-devel@lists.xen.org;
> boris.ostrovsky@oracle.com; konrad.wilk@oracle.com; Tim (Xen.org)
> <tim@xen.org>
> Subject: Re: [PATCH v4 3/3] x86/hvm: Implement hvmemul_write() using
> real mappings
>
> >>> On 20.09.17 at 11:22, <aisaila@bitdefender.com> wrote:
> > +static void *hvmemul_map_linear_addr(
> > + unsigned long linear, unsigned int bytes, uint32_t pfec,
> > + struct hvm_emulate_ctxt *hvmemul_ctxt)
> > +{
> > + struct vcpu *curr = current;
> > + void *err, *mapping;
> > +
> > + /* First and final gfns which need mapping. */
> > + unsigned long frame = linear >> PAGE_SHIFT, first = frame;
> > + unsigned long final = (linear + bytes - !!bytes) >> PAGE_SHIFT;
> > +
> > + /*
> > + * mfn points to the next free slot. All used slots have a page reference
> > + * held on them.
> > + */
> > + mfn_t *mfn = &hvmemul_ctxt->mfn[0];
> > +
> > + /*
> > + * The caller has no legitimate reason for trying a zero-byte write, but
> > + * final is calculate to fail safe in release builds.
> > + *
> > + * The maximum write size depends on the number of adjacent mfns[]
> which
> > + * can be vmap()'d, accouting for possible misalignment within the
> region.
> > + * The higher level emulation callers are responsible for ensuring that
> > + * mfns[] is large enough for the requested write size.
> > + */
> > + if ( bytes == 0 ||
> > + final - first >= ARRAY_SIZE(hvmemul_ctxt->mfn) )
> > + {
> > + ASSERT_UNREACHABLE();
> > + goto unhandleable;
> > + }
> > +
> > + do {
> > + enum hvm_translation_result res;
> > + struct page_info *page;
> > + pagefault_info_t pfinfo;
> > + p2m_type_t p2mt;
> > +
> > + /* Error checking. Confirm that the current slot is clean. */
> > + ASSERT(mfn_x(*mfn) == 0);
> > +
> > + res = hvm_translate_get_page(curr, frame << PAGE_SHIFT, true,
> pfec,
> > + &pfinfo, &page, NULL, &p2mt);
> > +
> > + switch ( res )
> > + {
> > + case HVMTRANS_okay:
> > + break;
> > +
> > + case HVMTRANS_bad_linear_to_gfn:
> > + x86_emul_pagefault(pfinfo.ec, pfinfo.linear, &hvmemul_ctxt-
> >ctxt);
> > + err = ERR_PTR(~X86EMUL_EXCEPTION);
> > + goto out;
> > +
> > + case HVMTRANS_bad_gfn_to_mfn:
> > + err = NULL;
> > + goto out;
> > +
> > + case HVMTRANS_gfn_paged_out:
> > + case HVMTRANS_gfn_shared:
> > + err = ERR_PTR(~X86EMUL_RETRY);
> > + goto out;
> > +
> > + default:
> > + goto unhandleable;
> > + }
> > +
> > + if ( p2m_is_discard_write(p2mt) )
> > + {
> > + err = ERR_PTR(~X86EMUL_OKAY);
> > + goto out;
> > + }
> > +
> > + *mfn++ = _mfn(page_to_mfn(page));
> > +
> > + } while ( ++frame < final );
>
> Interesting - I had specifically pointed out in a reply to v3 that the
> increment of mfn _cannot_ be moved down here: You're now
> leaking a page ref on the p2m_is_discard_write() error path afaict.
It could be left here if a put_page() is added to the above error path, which I'd clearly deluded myself was already there.
Paul
>
> Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-09-20 14:37 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-20 9:22 [PATCH v4 0/3] Various XSA followups Alexandru Isaila
2017-09-20 9:22 ` [PATCH v4 1/3] x86/hvm: Rename enum hvm_copy_result to hvm_translation_result Alexandru Isaila
2017-09-20 9:44 ` Jan Beulich
2017-09-20 12:29 ` Ping: " Jan Beulich
2017-09-20 13:01 ` Boris Ostrovsky
2017-09-20 9:22 ` [PATCH v4 2/3] x86/hvm: Break out __hvm_copy()'s translation logic Alexandru Isaila
2017-09-20 9:22 ` [PATCH v4 3/3] x86/hvm: Implement hvmemul_write() using real mappings Alexandru Isaila
2017-09-20 9:30 ` Paul Durrant
2017-09-20 12:24 ` Jan Beulich
2017-09-20 12:38 ` Alexandru Stefan ISAILA
2017-09-20 14:37 ` Paul Durrant [this message]
2017-09-25 8:00 ` Alexandru Stefan ISAILA
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=82f83b3a47804e089cad42bd998c6005@AMSPEX02CL03.citrite.net \
--to=paul.durrant@citrix.com \
--cc=Andrew.Cooper3@citrix.com \
--cc=George.Dunlap@citrix.com \
--cc=Ian.Jackson@citrix.com \
--cc=JBeulich@suse.com \
--cc=aisaila@bitdefender.com \
--cc=boris.ostrovsky@oracle.com \
--cc=jun.nakajima@intel.com \
--cc=kevin.tian@intel.com \
--cc=sstabellini@kernel.org \
--cc=suravee.suthikulpanit@amd.com \
--cc=tim@xen.org \
--cc=wei.liu2@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 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).