Commit cf26839d authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull iommufd fixes from Jason Gunthorpe:
 "A few minor fixes, other than the randconfig fix this is only relevant
  to test code, not releases:

   - Randconfig failure if CONFIG_DMA_SHARED_BUFFER is not set

   - Remove gcc warning in kselftest

   - Fix a refcount leak on an error path in the selftest support code

   - Fix missing overflow checks in the selftest support code"

* tag 'for-linus-iommufd' of git://git.kernel.org/pub/scm/linux/kernel/git/jgg/iommufd:
  iommufd/selftest: Check for overflow in IOMMU_TEST_OP_ADD_RESERVED
  iommufd/selftest: Do not leak the hwpt if IOMMU_TEST_OP_MD_CHECK_MAP fails
  iommufd/selftest: Make it clearer to gcc that the access is not out of bounds
  iommufd: Fix building without dmabuf
parents 7b8e9264 e6a973af
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -495,7 +495,11 @@ int iopt_map_file_pages(struct iommufd_ctx *ictx, struct io_pagetable *iopt,
		return -EOVERFLOW;

	start_byte = start - ALIGN_DOWN(start, PAGE_SIZE);
	if (IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
		dmabuf = dma_buf_get(fd);
	else
		dmabuf = ERR_PTR(-ENXIO);

	if (!IS_ERR(dmabuf)) {
		pages = iopt_alloc_dmabuf_pages(ictx, dmabuf, start_byte, start,
						length,
+11 −3
Original line number Diff line number Diff line
@@ -1184,14 +1184,20 @@ static int iommufd_test_add_reserved(struct iommufd_ucmd *ucmd,
				     unsigned int mockpt_id,
				     unsigned long start, size_t length)
{
	unsigned long last;
	struct iommufd_ioas *ioas;
	int rc;

	if (!length)
		return -EINVAL;
	if (check_add_overflow(start, length - 1, &last))
		return -EOVERFLOW;

	ioas = iommufd_get_ioas(ucmd->ictx, mockpt_id);
	if (IS_ERR(ioas))
		return PTR_ERR(ioas);
	down_write(&ioas->iopt.iova_rwsem);
	rc = iopt_reserve_iova(&ioas->iopt, start, start + length - 1, NULL);
	rc = iopt_reserve_iova(&ioas->iopt, start, last, NULL);
	up_write(&ioas->iopt.iova_rwsem);
	iommufd_put_object(ucmd->ictx, &ioas->obj);
	return rc;
@@ -1215,8 +1221,10 @@ static int iommufd_test_md_check_pa(struct iommufd_ucmd *ucmd,
	page_size = 1 << __ffs(mock->domain.pgsize_bitmap);
	if (iova % page_size || length % page_size ||
	    (uintptr_t)uptr % page_size ||
	    check_add_overflow((uintptr_t)uptr, (uintptr_t)length, &end))
		return -EINVAL;
	    check_add_overflow((uintptr_t)uptr, (uintptr_t)length, &end)) {
		rc = -EINVAL;
		goto out_put;
	}

	for (; length; length -= page_size) {
		struct page *pages[1];
+3 −5
Original line number Diff line number Diff line
@@ -755,9 +755,6 @@ TEST_F(iommufd_ioas, get_hw_info)
		struct iommu_test_hw_info info;
		uint64_t trailing_bytes;
	} buffer_larger;
	struct iommu_test_hw_info_buffer_smaller {
		__u32 flags;
	} buffer_smaller;

	if (self->device_id) {
		uint8_t max_pasid = 0;
@@ -789,8 +786,9 @@ TEST_F(iommufd_ioas, get_hw_info)
		 * the fields within the size range still gets updated.
		 */
		test_cmd_get_hw_info(self->device_id,
				     IOMMU_HW_INFO_TYPE_DEFAULT,
				     &buffer_smaller, sizeof(buffer_smaller));
				     IOMMU_HW_INFO_TYPE_DEFAULT, &buffer_exact,
				     offsetofend(struct iommu_test_hw_info,
						 flags));
		test_cmd_get_hw_info_pasid(self->device_id, &max_pasid);
		ASSERT_EQ(0, max_pasid);
		if (variant->pasid_capable) {