Skip to content

Commit cf62924

Browse files
hegdevasantjoergroedel
authored andcommitted
iommu/amd: Add support to invalidate multiple guest pages
Current interface supports invalidating single page or entire guest translation information for a single process address space. IOMMU CMD_INV_IOMMU_PAGES and CMD_INV_IOTLB_PAGES commands supports invalidating range of pages. Add support to invalidate multiple pages. This is preparatory patch before consolidating host and guest invalidation code into single function. Following patches will consolidation tlb invalidation code. Signed-off-by: Vasant Hegde <vasant.hegde@amd.com> Reviewed-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/20231122090215.6191-5-vasant.hegde@amd.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent a976da6 commit cf62924

1 file changed

Lines changed: 13 additions & 18 deletions

File tree

drivers/iommu/amd/iommu.c

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,40 +1152,36 @@ static void build_inv_iotlb_pages(struct iommu_cmd *cmd, u16 devid, int qdep,
11521152
}
11531153

11541154
static void build_inv_iommu_pasid(struct iommu_cmd *cmd, u16 domid, u32 pasid,
1155-
u64 address, bool size)
1155+
u64 address, size_t size)
11561156
{
1157-
memset(cmd, 0, sizeof(*cmd));
1157+
u64 inv_address = build_inv_address(address, size);
11581158

1159-
address &= ~(0xfffULL);
1159+
memset(cmd, 0, sizeof(*cmd));
11601160

11611161
cmd->data[0] = pasid;
11621162
cmd->data[1] = domid;
1163-
cmd->data[2] = lower_32_bits(address);
1164-
cmd->data[3] = upper_32_bits(address);
1163+
cmd->data[2] = lower_32_bits(inv_address);
1164+
cmd->data[3] = upper_32_bits(inv_address);
11651165
cmd->data[2] |= CMD_INV_IOMMU_PAGES_PDE_MASK;
11661166
cmd->data[2] |= CMD_INV_IOMMU_PAGES_GN_MASK;
1167-
if (size)
1168-
cmd->data[2] |= CMD_INV_IOMMU_PAGES_SIZE_MASK;
11691167
CMD_SET_TYPE(cmd, CMD_INV_IOMMU_PAGES);
11701168
}
11711169

11721170
static void build_inv_iotlb_pasid(struct iommu_cmd *cmd, u16 devid, u32 pasid,
1173-
int qdep, u64 address, bool size)
1171+
int qdep, u64 address, size_t size)
11741172
{
1175-
memset(cmd, 0, sizeof(*cmd));
1173+
u64 inv_address = build_inv_address(address, size);
11761174

1177-
address &= ~(0xfffULL);
1175+
memset(cmd, 0, sizeof(*cmd));
11781176

11791177
cmd->data[0] = devid;
11801178
cmd->data[0] |= ((pasid >> 8) & 0xff) << 16;
11811179
cmd->data[0] |= (qdep & 0xff) << 24;
11821180
cmd->data[1] = devid;
11831181
cmd->data[1] |= (pasid & 0xff) << 16;
1184-
cmd->data[2] = lower_32_bits(address);
1182+
cmd->data[2] = lower_32_bits(inv_address);
11851183
cmd->data[2] |= CMD_INV_IOMMU_PAGES_GN_MASK;
1186-
cmd->data[3] = upper_32_bits(address);
1187-
if (size)
1188-
cmd->data[2] |= CMD_INV_IOMMU_PAGES_SIZE_MASK;
1184+
cmd->data[3] = upper_32_bits(inv_address);
11891185
CMD_SET_TYPE(cmd, CMD_INV_IOTLB_PAGES);
11901186
}
11911187

@@ -2656,7 +2652,7 @@ const struct iommu_ops amd_iommu_ops = {
26562652
};
26572653

26582654
static int __flush_pasid(struct protection_domain *domain, u32 pasid,
2659-
u64 address, bool size)
2655+
u64 address, size_t size)
26602656
{
26612657
struct iommu_dev_data *dev_data;
26622658
struct iommu_cmd cmd;
@@ -2720,7 +2716,7 @@ static int __flush_pasid(struct protection_domain *domain, u32 pasid,
27202716
static int __amd_iommu_flush_page(struct protection_domain *domain, u32 pasid,
27212717
u64 address)
27222718
{
2723-
return __flush_pasid(domain, pasid, address, false);
2719+
return __flush_pasid(domain, pasid, address, PAGE_SIZE);
27242720
}
27252721

27262722
int amd_iommu_flush_page(struct iommu_domain *dom, u32 pasid,
@@ -2739,8 +2735,7 @@ int amd_iommu_flush_page(struct iommu_domain *dom, u32 pasid,
27392735

27402736
static int __amd_iommu_flush_tlb(struct protection_domain *domain, u32 pasid)
27412737
{
2742-
return __flush_pasid(domain, pasid, CMD_INV_IOMMU_ALL_PAGES_ADDRESS,
2743-
true);
2738+
return __flush_pasid(domain, pasid, 0, CMD_INV_IOMMU_ALL_PAGES_ADDRESS);
27442739
}
27452740

27462741
int amd_iommu_flush_tlb(struct iommu_domain *dom, u32 pasid)

0 commit comments

Comments
 (0)