Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp194330pjb; Thu, 16 Jul 2020 11:39:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsRRukBQnMJXqVP9ncISj9SUsXH97PuW+JUeyZ7MqVOdKaeQjq/NMWZ26rc+aSYeT7B5JA X-Received: by 2002:a17:906:fcab:: with SMTP id qw11mr5008087ejb.456.1594924764126; Thu, 16 Jul 2020 11:39:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594924764; cv=none; d=google.com; s=arc-20160816; b=gCZ2aaXx6XYUDxoTy0e72VZTn6Ux7Hjr+t+zP7sAT2mol2L8uvGnYTbasO2Q1Y2v/O knVGs8QzkoaUrrLKAocOE/QubwnXqy8JEnCp+rliajol9a4GG+QZC3JQhlX+vyIx7Oz4 NQYqb8e8w3TRQ9qNVBDwz45PPYejM+y75ZQZmW+6elqaM1c8SXZCNOgbLq5aMxLJK9ul lbtHUwrogx5/e4E3cPsNETNs8TIvz5Fm67HUjESPnUkYrMqTcrU1A9Adjg9JvjmkaCG5 Nu8J6m028EwvpL9204q4H7KIYoeK2pRVmE1XaApjfPJhuQvkIPEVyDCDNl3shGsgl7Gf K5RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:ironport-sdr:ironport-sdr; bh=H1j/GDRRNTWiZ0XhXt3eFfTUYKTIEz/y3s6Rua+ymZ0=; b=ZGZ1hU4megbZuqZGmrhpRsDA9/wt5lrA71YTJMnFqfousfyaksUkE0K8Hhxvc9uB89 yv26ULH+cgxL9PpZtVlcOJuG/PGt9VWhYiuSyFAybgrKuvR6nXA0CCxeX+O7jhZyN84I iGpYTmzJH8+eJHoewF3trfyBA4s2aWIoa4TXj4dvOu7XycCGD3cW8ZR+BF+kcbeXKp0i Ug5slUeFmiYhkyyluPZXb1DdY1o4hfhs4mXb8rUzgTEeUVCyRMuRZHyqGBBZLo1Jf1Mo Ziq86tSgLR/ajcsI1XD0+wsa+ZIui+zhoSeEfyBmJQglcvIYEZQN6NIA95suoNN7NovV +Hnw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bq21si3790745ejb.301.2020.07.16.11.39.01; Thu, 16 Jul 2020 11:39:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729432AbgGPSiu (ORCPT + 99 others); Thu, 16 Jul 2020 14:38:50 -0400 Received: from mga09.intel.com ([134.134.136.24]:21162 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729339AbgGPSiq (ORCPT ); Thu, 16 Jul 2020 14:38:46 -0400 IronPort-SDR: Zflb9oAZ9KUxITwvr4Z9ERJebZ5cAZ61g62NSljeUsRlWcx0tEf0jGvEHqSn9sD0XjMsA7b2Fs TaOTp8dXdlBA== X-IronPort-AV: E=McAfee;i="6000,8403,9684"; a="150857728" X-IronPort-AV: E=Sophos;i="5.75,360,1589266800"; d="scan'208";a="150857728" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jul 2020 11:38:42 -0700 IronPort-SDR: VBNESTAFO4SQvI9MmSy/hxTJhd1YuTNXBEQUsi2JPE129hE5NWLzvOmJBvCGx46ltY21kucEKS DVbn355gaYLg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,360,1589266800"; d="scan'208";a="460572046" Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga005.jf.intel.com with ESMTP; 16 Jul 2020 11:38:35 -0700 From: Jacob Pan To: iommu@lists.linux-foundation.org, LKML , Joerg Roedel , Alex Williamson Cc: "Lu Baolu" , David Woodhouse , Yi Liu , "Tian, Kevin" , Raj Ashok , "Christoph Hellwig" , Jean-Philippe Brucker , Eric Auger , Jonathan Corbet , Jacob Pan Subject: [PATCH v5 3/5] iommu/uapi: Use named union for user data Date: Thu, 16 Jul 2020 11:45:15 -0700 Message-Id: <1594925117-64892-4-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1594925117-64892-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1594925117-64892-1-git-send-email-jacob.jun.pan@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org IOMMU UAPI data size is filled by the user space which must be validated by ther kernel. To ensure backward compatibility, user data can only be extended by either re-purpose padding bytes or extend the variable sized union at the end. No size change is allowed before the union. Therefore, the minimum size is the offset of the union. To use offsetof() on the union, we must make it named. Link: https://lore.kernel.org/linux-iommu/20200611145518.0c2817d6@x1.home/ Signed-off-by: Jacob Pan Reviewed-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 24 ++++++++++++------------ drivers/iommu/intel/svm.c | 2 +- include/uapi/linux/iommu.h | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 6ad8b6f20235..f3a6ca88cf95 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -5409,8 +5409,8 @@ intel_iommu_sva_invalidate(struct iommu_domain *domain, struct device *dev, /* Size is only valid in address selective invalidation */ if (inv_info->granularity == IOMMU_INV_GRANU_ADDR) - size = to_vtd_size(inv_info->addr_info.granule_size, - inv_info->addr_info.nb_granules); + size = to_vtd_size(inv_info->granu.addr_info.granule_size, + inv_info->granu.addr_info.nb_granules); for_each_set_bit(cache_type, (unsigned long *)&inv_info->cache, @@ -5432,20 +5432,20 @@ intel_iommu_sva_invalidate(struct iommu_domain *domain, struct device *dev, * granularity. */ if (inv_info->granularity == IOMMU_INV_GRANU_PASID && - (inv_info->pasid_info.flags & IOMMU_INV_PASID_FLAGS_PASID)) - pasid = inv_info->pasid_info.pasid; + (inv_info->granu.pasid_info.flags & IOMMU_INV_PASID_FLAGS_PASID)) + pasid = inv_info->granu.pasid_info.pasid; else if (inv_info->granularity == IOMMU_INV_GRANU_ADDR && - (inv_info->addr_info.flags & IOMMU_INV_ADDR_FLAGS_PASID)) - pasid = inv_info->addr_info.pasid; + (inv_info->granu.addr_info.flags & IOMMU_INV_ADDR_FLAGS_PASID)) + pasid = inv_info->granu.addr_info.pasid; switch (BIT(cache_type)) { case IOMMU_CACHE_INV_TYPE_IOTLB: /* HW will ignore LSB bits based on address mask */ if (inv_info->granularity == IOMMU_INV_GRANU_ADDR && size && - (inv_info->addr_info.addr & ((BIT(VTD_PAGE_SHIFT + size)) - 1))) { + (inv_info->granu.addr_info.addr & ((BIT(VTD_PAGE_SHIFT + size)) - 1))) { WARN_ONCE(1, "Address out of range, 0x%llx, size order %llu\n", - inv_info->addr_info.addr, size); + inv_info->granu.addr_info.addr, size); } /* @@ -5453,9 +5453,9 @@ intel_iommu_sva_invalidate(struct iommu_domain *domain, struct device *dev, * We use npages = -1 to indicate that. */ qi_flush_piotlb(iommu, did, pasid, - mm_to_dma_pfn(inv_info->addr_info.addr), + mm_to_dma_pfn(inv_info->granu.addr_info.addr), (granu == QI_GRAN_NONG_PASID) ? -1 : 1 << size, - inv_info->addr_info.flags & IOMMU_INV_ADDR_FLAGS_LEAF); + inv_info->granu.addr_info.flags & IOMMU_INV_ADDR_FLAGS_LEAF); if (!info->ats_enabled) break; @@ -5476,13 +5476,13 @@ intel_iommu_sva_invalidate(struct iommu_domain *domain, struct device *dev, size = 64 - VTD_PAGE_SHIFT; addr = 0; } else if (inv_info->granularity == IOMMU_INV_GRANU_ADDR) - addr = inv_info->addr_info.addr; + addr = inv_info->granu.addr_info.addr; if (info->ats_enabled) qi_flush_dev_iotlb_pasid(iommu, sid, info->pfsid, pasid, info->ats_qdep, - inv_info->addr_info.addr, + inv_info->granu.addr_info.addr, size); else pr_warn_ratelimited("Passdown device IOTLB flush w/o ATS!\n"); diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index d386853121a2..713b3a218483 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -338,7 +338,7 @@ int intel_svm_bind_gpasid(struct iommu_domain *domain, struct device *dev, spin_lock(&iommu->lock); ret = intel_pasid_setup_nested(iommu, dev, (pgd_t *)(uintptr_t)data->gpgd, - data->hpasid, &data->vtd, dmar_domain, + data->hpasid, &data->vendor.vtd, dmar_domain, data->addr_width); spin_unlock(&iommu->lock); if (ret) { diff --git a/include/uapi/linux/iommu.h b/include/uapi/linux/iommu.h index d5e9014f690e..7c8e075c2b29 100644 --- a/include/uapi/linux/iommu.h +++ b/include/uapi/linux/iommu.h @@ -263,7 +263,7 @@ struct iommu_cache_invalidate_info { union { struct iommu_inv_pasid_info pasid_info; struct iommu_inv_addr_info addr_info; - }; + } granu; }; /** @@ -329,7 +329,7 @@ struct iommu_gpasid_bind_data { /* Vendor specific data */ union { struct iommu_gpasid_bind_data_vtd vtd; - }; + } vendor; }; #endif /* _UAPI_IOMMU_H */ -- 2.7.4