[PATCH v7 11/12] iommu: Assign the direct mapped domain to group->domain

2016-11-24 Thread Baoquan He
In iommu_request_dm_for_dev(), devices of group have all been attached to newly created direct mapped domain. We should store the domain into group->domain so that it works for iommu_get_domain_for_dev() and get_domain(). Signed-off-by: Baoquan He --- drivers/iommu/iommu.c | 1 + 1 file changed,

[PATCH v7 10/12] iommu/amd: Clear out the GV flag when handle deferred domain attach

2016-11-24 Thread Baoquan He
When handle deferred domain attach, we need check if the domain is v2. If not, should try to clear out the GV flag which could be copied from the old device table entry. Signed-off-by: Baoquan He --- drivers/iommu/amd_iommu.c | 18 +- 1 file changed, 17 insertions(+), 1 deletion(

[PATCH v7 12/12] iommu/amd: Allocate memory below 4G for dev table if translation pre-enabled

2016-11-24 Thread Baoquan He
AMD pointed out it's unsafe to update the device-table while iommu is enabled. It turns out that device-table pointer update is split up into two 32bit writes in the IOMMU hardware. So updating it while the IOMMU is enabled could have some nasty side effects. The only way to work around this is to

[PATCH v7 04/12] iommu/amd: Add function copy_dev_tables

2016-11-24 Thread Baoquan He
Add function copy_dev_tables to copy the old DEV table entries of the panicked kernel to the new allocated DEV table. Since all iommus share the same DTE table the copy only need be done once as long as the physical address of old DEV table is retrieved from iommu reg. Besides, we also need to:

[PATCH v7 02/12] iommu/amd: add several helper function

2016-11-24 Thread Baoquan He
Move per iommu enabling code into a wrapper function early_enable_iommu(). This can make later kdump change easier. And also add iommu_disable_command_buffer and iommu_disable_event_buffer for later usage. Signed-off-by: Baoquan He --- drivers/iommu/amd_iommu_init.c | 42 +++

[PATCH v7 08/12] iommu/amd: Add sanity check of irq remap information of old dev table entry

2016-11-24 Thread Baoquan He
Firstly split the dev table entry copy into address translation part and irq remapping part. Because these two parts could be configured to be available indepentently. Secondly check if IntCtl and IntTabLen are 10b and 1000b if they are set. Signed-off-by: Baoquan He --- drivers/iommu/amd_iommu

[PATCH v7 03/12] iommu/amd: Define bit fields for DTE particularly

2016-11-24 Thread Baoquan He
In amd-vi spec several bits of IO PTE fields and DTE fields are similar so that both of them can share the same MACRO definition. However defining their respecitve bit fields can make code more read-able. So do it in this patch. Signed-off-by: Baoquan He --- drivers/iommu/amd_iommu.c | 8

[PATCH v7 07/12] iommu/amd: Use is_attach_deferred call-back

2016-11-24 Thread Baoquan He
Implement call-back is_attach_deferred and use it to defer the domain attach from iommu driver init to device driver init when iommu is pre-enabled in kdump kernel. Signed-off-by: Baoquan He --- drivers/iommu/amd_iommu.c | 23 ++- 1 file changed, 22 insertions(+), 1 deletion(

[PATCH v7 09/12] iommu/amd: Don't copy GCR3 table root pointer

2016-11-24 Thread Baoquan He
When in kdump kernel iommu is pre_enabled, if a device is set up with guest translations (DTE.GV=1), then don't copy GCR3 table root pointer but move the device over to an empty guest-cr3 table and handle the faults in the PPR log (which answer them with INVALID). After all these PPR faults are rec

[PATCH v7 06/12] iommu: Add is_attach_deferred call-back to iommu-ops

2016-11-24 Thread Baoquan He
This new call-back will be used to check if the domain attach need be deferred for now. If yes, the domain attach/detach will return directly. Signed-off-by: Baoquan He --- drivers/iommu/iommu.c | 8 include/linux/iommu.h | 1 + 2 files changed, 9 insertions(+) diff --git a/drivers/iom

[PATCH v7 05/12] iommu/amd: copy old trans table from old kernel

2016-11-24 Thread Baoquan He
Here several things need be done: - If iommu is pre-enabled in a normal kernel, just disable it and print warning. - If failed to copy dev table of old kernel, continue to proceed as it does in normal kernel. - Disable and Re-enable event/cmd buffer, install the copied DTE table to reg, an

[PATCH v7 00/12] Fix kdump faults on system with amd iommu

2016-11-24 Thread Baoquan He
This is v7 post. The principle of the fix is similar to intel iommu. Just defer the assignment of device to domain to device driver init. In this version of post, a new call-back is_attach_deferred is added to iommu-ops, it's used to check whether we need defer the domain attach/detach in iommu-co

[PATCH v7 01/12] iommu/amd: Detect pre enabled translation

2016-11-24 Thread Baoquan He
Add functions to check whether translation is already enabled in IOMMU. Signed-off-by: Baoquan He --- drivers/iommu/amd_iommu_init.c | 25 + drivers/iommu/amd_iommu_proto.h | 1 + drivers/iommu/amd_iommu_types.h | 4 3 files changed, 30 insertions(+) diff --git a

Re: [PATCH V3 0/8] IOMMU probe deferral support

2016-11-24 Thread Robin Murphy
On 24/11/16 16:10, Sricharan wrote: > Hi Robin, > > > >> >>> iommu_group_get_for_dev which gets called in the add_device >>> callback, increases the reference count of the iommu_group, >>> so we do an iommu_group_put after that. iommu_group_get_for_dev >>> inturn calls device_gro

RE: [PATCH V3 0/8] IOMMU probe deferral support

2016-11-24 Thread Sricharan
Hi Robin, > >> iommu_group_get_for_dev which gets called in the add_device >> callback, increases the reference count of the iommu_group, >> so we do an iommu_group_put after that. iommu_group_get_for_dev >> inturn calls device_group callback and in the case of arm-smmu >> we

Re: [PATCH 4/5] iommu/exynos: Add default_domain check in iommu_attach_device

2016-11-24 Thread Marek Szyprowski
Hi Robin, On 2016-11-24 13:25, Robin Murphy wrote: Hi Marek, On 24/11/16 11:20, Marek Szyprowski wrote: This patch adds default_domain check before calling exynos_iommu_detach_device. This path was intended only to cope with default domains, which are automatically attached by the iommu core,

Re: [RFC PATCH v3 19/20] x86: Add support to make use of Secure Memory Encryption

2016-11-24 Thread Borislav Petkov
On Wed, Nov 09, 2016 at 06:38:26PM -0600, Tom Lendacky wrote: > This patch adds the support to check if SME has been enabled and if the > mem_encrypt=on command line option is set. If both of these conditions > are true, then the encryption mask is set and the kernel is encrypted > "in place." > >

Re: [PATCH 4/5] iommu/exynos: Add default_domain check in iommu_attach_device

2016-11-24 Thread Robin Murphy
Hi Marek, On 24/11/16 11:20, Marek Szyprowski wrote: > This patch adds default_domain check before calling > exynos_iommu_detach_device. This path was intended only to cope with > default domains, which are automatically attached by the iommu core, so > return error if user tries to attach device,

[PATCH 4/5] iommu/exynos: Add default_domain check in iommu_attach_device

2016-11-24 Thread Marek Szyprowski
This patch adds default_domain check before calling exynos_iommu_detach_device. This path was intended only to cope with default domains, which are automatically attached by the iommu core, so return error if user tries to attach device, which is already attached to other (non-default) domain. Sig

[PATCH 3/5] iommu/exynos: Ensure that SYSMMU is added only once to its master device

2016-11-24 Thread Marek Szyprowski
This patch prepares Exynos IOMMU driver for deferred probing support. Once it gets added, of_xlate() callback might be called more than once for the same SYSMMU controller and master device (for example it happens when masters device driver fails with EPROBE_DEFER). This patch adds a check, which e

[PATCH 0/5] Fixes for Exynos IOMMU driver

2016-11-24 Thread Marek Szyprowski
Hello, This is collection of fixes for Exynos IOMMU driver. Patches 1-2 are resend of the patches, which got lost on mainline list. Patch 3 adds a protection for the issue, which arises when IOMMU deferred probe patches will be merged. Patches 4-5 are fixes for default_domain handling. Patches ar

[PATCH 5/5] iommu/exynos: Properly release device from the default domain in ->remove

2016-11-24 Thread Marek Szyprowski
IOMMU core doesn't detach device from the default domain before calling ->iommu_remove_device, so check that and do the proper cleanup or warn if device is still attached to non-default domain. Signed-off-by: Marek Szyprowski --- drivers/iommu/exynos-iommu.c | 12 1 file changed, 12

[PATCH 2/5] iommu/exynos: Fix warnings from DMA-debug

2016-11-24 Thread Marek Szyprowski
Add a simple checks for dma_map_single() return value to make DMA-debug checker happly. Exynos IOMMU on Samsung Exynos SoCs always use device, which has linear DMA mapping ops (dma address is equal to physical memory address), so no failures are returned from dma_map_single(). Signed-off-by: Marek

[PATCH 1/5] iommu/exynos: Improve page fault debug message

2016-11-24 Thread Marek Szyprowski
Add master device name to default IOMMU fault message to make easier to find which device triggered the fault. While at it, move printing some information (like page table base and first level entry addresses) to dev_dbg(), because those are typically not very useful for typical device driver user/

[patch] iommu/amd: Missing error code in amd_iommu_init_device()

2016-11-24 Thread Dan Carpenter
We should set "ret" to -EINVAL if iommu_group_get() fails. Fixes: 55c99a4dc50f ("iommu/amd: Use iommu_attach_group()") Signed-off-by: Dan Carpenter diff --git a/drivers/iommu/amd_iommu_v2.c b/drivers/iommu/amd_iommu_v2.c index 594849a..f8ed8c9 100644 --- a/drivers/iommu/amd_iommu_v2.c +++ b/driv