Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3704234imu; Mon, 28 Jan 2019 09:19:23 -0800 (PST) X-Google-Smtp-Source: ALg8bN6GgOxW9HKe0fTjwra4EzJh2bEbS8NF75q1TzYX3+mmffPLE+7RYnchMm0YTUysz2hZgm4y X-Received: by 2002:a17:902:7296:: with SMTP id d22mr23045348pll.265.1548695963729; Mon, 28 Jan 2019 09:19:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548695963; cv=none; d=google.com; s=arc-20160816; b=cQoJpjASV68vQjev49G5cWaxUvRt58/rkkhhWp/dLvD5bYFD4HUAO3e86GNW40wgJa g6FXm6TpwMGSeCaBIdYyy1HSTrWV2XFVZjQ8hvF/YsLBP1uvCRdbP/7fsYxFtq/cRbNh vUY9diVF8lcrSi6oHzUn8/GVv8dhZvBFghceLttpVuzOZjOY+QIAkzQ1Lx1Q/XUoQfOF Z/3Q7MdGf2bVAT+StEtV8DuzaydemXRrT+weSExwB+Mswp9siC+amR4MITc+krCg5hyc xzgc/pnZTIb9TX2KbOBVjGU93Pndx1EJaIorFtgt49eSsUShd+ik5+KJVx97aF1OxKbb +94w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Tvkb9Z9NkIY5Ql/oworr8I1dsOxIvseJiao2ErD8IxU=; b=GD6BOpo1AjApbY6uwxgTfoXHdI9w//6sQ2wC3/j0JGDaUqjKvERXye+UJSJOyblgZ1 Am0TFyf1dZlsk3LW1HS3xAmQov7+lJ1Max12C3pNRmi0xutn6Qhcae0D2bHd14Bmalap 9dzh1yr6I1JZPuEbk45DwremalsguIZIsItCy5PjrsgdTimVjFwt2cdV55VOfPkHoooA MFZ08dR9zO0ceO5Xxe05q4KsvdDwclUwjzMxAO/EQz1t1AN0ityKuk1FlNNXHnWS7jGV ePSpDNHqs4/9EaE0FrWkxN+QUafhvukQkv9FlRbQempWa4u3TxpLWVUXoYcGFSbjgIlU 82UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="mhJeZMk/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 76si33342458pfw.66.2019.01.28.09.19.08; Mon, 28 Jan 2019 09:19:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="mhJeZMk/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731837AbfA1QF2 (ORCPT + 99 others); Mon, 28 Jan 2019 11:05:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:52000 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731235AbfA1QFY (ORCPT ); Mon, 28 Jan 2019 11:05:24 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B3F532147A; Mon, 28 Jan 2019 16:05:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691523; bh=uQYtjBKDZsFz2zCHnVnVeMlqRtrAmaMlhd8HHe38UpE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mhJeZMk/H/i+J+JKUGBneoMrHK4q54gZZmv9e2E3zGiYL352JhbHE2UzWZ0XyhP1k eiyhDjPZ6v4VJTvCXmb75ghz+LEh5yKDtxgu3uNGHW/SI4Sesm6gXROZG5fm6bTY/h ZsldJcAymtQkgwXKkYBxv7zVueFHRtn2ukr2jy2I= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zhen Lei , Will Deacon , Sasha Levin , iommu@lists.linux-foundation.org Subject: [PATCH AUTOSEL 4.19 128/258] iommu/arm-smmu-v3: Avoid memory corruption from Hisilicon MSI payloads Date: Mon, 28 Jan 2019 10:57:14 -0500 Message-Id: <20190128155924.51521-128-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhen Lei [ Upstream commit 84a9a75774961612d0c7dd34a1777e8f98a65abd ] The GITS_TRANSLATER MMIO doorbell register in the ITS hardware is architected to be 4 bytes in size, yet on hi1620 and earlier, Hisilicon have allocated the adjacent 4 bytes to carry some IMPDEF sideband information which results in an 8-byte MSI payload being delivered when signalling an interrupt: MSIAddr: |----4bytes----|----4bytes----| | MSIData | IMPDEF | This poses no problem for the ITS hardware because the adjacent 4 bytes are reserved in the memory map. However, when delivering MSIs to memory, as we do in the SMMUv3 driver for signalling the completion of a SYNC command, the extended payload will corrupt the 4 bytes adjacent to the "sync_count" member in struct arm_smmu_device. Fortunately, the current layout allocates these bytes to padding, but this is fragile and we should make this explicit. Reviewed-by: Robin Murphy Signed-off-by: Zhen Lei [will: Rewrote commit message and comment] Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- drivers/iommu/arm-smmu-v3.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 3e02aace38b1..4afb9cb99ea3 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -586,7 +586,11 @@ struct arm_smmu_device { struct arm_smmu_strtab_cfg strtab_cfg; - u32 sync_count; + /* Hi16xx adds an extra 32 bits of goodness to its MSI payload */ + union { + u32 sync_count; + u64 padding; + }; /* IOMMU core code handle */ struct iommu_device iommu; -- 2.19.1