Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1324108pxk; Fri, 4 Sep 2020 06:46:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5nwZoRFt9ou3K8U3lZ+MuMXGqCrJkRtLAONqM18g6rawn4zg5ESWC9bsv7R3AjKDMp1mC X-Received: by 2002:a17:906:38c7:: with SMTP id r7mr7790144ejd.118.1599227205615; Fri, 04 Sep 2020 06:46:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599227205; cv=none; d=google.com; s=arc-20160816; b=brwfMe/ss/PgqmF13qArsDFWmUpyFQgHhyiVNsJYKWzWUClcGtUBeRl/4LT3yWXXEF S231GV+f+VG3gGTdsY5Z82cNhykKcG6e9ooFnEld8mZ/ZB5rfftJJnXikTtacPv52IgJ +O4QLf/s5qZzaKfs7NWf1Z3pG6W4ENmske541wGPfrB5jrxvIe/e3E+0Tgn8/1dQeH94 7GUHydK3eB8XKlps2Wzb/wrmeaLmntJFZgWbRllyr5klTBI7NT9Oqv2N0HGC+9ynUscJ wG/BPpp0r5I3YDTZr0qEkQgdYmEdplWmHQTIDUliGbFTnNiTBe+yzF9tx24FaWwHiNn5 bdeQ== 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=yE7raTOPXNzHY81r1h/u2AKBYzMzGWDzQt5FmHt+umA=; b=PbQBaOU/hI0yxUA1wn2hvHHe+jwvM4Nm0ZjiqMTi7axRJ2g62QQA8+d7tZ3fxt7om5 d7v4QJFwmoYAErExx/y1B6TKOB1qdeEJLsWlyh/Q0fI/qib9/QrAZhUw6GaUjvgvCPqD R+OcVc6aQe9E+JAaHxsMjvJ6IKRZDhFJjjHXg3MQBZDBcSGI+9EjNj0/TYfiP3+AD3uw 3jhVKS2kUASeVqI/68APyYWc16AR/59TAsPMIqi6vGEQ5NjVNA6ocfZA8BeTIK0ghLSj dE3ENzF/3IP8Th8uep8HVIl2Jtv/m2OpYFy8IIuHgpHkXb9Va2Ze72Wa2mssU0md+edD jlJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="DmuO6/Gm"; 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=fail (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 g19si4641267ejz.608.2020.09.04.06.46.21; Fri, 04 Sep 2020 06:46:45 -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=@kernel.org header.s=default header.b="DmuO6/Gm"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730432AbgIDNoz (ORCPT + 99 others); Fri, 4 Sep 2020 09:44:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:38488 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730488AbgIDNeY (ORCPT ); Fri, 4 Sep 2020 09:34:24 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 DAB5E21734; Fri, 4 Sep 2020 13:31:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599226279; bh=5IwSshPpgozIPZMjbeg/fb3EXkle70zb11w810FYpW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DmuO6/Gm/vXZr09yyWeEN91h92YYLGW1ID6+xR9Mli84Vz9IvyUIC1qYIlrtqn8l/ t7zmuoa+Tx4jtMyhLxRK4fGkrWV6xIO40mydLCGPXZHoz7UT4U0rWTfLfxEdaTHh+H 0Md22jElYz9Ui7+PL1OAYAtIDThCmN6fGM1ZeFRE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, JiangYu , Daniel Meyerholt , Mike Christie , Bodo Stroesser , "Martin K. Petersen" Subject: [PATCH 5.8 17/17] scsi: target: tcmu: Optimize use of flush_dcache_page Date: Fri, 4 Sep 2020 15:30:16 +0200 Message-Id: <20200904120258.840415117@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200904120257.983551609@linuxfoundation.org> References: <20200904120257.983551609@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Bodo Stroesser commit 3c58f737231e2c8cbf543a09d84d8c8e80e05e43 upstream. (scatter|gather)_data_area() need to flush dcache after writing data to or before reading data from a page in uio data area. The two routines are able to handle data transfer to/from such a page in fragments and flush the cache after each fragment was copied by calling the wrapper tcmu_flush_dcache_range(). That means: 1) flush_dcache_page() can be called multiple times for the same page. 2) Calling flush_dcache_page() indirectly using the wrapper does not make sense, because each call of the wrapper is for one single page only and the calling routine already has the correct page pointer. Change (scatter|gather)_data_area() such that, instead of calling tcmu_flush_dcache_range() before/after each memcpy, it now calls flush_dcache_page() before unmapping a page (when writing is complete for that page) or after mapping a page (when starting to read the page). After this change only calls to tcmu_flush_dcache_range() for addresses in vmalloc'ed command ring are left over. The patch was tested on ARM with kernel 4.19.118 and 5.7.2 Link: https://lore.kernel.org/r/20200618131632.32748-2-bstroesser@ts.fujitsu.com Tested-by: JiangYu Tested-by: Daniel Meyerholt Acked-by: Mike Christie Signed-off-by: Bodo Stroesser Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/target/target_core_user.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -676,8 +676,10 @@ static void scatter_data_area(struct tcm from = kmap_atomic(sg_page(sg)) + sg->offset; while (sg_remaining > 0) { if (block_remaining == 0) { - if (to) + if (to) { + flush_dcache_page(page); kunmap_atomic(to); + } block_remaining = DATA_BLOCK_SIZE; dbi = tcmu_cmd_get_dbi(tcmu_cmd); @@ -722,7 +724,6 @@ static void scatter_data_area(struct tcm memcpy(to + offset, from + sg->length - sg_remaining, copy_bytes); - tcmu_flush_dcache_range(to, copy_bytes); } sg_remaining -= copy_bytes; @@ -731,8 +732,10 @@ static void scatter_data_area(struct tcm kunmap_atomic(from - sg->offset); } - if (to) + if (to) { + flush_dcache_page(page); kunmap_atomic(to); + } } static void gather_data_area(struct tcmu_dev *udev, struct tcmu_cmd *cmd, @@ -778,13 +781,13 @@ static void gather_data_area(struct tcmu dbi = tcmu_cmd_get_dbi(cmd); page = tcmu_get_block_page(udev, dbi); from = kmap_atomic(page); + flush_dcache_page(page); } copy_bytes = min_t(size_t, sg_remaining, block_remaining); if (read_len < copy_bytes) copy_bytes = read_len; offset = DATA_BLOCK_SIZE - block_remaining; - tcmu_flush_dcache_range(from, copy_bytes); memcpy(to + sg->length - sg_remaining, from + offset, copy_bytes);