* [Qemu-devel] [PATCH for-2.8] megasas: do not call pci_dma_unmap after having freed the frame once
@ 2016-11-10 15:27 Paolo Bonzini
2016-11-11 12:47 ` Stefan Hajnoczi
0 siblings, 1 reply; 2+ messages in thread
From: Paolo Bonzini @ 2016-11-10 15:27 UTC (permalink / raw)
To: qemu-devel
Commit 8cc4678 ("megasas: remove useless check for cmd->frame", 2016-07-17) was
wrong because I trusted Coverity too much. It turns out that there _is_ a
path through which cmd->frame can become NULL. After megasas_handle_frame's
switch (md->frame->header.frame_cmd), megasas_init_firmware can be called.
>From there, megasas_reset_frames will call megasas_unmap_frame which resets
cmd->frame = NULL.
However, there is another bug to fix in there, because megasas_unmap_frame
is called again after setting the command status. In this case QEMU should
not do anything, instead it calls pci_dma_unmap again. Harmless, but
better fix it.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi/megasas.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
index 52a4123..ca62952 100644
--- a/hw/scsi/megasas.c
+++ b/hw/scsi/megasas.c
@@ -461,9 +461,12 @@ static void megasas_unmap_frame(MegasasState *s, MegasasCmd *cmd)
{
PCIDevice *p = PCI_DEVICE(s);
- pci_dma_unmap(p, cmd->frame, cmd->pa_size, 0, 0);
+ if (cmd->pa_size) {
+ pci_dma_unmap(p, cmd->frame, cmd->pa_size, 0, 0);
+ }
cmd->frame = NULL;
cmd->pa = 0;
+ cmd->pa_size = 0;
clear_bit(cmd->index, s->frame_map);
}
--
2.9.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH for-2.8] megasas: do not call pci_dma_unmap after having freed the frame once
2016-11-10 15:27 [Qemu-devel] [PATCH for-2.8] megasas: do not call pci_dma_unmap after having freed the frame once Paolo Bonzini
@ 2016-11-11 12:47 ` Stefan Hajnoczi
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2016-11-11 12:47 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 938 bytes --]
On Thu, Nov 10, 2016 at 04:27:50PM +0100, Paolo Bonzini wrote:
> Commit 8cc4678 ("megasas: remove useless check for cmd->frame", 2016-07-17) was
> wrong because I trusted Coverity too much. It turns out that there _is_ a
> path through which cmd->frame can become NULL. After megasas_handle_frame's
> switch (md->frame->header.frame_cmd), megasas_init_firmware can be called.
> From there, megasas_reset_frames will call megasas_unmap_frame which resets
> cmd->frame = NULL.
>
> However, there is another bug to fix in there, because megasas_unmap_frame
> is called again after setting the command status. In this case QEMU should
> not do anything, instead it calls pci_dma_unmap again. Harmless, but
> better fix it.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> hw/scsi/megasas.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-11-11 12:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-10 15:27 [Qemu-devel] [PATCH for-2.8] megasas: do not call pci_dma_unmap after having freed the frame once Paolo Bonzini
2016-11-11 12:47 ` Stefan Hajnoczi
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).