From: Paolo Bonzini <pbonzini@redhat.com>
To: Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
Lan Tianyu <tianyu.lan@intel.com>
Cc: mjt@tls.msk.ru, qemu-devel@nongnu.org, jbeulich@suse.com,
konrad.wilk@oracle.com
Subject: Re: [Qemu-devel] [Fix PATCH] Qemu/Xen: Fix early freeing MSIX MMIO memory region
Date: Tue, 6 Oct 2015 15:33:56 +0200 [thread overview]
Message-ID: <5613CDC4.1070602@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1510051713580.1179@kaball.uk.xensource.com>
On 05/10/2015 18:53, Stefano Stabellini wrote:
>> This patch is to fix the issue via moving MSIX MMIO memory region into
>> struct XenPCIPassthroughState and free it together with pt device's obj.
>
> Given that all the MSI-X related info are in XenPTMSIX, I would prefer
> to keep the mmio memory region there, if possible.
>
> Couldn't you just unhook msix->mmio from XenPCIPassthroughState's object
> in xen_pt_msix_delete? Calling object_property_del_child or
> object_unparent?
This is the right thing to do, but there are two separate things to fix.
One is the use-after-free of msix->mmio, the other is that freeing
s->msix and in general xen_pt_config_delete should be done from the
.instance_finalize callback. This is documented in docs/memory.txt.
This is an attempt at a patch (not even compiled):
diff --git a/hw/xen/xen_pt_msi.c b/hw/xen/xen_pt_msi.c
index e3d7194..e476bac 100644
--- a/hw/xen/xen_pt_msi.c
+++ b/hw/xen/xen_pt_msi.c
@@ -610,7 +610,7 @@ error_out:
return rc;
}
-void xen_pt_msix_delete(XenPCIPassthroughState *s)
+void xen_pt_msix_unmap(XenPCIPassthroughState *s)
{
XenPTMSIX *msix = s->msix;
@@ -627,6 +627,17 @@ void xen_pt_msix_delete(XenPCIPassthroughState *s)
}
memory_region_del_subregion(&s->bar[msix->bar_index], &msix->mmio);
+}
+
+void xen_pt_msix_delete(XenPCIPassthroughState *s)
+{
+ XenPTMSIX *msix = s->msix;
+
+ if (!msix) {
+ return;
+ }
+
+ object_unparent(&msix->mmio);
g_free(s->msix);
s->msix = NULL;
where xen_pt_config_unmap would be called from xen_pt_destroy, and the call
to xen_pt_config_delete would be moved to xen_pci_passthrough_info's
instance_finalize member.
Paolo
next prev parent reply other threads:[~2015-10-06 13:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-30 6:51 [Qemu-devel] [Fix PATCH] Qemu/Xen: Fix early freeing MSIX MMIO memory region Lan Tianyu
2015-10-05 16:53 ` Stefano Stabellini
2015-10-06 13:33 ` Paolo Bonzini [this message]
2015-10-06 13:49 ` Stefano Stabellini
2015-10-06 15:18 ` Lan, Tianyu
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=5613CDC4.1070602@redhat.com \
--to=pbonzini@redhat.com \
--cc=jbeulich@suse.com \
--cc=konrad.wilk@oracle.com \
--cc=mjt@tls.msk.ru \
--cc=qemu-devel@nongnu.org \
--cc=stefano.stabellini@eu.citrix.com \
--cc=tianyu.lan@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).