From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F856C282D7 for ; Mon, 11 Feb 2019 15:17:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4BDC0222A8 for ; Mon, 11 Feb 2019 15:17:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549898235; bh=nS2RhgDsxWzdny6ZoAvkG3QAcnWyRgn/k1Hbuvt8cag=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=rwpNZM7Um63WqoMzek5O/yIp7M8poTgZ4nAu8IuIA0hnSqMLmxApKuGCQYDajAbHO Wrndf+xWY1vGFjumJDhkJFDLyRABhFa389aYhwLaN+IqftL5tnXRJouQ8izbfO3JGv xM+ujmDCB/+pjcxZ/5mBvvjVAvf3nb/2ZR6WYAN4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390633AbfBKPGO (ORCPT ); Mon, 11 Feb 2019 10:06:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:55750 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390418AbfBKPGN (ORCPT ); Mon, 11 Feb 2019 10:06:13 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 5E411217D9; Mon, 11 Feb 2019 15:06:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549897572; bh=nS2RhgDsxWzdny6ZoAvkG3QAcnWyRgn/k1Hbuvt8cag=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PP5sKUilCmCRTIvKdwK52vMw3MBj4hR3vch9AG/AqGJaxMZytg9+CZZa9iJfOhufS ybcMzZzvze0djmkdymD8SmhkTtSRJ90syCDDf3LO12sBJR0PXoPbD/ub1GUglvj4z8 ap9+YNIie5R7JkZAc0Q7tx5i84DADcrXSldHxVkw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yu Zhao , Joerg Roedel , Sasha Levin Subject: [PATCH 4.9 041/137] iommu/amd: Fix amd_iommu=force_isolation Date: Mon, 11 Feb 2019 15:18:42 +0100 Message-Id: <20190211141815.786038643@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141811.964925535@linuxfoundation.org> References: <20190211141811.964925535@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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 bba1b9f2f782..e984418ffa2a 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -464,7 +464,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