irqchip/gic-v3-its: Add VPE scheduling

When a VPE is scheduled to run, the corresponding redistributor must
be told so, by setting VPROPBASER to the VM's property table, and
VPENDBASER to the vcpu's pending table.

When scheduled out, we preserve the IDAI and PendingLast bits. The
latter is specially important, as it tells the hypervisor that
there are pending interrupts for this vcpu.

Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>

+143
+85
drivers/irqchip/irq-gic-v3-its.c
··· 152 152 153 153 #define gic_data_rdist() (raw_cpu_ptr(gic_rdists->rdist)) 154 154 #define gic_data_rdist_rd_base() (gic_data_rdist()->rd_base) 155 + #define gic_data_rdist_vlpi_base() (gic_data_rdist_rd_base() + SZ_128K) 155 156 156 157 static struct its_collection *dev_event_to_col(struct its_device *its_dev, 157 158 u32 event) ··· 2154 2153 .deactivate = its_irq_domain_deactivate, 2155 2154 }; 2156 2155 2156 + static void its_vpe_schedule(struct its_vpe *vpe) 2157 + { 2158 + void * __iomem vlpi_base = gic_data_rdist_vlpi_base(); 2159 + u64 val; 2160 + 2161 + /* Schedule the VPE */ 2162 + val = virt_to_phys(page_address(vpe->its_vm->vprop_page)) & 2163 + GENMASK_ULL(51, 12); 2164 + val |= (LPI_NRBITS - 1) & GICR_VPROPBASER_IDBITS_MASK; 2165 + val |= GICR_VPROPBASER_RaWb; 2166 + val |= GICR_VPROPBASER_InnerShareable; 2167 + gits_write_vpropbaser(val, vlpi_base + GICR_VPROPBASER); 2168 + 2169 + val = virt_to_phys(page_address(vpe->vpt_page)) & 2170 + GENMASK_ULL(51, 16); 2171 + val |= GICR_VPENDBASER_RaWaWb; 2172 + val |= GICR_VPENDBASER_NonShareable; 2173 + /* 2174 + * There is no good way of finding out if the pending table is 2175 + * empty as we can race against the doorbell interrupt very 2176 + * easily. So in the end, vpe->pending_last is only an 2177 + * indication that the vcpu has something pending, not one 2178 + * that the pending table is empty. A good implementation 2179 + * would be able to read its coarse map pretty quickly anyway, 2180 + * making this a tolerable issue. 2181 + */ 2182 + val |= GICR_VPENDBASER_PendingLast; 2183 + val |= vpe->idai ? GICR_VPENDBASER_IDAI : 0; 2184 + val |= GICR_VPENDBASER_Valid; 2185 + gits_write_vpendbaser(val, vlpi_base + GICR_VPENDBASER); 2186 + } 2187 + 2188 + static void its_vpe_deschedule(struct its_vpe *vpe) 2189 + { 2190 + void * __iomem vlpi_base = gic_data_rdist_vlpi_base(); 2191 + u32 count = 1000000; /* 1s! */ 2192 + bool clean; 2193 + u64 val; 2194 + 2195 + /* We're being scheduled out */ 2196 + val = gits_read_vpendbaser(vlpi_base + GICR_VPENDBASER); 2197 + val &= ~GICR_VPENDBASER_Valid; 2198 + gits_write_vpendbaser(val, vlpi_base + GICR_VPENDBASER); 2199 + 2200 + do { 2201 + val = gits_read_vpendbaser(vlpi_base + GICR_VPENDBASER); 2202 + clean = !(val & GICR_VPENDBASER_Dirty); 2203 + if (!clean) { 2204 + count--; 2205 + cpu_relax(); 2206 + udelay(1); 2207 + } 2208 + } while (!clean && count); 2209 + 2210 + if (unlikely(!clean && !count)) { 2211 + pr_err_ratelimited("ITS virtual pending table not cleaning\n"); 2212 + vpe->idai = false; 2213 + vpe->pending_last = true; 2214 + } else { 2215 + vpe->idai = !!(val & GICR_VPENDBASER_IDAI); 2216 + vpe->pending_last = !!(val & GICR_VPENDBASER_PendingLast); 2217 + } 2218 + } 2219 + 2220 + static int its_vpe_set_vcpu_affinity(struct irq_data *d, void *vcpu_info) 2221 + { 2222 + struct its_vpe *vpe = irq_data_get_irq_chip_data(d); 2223 + struct its_cmd_info *info = vcpu_info; 2224 + 2225 + switch (info->cmd_type) { 2226 + case SCHEDULE_VPE: 2227 + its_vpe_schedule(vpe); 2228 + return 0; 2229 + 2230 + case DESCHEDULE_VPE: 2231 + its_vpe_deschedule(vpe); 2232 + return 0; 2233 + 2234 + default: 2235 + return -EINVAL; 2236 + } 2237 + } 2238 + 2157 2239 static struct irq_chip its_vpe_irq_chip = { 2158 2240 .name = "GICv4-vpe", 2241 + .irq_set_vcpu_affinity = its_vpe_set_vcpu_affinity, 2159 2242 }; 2160 2243 2161 2244 static int its_vpe_id_alloc(void)
+58
include/linux/irqchip/arm-gic-v3.h
··· 212 212 #define LPI_PROP_GROUP1 (1 << 1) 213 213 #define LPI_PROP_ENABLED (1 << 0) 214 214 215 + /* 216 + * Re-Distributor registers, offsets from VLPI_base 217 + */ 218 + #define GICR_VPROPBASER 0x0070 219 + 220 + #define GICR_VPROPBASER_IDBITS_MASK 0x1f 221 + 222 + #define GICR_VPROPBASER_SHAREABILITY_SHIFT (10) 223 + #define GICR_VPROPBASER_INNER_CACHEABILITY_SHIFT (7) 224 + #define GICR_VPROPBASER_OUTER_CACHEABILITY_SHIFT (56) 225 + 226 + #define GICR_VPROPBASER_SHAREABILITY_MASK \ 227 + GIC_BASER_SHAREABILITY(GICR_VPROPBASER, SHAREABILITY_MASK) 228 + #define GICR_VPROPBASER_INNER_CACHEABILITY_MASK \ 229 + GIC_BASER_CACHEABILITY(GICR_VPROPBASER, INNER, MASK) 230 + #define GICR_VPROPBASER_OUTER_CACHEABILITY_MASK \ 231 + GIC_BASER_CACHEABILITY(GICR_VPROPBASER, OUTER, MASK) 232 + #define GICR_VPROPBASER_CACHEABILITY_MASK \ 233 + GICR_VPROPBASER_INNER_CACHEABILITY_MASK 234 + 235 + #define GICR_VPROPBASER_InnerShareable \ 236 + GIC_BASER_SHAREABILITY(GICR_VPROPBASER, InnerShareable) 237 + 238 + #define GICR_VPROPBASER_nCnB GIC_BASER_CACHEABILITY(GICR_VPROPBASER, INNER, nCnB) 239 + #define GICR_VPROPBASER_nC GIC_BASER_CACHEABILITY(GICR_VPROPBASER, INNER, nC) 240 + #define GICR_VPROPBASER_RaWt GIC_BASER_CACHEABILITY(GICR_VPROPBASER, INNER, RaWt) 241 + #define GICR_VPROPBASER_RaWb GIC_BASER_CACHEABILITY(GICR_VPROPBASER, INNER, RaWt) 242 + #define GICR_VPROPBASER_WaWt GIC_BASER_CACHEABILITY(GICR_VPROPBASER, INNER, WaWt) 243 + #define GICR_VPROPBASER_WaWb GIC_BASER_CACHEABILITY(GICR_VPROPBASER, INNER, WaWb) 244 + #define GICR_VPROPBASER_RaWaWt GIC_BASER_CACHEABILITY(GICR_VPROPBASER, INNER, RaWaWt) 245 + #define GICR_VPROPBASER_RaWaWb GIC_BASER_CACHEABILITY(GICR_VPROPBASER, INNER, RaWaWb) 246 + 247 + #define GICR_VPENDBASER 0x0078 248 + 249 + #define GICR_VPENDBASER_SHAREABILITY_SHIFT (10) 250 + #define GICR_VPENDBASER_INNER_CACHEABILITY_SHIFT (7) 251 + #define GICR_VPENDBASER_OUTER_CACHEABILITY_SHIFT (56) 252 + #define GICR_VPENDBASER_SHAREABILITY_MASK \ 253 + GIC_BASER_SHAREABILITY(GICR_VPENDBASER, SHAREABILITY_MASK) 254 + #define GICR_VPENDBASER_INNER_CACHEABILITY_MASK \ 255 + GIC_BASER_CACHEABILITY(GICR_VPENDBASER, INNER, MASK) 256 + #define GICR_VPENDBASER_OUTER_CACHEABILITY_MASK \ 257 + GIC_BASER_CACHEABILITY(GICR_VPENDBASER, OUTER, MASK) 258 + #define GICR_VPENDBASER_CACHEABILITY_MASK \ 259 + GICR_VPENDBASER_INNER_CACHEABILITY_MASK 260 + 261 + #define GICR_VPENDBASER_NonShareable \ 262 + GIC_BASER_SHAREABILITY(GICR_VPENDBASER, NonShareable) 263 + 264 + #define GICR_VPENDBASER_nCnB GIC_BASER_CACHEABILITY(GICR_VPENDBASER, INNER, nCnB) 265 + #define GICR_VPENDBASER_nC GIC_BASER_CACHEABILITY(GICR_VPENDBASER, INNER, nC) 266 + #define GICR_VPENDBASER_RaWt GIC_BASER_CACHEABILITY(GICR_VPENDBASER, INNER, RaWt) 267 + #define GICR_VPENDBASER_RaWb GIC_BASER_CACHEABILITY(GICR_VPENDBASER, INNER, RaWt) 268 + #define GICR_VPENDBASER_WaWt GIC_BASER_CACHEABILITY(GICR_VPENDBASER, INNER, WaWt) 269 + #define GICR_VPENDBASER_WaWb GIC_BASER_CACHEABILITY(GICR_VPENDBASER, INNER, WaWb) 270 + #define GICR_VPENDBASER_RaWaWt GIC_BASER_CACHEABILITY(GICR_VPENDBASER, INNER, RaWaWt) 271 + #define GICR_VPENDBASER_RaWaWb GIC_BASER_CACHEABILITY(GICR_VPENDBASER, INNER, RaWaWb) 272 + 215 273 #define GICR_VPENDBASER_Dirty (1ULL << 60) 216 274 #define GICR_VPENDBASER_PendingLast (1ULL << 61) 217 275 #define GICR_VPENDBASER_IDAI (1ULL << 62)