Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp240762pxf; Wed, 10 Mar 2021 05:27:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJwVy19KPcWz9zZPN/aLT7vyB/Untwb4aNoFxZ5uwptEdrLLNFljhJHZOSwgDte18KlRfAEW X-Received: by 2002:a17:906:229b:: with SMTP id p27mr3755751eja.287.1615382823658; Wed, 10 Mar 2021 05:27:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615382823; cv=none; d=google.com; s=arc-20160816; b=KB5q3fotU9xejQnBPq6aUXJqvKRvv5Jgrh20UEuzgl+6X8rCPqUESPRI9PbWIEj7kX /WZknSwb8jrBr/BTAUcXbDV/iX7OaE20d/5zcv+pTHg+NR9Nm3JqIxum+ezRrAsQDmfG Yf3IsI1HFLXjT/hALQ3hqTD6EoaqSUAZl9u+WaHxTQrkNPqlzhpl/RLEIIQfdfrEkW7x fUQCp4maulha0oCOfXsbOGTTu7digBqeb0ykp43knHvggmg4YuCHa2CbkKHIYpd/6l35 ED0DP/QDuHKblmwG+sqQBLJ9TIXWQVGHMMFH16ceGGuywY+PxXdKvDnpexh282emFRaq TWow== 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=Jnol1IAvzArabCP3H+P+WvvLXS4N32QtEJqoOdiwHOE=; b=jpQi9RhkazZgUeSfKoMaxqPhD+TllAy7FihuxAUGOZJY9kFb9Cl34tyZReSbTy6MZG 2gHFSd2yGaeV3npkYIkCLqZju6hTz8xUE1m+eD0qfIM48lVW58NjDyj1vCr7uj2VClTY 6IaE47LxI/LtVJpv8MI6EDrNSQFJG1IEPyPYfUkAMg6CC/M5qG2claP6GkXOct4aARc+ Ixk+9eoHSB8hx4iv4eeI1Nyx7OcyVm2vYMVhFWytZlGd6/NE4Svo/MC7a9gV0g1T9S/S Q+SVaRC6hMLBhKlZ/6AvlziWTh14uWfMf30jOfkEKFfAoLkFWhfreVubjTfybWOq4wKx AwIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="1BO8N/AZ"; 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 bf4si11576232edb.291.2021.03.10.05.26.40; Wed, 10 Mar 2021 05:27:03 -0800 (PST) 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="1BO8N/AZ"; 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 S233391AbhCJNZc (ORCPT + 99 others); Wed, 10 Mar 2021 08:25:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:45690 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232833AbhCJNYc (ORCPT ); Wed, 10 Mar 2021 08:24:32 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5001664FD8; Wed, 10 Mar 2021 13:24:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615382672; bh=9wcc4n78aKOWTbHWA8sNTGBa5H3IwLzze4odfHEKW6U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1BO8N/AZTsHG/nlcHpJgUWPWRSuVS1KRAmZSLmZ7NdloJlilohi6p7qWGe6P0eGML EmO7DR/A0o+8HxijgcxdIccEVxOatGQ4a4xp6t19yDcBeVNhrNvUUMwckBSZVj1vGC Lj2UH+06zTzIRF/TDgakGuN36/QO1k8sT49BXYJA= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kiwoong Kim , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.11 21/36] scsi: ufs: Introduce a quirk to allow only page-aligned sg entries Date: Wed, 10 Mar 2021 14:23:34 +0100 Message-Id: <20210310132321.175120859@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210310132320.510840709@linuxfoundation.org> References: <20210310132320.510840709@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: Greg Kroah-Hartman From: Kiwoong Kim [ Upstream commit 2b2bfc8aa519f696087475ed8e8c61850c673272 ] Some SoCs require a single scatterlist entry for smaller than page size, i.e. 4KB. When dispatching commands with more than one scatterlist entry under 4KB in size the following behavior is observed: A command to read a block range is dispatched with two scatterlist entries that are named AAA and BBB. After dispatching, the host builds two PRDT entries and during transmission, device sends just one DATA IN because device doesn't care about host DMA. The host then transfers the combined amount of data from start address of the area named AAA. As a consequence, the area that follows AAA in memory would be corrupted. |<------------->| +-------+------------ +-------+ + AAA + (corrupted) ... + BBB + +-------+------------ +-------+ To avoid this we need to enforce page size alignment for sg entries. Link: https://lore.kernel.org/r/56dddef94f60bd9466fd77e69f64bbbd657ed2a1.1611026909.git.kwmad.kim@samsung.com Signed-off-by: Kiwoong Kim Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/ufs/ufshcd.c | 2 ++ drivers/scsi/ufs/ufshcd.h | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 8ecdd53c9746..428b9e0ac47e 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -4831,6 +4831,8 @@ static int ufshcd_slave_configure(struct scsi_device *sdev) struct request_queue *q = sdev->request_queue; blk_queue_update_dma_pad(q, PRDT_DATA_BYTE_COUNT_PAD - 1); + if (hba->quirks & UFSHCD_QUIRK_ALIGN_SG_WITH_PAGE_SIZE) + blk_queue_update_dma_alignment(q, PAGE_SIZE - 1); if (ufshcd_is_rpm_autosuspend_allowed(hba)) sdev->rpm_autosuspend = 1; diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 85f9d0fbfbd9..8cb64ae95462 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -557,6 +557,10 @@ enum ufshcd_quirks { */ UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING = 1 << 13, + /* + * This quirk allows only sg entries aligned with page size. + */ + UFSHCD_QUIRK_ALIGN_SG_WITH_PAGE_SIZE = 1 << 13, }; enum ufshcd_caps { -- 2.30.1