@@ -262,6 +262,79 @@ static unsigned long calculate_psi_aligned_address(unsigned long start,
262
262
return ALIGN_DOWN (start , VTD_PAGE_SIZE << mask );
263
263
}
264
264
265
+ static void qi_batch_flush_descs (struct intel_iommu * iommu , struct qi_batch * batch )
266
+ {
267
+ if (!iommu || !batch -> index )
268
+ return ;
269
+
270
+ qi_submit_sync (iommu , batch -> descs , batch -> index , 0 );
271
+
272
+ /* Reset the index value and clean the whole batch buffer. */
273
+ memset (batch , 0 , sizeof (* batch ));
274
+ }
275
+
276
+ static void qi_batch_increment_index (struct intel_iommu * iommu , struct qi_batch * batch )
277
+ {
278
+ if (++ batch -> index == QI_MAX_BATCHED_DESC_COUNT )
279
+ qi_batch_flush_descs (iommu , batch );
280
+ }
281
+
282
+ static void qi_batch_add_iotlb (struct intel_iommu * iommu , u16 did , u64 addr ,
283
+ unsigned int size_order , u64 type ,
284
+ struct qi_batch * batch )
285
+ {
286
+ qi_desc_iotlb (iommu , did , addr , size_order , type , & batch -> descs [batch -> index ]);
287
+ qi_batch_increment_index (iommu , batch );
288
+ }
289
+
290
+ static void qi_batch_add_dev_iotlb (struct intel_iommu * iommu , u16 sid , u16 pfsid ,
291
+ u16 qdep , u64 addr , unsigned int mask ,
292
+ struct qi_batch * batch )
293
+ {
294
+ /*
295
+ * According to VT-d spec, software is recommended to not submit any Device-TLB
296
+ * invalidation requests while address remapping hardware is disabled.
297
+ */
298
+ if (!(iommu -> gcmd & DMA_GCMD_TE ))
299
+ return ;
300
+
301
+ qi_desc_dev_iotlb (sid , pfsid , qdep , addr , mask , & batch -> descs [batch -> index ]);
302
+ qi_batch_increment_index (iommu , batch );
303
+ }
304
+
305
+ static void qi_batch_add_piotlb (struct intel_iommu * iommu , u16 did , u32 pasid ,
306
+ u64 addr , unsigned long npages , bool ih ,
307
+ struct qi_batch * batch )
308
+ {
309
+ /*
310
+ * npages == -1 means a PASID-selective invalidation, otherwise,
311
+ * a positive value for Page-selective-within-PASID invalidation.
312
+ * 0 is not a valid input.
313
+ */
314
+ if (!npages )
315
+ return ;
316
+
317
+ qi_desc_piotlb (did , pasid , addr , npages , ih , & batch -> descs [batch -> index ]);
318
+ qi_batch_increment_index (iommu , batch );
319
+ }
320
+
321
+ static void qi_batch_add_pasid_dev_iotlb (struct intel_iommu * iommu , u16 sid , u16 pfsid ,
322
+ u32 pasid , u16 qdep , u64 addr ,
323
+ unsigned int size_order , struct qi_batch * batch )
324
+ {
325
+ /*
326
+ * According to VT-d spec, software is recommended to not submit any
327
+ * Device-TLB invalidation requests while address remapping hardware
328
+ * is disabled.
329
+ */
330
+ if (!(iommu -> gcmd & DMA_GCMD_TE ))
331
+ return ;
332
+
333
+ qi_desc_dev_iotlb_pasid (sid , pfsid , pasid , qdep , addr , size_order ,
334
+ & batch -> descs [batch -> index ]);
335
+ qi_batch_increment_index (iommu , batch );
336
+ }
337
+
265
338
static void cache_tag_flush_iotlb (struct dmar_domain * domain , struct cache_tag * tag ,
266
339
unsigned long addr , unsigned long pages ,
267
340
unsigned long mask , int ih )
@@ -270,7 +343,8 @@ static void cache_tag_flush_iotlb(struct dmar_domain *domain, struct cache_tag *
270
343
u64 type = DMA_TLB_PSI_FLUSH ;
271
344
272
345
if (domain -> use_first_level ) {
273
- qi_flush_piotlb (iommu , tag -> domain_id , tag -> pasid , addr , pages , ih );
346
+ qi_batch_add_piotlb (iommu , tag -> domain_id , tag -> pasid , addr ,
347
+ pages , ih , domain -> qi_batch );
274
348
return ;
275
349
}
276
350
@@ -287,7 +361,8 @@ static void cache_tag_flush_iotlb(struct dmar_domain *domain, struct cache_tag *
287
361
}
288
362
289
363
if (ecap_qis (iommu -> ecap ))
290
- qi_flush_iotlb (iommu , tag -> domain_id , addr | ih , mask , type );
364
+ qi_batch_add_iotlb (iommu , tag -> domain_id , addr | ih , mask , type ,
365
+ domain -> qi_batch );
291
366
else
292
367
__iommu_flush_iotlb (iommu , tag -> domain_id , addr | ih , mask , type );
293
368
}
@@ -303,19 +378,20 @@ static void cache_tag_flush_devtlb_psi(struct dmar_domain *domain, struct cache_
303
378
sid = PCI_DEVID (info -> bus , info -> devfn );
304
379
305
380
if (tag -> pasid == IOMMU_NO_PASID ) {
306
- qi_flush_dev_iotlb (iommu , sid , info -> pfsid , info -> ats_qdep ,
307
- addr , mask );
381
+ qi_batch_add_dev_iotlb (iommu , sid , info -> pfsid , info -> ats_qdep ,
382
+ addr , mask , domain -> qi_batch );
308
383
if (info -> dtlb_extra_inval )
309
- qi_flush_dev_iotlb (iommu , sid , info -> pfsid ,
310
- info -> ats_qdep , addr , mask );
384
+ qi_batch_add_dev_iotlb (iommu , sid , info -> pfsid , info -> ats_qdep ,
385
+ addr , mask , domain -> qi_batch );
311
386
return ;
312
387
}
313
388
314
- qi_flush_dev_iotlb_pasid (iommu , sid , info -> pfsid , tag -> pasid ,
315
- info -> ats_qdep , addr , mask );
389
+ qi_batch_add_pasid_dev_iotlb (iommu , sid , info -> pfsid , tag -> pasid ,
390
+ info -> ats_qdep , addr , mask , domain -> qi_batch );
316
391
if (info -> dtlb_extra_inval )
317
- qi_flush_dev_iotlb_pasid (iommu , sid , info -> pfsid , tag -> pasid ,
318
- info -> ats_qdep , addr , mask );
392
+ qi_batch_add_pasid_dev_iotlb (iommu , sid , info -> pfsid , tag -> pasid ,
393
+ info -> ats_qdep , addr , mask ,
394
+ domain -> qi_batch );
319
395
}
320
396
321
397
static void cache_tag_flush_devtlb_all (struct dmar_domain * domain , struct cache_tag * tag )
@@ -327,11 +403,11 @@ static void cache_tag_flush_devtlb_all(struct dmar_domain *domain, struct cache_
327
403
info = dev_iommu_priv_get (tag -> dev );
328
404
sid = PCI_DEVID (info -> bus , info -> devfn );
329
405
330
- qi_flush_dev_iotlb (iommu , sid , info -> pfsid , info -> ats_qdep , 0 ,
331
- MAX_AGAW_PFN_WIDTH );
406
+ qi_batch_add_dev_iotlb (iommu , sid , info -> pfsid , info -> ats_qdep , 0 ,
407
+ MAX_AGAW_PFN_WIDTH , domain -> qi_batch );
332
408
if (info -> dtlb_extra_inval )
333
- qi_flush_dev_iotlb (iommu , sid , info -> pfsid , info -> ats_qdep , 0 ,
334
- MAX_AGAW_PFN_WIDTH );
409
+ qi_batch_add_dev_iotlb (iommu , sid , info -> pfsid , info -> ats_qdep , 0 ,
410
+ MAX_AGAW_PFN_WIDTH , domain -> qi_batch );
335
411
}
336
412
337
413
/*
@@ -341,6 +417,7 @@ static void cache_tag_flush_devtlb_all(struct dmar_domain *domain, struct cache_
341
417
void cache_tag_flush_range (struct dmar_domain * domain , unsigned long start ,
342
418
unsigned long end , int ih )
343
419
{
420
+ struct intel_iommu * iommu = NULL ;
344
421
unsigned long pages , mask , addr ;
345
422
struct cache_tag * tag ;
346
423
unsigned long flags ;
@@ -349,6 +426,10 @@ void cache_tag_flush_range(struct dmar_domain *domain, unsigned long start,
349
426
350
427
spin_lock_irqsave (& domain -> cache_lock , flags );
351
428
list_for_each_entry (tag , & domain -> cache_tags , node ) {
429
+ if (iommu && iommu != tag -> iommu )
430
+ qi_batch_flush_descs (iommu , domain -> qi_batch );
431
+ iommu = tag -> iommu ;
432
+
352
433
switch (tag -> type ) {
353
434
case CACHE_TAG_IOTLB :
354
435
case CACHE_TAG_NESTING_IOTLB :
@@ -372,6 +453,7 @@ void cache_tag_flush_range(struct dmar_domain *domain, unsigned long start,
372
453
373
454
trace_cache_tag_flush_range (tag , start , end , addr , pages , mask );
374
455
}
456
+ qi_batch_flush_descs (iommu , domain -> qi_batch );
375
457
spin_unlock_irqrestore (& domain -> cache_lock , flags );
376
458
}
377
459
@@ -381,11 +463,16 @@ void cache_tag_flush_range(struct dmar_domain *domain, unsigned long start,
381
463
*/
382
464
void cache_tag_flush_all (struct dmar_domain * domain )
383
465
{
466
+ struct intel_iommu * iommu = NULL ;
384
467
struct cache_tag * tag ;
385
468
unsigned long flags ;
386
469
387
470
spin_lock_irqsave (& domain -> cache_lock , flags );
388
471
list_for_each_entry (tag , & domain -> cache_tags , node ) {
472
+ if (iommu && iommu != tag -> iommu )
473
+ qi_batch_flush_descs (iommu , domain -> qi_batch );
474
+ iommu = tag -> iommu ;
475
+
389
476
switch (tag -> type ) {
390
477
case CACHE_TAG_IOTLB :
391
478
case CACHE_TAG_NESTING_IOTLB :
@@ -399,6 +486,7 @@ void cache_tag_flush_all(struct dmar_domain *domain)
399
486
400
487
trace_cache_tag_flush_all (tag );
401
488
}
489
+ qi_batch_flush_descs (iommu , domain -> qi_batch );
402
490
spin_unlock_irqrestore (& domain -> cache_lock , flags );
403
491
}
404
492
@@ -416,6 +504,7 @@ void cache_tag_flush_all(struct dmar_domain *domain)
416
504
void cache_tag_flush_range_np (struct dmar_domain * domain , unsigned long start ,
417
505
unsigned long end )
418
506
{
507
+ struct intel_iommu * iommu = NULL ;
419
508
unsigned long pages , mask , addr ;
420
509
struct cache_tag * tag ;
421
510
unsigned long flags ;
@@ -424,7 +513,9 @@ void cache_tag_flush_range_np(struct dmar_domain *domain, unsigned long start,
424
513
425
514
spin_lock_irqsave (& domain -> cache_lock , flags );
426
515
list_for_each_entry (tag , & domain -> cache_tags , node ) {
427
- struct intel_iommu * iommu = tag -> iommu ;
516
+ if (iommu && iommu != tag -> iommu )
517
+ qi_batch_flush_descs (iommu , domain -> qi_batch );
518
+ iommu = tag -> iommu ;
428
519
429
520
if (!cap_caching_mode (iommu -> cap ) || domain -> use_first_level ) {
430
521
iommu_flush_write_buffer (iommu );
@@ -437,5 +528,6 @@ void cache_tag_flush_range_np(struct dmar_domain *domain, unsigned long start,
437
528
438
529
trace_cache_tag_flush_range_np (tag , start , end , addr , pages , mask );
439
530
}
531
+ qi_batch_flush_descs (iommu , domain -> qi_batch );
440
532
spin_unlock_irqrestore (& domain -> cache_lock , flags );
441
533
}
0 commit comments