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

Re: [PATCH v2 05/18] IOMMU: have iommu_{,un}map() split requests into largest possible chunks


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 2 Dec 2021 16:59:35 +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=Q4gXzBgNyOmjr0o1kPGL4Qi8t5k/TrlIA/QIcQvPeQI=; b=WZAsMcnivzk+tyP01msUTSKahP3l5OxyQB1+VnC8kD8s5EpZ3JaWYmkladf1CE/y44q7781gLrbmh1QujDCZ9WYvr6akQ/Es8zihRw/vIi5H1J2Lj9snXl7GRpOv5IGzkpAjhT616wqJzg4YX5b5JZVcjXjy8TfqxPbfxfx++epNXEO2fOEud/C1DFAXxaJ7dtsYLNVAlxkujb3pBkd9DYMMPy2WjAoWmg5SBCO3r7zi18WKXezrDFuVQSMQT9u/pVlCIxCP0MgNzWg8KwyhsJ7qYT/PqBcCS380kl+KFDmG2Fca+08zPlrhKvE/gsIVP2d1gWLL0YmREakbpbE7cQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Keo5mhAo5zx7kPjz3EJNJ6jtQlADdpDfWNaV9UQ9855zSvKyqEA2QYlXPd+B0M5nbyNwbWeEfjgWIuTCcdgl4s4iM0qToI0PgOPXsTHITTYA9MV99/uEz5P+vLTWWW74nixpwxXDyFHAxekL3XaTjnD//u6mRkaimR/8lQ2wgBm4Wl0mS2Sgeb+/TD96spqzAj7joa0z/AmVDh6d9mv0rOH4nkR5HxJgk5ZxGIRWXIpoBmwM4bLv5hXdy5ukW6yj8mmjRzVPwMhbLQnMiLIknWPJQTRjytRf6HbabkRcV2AK99SsPWbFMafOUNEI4AotGjLj0HiYo7scJ4nx5n7Qjw==
  • 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>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Paul Durrant <paul@xxxxxxx>
  • Delivery-date: Thu, 02 Dec 2021 15:59:47 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 30.11.2021 16:24, Roger Pau Monné wrote:
> On Fri, Sep 24, 2021 at 11:45:57AM +0200, Jan Beulich wrote:
>> --- a/xen/drivers/passthrough/iommu.c
>> +++ b/xen/drivers/passthrough/iommu.c
>> @@ -260,12 +260,38 @@ void iommu_domain_destroy(struct domain
>>      arch_iommu_domain_destroy(d);
>>  }
>>  
>> -int iommu_map(struct domain *d, dfn_t dfn, mfn_t mfn,
>> +static unsigned int mapping_order(const struct domain_iommu *hd,
>> +                                  dfn_t dfn, mfn_t mfn, unsigned long nr)
>> +{
>> +    unsigned long res = dfn_x(dfn) | mfn_x(mfn);
>> +    unsigned long sizes = hd->platform_ops->page_sizes;
>> +    unsigned int bit = find_first_set_bit(sizes), order = 0;
>> +
>> +    ASSERT(bit == PAGE_SHIFT);
>> +
>> +    while ( (sizes = (sizes >> bit) & ~1) )
>> +    {
>> +        unsigned long mask;
>> +
>> +        bit = find_first_set_bit(sizes);
>> +        mask = (1UL << bit) - 1;
>> +        if ( nr <= mask || (res & mask) )
>> +            break;
>> +        order += bit;
>> +        nr >>= bit;
>> +        res >>= bit;
>> +    }
>> +
>> +    return order;
>> +}
> 
> This looks like it could be used in other places, I would at least
> consider using it in pvh_populate_memory_range where we also need to
> figure out the maximum order given an address and a number of pages.
> 
> Do you think you could place it in a more generic file and also use
> more generic parameters (ie: unsigned long gfn and mfn)?

The function as is surely isn't reusable, for its use of IOMMU
specific data. If and when a 2nd user appears, it'll be far clearer
whether and if so how much of it is worth generalizing. (Among other
things I'd like to retain the typesafe parameter types here.)

>> @@ -284,14 +316,18 @@ int iommu_map(struct domain *d, dfn_t df
>>          if ( !d->is_shutting_down && printk_ratelimit() )
>>              printk(XENLOG_ERR
>>                     "d%d: IOMMU mapping dfn %"PRI_dfn" to mfn %"PRI_mfn" 
>> failed: %d\n",
>> -                   d->domain_id, dfn_x(dfn_add(dfn, i)),
>> -                   mfn_x(mfn_add(mfn, i)), rc);
>> +                   d->domain_id, dfn_x(dfn), mfn_x(mfn), rc);
>> +
>> +        for ( j = 0; j < i; j += 1UL << order )
>> +        {
>> +            dfn = dfn_add(dfn0, j);
>> +            order = mapping_order(hd, dfn, _mfn(0), i - j);
>>  
>> -        while ( i-- )
>>              /* if statement to satisfy __must_check */
>> -            if ( iommu_call(hd->platform_ops, unmap_page, d, dfn_add(dfn, 
>> i),
>> -                            0, flush_flags) )
>> +            if ( iommu_call(hd->platform_ops, unmap_page, d, dfn, order,
>> +                            flush_flags) )
>>                  continue;
>> +        }
> 
> Why you need this unmap loop here, can't you just use iommu_unmap?

Good question - I merely converted the loop that was already there.
Looks like that could have been changed to a simple call already
before. I'll change it here, on the assumption that splitting this
out isn't going to be a worthwhile exercise.

Jan




 


Rackspace

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