From patchwork Mon May 31 13:15:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "gregkh@linuxfoundation.org" X-Patchwork-Id: 450523 Delivered-To: patch@linaro.org Received: by 2002:a02:c735:0:0:0:0:0 with SMTP id h21csp900005jao; Mon, 31 May 2021 07:56:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0k6RohS/byO0xyrl2LgnoFN1anlDn2ZeKrEmhidm9fsVupdgrL0QQt1MxhG5TT1tqRteM X-Received: by 2002:a05:6402:343:: with SMTP id r3mr4465683edw.22.1622472975647; Mon, 31 May 2021 07:56:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622472975; cv=none; d=google.com; s=arc-20160816; b=zvZJ2qE22Hnwt9a+J//3E0HGby/7XiIZW/+E/MurdBnVyrwD79j05rA5xivTVrMWVP lVxlp2Frg0emjcMNTuSmN2M6288KnhUAt3DjNx2ISGlgMULJsLnW6Aj1sAsqLuNRRFJn oUDGu68UVLXXVpMFvNgWLo3EDtnyFG9f2MwWp7R2dFnqCCR8aHK3f4Q3MRcyKoNRJIkE 84sVubhlG7XpJxc7T1LsWJ3CY75QiEtaQ4Kz0qDbW3MAYnVypOtmxZwbW8RKKdENROrG DdEi3q5CoMOUuB/dX1wzFfqV2A+6eV/SFzfDZkqE+g2Lf/TdYj7irIl8fnhwSI4hvg3F yIQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MRoWw6UR5biuhYOPcA+1/FIA4jgQ0DhXM7JYUUNCsfQ=; b=LDHbr4q6sVx/BxSgyh8g9SzTLEibmV6VPdCCxg6Bk4rSnsxbDy69wjSmrNOM8JdauU WpwnNQc3TU1fjWLEygzoNGD1MRzLQSRNs0gL0I4SLjKzD1t1geN6a6NQt+ZpXhZk4OId 6ygeQy+l4E88CjoQ/Sw0a0c+w2vpvXxJanMyfmBg0XlIKL0ETcz4a0wFsdfxPnO9GUcS XuYBDREVtXD65VIzdVAzmXp/gU+4mU5jeVGOc0uyiBIh5dcNf/kJwjNUqWCrARtMvuoK 02wR/qyQEB0SOOeVy8NGs2/1ocJLBu73ey/LPBYgMnCjPwKxbbjr1eLewCQX7cXKgeiz SEYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FWiVZySA; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (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 w4si8890171edu.173.2021.05.31.07.56.15; Mon, 31 May 2021 07:56:15 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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=@linuxfoundation.org header.s=korg header.b=FWiVZySA; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234222AbhEaO5q (ORCPT + 12 others); Mon, 31 May 2021 10:57:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:48408 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232364AbhEaOzg (ORCPT ); Mon, 31 May 2021 10:55:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 64C3261935; Mon, 31 May 2021 13:59:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469587; bh=I3MFQZEYwlfs0WAgyazAsru7RkY9wmdUF6WGBdOVvN4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FWiVZySAWZLjIVSYVXDtTkDP36zCS49dMNPQZfoZ6WPAPDoHcnxuDMNAVtQlfGWvZ XMa4wkTzTXpZGuOHrQPZ0sr0BpSC57K1GNUC9teYJpHE59Cab/eH6gM6V1VNXDgddY 5Qn7IzChjdAPGfuzCQVDgYFJgIWkIzi1ZL6iGQwQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jean-Philippe Brucker , Joerg Roedel , Sasha Levin Subject: [PATCH 5.12 256/296] iommu/amd: Clear DMA ops when switching domain Date: Mon, 31 May 2021 15:15:11 +0200 Message-Id: <20210531130712.363990117@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jean-Philippe Brucker [ Upstream commit d6177a6556f853785867e2ec6d5b7f4906f0d809 ] Since commit 08a27c1c3ecf ("iommu: Add support to change default domain of an iommu group") a user can switch a device between IOMMU and direct DMA through sysfs. This doesn't work for AMD IOMMU at the moment because dev->dma_ops is not cleared when switching from a DMA to an identity IOMMU domain. The DMA layer thus attempts to use the dma-iommu ops on an identity domain, causing an oops: # echo 0000:00:05.0 > /sys/sys/bus/pci/drivers/e1000e/unbind # echo identity > /sys/bus/pci/devices/0000:00:05.0/iommu_group/type # echo 0000:00:05.0 > /sys/sys/bus/pci/drivers/e1000e/bind ... BUG: kernel NULL pointer dereference, address: 0000000000000028 ... Call Trace: iommu_dma_alloc e1000e_setup_tx_resources e1000e_open Since iommu_change_dev_def_domain() calls probe_finalize() again, clear the dma_ops there like Vt-d does. Fixes: 08a27c1c3ecf ("iommu: Add support to change default domain of an iommu group") Signed-off-by: Jean-Philippe Brucker Link: https://lore.kernel.org/r/20210422094216.2282097-1-jean-philippe@linaro.org Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/amd/iommu.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.30.2 diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index a69a8b573e40..7de7a260706b 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -1747,6 +1747,8 @@ static void amd_iommu_probe_finalize(struct device *dev) domain = iommu_get_domain_for_dev(dev); if (domain->type == IOMMU_DOMAIN_DMA) iommu_setup_dma_ops(dev, IOVA_START_PFN << PAGE_SHIFT, 0); + else + set_dma_ops(dev, NULL); } static void amd_iommu_release_device(struct device *dev)