Vasant Hegde
214a05c1c2
iommu/amd: Update amd_iommu_fault structure to include PCI seg ID
...
Rename 'device_id' as 'sbdf' and extend it to 32bit so that we can
pass PCI segment ID to ppr_notifier(). Also pass PCI segment ID to
pci_get_domain_bus_and_slot() instead of default value.
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com >
Link: https://lore.kernel.org/r/20220706113825.25582-36-vasant.hegde@amd.com
Signed-off-by: Joerg Roedel <jroedel@suse.de >
2022-07-07 09:37:54 +02:00
Vasant Hegde
196dff712e
iommu/amd: Update device_state structure to include PCI seg ID
...
Rename struct device_state.devid variable to struct device_state.sbdf
and extend it to 32-bit to include the 16-bit PCI segment ID via
the helper function get_pci_sbdf_id().
Co-developed-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com >
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com >
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com >
Link: https://lore.kernel.org/r/20220706113825.25582-35-vasant.hegde@amd.com
Signed-off-by: Joerg Roedel <jroedel@suse.de >
2022-07-07 09:37:54 +02:00
Suravee Suthikulpanit
5edde870d3
iommu/amd: Do not call sleep while holding spinlock
...
Smatch static checker warns:
drivers/iommu/amd/iommu_v2.c:133 free_device_state()
warn: sleeping in atomic context
Fixes by storing the list of struct device_state in a temporary
list, and then free the memory after releasing the spinlock.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com >
Fixes: 9f968fc70d ("iommu/amd: Improve amd_iommu_v2_exit()")
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com >
Link: https://lore.kernel.org/r/20220314024321.37411-1-suravee.suthikulpanit@amd.com
Signed-off-by: Joerg Roedel <jroedel@suse.de >
2022-05-04 10:32:11 +02:00
Joerg Roedel
e17c6debd4
Merge branches 'arm/mediatek', 'arm/msm', 'arm/renesas', 'arm/rockchip', 'arm/smmu', 'x86/vt-d' and 'x86/amd' into next
2022-03-08 12:21:31 +01:00
Suravee Suthikulpanit
9f968fc70d
iommu/amd: Improve amd_iommu_v2_exit()
...
During module exit, the current logic loops through all possible
16-bit device ID space to search for existing devices and clean up
device state structures. This can be simplified by looping through
the device state list.
Also, refactor various clean up logic into free_device_state()
for better reusability.
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com >
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com >
Link: https://lore.kernel.org/r/20220301085626.87680-6-vasant.hegde@amd.com
Signed-off-by: Joerg Roedel <jroedel@suse.de >
2022-03-08 12:19:29 +01:00
Vasant Hegde
c1d5b57a1e
iommu/amd: Remove unused struct fault.devid
...
This variable has not been used since it was introduced.
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com >
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com >
Link: https://lore.kernel.org/r/20220301085626.87680-5-vasant.hegde@amd.com
Signed-off-by: Joerg Roedel <jroedel@suse.de >
2022-03-08 12:19:24 +01:00
Lu Baolu
41bb23e70b
iommu: Remove unused argument in is_attach_deferred
...
The is_attach_deferred iommu_ops callback is a device op. The domain
argument is unnecessary and never used. Remove it to make code clean.
Suggested-by: Robin Murphy <robin.murphy@arm.com >
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com >
Reviewed-by: Christoph Hellwig <hch@lst.de >
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com >
Link: https://lore.kernel.org/r/20220216025249.3459465-9-baolu.lu@linux.intel.com
Signed-off-by: Joerg Roedel <jroedel@suse.de >
2022-02-28 13:25:49 +01:00
Joerg Roedel
717e88aad3
iommu/amd: Clarify AMD IOMMUv2 initialization messages
...
The messages printed on the initialization of the AMD IOMMUv2 driver
have caused some confusion in the past. Clarify the messages to lower
the confusion in the future.
Cc: stable@vger.kernel.org
Signed-off-by: Joerg Roedel <jroedel@suse.de >
Link: https://lore.kernel.org/r/20211123105507.7654-3-joro@8bytes.org
2021-11-26 22:54:20 +01:00
Tom Lendacky
e9d1d2bb75
treewide: Replace the use of mem_encrypt_active() with cc_platform_has()
...
Replace uses of mem_encrypt_active() with calls to cc_platform_has() with
the CC_ATTR_MEM_ENCRYPT attribute.
Remove the implementation of mem_encrypt_active() across all arches.
For s390, since the default implementation of the cc_platform_has()
matches the s390 implementation of mem_encrypt_active(), cc_platform_has()
does not need to be implemented in s390 (the config option
ARCH_HAS_CC_PLATFORM is not set).
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com >
Signed-off-by: Borislav Petkov <bp@suse.de >
Link: https://lkml.kernel.org/r/20210928191009.32551-9-bp@alien8.de
2021-10-04 11:47:24 +02:00
Xiyu Yang via iommu
8bc54824da
iommu/amd: Convert from atomic_t to refcount_t on pasid_state->count
...
refcount_t type and corresponding API can protect refcounters from
accidental underflow and overflow and further use-after-free situations.
Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn >
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com >
Reviewed-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com >
Link: https://lore.kernel.org/r/1626683578-64214-1-git-send-email-xiyuyang19@fudan.edu.cn
Signed-off-by: Joerg Roedel <jroedel@suse.de >
2021-07-26 13:46:57 +02:00
Zheng Yongjun
106650f1e9
iommu/amd: Use DEFINE_SPINLOCK() for spinlock
...
Spinlock can be initialized automatically with DEFINE_SPINLOCK()
rather than explicitly calling spin_lock_init().
Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com >
Link: https://lore.kernel.org/r/20201228135112.28621-1-zhengyongjun3@huawei.com
Signed-off-by: Joerg Roedel <jroedel@suse.de >
2021-01-27 12:41:11 +01:00
Fenghua Yu
c7b6bac9c7
drm, iommu: Change type of pasid to u32
...
PASID is defined as a few different types in iommu including "int",
"u32", and "unsigned int". To be consistent and to match with uapi
definitions, define PASID and its variations (e.g. max PASID) as "u32".
"u32" is also shorter and a little more explicit than "unsigned int".
No PASID type change in uapi although it defines PASID as __u64 in
some places.
Suggested-by: Thomas Gleixner <tglx@linutronix.de >
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com >
Signed-off-by: Borislav Petkov <bp@suse.de >
Reviewed-by: Tony Luck <tony.luck@intel.com >
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com >
Acked-by: Felix Kuehling <Felix.Kuehling@amd.com >
Acked-by: Joerg Roedel <jroedel@suse.de >
Link: https://lkml.kernel.org/r/1600187413-163670-2-git-send-email-fenghua.yu@intel.com
2020-09-17 19:21:16 +02:00
Joerg Roedel
2822e58250
iommu/amd: Do not use IOMMUv2 functionality when SME is active
...
When memory encryption is active the device is likely not in a direct
mapped domain. Forbid using IOMMUv2 functionality for now until finer
grained checks for this have been implemented.
Signed-off-by: Joerg Roedel <jroedel@suse.de >
Link: https://lore.kernel.org/r/20200824105415.21000-3-joro@8bytes.org
Signed-off-by: Joerg Roedel <jroedel@suse.de >
2020-09-04 12:07:08 +02:00
Peter Xu
bce617edec
mm: do page fault accounting in handle_mm_fault
...
Patch series "mm: Page fault accounting cleanups", v5.
This is v5 of the pf accounting cleanup series. It originates from Gerald
Schaefer's report on an issue a week ago regarding to incorrect page fault
accountings for retried page fault after commit 4064b98270 ("mm: allow
VM_FAULT_RETRY for multiple times"):
https://lore.kernel.org/lkml/20200610174811.44b94525@thinkpad/
What this series did:
- Correct page fault accounting: we do accounting for a page fault
(no matter whether it's from #PF handling, or gup, or anything else)
only with the one that completed the fault. For example, page fault
retries should not be counted in page fault counters. Same to the
perf events.
- Unify definition of PERF_COUNT_SW_PAGE_FAULTS: currently this perf
event is used in an adhoc way across different archs.
Case (1): for many archs it's done at the entry of a page fault
handler, so that it will also cover e.g. errornous faults.
Case (2): for some other archs, it is only accounted when the page
fault is resolved successfully.
Case (3): there're still quite some archs that have not enabled
this perf event.
Since this series will touch merely all the archs, we unify this
perf event to always follow case (1), which is the one that makes most
sense. And since we moved the accounting into handle_mm_fault, the
other two MAJ/MIN perf events are well taken care of naturally.
- Unify definition of "major faults": the definition of "major
fault" is slightly changed when used in accounting (not
VM_FAULT_MAJOR). More information in patch 1.
- Always account the page fault onto the one that triggered the page
fault. This does not matter much for #PF handlings, but mostly for
gup. More information on this in patch 25.
Patchset layout:
Patch 1: Introduced the accounting in handle_mm_fault(), not enabled.
Patch 2-23: Enable the new accounting for arch #PF handlers one by one.
Patch 24: Enable the new accounting for the rest outliers (gup, iommu, etc.)
Patch 25: Cleanup GUP task_struct pointer since it's not needed any more
This patch (of 25):
This is a preparation patch to move page fault accountings into the
general code in handle_mm_fault(). This includes both the per task
flt_maj/flt_min counters, and the major/minor page fault perf events. To
do this, the pt_regs pointer is passed into handle_mm_fault().
PERF_COUNT_SW_PAGE_FAULTS should still be kept in per-arch page fault
handlers.
So far, all the pt_regs pointer that passed into handle_mm_fault() is
NULL, which means this patch should have no intented functional change.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org >
Signed-off-by: Peter Xu <peterx@redhat.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Cc: Albert Ou <aou@eecs.berkeley.edu >
Cc: Alexander Gordeev <agordeev@linux.ibm.com >
Cc: Andy Lutomirski <luto@kernel.org >
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org >
Cc: Borislav Petkov <bp@alien8.de >
Cc: Brian Cain <bcain@codeaurora.org >
Cc: Catalin Marinas <catalin.marinas@arm.com >
Cc: Christian Borntraeger <borntraeger@de.ibm.com >
Cc: Chris Zankel <chris@zankel.net >
Cc: Dave Hansen <dave.hansen@linux.intel.com >
Cc: David S. Miller <davem@davemloft.net >
Cc: Geert Uytterhoeven <geert@linux-m68k.org >
Cc: Gerald Schaefer <gerald.schaefer@de.ibm.com >
Cc: Greentime Hu <green.hu@gmail.com >
Cc: Guo Ren <guoren@kernel.org >
Cc: Heiko Carstens <heiko.carstens@de.ibm.com >
Cc: Helge Deller <deller@gmx.de >
Cc: H. Peter Anvin <hpa@zytor.com >
Cc: Ingo Molnar <mingo@redhat.com >
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru >
Cc: James E.J. Bottomley <James.Bottomley@HansenPartnership.com >
Cc: John Hubbard <jhubbard@nvidia.com >
Cc: Jonas Bonn <jonas@southpole.se >
Cc: Ley Foon Tan <ley.foon.tan@intel.com >
Cc: "Luck, Tony" <tony.luck@intel.com >
Cc: Matt Turner <mattst88@gmail.com >
Cc: Max Filippov <jcmvbkbc@gmail.com >
Cc: Michael Ellerman <mpe@ellerman.id.au >
Cc: Michal Simek <monstr@monstr.eu >
Cc: Nick Hu <nickhu@andestech.com >
Cc: Palmer Dabbelt <palmer@dabbelt.com >
Cc: Paul Mackerras <paulus@samba.org >
Cc: Paul Walmsley <paul.walmsley@sifive.com >
Cc: Pekka Enberg <penberg@kernel.org >
Cc: Peter Zijlstra <peterz@infradead.org >
Cc: Richard Henderson <rth@twiddle.net >
Cc: Rich Felker <dalias@libc.org >
Cc: Russell King <linux@armlinux.org.uk >
Cc: Stafford Horne <shorne@gmail.com >
Cc: Stefan Kristiansson <stefan.kristiansson@saunalahti.fi >
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de >
Cc: Thomas Gleixner <tglx@linutronix.de >
Cc: Vasily Gorbik <gor@linux.ibm.com >
Cc: Vincent Chen <deanbo422@gmail.com >
Cc: Vineet Gupta <vgupta@synopsys.com >
Cc: Will Deacon <will@kernel.org >
Cc: Yoshinori Sato <ysato@users.sourceforge.jp >
Link: http://lkml.kernel.org/r/20200707225021.200906-1-peterx@redhat.com
Link: http://lkml.kernel.org/r/20200707225021.200906-2-peterx@redhat.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2020-08-12 10:58:02 -07:00
Linus Torvalds
8f02f363f7
Merge tag 'iommu-drivers-move-v5.8' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu
...
Pull iommu driver directory structure cleanup from Joerg Roedel:
"Move the Intel and AMD IOMMU drivers into their own subdirectory.
Both drivers consist of several files by now and giving them their own
directory unclutters the IOMMU top-level directory a bit"
* tag 'iommu-drivers-move-v5.8' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu:
iommu/vt-d: Move Intel IOMMU driver into subdirectory
iommu/amd: Move AMD IOMMU driver into subdirectory
2020-06-12 12:19:13 -07:00
Joerg Roedel
ad8694bac4
iommu/amd: Move AMD IOMMU driver into subdirectory
...
Move all files related to the AMD IOMMU driver into its own
subdirectory.
Signed-off-by: Joerg Roedel <jroedel@suse.de >
Reviewed-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com >
Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com >
Link: https://lore.kernel.org/r/20200609130303.26974-2-joro@8bytes.org
2020-06-10 17:46:42 +02:00