mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-01 16:14:13 +08:00
intel-iommu: Introduce domain_pfn_mapping()
... and use it in the trivial cases; the other callers want individual (and bisectable) attention, since I screwed them up the first time... Make the BUG_ON() happen on too-large virtual address rather than physical address, too. That's the one we care about. Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
This commit is contained in:
parent
1c5a46ed49
commit
61df744314
@ -1643,40 +1643,48 @@ static int domain_context_mapped(struct pci_dev *pdev)
|
|||||||
tmp->devfn);
|
tmp->devfn);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int domain_pfn_mapping(struct dmar_domain *domain, unsigned long iov_pfn,
|
||||||
domain_page_mapping(struct dmar_domain *domain, dma_addr_t iova,
|
unsigned long phys_pfn, unsigned long nr_pages,
|
||||||
u64 hpa, size_t size, int prot)
|
int prot)
|
||||||
{
|
{
|
||||||
unsigned long start_pfn = hpa >> VTD_PAGE_SHIFT;
|
|
||||||
unsigned long last_pfn = (hpa + size - 1) >> VTD_PAGE_SHIFT;
|
|
||||||
struct dma_pte *pte;
|
struct dma_pte *pte;
|
||||||
int index = 0;
|
|
||||||
int addr_width = agaw_to_width(domain->agaw) - VTD_PAGE_SHIFT;
|
int addr_width = agaw_to_width(domain->agaw) - VTD_PAGE_SHIFT;
|
||||||
|
|
||||||
BUG_ON(addr_width < BITS_PER_LONG && last_pfn >> addr_width);
|
BUG_ON(addr_width < BITS_PER_LONG && (iov_pfn + nr_pages - 1) >> addr_width);
|
||||||
|
|
||||||
if ((prot & (DMA_PTE_READ|DMA_PTE_WRITE)) == 0)
|
if ((prot & (DMA_PTE_READ|DMA_PTE_WRITE)) == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
while (start_pfn <= last_pfn) {
|
while (nr_pages--) {
|
||||||
pte = pfn_to_dma_pte(domain, (iova >> VTD_PAGE_SHIFT) + index);
|
pte = pfn_to_dma_pte(domain, iov_pfn);
|
||||||
if (!pte)
|
if (!pte)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
/* We don't need lock here, nobody else
|
/* We don't need lock here, nobody else
|
||||||
* touches the iova range
|
* touches the iova range
|
||||||
*/
|
*/
|
||||||
BUG_ON(dma_pte_addr(pte));
|
BUG_ON(dma_pte_addr(pte));
|
||||||
dma_set_pte_pfn(pte, start_pfn);
|
dma_set_pte_pfn(pte, phys_pfn);
|
||||||
dma_set_pte_prot(pte, prot);
|
dma_set_pte_prot(pte, prot);
|
||||||
if (prot & DMA_PTE_SNP)
|
if (prot & DMA_PTE_SNP)
|
||||||
dma_set_pte_snp(pte);
|
dma_set_pte_snp(pte);
|
||||||
domain_flush_cache(domain, pte, sizeof(*pte));
|
domain_flush_cache(domain, pte, sizeof(*pte));
|
||||||
start_pfn++;
|
iov_pfn++;
|
||||||
index++;
|
phys_pfn++;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int domain_page_mapping(struct dmar_domain *domain, dma_addr_t iova,
|
||||||
|
u64 hpa, size_t size, int prot)
|
||||||
|
{
|
||||||
|
unsigned long first_pfn = hpa >> VTD_PAGE_SHIFT;
|
||||||
|
unsigned long last_pfn = (hpa + size - 1) >> VTD_PAGE_SHIFT;
|
||||||
|
|
||||||
|
return domain_pfn_mapping(domain, iova >> VTD_PAGE_SHIFT, first_pfn,
|
||||||
|
last_pfn - first_pfn + 1, prot);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static void iommu_detach_dev(struct intel_iommu *iommu, u8 bus, u8 devfn)
|
static void iommu_detach_dev(struct intel_iommu *iommu, u8 bus, u8 devfn)
|
||||||
{
|
{
|
||||||
if (!iommu)
|
if (!iommu)
|
||||||
@ -1893,7 +1901,9 @@ static int iommu_domain_identity_map(struct dmar_domain *domain,
|
|||||||
dma_pte_clear_range(domain, base >> VTD_PAGE_SHIFT,
|
dma_pte_clear_range(domain, base >> VTD_PAGE_SHIFT,
|
||||||
(base + size - 1) >> VTD_PAGE_SHIFT);
|
(base + size - 1) >> VTD_PAGE_SHIFT);
|
||||||
|
|
||||||
return domain_page_mapping(domain, base, base, size,
|
return domain_pfn_mapping(domain, base >> VTD_PAGE_SHIFT,
|
||||||
|
base >> VTD_PAGE_SHIFT,
|
||||||
|
size >> VTD_PAGE_SHIFT,
|
||||||
DMA_PTE_READ|DMA_PTE_WRITE);
|
DMA_PTE_READ|DMA_PTE_WRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user