Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3704415imu; Mon, 28 Jan 2019 09:19:35 -0800 (PST) X-Google-Smtp-Source: ALg8bN5Vjjtkz3EmZgxQN5k5cUJvLJM0KozI2ui1v2oMSjyI1pSBQJ8K2Fte6vnmzcEernEVK8jC X-Received: by 2002:a63:2643:: with SMTP id m64mr20208624pgm.35.1548695975170; Mon, 28 Jan 2019 09:19:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548695975; cv=none; d=google.com; s=arc-20160816; b=yFIe2ijPZBn9E/JlQ5Jz1KgbEk+taO9FN76Z2VybM5iUtE9+qq87UetfrFT0OIYJun BgUddMdDJtgk1sQK4P/BBoql8CCtldAKCT+/PzKdW3DCqAtLnxBvHpELocTSInzJdxXu eZ3VOtm8hZVV96kbGCuhow/HSUCgxWjXp1+mxj0OnAjPRlF/ZXTP2a6E1r9iRmcff+Sq 8Sqbb6CVrqOOr4B4oyX9df1Uswf8B1xrStvlTGCLUkD4vluHWLJCseh+sdwnkTw1SY4n JIIPYGOWVLPwZ56k0toX5JvOKqaLAZdUpV/ip2hyGEQu6W9v8hclfJkQYBYU8OLA8KsH 9p0w== 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=LV9h3J74/Oh8yBttbxkSKoB+6R3hxUx6/qGYPUhPVl4=; b=zU0/aF4DxBeTv9NXIPeDb7e3dDVdUYhkmKMNiN2JXjhe54o5GJAnTQ8CcvMlsi/z8L iysf668jqJn3Nb6EbPISFcN7SZM//vx/5Wnmol6kGv1AWkjK/9GztXdr6XDVv23tqDLW UlK2yjpSYRz8SmeOzmoMyb0hQw5+MC40qUcocMNFfyr8ANabO7NZG2q8ETO1h4z3QwMB 1hYtZxj65NaeXu/phJGBTjzCKmj5p/phhKsmuz46MHZnnb3++03GcWhKLOEBl6q91qur SFvsN/4eSCu36dy9hDW84j3+qDIFMRyN2STeibJVusaJqP2OaNQvh042HqBsO2sWLf4t KdSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=un3gPL1v; 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 38si9839679pln.313.2019.01.28.09.19.20; Mon, 28 Jan 2019 09:19:35 -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=un3gPL1v; 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 S1731745AbfA1QFF (ORCPT + 99 others); Mon, 28 Jan 2019 11:05:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:51180 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730962AbfA1QFB (ORCPT ); Mon, 28 Jan 2019 11:05:01 -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 AECDC2171F; Mon, 28 Jan 2019 16:04:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691500; bh=h/ShXZmUtndpFgzPk/sJLpEnNUyArze+1iQgZvXa180=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=un3gPL1vVrYpLyjj1j39wZiZ0p4qAGpHb32HJ4aKGjXPzEsKX4QebzMPa32QHgHJ8 3VJJ0AN2LTOLS0pKYuIA3RJ95ScQ5B9jahwuQhT4v4OJ5BBpIH4N2L6eEg+Pas9x68 Bb5vXgolUxlUkHN2QG/MoOUODnHQCjwP7j9qA6OI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yu Zhao , Joerg Roedel , Sasha Levin , iommu@lists.linux-foundation.org Subject: [PATCH AUTOSEL 4.19 118/258] iommu/amd: Fix amd_iommu=force_isolation Date: Mon, 28 Jan 2019 10:57:04 -0500 Message-Id: <20190128155924.51521-118-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: Yu Zhao [ Upstream commit c12b08ebbe16f0d3a96a116d86709b04c1ee8e74 ] The parameter is still there but it's ignored. We need to check its value before deciding to go into passthrough mode for AMD IOMMU v2 capable device. We occasionally use this parameter to force v2 capable device into translation mode to debug memory corruption that we suspect is caused by DMA writes. To address the following comment from Joerg Roedel on the first version, v2 capability of device is completely ignored. > This breaks the iommu_v2 use-case, as it needs a direct mapping for the > devices that support it. And from Documentation/admin-guide/kernel-parameters.txt: This option does not override iommu=pt Fixes: aafd8ba0ca74 ("iommu/amd: Implement add_device and remove_device") Signed-off-by: Yu Zhao Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/amd_iommu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index bee0dfb7b93b..34c9aa76a7bd 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -438,7 +438,14 @@ static int iommu_init_device(struct device *dev) dev_data->alias = get_alias(dev); - if (dev_is_pci(dev) && pci_iommuv2_capable(to_pci_dev(dev))) { + /* + * By default we use passthrough mode for IOMMUv2 capable device. + * But if amd_iommu=force_isolation is set (e.g. to debug DMA to + * invalid address), we ignore the capability for the device so + * it'll be forced to go into translation mode. + */ + if ((iommu_pass_through || !amd_iommu_force_isolation) && + dev_is_pci(dev) && pci_iommuv2_capable(to_pci_dev(dev))) { struct amd_iommu *iommu; iommu = amd_iommu_rlookup_table[dev_data->devid]; -- 2.19.1