From: Sasha Levin <sashal@kernel.org> To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>, Boris Ostrovsky <boris.ostrovsky@oracle.com>, Brijesh Singh <brijesh.singh@amd.com>, Joerg Roedel <jroedel@suse.de>, Sasha Levin <sashal@kernel.org>, iommu@lists.linux-foundation.org Subject: [PATCH AUTOSEL 4.9 09/32] iommu/amd: Fix IOMMU page flush when detach device from a domain Date: Sat, 23 Feb 2019 16:09:28 -0500 [thread overview] Message-ID: <20190223210951.202268-9-sashal@kernel.org> (raw) In-Reply-To: <20190223210951.202268-1-sashal@kernel.org> From: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> [ Upstream commit 9825bd94e3a2baae1f4874767ae3a7d4c049720e ] When a VM is terminated, the VFIO driver detaches all pass-through devices from VFIO domain by clearing domain id and page table root pointer from each device table entry (DTE), and then invalidates the DTE. Then, the VFIO driver unmap pages and invalidate IOMMU pages. Currently, the IOMMU driver keeps track of which IOMMU and how many devices are attached to the domain. When invalidate IOMMU pages, the driver checks if the IOMMU is still attached to the domain before issuing the invalidate page command. However, since VFIO has already detached all devices from the domain, the subsequent INVALIDATE_IOMMU_PAGES commands are being skipped as there is no IOMMU attached to the domain. This results in data corruption and could cause the PCI device to end up in indeterministic state. Fix this by invalidate IOMMU pages when detach a device, and before decrementing the per-domain device reference counts. Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Suggested-by: Joerg Roedel <joro@8bytes.org> Co-developed-by: Brijesh Singh <brijesh.singh@amd.com> Signed-off-by: Brijesh Singh <brijesh.singh@amd.com> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> Fixes: 6de8ad9b9ee0 ('x86/amd-iommu: Make iommu_flush_pages aware of multiple IOMMUs') Signed-off-by: Joerg Roedel <jroedel@suse.de> Signed-off-by: Sasha Levin <sashal@kernel.org> --- drivers/iommu/amd_iommu.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 80fb16c8c05e9..7766f07ab9b45 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -1889,6 +1889,7 @@ static void do_attach(struct iommu_dev_data *dev_data, static void do_detach(struct iommu_dev_data *dev_data) { + struct protection_domain *domain = dev_data->domain; struct amd_iommu *iommu; u16 alias; @@ -1904,10 +1905,6 @@ static void do_detach(struct iommu_dev_data *dev_data) iommu = amd_iommu_rlookup_table[dev_data->devid]; alias = dev_data->alias; - /* decrease reference counters */ - dev_data->domain->dev_iommu[iommu->index] -= 1; - dev_data->domain->dev_cnt -= 1; - /* Update data structures */ dev_data->domain = NULL; list_del(&dev_data->list); @@ -1917,6 +1914,16 @@ static void do_detach(struct iommu_dev_data *dev_data) /* Flush the DTE entry */ device_flush_dte(dev_data); + + /* Flush IOTLB */ + domain_flush_tlb_pde(domain); + + /* Wait for the flushes to finish */ + domain_flush_complete(domain); + + /* decrease reference counters - needs to happen after the flushes */ + domain->dev_iommu[iommu->index] -= 1; + domain->dev_cnt -= 1; } /* -- 2.19.1
WARNING: multiple messages have this Message-ID (diff)
From: Sasha Levin <sashal-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> To: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Cc: Sasha Levin <sashal-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>, Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>, Brijesh Singh <brijesh.singh-5C7GfCeVMHo@public.gmane.org>, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, Boris Ostrovsky <boris.ostrovsky-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org> Subject: [PATCH AUTOSEL 4.9 09/32] iommu/amd: Fix IOMMU page flush when detach device from a domain Date: Sat, 23 Feb 2019 16:09:28 -0500 [thread overview] Message-ID: <20190223210951.202268-9-sashal@kernel.org> (raw) In-Reply-To: <20190223210951.202268-1-sashal-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> From: Suravee Suthikulpanit <suravee.suthikulpanit-5C7GfCeVMHo@public.gmane.org> [ Upstream commit 9825bd94e3a2baae1f4874767ae3a7d4c049720e ] When a VM is terminated, the VFIO driver detaches all pass-through devices from VFIO domain by clearing domain id and page table root pointer from each device table entry (DTE), and then invalidates the DTE. Then, the VFIO driver unmap pages and invalidate IOMMU pages. Currently, the IOMMU driver keeps track of which IOMMU and how many devices are attached to the domain. When invalidate IOMMU pages, the driver checks if the IOMMU is still attached to the domain before issuing the invalidate page command. However, since VFIO has already detached all devices from the domain, the subsequent INVALIDATE_IOMMU_PAGES commands are being skipped as there is no IOMMU attached to the domain. This results in data corruption and could cause the PCI device to end up in indeterministic state. Fix this by invalidate IOMMU pages when detach a device, and before decrementing the per-domain device reference counts. Cc: Boris Ostrovsky <boris.ostrovsky-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org> Suggested-by: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org> Co-developed-by: Brijesh Singh <brijesh.singh-5C7GfCeVMHo@public.gmane.org> Signed-off-by: Brijesh Singh <brijesh.singh-5C7GfCeVMHo@public.gmane.org> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit-5C7GfCeVMHo@public.gmane.org> Fixes: 6de8ad9b9ee0 ('x86/amd-iommu: Make iommu_flush_pages aware of multiple IOMMUs') Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org> Signed-off-by: Sasha Levin <sashal-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> --- drivers/iommu/amd_iommu.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 80fb16c8c05e9..7766f07ab9b45 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -1889,6 +1889,7 @@ static void do_attach(struct iommu_dev_data *dev_data, static void do_detach(struct iommu_dev_data *dev_data) { + struct protection_domain *domain = dev_data->domain; struct amd_iommu *iommu; u16 alias; @@ -1904,10 +1905,6 @@ static void do_detach(struct iommu_dev_data *dev_data) iommu = amd_iommu_rlookup_table[dev_data->devid]; alias = dev_data->alias; - /* decrease reference counters */ - dev_data->domain->dev_iommu[iommu->index] -= 1; - dev_data->domain->dev_cnt -= 1; - /* Update data structures */ dev_data->domain = NULL; list_del(&dev_data->list); @@ -1917,6 +1914,16 @@ static void do_detach(struct iommu_dev_data *dev_data) /* Flush the DTE entry */ device_flush_dte(dev_data); + + /* Flush IOTLB */ + domain_flush_tlb_pde(domain); + + /* Wait for the flushes to finish */ + domain_flush_complete(domain); + + /* decrease reference counters - needs to happen after the flushes */ + domain->dev_iommu[iommu->index] -= 1; + domain->dev_cnt -= 1; } /* -- 2.19.1
next prev parent reply other threads:[~2019-02-23 21:17 UTC|newest] Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-02-23 21:09 [PATCH AUTOSEL 4.9 01/32] vti4: Fix a ipip packet processing bug in 'IPCOMP' virtual tunnel Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 02/32] xfrm: refine validation of template and selector families Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 03/32] perf core: Fix perf_proc_update_handler() bug Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 04/32] perf tools: Handle TOPOLOGY headers with no CPU Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 05/32] IB/{hfi1, qib}: Fix WC.byte_len calculation for UD_SEND_WITH_IMM Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 06/32] iommu/amd: Call free_iova_fast with pfn in map_sg Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 07/32] iommu/amd: Unmap all mapped pages in error path of map_sg Sasha Levin 2019-02-23 21:09 ` Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 08/32] ipvs: Fix signed integer overflow when setsockopt timeout Sasha Levin 2019-02-23 21:09 ` Sasha Levin [this message] 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 09/32] iommu/amd: Fix IOMMU page flush when detach device from a domain Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 10/32] xtensa: SMP: fix ccount_timer_shutdown Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 11/32] xtensa: SMP: fix secondary CPU initialization Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 12/32] xtensa: smp_lx200_defconfig: fix vectors clash Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 13/32] xtensa: SMP: mark each possible CPU as present Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 14/32] xtensa: SMP: limit number of possible CPUs by NR_CPUS Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 15/32] net: altera_tse: fix msgdma_tx_completion on non-zero fill_level case Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 16/32] net: hns: Fix for missing of_node_put() after of_parse_phandle() Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 17/32] net: hns: Fix wrong read accesses via Clause 45 MDIO protocol Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 18/32] net: stmmac: dwmac-rk: fix error handling in rk_gmac_powerup() Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 19/32] gpio: vf610: Mask all GPIO interrupts Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 20/32] nfs: Fix NULL pointer dereference of dev_name Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 21/32] qed: Fix VF probe failure while FLR Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 22/32] scsi: libfc: free skb when receiving invalid flogi resp Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 23/32] platform/x86: Fix unmet dependency warning for SAMSUNG_Q10 Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 24/32] cifs: fix computation for MAX_SMB2_HDR_SIZE Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 25/32] arm64: kprobe: Always blacklist the KVM world-switch code Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 26/32] x86/kexec: Don't setup EFI info if EFI runtime is not enabled Sasha Levin 2019-02-23 21:09 ` Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 27/32] x86_64: increase stack size for KASAN_EXTRA Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 28/32] mm, memory_hotplug: is_mem_section_removable do not pass the end of a zone Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 29/32] mm, memory_hotplug: test_pages_in_a_zone do not pass the end of zone Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 30/32] fs/drop_caches.c: avoid softlockups in drop_pagecache_sb() Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 31/32] autofs: drop dentry reference only when it is never used Sasha Levin 2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 32/32] autofs: fix error return in autofs_fill_super() Sasha Levin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20190223210951.202268-9-sashal@kernel.org \ --to=sashal@kernel.org \ --cc=boris.ostrovsky@oracle.com \ --cc=brijesh.singh@amd.com \ --cc=iommu@lists.linux-foundation.org \ --cc=jroedel@suse.de \ --cc=linux-kernel@vger.kernel.org \ --cc=stable@vger.kernel.org \ --cc=suravee.suthikulpanit@amd.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.