From patchwork Thu Feb 8 15:08:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 10207255 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BB0B160327 for ; Thu, 8 Feb 2018 15:10:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD7362956D for ; Thu, 8 Feb 2018 15:10:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC0C429582; Thu, 8 Feb 2018 15:10:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1DA342956D for ; Thu, 8 Feb 2018 15:10:27 +0000 (UTC) Received: from localhost ([::1]:42335 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejnqE-00012f-Oq for patchwork-qemu-devel@patchwork.kernel.org; Thu, 08 Feb 2018 10:10:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46317) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejnom-0007qR-9Z for qemu-devel@nongnu.org; Thu, 08 Feb 2018 10:09:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ejnol-0005p1-5L for qemu-devel@nongnu.org; Thu, 08 Feb 2018 10:08:56 -0500 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:33214) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ejnok-0005ob-TX for qemu-devel@nongnu.org; Thu, 08 Feb 2018 10:08:55 -0500 Received: by mail-wm0-x22f.google.com with SMTP id x4-v6so27703737wmc.0 for ; Thu, 08 Feb 2018 07:08:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=t0orFGJNYWveEzLYdMdUz8oI1GDffzdYpsuRr16yHkI=; b=jZSyFq++lW3U0+lq/4s70f0DvYUNE9+5+DrCvvsWLkzOxK70dSnGH7y1cUuNXx9Xjz myMBz6EanhDbUqliwdFGRN7oxWS0l77mhG9MCP7yeblUC1+/0MynW4ebqBQZ8T+vqIGH 4PeDaUPwjLWYH27uKUCzaCt3WCLhI6szzHIGIYppzVrA9XKpukfOCn3x3jUSbsWRVMO8 5nzm2GjNsWJdEf6zOIH1KkgchhKBozEnNAW/gW8NiWJ9F3Fj51SDjjtpD0WlQGjUzA5R 2Ir7x86SV4yEK/VAvbxZC7I9FpH6BqhJ1BRooEafEdU6NGI5D0j/8V+iGnuTRhJolOGO y6Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=t0orFGJNYWveEzLYdMdUz8oI1GDffzdYpsuRr16yHkI=; b=FN/7StGvrMj9ofnaefz4bK/PosS4CsMIa4d1qFtXxsXn8R/cZke+u3dACmyG1a+48p O8OrtnCjLjnw9wjRg6mt7K9bAEx4AOlp+lRmLEYnzApgTSSZQHSfrktKHY2filUecv2e fzYRY1ykqk2V8YodX8eXn+mZB5pm1bO5Aw38uuxycxYx2Sy1448Crqmkp/FSnpjvXmXF HMiV5z/3dpg/+LbJT/2ao+ER4UFUcKt5FrbbwLJvlz6eMxQWtaSv2qercxR/R7MvX0CS Xi5rpvK8xOhn+jWJxxJlL1Dr2lwly0zkh9p4wWjohwj42IGTMzEzsUPZoiuqmG4U2ot8 bnRQ== X-Gm-Message-State: APf1xPBbsZyY90VhHoYSWWYC2Yc0SDITUMf1e1C4HWza06tfnN0ZYhPI FcWKks9PCb7Grd11lU8oyR4wk1oFMdocYWi9zLg= X-Google-Smtp-Source: AH8x225mVIEPpYYhrOsPzYV3at+q4xRBQevGc8wjpwdhRrArx8mAY+zUdsnhVCNhPGr1hPFPwbJRt/OaMHN3FPRHOp0= X-Received: by 10.28.35.200 with SMTP id j191mr1464704wmj.146.1518102533794; Thu, 08 Feb 2018 07:08:53 -0800 (PST) MIME-Version: 1.0 Received: by 10.223.170.146 with HTTP; Thu, 8 Feb 2018 07:08:53 -0800 (PST) In-Reply-To: References: From: Stefan Hajnoczi Date: Thu, 8 Feb 2018 15:08:53 +0000 Message-ID: To: Paolo Bonzini X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22f Subject: Re: [Qemu-devel] libiscsi task cancellation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hannes Reinecke , Peter Lieven , qemu-devel , ronnie sahlberg , Felipe Franciosi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Feb 8, 2018 at 2:14 PM, Paolo Bonzini wrote: > On 08/02/2018 15:08, Stefan Hajnoczi wrote: >> Now on to libiscsi: >> >> The iscsi_task_mgmt_async() API documentation says: >> >> * abort_task will also cancel the scsi task. The callback for the >> scsi task will be invoked with >> * SCSI_STATUS_CANCELLED >> >> I see that the ABORT TASK TMF response invokes the user's >> iscsi_task_mgmt_async() callback but not the command callback. I'm >> not sure how the command callback is invoked with >> SCSI_STATUS_CANCELLED unless libiscsi is relying on the target to send >> that response. >> >> Is libiscsi honoring its iscsi_task_mgmt_async() contract? > > No, and QEMU is assuming the "wrong" behavior: > > static void > iscsi_abort_task_cb(struct iscsi_context *iscsi, int status, void *command_data, > void *private_data) > { > IscsiAIOCB *acb = private_data; > > acb->status = -ECANCELED; > iscsi_schedule_bh(acb); > } FWIW My recent use-after-free fix series is still pending review: https://lists.gnu.org/archive/html/qemu-devel/2018-02/msg00570.html It changes the code and fixes a QEMU bug, but it doesn't address the iscsi_task_mgmt_async() issue we're discussing now. I think users *can* work around the iscsi_task_mgmt_async() issue as follows: If the command callback has not been invoked yet when the ABORT TASK TMF callback is invoked, call iscsi_scsi_cancel_task() so that libiscsi invokes the command callback with SCSI_STATUS_CANCELLED and frees the PDU. Here is how that looks in QEMU: Reviewed-by: Felipe Franciosi Tested-by: Sreejith Mohanan diff --git a/block/iscsi.c b/block/iscsi.c index 8140baac15..7b4b43dc55 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -290,8 +290,12 @@ iscsi_abort_task_cb(struct iscsi_context *iscsi, int status, void *command_data, { IscsiAIOCB *acb = private_data; - acb->status = -ECANCELED; - iscsi_schedule_bh(acb); + /* If the command callback hasn't been called yet, drop the task */ + if (!acb->bh) { + /* Call iscsi_aio_ioctl_cb() with SCSI_STATUS_CANCELLED */ + iscsi_scsi_cancel_task(iscsi, acb->task); + } + qemu_aio_unref(acb); /* acquired in iscsi_aio_cancel() */ }