[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 6/6] VT-d: avoid allocating domid_{bit,}map[] when possible


  • To: "Tian, Kevin" <kevin.tian@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 15 Nov 2021 10:37:13 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+0z9v3e7uvsSfPOf18zuGbOzN4Eybg9gba8lpFe8lVo=; b=NxGFyTFvdDssAqZVOsV1U6vYLHx++w9bGt8YE7jywMcgxi4OO3zGDvIB2Q4p9ebUvtsPMES7Z64YIyiAaVFLuJ5vLXHU70FvCEWYRFVgBfZIGX21mE3tXmEe21ehSVABk4MUIT77H7n1EMvO472lvYOumhyRxtXB8gnQD8M574fTR6XV0+7/1c0odzsCimWK4YNhMkPNfCaJ+cGeMTubmAdrpQAjm5HS0xwPziCKAzxQ7c8wfADc7xktMxluymgyEGXzqH7LW1cOWhOO1NlgbKs/wQAHvk0+Bo6vivlu62y/8/2V/q1Jh+c7HH05d7yaSQIqx4poC3lSPAS1RKokCw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jW7WMezZMuaW5M6epJtP4A3hOSPZnFejc4W/yjUf8qQshYnwMevdRlrLnm6zYXiKK5YVj+iHdYpKgUhfClK8TMMJayFl94RX/u/gIdMxUjbm47Td5KX0ps5TNVB6zKilFV1Mx9eVwA+G4GBjxDOWxh+DpkpplPeYwQFVI2r386D24GoAQweiAYMbGF7paJK+2eOQEkdb3Q6S4164xirBhpjtGyxIdXYuLOTCI9EeIGWDZ4RX3/zw2DlPI09wiEBG6cmkWQGiztYXav1D1+/w4ShEl680djynt6YvmF/hO7aeUOqVYUekGEWk4J1SK5zV4MibieyznRoMBZr+D7idtA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 15 Nov 2021 09:37:30 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 15.11.2021 07:18, Tian, Kevin wrote:
>> From: Jan Beulich <jbeulich@xxxxxxxx>
>> Sent: Friday, November 12, 2021 5:50 PM
>>
>> When an IOMMU implements the full 16 bits worth of DID in context
>> entries, there's no point going through a memory base translation table.
>> For IOMMUs not using Caching Mode we can simply use the domain IDs
>> verbatim, while for Caching Mode we need to avoid DID 0.
>>
>> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
>> ---
>> For the case where the memory tables are needed, xvzalloc_array() would
>> of course be an option to use here as well, despite this being boot time
>> allocations. Yet the introduction of xvmalloc() et al continues to be
>> stuck ...
>>
>> --- a/xen/drivers/passthrough/vtd/iommu.c
>> +++ b/xen/drivers/passthrough/vtd/iommu.c
>> @@ -62,11 +62,32 @@ static struct tasklet vtd_fault_tasklet;
>>  static int setup_hwdom_device(u8 devfn, struct pci_dev *);
>>  static void setup_hwdom_rmrr(struct domain *d);
>>
>> +static bool domid_mapping(const struct vtd_iommu *iommu)
>> +{
>> +    return (const void *)iommu->domid_bitmap != (const void *)iommu-
>>> domid_map;
>> +}
>> +
>> +static domid_t convert_domid(const struct vtd_iommu *iommu, domid_t
>> domid)
>> +{
>> +    /*
>> +     * While we need to avoid DID 0 for caching-mode IOMMUs, maintain
>> +     * the property of the transformation being the same in either
>> +     * direction. By clipping to 16 bits we ensure that the resulting
>> +     * DID will fit in the respective context entry field.
>> +     */
>> +    BUILD_BUG_ON(sizeof(domid_t) > sizeof(uint16_t));
>> +
>> +    return !cap_caching_mode(iommu->cap) ? domid : ~domid;
> 
> If DOMID_MASK grows to 0xFFFF (though unlikely),

I did consider this too unlikely to warrant taking care of. Now that
you ask for it anyway, ...

> then it translates 
> to '0' when caching mode is true. We need extend BUILD_BUG_ON() to 
> check DOMID_MASK in this case, since caching mode implies
> total_size minus one for available domain IDs 

... I guess I'd rather replace the BUILD_BUG_ON() than extend it or
add a 2nd one.

Jan




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.