Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1324599pxk; Fri, 4 Sep 2020 06:47:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8JOZpEUtfRl7Yv/+EHUiiPLUdz3zmLWhbSUPkn501kh2EjyCwDi+NTVUq6L2ehS5xXJRY X-Received: by 2002:a17:906:556:: with SMTP id k22mr6426705eja.369.1599227253069; Fri, 04 Sep 2020 06:47:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599227253; cv=none; d=google.com; s=arc-20160816; b=Bllw1bXqQ5FepU8bY3j0m9cCSUjIsc7RyRrVdLNFzORfPSTCcMi+R1QXan8OOteVwv HChUYMQQ6VrmLVXhwz0MObknOq6h6gCjeTZzFu7GI/2WcMW/deAv3Lsh8iwXOKvLiKgs i+/GdcdwtV/JkytVgKZaqVMT/zBQjz56R7wD4XyNKfyyoLqq1Mng8HZMe9qcXS1+Pb3k vHZSlSlDgX8ZI04MA6go3jww87T8V/A8DuKICiuOj8ugJKaI3Ie31Qy2zuWS98ab8TjZ gDgjKB5EfflGliovSPW12opexsN3g8YkzpdHI8Etk8d0fk9i/lLHmv6ru4gxtJ9+ZDP9 qbKg== 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=fKJsj3UxuE/bcgSPk7lwEZLX4KgCvlf5myiH/hiXdzQ=; b=XZLsOg7MkmXmWN8XvNgcLRk4VqHvZ8M+olp91v3LSepRJRoQbXpgKYujwCWgsiF2oM wHsscOjAlOgGOsc/gi6fkbd4xaHV9HL1ppCYyq+32noAafVqgD2p5JZyqH4//ktkoz0G yBjrmBFwSIYe6AsHJ4hENf3BDczAJ96oCGpGZn++Y3W0XXJeUNUmHDKrlFXuPx2MpA9R vYI8bQtiONyw0lVnz4gnOlQKcrzinR+MeIDIBCW8ZdUFDv72tL4ip3xweKK2xAkyO+Pu 2nZcWVSA5lOgMbOVwPl7DAo+nnt7LIiwzMcbCpUg1F9fKJaBTX7ZKwN8IO06t/14tqQV UVvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nE87rAyX; 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 s5si3889194edu.65.2020.09.04.06.47.08; Fri, 04 Sep 2020 06:47:33 -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=nE87rAyX; 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 S1730595AbgIDNpX (ORCPT + 99 others); Fri, 4 Sep 2020 09:45:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:43914 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730212AbgIDNmd (ORCPT ); Fri, 4 Sep 2020 09:42:33 -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 A94A520C09; Fri, 4 Sep 2020 13:30:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599226227; bh=aTdgrapGl6hhy72V1j6OvtPhsNpHmNOqrIOa/HJfm8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nE87rAyXzK6VI1WLFVLiKC9cALLyVrFxJbyW6cpgXaJfvcR1Mj9De6yhJcY7ImuwJ xHbpVCrlpZbx9sWbMrQBBLGpbJpO8+wgpI8O5mSl1k6vo9EX8sK+aQxwVeXKh8MutI zI0PAsTPPuzBv0YMUjCrnqueqqJadda9oVvppF0w= 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 5.4 15/16] scsi: target: tcmu: Fix size in calls to tcmu_flush_dcache_range Date: Fri, 4 Sep 2020 15:30:08 +0200 Message-Id: <20200904120257.940624145@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200904120257.203708503@linuxfoundation.org> References: <20200904120257.203708503@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 @@ -1007,7 +1007,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)); @@ -1072,7 +1072,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));