Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4149134pxb; Mon, 27 Sep 2021 10:23:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLALiHliw+lZ61WHkKaXSbj8HXd5WT3c6D7RkVClSuVi1oSce7tv6Unx+Nwa1frOFzlqE7 X-Received: by 2002:a17:90a:7345:: with SMTP id j5mr291091pjs.48.1632763398085; Mon, 27 Sep 2021 10:23:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632763398; cv=none; d=google.com; s=arc-20160816; b=r4RsNYKGRpsqWhXH2x5Y5+pZggctI1PqpMnDSYZjNvZbhUrL76uxrpHw4EsnZ7lF0H Ukg61F6YcegBpXUVg0dqGOBl66FS6slTKkJyzAJnItQ24QALNeKqevmu3ihMErGv9s0+ VMRkuQtssaemrhco1NveZP0ty0rul3ZpFIQkeccGVtRPO+42lguC/41ubbgyZFoqQx/Q oE9zHGVtRnvILYQL4OKINJX14pqbkp5ed8WNyv03Gwj+uQo5oNEFzW9GbWm4YTwGNxNo 7gzdc2jGkBXWTcVCrEYG1e3E/L5pFLnFhGeBNM6MdrwHIZ2CHmI+wXN6e8l9gw1VZqmd 4XZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HFoPuP2bCV3tmDMg5LvQIqx93z8RfAJOYJQX1B9CAZo=; b=ft1PlX3bAiqJjUB01y0Zt6fx/kTKhaI7lnHA4FCLnaes2ofGC2SVBS71wHlU8ImQKd 1vx5E5MQMSQaV1yrbzbr43CmWNYlu9hVJAkEeNwtkxfsg2KEkpe2C4Go4cRS9Ev7IcJJ /bM3ryCC7zKOOQ6/iR2n3snIMdjCaWuZdIw0VdNKuTiOAIrnLjM8geKcac2cS86pc9/x frOZrv3A3Vw1hVpIXTae91TecU8Up4YJMMKYmmE0fBHjvzjr7tVrxlfQ5IW5ZGZWB3aK Y2y1mTZ+Tc5LvjmJ8UZIeyBkyJ+csP+OAoQuWa98QZcfasnhiqW8TA/JA/lZCMAlOLc9 IE0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2bcy7+vk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n26si21305478pgv.97.2021.09.27.10.23.05; Mon, 27 Sep 2021 10:23:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2bcy7+vk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237078AbhI0RWg (ORCPT + 99 others); Mon, 27 Sep 2021 13:22:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:35962 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237663AbhI0RTC (ORCPT ); Mon, 27 Sep 2021 13:19:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7629061288; Mon, 27 Sep 2021 17:12:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632762758; bh=rgGC/9Gq+574w1jl5yUnIwXFS6gj6iay2b1K2pqlZ3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2bcy7+vkyWkw6K00Yj7CrKBkE2Arg0dRck/O7IkbhP1MAvFm4+x62+bC6F7CR95Bh V06UEWx0ATT3aAUwLlYYB8lMn9vIhDWxi2B8q+0akqtDpYS/BSejBJm5ePq8Js5IeL Fmshfq9Q6ZLKoJ96RNZjnY5HU6JV9LC3Fuhz5iEM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johannes Thumshirn , Damien Le Moal , Himanshu Madhani , Naohiro Aota , "Martin K. Petersen" Subject: [PATCH 5.14 040/162] scsi: sd_zbc: Ensure buffer size is aligned to SECTOR_SIZE Date: Mon, 27 Sep 2021 19:01:26 +0200 Message-Id: <20210927170234.885541432@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210927170233.453060397@linuxfoundation.org> References: <20210927170233.453060397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Naohiro Aota commit 7215e909814fed7cda33c954943a4050d8348204 upstream. Reporting zones on a SCSI device sometimes fail with the following error: [76248.516390] ata16.00: invalid transfer count 131328 [76248.523618] sd 15:0:0:0: [sda] REPORT ZONES start lba 536870912 failed The error (from drivers/ata/libata-scsi.c:ata_scsi_zbc_in_xlat()) indicates that buffer size is not aligned to SECTOR_SIZE. This happens when the __vmalloc() failed. Consider we are reporting 4096 zones, then we will have "bufsize = roundup((4096 + 1) * 64, SECTOR_SIZE)" = (513 * 512) = 262656. Then, __vmalloc() failure halves the bufsize to 131328, which is no longer aligned to SECTOR_SIZE. Use rounddown() to ensure the size is always aligned to SECTOR_SIZE and fix the comment as well. Link: https://lore.kernel.org/r/20210906140642.2267569-1-naohiro.aota@wdc.com Fixes: 23a50861adda ("scsi: sd_zbc: Cleanup sd_zbc_alloc_report_buffer()") Cc: stable@vger.kernel.org # 5.5+ Reviewed-by: Johannes Thumshirn Reviewed-by: Damien Le Moal Reviewed-by: Himanshu Madhani Signed-off-by: Naohiro Aota Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/sd_zbc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -154,8 +154,8 @@ static void *sd_zbc_alloc_report_buffer( /* * Report zone buffer size should be at most 64B times the number of - * zones requested plus the 64B reply header, but should be at least - * SECTOR_SIZE for ATA devices. + * zones requested plus the 64B reply header, but should be aligned + * to SECTOR_SIZE for ATA devices. * Make sure that this size does not exceed the hardware capabilities. * Furthermore, since the report zone command cannot be split, make * sure that the allocated buffer can always be mapped by limiting the @@ -174,7 +174,7 @@ static void *sd_zbc_alloc_report_buffer( *buflen = bufsize; return buf; } - bufsize >>= 1; + bufsize = rounddown(bufsize >> 1, SECTOR_SIZE); } return NULL;