From patchwork Thu Mar 23 16:02:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Tsitsimpis X-Patchwork-Id: 9641525 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 7A75B602CA for ; Thu, 23 Mar 2017 16:02:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67586281F9 for ; Thu, 23 Mar 2017 16:02:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 599F227F07; Thu, 23 Mar 2017 16:02:42 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B42DD27F07 for ; Thu, 23 Mar 2017 16:02:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965377AbdCWQCl (ORCPT ); Thu, 23 Mar 2017 12:02:41 -0400 Received: from mx0.arrikto.com ([212.71.252.59]:48404 "EHLO mx0.arrikto.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965362AbdCWQCk (ORCPT ); Thu, 23 Mar 2017 12:02:40 -0400 Received: from troi.arr-srv (mail.arr-srv [192.168.98.4]) by mx0.arrikto.com (Postfix) with ESMTP id D80CCA07E; Thu, 23 Mar 2017 18:02:37 +0200 (EET) Received: from localhost (dhcp-108.hq.arr [10.94.250.108]) by troi.arr-srv (Postfix) with ESMTPSA id 701472E3; Thu, 23 Mar 2017 18:02:37 +0200 (EET) Date: Thu, 23 Mar 2017 18:02:37 +0200 From: Ilias Tsitsimpis To: lixiubo@cmss.chinamobile.com Cc: agrover@redhat.com, nab@linux-iscsi.org, mchristi@redhat.com, shli@kernel.org, sheng@yasker.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, namei.unix@gmail.com, bryantly@linux.vnet.ibm.com Subject: Re: [PATCHv4 0/4] tcmu: bug fix and dynamic growing data area support Message-ID: <20170323160237.qqofpc7v7aoazfqd@iliastsi-m.arr> References: <1490085382-28658-1-git-send-email-lixiubo@cmss.chinamobile.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1490085382-28658-1-git-send-email-lixiubo@cmss.chinamobile.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Xiubo, On Tue, Mar 21, 2017 at 04:36PM, lixiubo@cmss.chinamobile.com wrote: > [...] > tcmu: Fix possible overwrite of t_data_sg's last iov[] > tcmu: Fix wrongly calculating of the base_command_size I tested these two patches, which try to fix the broken support for BIDI commands in target/user. Both look good to me, but unfortunately, there is also another regression which got introduced with the use of the data_bitmap. More specifically, in case of BIDI commands, the data bitmap records both the Data-Out and the Data-In buffer, and so when gathering the data in the tcmu_handle_completion() function, care should be taken in order to discard the Data-Out buffer before gathering the Data-In buffer. Something like this should do the trick: With your patches, and the above diff, support for BIDI commands in the target/user seems to be working again. Could you please validate the above snippet, and update your patches to include it? diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index 1108bf5..7075161 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -610,10 +610,22 @@ static void tcmu_handle_completion(struct tcmu_cmd *cmd, struct tcmu_cmd_entry * se_cmd->scsi_sense_length); free_data_area(udev, cmd); } else if (se_cmd->se_cmd_flags & SCF_BIDI) { + struct scatterlist *sg; + int n, block, sg_remaining = 0; DECLARE_BITMAP(bitmap, DATA_BLOCK_BITS); - /* Get Data-In buffer before clean up */ bitmap_copy(bitmap, cmd->data_bitmap, DATA_BLOCK_BITS); + + /* Discard Data-Out buffer */ + for_each_sg(se_cmd->t_data_sg, sg, se_cmd->t_data_nents, n) { + sg_remaining += sg->length; + while (sg_remaining > 0) { + block = find_first_bit(bitmap, DATA_BLOCK_BITS); + clear_bit(block, bitmap); + sg_remaining -= DATA_BLOCK_SIZE; + } + } + + /* Get Data-In buffer before clean up */ gather_data_area(udev, bitmap, se_cmd->t_bidi_data_sg, se_cmd->t_bidi_data_nents); free_data_area(udev, cmd);