Skip to content

Commit 12ff4bf

Browse files
committed
Merge branch 'amd-iommu/fixes' into iommu/fixes
2 parents 2eaa9cf + 20a1cfb commit 12ff4bf

5 files changed

Lines changed: 50 additions & 32 deletions

File tree

‎Documentation/kernel-parameters.txt‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,6 @@ and is between 256 and 4096 characters. It is defined in the file
320320
amd_iommu= [HW,X86-84]
321321
Pass parameters to the AMD IOMMU driver in the system.
322322
Possible values are:
323-
isolate - enable device isolation (each device, as far
324-
as possible, will get its own protection
325-
domain) [default]
326-
share - put every device behind one IOMMU into the
327-
same protection domain
328323
fullflush - enable flushing of IO/TLB entries when
329324
they are unmapped. Otherwise they are
330325
flushed before they will be reused, which

‎arch/x86/include/asm/amd_iommu_types.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define _ASM_X86_AMD_IOMMU_TYPES_H
2222

2323
#include <linux/types.h>
24+
#include <linux/mutex.h>
2425
#include <linux/list.h>
2526
#include <linux/spinlock.h>
2627

@@ -140,6 +141,7 @@
140141

141142
/* constants to configure the command buffer */
142143
#define CMD_BUFFER_SIZE 8192
144+
#define CMD_BUFFER_UNINITIALIZED 1
143145
#define CMD_BUFFER_ENTRIES 512
144146
#define MMIO_CMD_SIZE_SHIFT 56
145147
#define MMIO_CMD_SIZE_512 (0x9ULL << MMIO_CMD_SIZE_SHIFT)
@@ -237,6 +239,7 @@ struct protection_domain {
237239
struct list_head list; /* for list of all protection domains */
238240
struct list_head dev_list; /* List of all devices in this domain */
239241
spinlock_t lock; /* mostly used to lock the page table*/
242+
struct mutex api_lock; /* protect page tables in the iommu-api path */
240243
u16 id; /* the domain id written to the device table */
241244
int mode; /* paging mode (0-6 levels) */
242245
u64 *pt_root; /* page table root pointer */

‎arch/x86/kernel/amd_iommu.c‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static bool check_device(struct device *dev)
118118
return false;
119119

120120
/* No device or no PCI device */
121-
if (!dev || dev->bus != &pci_bus_type)
121+
if (dev->bus != &pci_bus_type)
122122
return false;
123123

124124
devid = get_device_id(dev);
@@ -392,6 +392,7 @@ static int __iommu_queue_command(struct amd_iommu *iommu, struct iommu_cmd *cmd)
392392
u32 tail, head;
393393
u8 *target;
394394

395+
WARN_ON(iommu->cmd_buf_size & CMD_BUFFER_UNINITIALIZED);
395396
tail = readl(iommu->mmio_base + MMIO_CMD_TAIL_OFFSET);
396397
target = iommu->cmd_buf + tail;
397398
memcpy_toio(target, cmd, sizeof(*cmd));
@@ -2186,7 +2187,7 @@ static void prealloc_protection_domains(void)
21862187
struct dma_ops_domain *dma_dom;
21872188
u16 devid;
21882189

2189-
while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
2190+
for_each_pci_dev(dev) {
21902191

21912192
/* Do we handle this device? */
21922193
if (!check_device(&dev->dev))
@@ -2298,7 +2299,7 @@ static void cleanup_domain(struct protection_domain *domain)
22982299
list_for_each_entry_safe(dev_data, next, &domain->dev_list, list) {
22992300
struct device *dev = dev_data->dev;
23002301

2301-
do_detach(dev);
2302+
__detach_device(dev);
23022303
atomic_set(&dev_data->bind, 0);
23032304
}
23042305

@@ -2327,6 +2328,7 @@ static struct protection_domain *protection_domain_alloc(void)
23272328
return NULL;
23282329

23292330
spin_lock_init(&domain->lock);
2331+
mutex_init(&domain->api_lock);
23302332
domain->id = domain_id_alloc();
23312333
if (!domain->id)
23322334
goto out_err;
@@ -2379,9 +2381,7 @@ static void amd_iommu_domain_destroy(struct iommu_domain *dom)
23792381

23802382
free_pagetable(domain);
23812383

2382-
domain_id_free(domain->id);
2383-
2384-
kfree(domain);
2384+
protection_domain_free(domain);
23852385

23862386
dom->priv = NULL;
23872387
}
@@ -2456,6 +2456,8 @@ static int amd_iommu_map_range(struct iommu_domain *dom,
24562456
iova &= PAGE_MASK;
24572457
paddr &= PAGE_MASK;
24582458

2459+
mutex_lock(&domain->api_lock);
2460+
24592461
for (i = 0; i < npages; ++i) {
24602462
ret = iommu_map_page(domain, iova, paddr, prot, PM_MAP_4k);
24612463
if (ret)
@@ -2465,6 +2467,8 @@ static int amd_iommu_map_range(struct iommu_domain *dom,
24652467
paddr += PAGE_SIZE;
24662468
}
24672469

2470+
mutex_unlock(&domain->api_lock);
2471+
24682472
return 0;
24692473
}
24702474

@@ -2477,12 +2481,16 @@ static void amd_iommu_unmap_range(struct iommu_domain *dom,
24772481

24782482
iova &= PAGE_MASK;
24792483

2484+
mutex_lock(&domain->api_lock);
2485+
24802486
for (i = 0; i < npages; ++i) {
24812487
iommu_unmap_page(domain, iova, PM_MAP_4k);
24822488
iova += PAGE_SIZE;
24832489
}
24842490

24852491
iommu_flush_tlb_pde(domain);
2492+
2493+
mutex_unlock(&domain->api_lock);
24862494
}
24872495

24882496
static phys_addr_t amd_iommu_iova_to_phys(struct iommu_domain *dom,

‎arch/x86/kernel/amd_iommu_init.c‎

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ int amd_iommus_present;
138138
bool amd_iommu_np_cache __read_mostly;
139139

140140
/*
141-
* Set to true if ACPI table parsing and hardware intialization went properly
141+
* The ACPI table parsing functions set this variable on an error
142142
*/
143-
static bool amd_iommu_initialized;
143+
static int __initdata amd_iommu_init_err;
144144

145145
/*
146146
* List of protection domains - used during resume
@@ -391,9 +391,11 @@ static int __init find_last_devid_acpi(struct acpi_table_header *table)
391391
*/
392392
for (i = 0; i < table->length; ++i)
393393
checksum += p[i];
394-
if (checksum != 0)
394+
if (checksum != 0) {
395395
/* ACPI table corrupt */
396-
return -ENODEV;
396+
amd_iommu_init_err = -ENODEV;
397+
return 0;
398+
}
397399

398400
p += IVRS_HEADER_LENGTH;
399401

@@ -436,7 +438,7 @@ static u8 * __init alloc_command_buffer(struct amd_iommu *iommu)
436438
if (cmd_buf == NULL)
437439
return NULL;
438440

439-
iommu->cmd_buf_size = CMD_BUFFER_SIZE;
441+
iommu->cmd_buf_size = CMD_BUFFER_SIZE | CMD_BUFFER_UNINITIALIZED;
440442

441443
return cmd_buf;
442444
}
@@ -472,12 +474,13 @@ static void iommu_enable_command_buffer(struct amd_iommu *iommu)
472474
&entry, sizeof(entry));
473475

474476
amd_iommu_reset_cmd_buffer(iommu);
477+
iommu->cmd_buf_size &= ~(CMD_BUFFER_UNINITIALIZED);
475478
}
476479

477480
static void __init free_command_buffer(struct amd_iommu *iommu)
478481
{
479482
free_pages((unsigned long)iommu->cmd_buf,
480-
get_order(iommu->cmd_buf_size));
483+
get_order(iommu->cmd_buf_size & ~(CMD_BUFFER_UNINITIALIZED)));
481484
}
482485

483486
/* allocates the memory where the IOMMU will log its events to */
@@ -920,11 +923,16 @@ static int __init init_iommu_all(struct acpi_table_header *table)
920923
h->mmio_phys);
921924

922925
iommu = kzalloc(sizeof(struct amd_iommu), GFP_KERNEL);
923-
if (iommu == NULL)
924-
return -ENOMEM;
926+
if (iommu == NULL) {
927+
amd_iommu_init_err = -ENOMEM;
928+
return 0;
929+
}
930+
925931
ret = init_iommu_one(iommu, h);
926-
if (ret)
927-
return ret;
932+
if (ret) {
933+
amd_iommu_init_err = ret;
934+
return 0;
935+
}
928936
break;
929937
default:
930938
break;
@@ -934,8 +942,6 @@ static int __init init_iommu_all(struct acpi_table_header *table)
934942
}
935943
WARN_ON(p != end);
936944

937-
amd_iommu_initialized = true;
938-
939945
return 0;
940946
}
941947

@@ -1211,6 +1217,10 @@ static int __init amd_iommu_init(void)
12111217
if (acpi_table_parse("IVRS", find_last_devid_acpi) != 0)
12121218
return -ENODEV;
12131219

1220+
ret = amd_iommu_init_err;
1221+
if (ret)
1222+
goto out;
1223+
12141224
dev_table_size = tbl_size(DEV_TABLE_ENTRY_SIZE);
12151225
alias_table_size = tbl_size(ALIAS_TABLE_ENTRY_SIZE);
12161226
rlookup_table_size = tbl_size(RLOOKUP_TABLE_ENTRY_SIZE);
@@ -1270,12 +1280,19 @@ static int __init amd_iommu_init(void)
12701280
if (acpi_table_parse("IVRS", init_iommu_all) != 0)
12711281
goto free;
12721282

1273-
if (!amd_iommu_initialized)
1283+
if (amd_iommu_init_err) {
1284+
ret = amd_iommu_init_err;
12741285
goto free;
1286+
}
12751287

12761288
if (acpi_table_parse("IVRS", init_memory_definitions) != 0)
12771289
goto free;
12781290

1291+
if (amd_iommu_init_err) {
1292+
ret = amd_iommu_init_err;
1293+
goto free;
1294+
}
1295+
12791296
ret = sysdev_class_register(&amd_iommu_sysdev_class);
12801297
if (ret)
12811298
goto free;
@@ -1288,6 +1305,8 @@ static int __init amd_iommu_init(void)
12881305
if (ret)
12891306
goto free;
12901307

1308+
enable_iommus();
1309+
12911310
if (iommu_pass_through)
12921311
ret = amd_iommu_init_passthrough();
12931312
else
@@ -1300,8 +1319,6 @@ static int __init amd_iommu_init(void)
13001319

13011320
amd_iommu_init_notifier();
13021321

1303-
enable_iommus();
1304-
13051322
if (iommu_pass_through)
13061323
goto out;
13071324

@@ -1315,6 +1332,7 @@ static int __init amd_iommu_init(void)
13151332
return ret;
13161333

13171334
free:
1335+
disable_iommus();
13181336

13191337
amd_iommu_uninit_devices();
13201338

‎arch/x86/kernel/crash.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <asm/cpu.h>
2828
#include <asm/reboot.h>
2929
#include <asm/virtext.h>
30-
#include <asm/x86_init.h>
3130

3231
#if defined(CONFIG_SMP) && defined(CONFIG_X86_LOCAL_APIC)
3332

@@ -103,10 +102,5 @@ void native_machine_crash_shutdown(struct pt_regs *regs)
103102
#ifdef CONFIG_HPET_TIMER
104103
hpet_disable();
105104
#endif
106-
107-
#ifdef CONFIG_X86_64
108-
x86_platform.iommu_shutdown();
109-
#endif
110-
111105
crash_save_cpu(regs, safe_smp_processor_id());
112106
}

0 commit comments

Comments
 (0)