Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4155411pxk; Tue, 8 Sep 2020 12:05:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFcaG5KigkTpuyL5uJuhq7dJluY0etR5jfOwLVCSCbrvX4+sVju8h2UcYblqpB/U0ERcRQ X-Received: by 2002:aa7:d6ce:: with SMTP id x14mr424833edr.359.1599591946758; Tue, 08 Sep 2020 12:05:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599591946; cv=none; d=google.com; s=arc-20160816; b=fGXxSF+Z0xY9HdQmb9g6kXaIX99bTdktY350gnE3jk/OwSW/bF/2IxLmTYX7A6pHV3 SdE9CFRNf69xXdX46HMZcb9nytgEvsIPRRiTvgDs79JNsRX8iWKIWALa4d+eMXmo+eRW rrybGXJpIqq9DbrjaJwqk/dXxEPKyw+njs53CCYj9lJDkgHRbPQnHbj0VDewal93bo7u IqxPyDcDg3ZvbDWi4txs6zvxlMiZGmUq3GaUfeOy0PboBJaFayWCDz2w2vUSHrPwva0K m6ZpZUEulT/Ryq8a7Oa2piUlwLxRvFV+X5f7ZHEhWMUjyFOdVNoaK5L6tDsxFmG0u0SU c7pw== 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=w7dSY/ttoOWBhGrZwmLjEopf0KJOdjCJSLKBkhiNmFU=; b=l0aCsR67mNDGjsZWpIcISVbZQUIjyHTbB00DVdQ49B7ulLOFOOdCFe6nW57hdgtzyz JXJQxyV9l/1pximEE66lCYW8QvMroq4X/TFUVBtkavrGTPE18RYbk/Hn1jzhzHZDaKtW vp3U/6eduOmrNVYVad9j7Hbd6glNpe/bInFzHsWdfEFi5oe+pb0dXD3fiyaFgGkw+H+Z jgjzpdIFm5S8MSr6tPxxSBTKV8ivnczxzTxf5Rf3u/iIAHMyp6cGwRwn+N5nact1p0dd pBdHtqGLdTkF8lh0JoP+3UrxEr5Gh03CLwyGO4n6FVGfpDi+wQGUcavWNIwLsGluF9b3 TOIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=s3+R1OnL; 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 cy15si3949130edb.525.2020.09.08.12.05.23; Tue, 08 Sep 2020 12:05:46 -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=s3+R1OnL; 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 S1731602AbgIHTCB (ORCPT + 99 others); Tue, 8 Sep 2020 15:02:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:53450 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731285AbgIHQIC (ORCPT ); Tue, 8 Sep 2020 12:08:02 -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 A0AB723ED0; Tue, 8 Sep 2020 15:47:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599580055; bh=eJp0/DnFSscwd70dd5JbDYkMNPYryCg7Ab/hvU1fyZA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s3+R1OnLTqSxQVMRv2qbINAG1fGb7UEcjaXeMOV3VE4HZ+a37v5hbKKnBCeKR3wSd WfRuuUI8d2XxC2U84RtPDF/1JgPpxcf2sxlrFSIU/uaaOAjpgHCmpj8FdnpU9Me5Z1 nUwmvxzXNJfMmsZ6gkS+qw4Sa5nrTVtwCjhrAapg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mike Christie , Bodo Stroesser , "Martin K. Petersen" Subject: [PATCH 4.19 04/88] scsi: target: tcmu: Fix size in calls to tcmu_flush_dcache_range Date: Tue, 8 Sep 2020 17:25:05 +0200 Message-Id: <20200908152221.304149512@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200908152221.082184905@linuxfoundation.org> References: <20200908152221.082184905@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 8c4e0f212398cdd1eb4310a5981d06a723cdd24f upstream. 1) If remaining ring space before the end of the ring is smaller then the next cmd to write, tcmu writes a padding entry which fills the remaining space at the end of the ring. Then tcmu calls tcmu_flush_dcache_range() with the size of struct tcmu_cmd_entry as data length to flush. If the space filled by the padding was smaller then tcmu_cmd_entry, tcmu_flush_dcache_range() is called for an address range reaching behind the end of the vmalloc'ed ring. tcmu_flush_dcache_range() in a loop calls flush_dcache_page(virt_to_page(start)); for every page being part of the range. On x86 the line is optimized out by the compiler, as flush_dcache_page() is empty on x86. But I assume the above can cause trouble on other architectures that really have a flush_dcache_page(). For paddings only the header part of an entry is relevant due to alignment rules the header always fits in the remaining space, if padding is needed. So tcmu_flush_dcache_range() can safely be called with sizeof(entry->hdr) as the length here. 2) After it has written a command to cmd ring, tcmu calls tcmu_flush_dcache_range() using the size of a struct tcmu_cmd_entry as data length to flush. But if a command needs many iovecs, the real size of the command may be bigger then tcmu_cmd_entry, so a part of the written command is not flushed then. Link: https://lore.kernel.org/r/20200528193108.9085-1-bstroesser@ts.fujitsu.com 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -1018,7 +1018,7 @@ static int queue_cmd_ring(struct tcmu_cm entry->hdr.cmd_id = 0; /* not used for PAD */ entry->hdr.kflags = 0; entry->hdr.uflags = 0; - tcmu_flush_dcache_range(entry, sizeof(*entry)); + tcmu_flush_dcache_range(entry, sizeof(entry->hdr)); UPDATE_HEAD(mb->cmd_head, pad_size, udev->cmdr_size); tcmu_flush_dcache_range(mb, sizeof(*mb)); @@ -1083,7 +1083,7 @@ static int queue_cmd_ring(struct tcmu_cm cdb_off = CMDR_OFF + cmd_head + base_command_size; memcpy((void *) mb + cdb_off, se_cmd->t_task_cdb, scsi_command_size(se_cmd->t_task_cdb)); entry->req.cdb_off = cdb_off; - tcmu_flush_dcache_range(entry, sizeof(*entry)); + tcmu_flush_dcache_range(entry, command_size); UPDATE_HEAD(mb->cmd_head, command_size, udev->cmdr_size); tcmu_flush_dcache_range(mb, sizeof(*mb));