Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2267938imc; Tue, 12 Mar 2019 10:14:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqzaFsCzEoP1f1pc4chyMVOWdPQUXnPVhN+HqV+83pwa9jPR9Y8hDPq/NFtIvrnEMZuwFAlb X-Received: by 2002:a17:902:2ba7:: with SMTP id l36mr18919687plb.246.1552410881723; Tue, 12 Mar 2019 10:14:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552410881; cv=none; d=google.com; s=arc-20160816; b=x86h9ZaxFwUxGZmaE2b4wiUAwImgPN9Dv8hBlP4y7fcf8fD2qD1V47BV7v+HM9354B pQ4J8cve8to9doWz4lTE1NAu8NXvMn89JKfehjP/47YEhm6Bp6cLEGgg0hro5QZZL8wq fa1afhzlhj+RU1aB2Ue0kRCMtya127OMkcCUtnJShPe8qR7gJqRT8zEFDOgDd+4boYDT pG2CsXmaU3PwEsct5R9TxBIcIKIVcNp6L5asS++dHH0B0FJvugU5QMfaIjkz1tIltz7F EXSQ/621LfQAM3KfvMab0He1lcoInlStB9uuF3RE0mkX2X7G6uMwndI25eVoE+zUAxfy swyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Uc/Erk4kCN93JKhWksYAJP6o7SQcKgo+juJ1R0OqQVI=; b=dh48zEejumPwiAZ3//0qC+cziN+pMaJLRkQD9cVBhVMZzfYKkk+F5UDZ3S2U9oIS7T w425k2JMobrFP0vIEFtNo3xyGv1bbMNZSFUAO5S/mroeP8DZypec05sMZzI5uymNWPFc X3mLCXkiOS+9jjf8Axh2rF7YGnCNAh9mkPTsEbffgFTNIGgSRrOLY2bbMxinksKwCQuG ezcAbRG2k0rJMHlpDN9NWqTG6Uov6/cU9SK3HW4oU7KlSeocwN+w5hSPOEoJgUMXiO10 8NVztQoNXVLwQJv0FTLkD8pXd1OeyCTWoxANsNqgI5tcmMI/X1WktwddgEKhsi7Ku9IY 0WXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YSIXOOQx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m2si8229998pfj.111.2019.03.12.10.14.26; Tue, 12 Mar 2019 10:14:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YSIXOOQx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727469AbfCLRM0 (ORCPT + 99 others); Tue, 12 Mar 2019 13:12:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:46722 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727304AbfCLRMI (ORCPT ); Tue, 12 Mar 2019 13:12:08 -0400 Received: from localhost (unknown [104.133.8.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 30621214AF; Tue, 12 Mar 2019 17:12:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552410728; bh=BH3YbTtp/aSAl6f6hEFWVfSwx+3Xwt0ijTDqGTZqI04=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YSIXOOQx3Ra2QRG3xsDwKPP82Qm5pSMnMT9ZziZ1RhJmwZMdKRA235sAoZJX4QWd/ gCSYRokz7aqPBJxUG2NWTDFROpfBXY8HeGGbsOf1KIq8XqYM9gaCA7KhIDhnJTtCS2 SOZ/hv95RA3qIeVULJGzZDFWTyESTaRPfHqk29rU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Douglas Gilbert , Bart Van Assche , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.20 047/171] scsi: scsi_debug: fix write_same with virtual_gb problem Date: Tue, 12 Mar 2019 10:07:07 -0700 Message-Id: <20190312170352.180302473@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190312170347.868927101@linuxfoundation.org> References: <20190312170347.868927101@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 40d07b523cf434f252b134c86b1f8f2d907ffb0b ] The WRITE SAME(10) and (16) implementations didn't take account of the buffer wrap required when the virtual_gb parameter is greater than 0. Fix that and rename the fake_store() function to lba2fake_store() to lessen confusion with the global fake_storep pointer. Bump version date. Signed-off-by: Douglas Gilbert Reported-by: Bart Van Assche Tested by: Bart Van Assche Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/scsi_debug.c | 41 ++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 60bcc6df97a9..65305b3848bc 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -62,7 +62,7 @@ /* make sure inq_product_rev string corresponds to this version */ #define SDEBUG_VERSION "0188" /* format to fit INQUIRY revision field */ -static const char *sdebug_version_date = "20180128"; +static const char *sdebug_version_date = "20190125"; #define MY_NAME "scsi_debug" @@ -735,7 +735,7 @@ static inline bool scsi_debug_lbp(void) (sdebug_lbpu || sdebug_lbpws || sdebug_lbpws10); } -static void *fake_store(unsigned long long lba) +static void *lba2fake_store(unsigned long long lba) { lba = do_div(lba, sdebug_store_sectors); @@ -2514,8 +2514,8 @@ static int do_device_access(struct scsi_cmnd *scmd, u32 sg_skip, u64 lba, return ret; } -/* If fake_store(lba,num) compares equal to arr(num), then copy top half of - * arr into fake_store(lba,num) and return true. If comparison fails then +/* If lba2fake_store(lba,num) compares equal to arr(num), then copy top half of + * arr into lba2fake_store(lba,num) and return true. If comparison fails then * return false. */ static bool comp_write_worker(u64 lba, u32 num, const u8 *arr) { @@ -2643,7 +2643,7 @@ static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec, if (sdt->app_tag == cpu_to_be16(0xffff)) continue; - ret = dif_verify(sdt, fake_store(sector), sector, ei_lba); + ret = dif_verify(sdt, lba2fake_store(sector), sector, ei_lba); if (ret) { dif_errors++; return ret; @@ -3261,10 +3261,12 @@ static int resp_write_scat(struct scsi_cmnd *scp, static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, u32 ei_lba, bool unmap, bool ndob) { + int ret; unsigned long iflags; unsigned long long i; - int ret; - u64 lba_off; + u32 lb_size = sdebug_sector_size; + u64 block, lbaa; + u8 *fs1p; ret = check_device_access_params(scp, lba, num); if (ret) @@ -3276,31 +3278,30 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, unmap_region(lba, num); goto out; } - - lba_off = lba * sdebug_sector_size; + lbaa = lba; + block = do_div(lbaa, sdebug_store_sectors); /* if ndob then zero 1 logical block, else fetch 1 logical block */ + fs1p = fake_storep + (block * lb_size); if (ndob) { - memset(fake_storep + lba_off, 0, sdebug_sector_size); + memset(fs1p, 0, lb_size); ret = 0; } else - ret = fetch_to_dev_buffer(scp, fake_storep + lba_off, - sdebug_sector_size); + ret = fetch_to_dev_buffer(scp, fs1p, lb_size); if (-1 == ret) { write_unlock_irqrestore(&atomic_rw, iflags); return DID_ERROR << 16; - } else if (sdebug_verbose && !ndob && (ret < sdebug_sector_size)) + } else if (sdebug_verbose && !ndob && (ret < lb_size)) sdev_printk(KERN_INFO, scp->device, "%s: %s: lb size=%u, IO sent=%d bytes\n", - my_name, "write same", - sdebug_sector_size, ret); + my_name, "write same", lb_size, ret); /* Copy first sector to remaining blocks */ - for (i = 1 ; i < num ; i++) - memcpy(fake_storep + ((lba + i) * sdebug_sector_size), - fake_storep + lba_off, - sdebug_sector_size); - + for (i = 1 ; i < num ; i++) { + lbaa = lba + i; + block = do_div(lbaa, sdebug_store_sectors); + memmove(fake_storep + (block * lb_size), fs1p, lb_size); + } if (scsi_debug_lbp()) map_region(lba, num); out: -- 2.19.1