Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2750485pxj; Mon, 31 May 2021 09:48:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWtJsTqT4e6EEKc+KmVuC0XvbCYMtqaswqN7IHly5+q4xIQjJIAaVWaoaU6AbeEsRHkGcu X-Received: by 2002:a05:6402:1052:: with SMTP id e18mr26949632edu.366.1622479706976; Mon, 31 May 2021 09:48:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622479706; cv=none; d=google.com; s=arc-20160816; b=SEJA0ycDeDdGJwrKXP8EgJ+7+iw2SYmMNrG3PN/Upqfgi9hbyl9COgfHAZ6AE7JJC1 or/XScyaYBogEH+AGfM/Cu8Xvc+mpvC72v2BhV0jmuUQ6gVfwEsa1HgYiBntD5u8cu78 zc52zX7N5ib1hkkP3nsh3ugk7EoG/d+dHXpd9CfBLt0F82iHiINip79F9CZlDgQ5QMV7 TYEy8ydfdLxR4ORbCuF0dDdOKaZB8mGi+DPAizwlR+lnAkzPdOyeQRsgbvBX9/tzUv/e SoMExHpWxZe1ndaMXjTDPePtJcstZJ3HyIz90qkXpGtUxzya08Y6RYY/Vnusfl3E59j/ WG6g== 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=L20+WenEwCxVuzB+QaerdcV1UXyQA0l1cBQhTEfAwkk9Og4pFhPQk1EYZT26u3RvDm +07JmB7MGZWiw+JTjzngFxroU2gHzbr18qch3Gq4qMkWrmy4hnenlmw5e5a++kWJYKD4 +R0O441CZPIMuRCLjPakzd6rq7sdIYWQ8bd19D25sPBFM9RShJxf3CwbFxuPU0V0ciGN gvEm+1CdvsZhgcwfELE1DLrK9sS51hd65n2fEfNdS0ekd/nyuCSw8DG3t1ue1TPzFpG6 caAf6Bd1uT5POTTUV/CO8y/wWe5/EbLBjwwAZq+Z6qk8FIEvHKc+sTY+mbdf5FBUBrYa Fnag== 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 linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 k17si8304389ejk.238.2021.05.31.09.48.03; Mon, 31 May 2021 09:48:26 -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=@linuxfoundation.org header.s=korg header.b=FWiVZySA; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232080AbhEaQsg (ORCPT + 99 others); Mon, 31 May 2021 12:48:36 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(+) 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) -- 2.30.2