Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iommufd/device: Replace idev->igroup with local variable

With more use of the fields of igroup, use a local vairable instead of
using the idev->igroup heavily.

No functional change expected.

Link: https://patch.msgid.link/r/20250321171940.7213-6-yi.l.liu@intel.com
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

authored by

Yi Liu and committed by
Jason Gunthorpe
2eaa7f84 bc06f7f6

+23 -20
+23 -20
drivers/iommu/iommufd/device.c
··· 333 333 iommufd_device_attach_reserved_iova(struct iommufd_device *idev, 334 334 struct iommufd_hwpt_paging *hwpt_paging) 335 335 { 336 + struct iommufd_group *igroup = idev->igroup; 336 337 int rc; 337 338 338 - lockdep_assert_held(&idev->igroup->lock); 339 + lockdep_assert_held(&igroup->lock); 339 340 340 341 rc = iopt_table_enforce_dev_resv_regions(&hwpt_paging->ioas->iopt, 341 342 idev->dev, 342 - &idev->igroup->sw_msi_start); 343 + &igroup->sw_msi_start); 343 344 if (rc) 344 345 return rc; 345 346 346 - if (list_empty(&idev->igroup->device_list)) { 347 - rc = iommufd_group_setup_msi(idev->igroup, hwpt_paging); 347 + if (list_empty(&igroup->device_list)) { 348 + rc = iommufd_group_setup_msi(igroup, hwpt_paging); 348 349 if (rc) { 349 350 iopt_remove_reserved_iova(&hwpt_paging->ioas->iopt, 350 351 idev->dev); ··· 485 484 { 486 485 struct iommufd_hwpt_paging *hwpt_paging = find_hwpt_paging(hwpt); 487 486 bool attach_resv = hwpt_paging && pasid == IOMMU_NO_PASID; 487 + struct iommufd_group *igroup = idev->igroup; 488 488 int rc; 489 489 490 - mutex_lock(&idev->igroup->lock); 490 + mutex_lock(&igroup->lock); 491 491 492 - if (idev->igroup->hwpt != NULL && idev->igroup->hwpt != hwpt) { 492 + if (igroup->hwpt && igroup->hwpt != hwpt) { 493 493 rc = -EINVAL; 494 494 goto err_unlock; 495 495 } ··· 508 506 * reserved regions are only updated during individual device 509 507 * attachment. 510 508 */ 511 - if (list_empty(&idev->igroup->device_list)) { 509 + if (list_empty(&igroup->device_list)) { 512 510 rc = iommufd_hwpt_attach_device(hwpt, idev, pasid); 513 511 if (rc) 514 512 goto err_unresv; 515 - idev->igroup->hwpt = hwpt; 513 + igroup->hwpt = hwpt; 516 514 } 517 515 refcount_inc(&hwpt->obj.users); 518 - list_add_tail(&idev->group_item, &idev->igroup->device_list); 519 - mutex_unlock(&idev->igroup->lock); 516 + list_add_tail(&idev->group_item, &igroup->device_list); 517 + mutex_unlock(&igroup->lock); 520 518 return 0; 521 519 err_unresv: 522 520 if (attach_resv) 523 521 iopt_remove_reserved_iova(&hwpt_paging->ioas->iopt, idev->dev); 524 522 err_unlock: 525 - mutex_unlock(&idev->igroup->lock); 523 + mutex_unlock(&igroup->lock); 526 524 return rc; 527 525 } 528 526 529 527 struct iommufd_hw_pagetable * 530 528 iommufd_hw_pagetable_detach(struct iommufd_device *idev, ioasid_t pasid) 531 529 { 532 - struct iommufd_hw_pagetable *hwpt = idev->igroup->hwpt; 530 + struct iommufd_group *igroup = idev->igroup; 531 + struct iommufd_hw_pagetable *hwpt = igroup->hwpt; 533 532 struct iommufd_hwpt_paging *hwpt_paging = find_hwpt_paging(hwpt); 534 533 535 - mutex_lock(&idev->igroup->lock); 534 + mutex_lock(&igroup->lock); 536 535 list_del(&idev->group_item); 537 - if (list_empty(&idev->igroup->device_list)) { 536 + if (list_empty(&igroup->device_list)) { 538 537 iommufd_hwpt_detach_device(hwpt, idev, pasid); 539 - idev->igroup->hwpt = NULL; 538 + igroup->hwpt = NULL; 540 539 } 541 540 if (hwpt_paging && pasid == IOMMU_NO_PASID) 542 541 iopt_remove_reserved_iova(&hwpt_paging->ioas->iopt, idev->dev); 543 - mutex_unlock(&idev->igroup->lock); 542 + mutex_unlock(&igroup->lock); 544 543 545 544 /* Caller must destroy hwpt */ 546 545 return hwpt; ··· 613 610 unsigned int num_devices; 614 611 int rc; 615 612 616 - mutex_lock(&idev->igroup->lock); 613 + mutex_lock(&igroup->lock); 617 614 618 615 if (igroup->hwpt == NULL) { 619 616 rc = -EINVAL; ··· 626 623 } 627 624 628 625 if (hwpt == igroup->hwpt) { 629 - mutex_unlock(&idev->igroup->lock); 626 + mutex_unlock(&igroup->lock); 630 627 return NULL; 631 628 } 632 629 ··· 657 654 if (num_devices > 1) 658 655 WARN_ON(refcount_sub_and_test(num_devices - 1, 659 656 &old_hwpt->obj.users)); 660 - mutex_unlock(&idev->igroup->lock); 657 + mutex_unlock(&igroup->lock); 661 658 662 659 /* Caller must destroy old_hwpt */ 663 660 return old_hwpt; ··· 665 662 if (attach_resv) 666 663 iommufd_group_remove_reserved_iova(igroup, hwpt_paging); 667 664 err_unlock: 668 - mutex_unlock(&idev->igroup->lock); 665 + mutex_unlock(&igroup->lock); 669 666 return ERR_PTR(rc); 670 667 } 671 668