From patchwork Wed Jan 10 20:21:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Long Li X-Patchwork-Id: 10156095 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 187B060223 for ; Wed, 10 Jan 2018 20:59:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B82F28590 for ; Wed, 10 Jan 2018 20:59:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3B99285DC; Wed, 10 Jan 2018 20:59:22 +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=unavailable 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 A8F6328590 for ; Wed, 10 Jan 2018 20:59:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752577AbeAJU7K (ORCPT ); Wed, 10 Jan 2018 15:59:10 -0500 Received: from a2nlsmtp01-03.prod.iad2.secureserver.net ([198.71.225.37]:59684 "EHLO a2nlsmtp01-03.prod.iad2.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752472AbeAJU7I (ORCPT ); Wed, 10 Jan 2018 15:59:08 -0500 X-Greylist: delayed 2193 seconds by postgrey-1.27 at vger.kernel.org; Wed, 10 Jan 2018 15:59:08 EST Received: from linuxonhyperv.com ([107.180.71.197]) by : HOSTING RELAY : with SMTP id ZMsQe1RIXdmHCZMsQeFdOp; Wed, 10 Jan 2018 13:21:34 -0700 x-originating-ip: 107.180.71.197 Received: from longli by linuxonhyperv.com with local (Exim 4.89_1) (envelope-from ) id 1eZMsQ-0007U7-M6; Wed, 10 Jan 2018 13:21:34 -0700 From: Long Li To: "K . Y . Srinivasan" , Haiyang Zhang , "James E . J . Bottomley" , devel@linuxdriverproject.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Long Li Subject: [PATCH v2] storvsc: do not assume SG list is continuous when doing bounce buffers (for 4.1 and prior stable kernels) Date: Wed, 10 Jan 2018 13:21:29 -0700 Message-Id: <20180110202129.28730-1-longli@exchange.microsoft.com> X-Mailer: git-send-email 2.15.1 X-CMAE-Envelope: MS4wfNaxnbFOcQW1YKWdS+LI7OTPOOw8hXJzcxcE/h5dYMIHs7ix1Cq1gCASncLiBkOPKPaN04tjagkOMM7fDfKSgKbUB5lgbtFgvCw3DUqwjqGOtYId6lX3 23XNyBXbhawSLnZw5Fgxyjou7vu62ji2+2zKJsFGPn8Jxfx2vLucYQiD2nDkfTe/d4TeztTXa6BjxpY3Zhv2hbRJbq/vY7qla0EIGJYMgRzMdyidogEoyoHm AqpErvGk3tzcmARQ8jF2Gsdc0XT4GBJptfHIRR1VPVkosEV3MJwAmB6LWXe8S0qWKuOHyq/7v8CyhXtmaZZzzCZqowLPJ/x5JDbePEEA7KjCk2i8TvNMwpyU /sLka1ERqe5P+CB//aX4e2VZoQWfTbo/prPDrwoMb6E34jsUpJrpZ0gBRXeLlsUj+oHxO8CT9yb4Dq+bg6xlgPDZfOzc+A== Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Long Li The original patch was made for stable 4.1 and was Acked on 08/22/2017, but for some reason it never made it to the stable tree. Change from v1: Changed comment that this patch is for linux-stable 4.1 and all prior stable kernels. storvsc checks the SG list for gaps before passing them to Hyper-v device. If there are gaps, data is copied to a bounce buffer and a continuous data buffer is passed to Hyper-V. The check on gaps assumes SG list is continuous, and not chained. This is not always true. Failing the check may result in incorrect I/O data passed to the Hyper-v device. This code path is not used post Linux 4.1. Signed-off-by: Long Li Acked-by: Martin K. Petersen --- drivers/scsi/storvsc_drv.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c index 6c52d14..14dc5c6 100644 --- a/drivers/scsi/storvsc_drv.c +++ b/drivers/scsi/storvsc_drv.c @@ -584,17 +584,18 @@ static int do_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count) for (i = 0; i < sg_count; i++) { if (i == 0) { /* make sure 1st one does not have hole */ - if (sgl[i].offset + sgl[i].length != PAGE_SIZE) + if (sgl->offset + sgl->length != PAGE_SIZE) return i; } else if (i == sg_count - 1) { /* make sure last one does not have hole */ - if (sgl[i].offset != 0) + if (sgl->offset != 0) return i; } else { /* make sure no hole in the middle */ - if (sgl[i].length != PAGE_SIZE || sgl[i].offset != 0) + if (sgl->length != PAGE_SIZE || sgl->offset != 0) return i; } + sgl = sg_next(sgl); } return -1; }