Received: from eggs.gnu.org ([2001:4830:134:3::10]:37323) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLUgz-0000ik-Sx for qemu-devel@nongnu.org; Sat, 01 Aug 2015 07:11:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZLUgw-0006nP-MV for qemu-devel@nongnu.org; Sat, 01 Aug 2015 07:11:05 -0400 Received: from s16892447.onlinehome-server.info ([82.165.15.123]:52218) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLUgw-0006iB-Gp for qemu-devel@nongnu.org; Sat, 01 Aug 2015 07:11:02 -0400 Message-ID: <55BCA933.9000401@ilande.co.uk> Date: Sat, 01 Aug 2015 12:10:43 +0100 From: Mark Cave-Ayland MIME-Version: 1.0 References: <1438198068-32428-1-git-send-email-aurelien@aurel32.net> In-Reply-To: <1438198068-32428-1-git-send-email-aurelien@aurel32.net> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH for-2.4] macio: re-add TRIM support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Aurelien Jarno , qemu-devel@nongnu.org Cc: John Snow On 29/07/15 20:27, Aurelien Jarno wrote: > Commit bd4214fc dropped TRIM support by mistake. Given it is still > advertised to the host when using a drive with discard=on, this cause > the IDE bus to hang when the host issues a TRIM command. > > This patch fixes that by re-adding the TRIM code, ported to the new > new DMA implementation. > > Cc: Mark Cave-Ayland > Cc: John Snow > Signed-off-by: Aurelien Jarno > --- > hw/ide/macio.c | 28 ++++++++++++++++++++++++++++ > 1 file changed, 28 insertions(+) > > diff --git a/hw/ide/macio.c b/hw/ide/macio.c > index a55a479..66ac2ba 100644 > --- a/hw/ide/macio.c > +++ b/hw/ide/macio.c > @@ -208,6 +208,33 @@ static void pmac_dma_write(BlockBackend *blk, > cb, io); > } > > +static void pmac_dma_trim(BlockBackend *blk, > + int64_t offset, int bytes, > + void (*cb)(void *opaque, int ret), void *opaque) > +{ > + DBDMA_io *io = opaque; > + MACIOIDEState *m = io->opaque; > + IDEState *s = idebus_active_if(&m->bus); > + dma_addr_t dma_addr, dma_len; > + void *mem; > + > + qemu_iovec_destroy(&io->iov); > + qemu_iovec_init(&io->iov, io->len / MACIO_PAGE_SIZE + 1); > + > + dma_addr = io->addr; > + dma_len = io->len; > + mem = dma_memory_map(&address_space_memory, dma_addr, &dma_len, > + DMA_DIRECTION_TO_DEVICE); > + > + qemu_iovec_add(&io->iov, mem, io->len); > + s->io_buffer_size -= io->len; > + s->io_buffer_index += io->len; > + io->len = 0; > + > + m->aiocb = ide_issue_trim(blk, (offset >> 9), &io->iov, (bytes >> 9), > + cb, io); > +} > + > static void pmac_ide_atapi_transfer_cb(void *opaque, int ret) > { > DBDMA_io *io = opaque; > @@ -313,6 +340,7 @@ static void pmac_ide_transfer_cb(void *opaque, int ret) > pmac_dma_write(s->blk, offset, io->len, pmac_ide_transfer_cb, io); > break; > case IDE_DMA_TRIM: > + pmac_dma_trim(s->blk, offset, io->len, pmac_ide_transfer_cb, io); > break; > } Apologies for the slow response on this (it has been a busy week here). The basic patch itself looks good, my only question would be about the effect on the Darwin/OS X family, since like the previous code the TRIM request is rounded to the nearest sector whereas these OSs do use byte-aligned DMA buffers. Having said that, since the option has to be explicitly enabled for the guest (and does the OS driver even support TRIM on these OSs?) then I think this patch is fine, and I can confirm it passes my tests here. ATB, Mark.