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

Re: [PATCH v3 2/6] arm/mpu: Implement vmap functions for MPU


  • To: "Orzel, Michal" <michal.orzel@xxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Wed, 14 Jan 2026 11:07:31 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 4.158.2.129) smtp.rcpttodomain=amd.com smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=uaSyDhtGvTHeVrT4IN3p8vE5r39tyrkkpkQ7ahmkb8k=; b=WP/NL+7G/NnSAWXZe/nlcuum2m/no1PwGGLA3BkdtPhJtl9BlvBXR0+OLI0SmO424i//T0Gz1mKZvLMr56b+b09W3jn4eO8LXPuq5dQPD6M4otlr9aQe4KD/XlC9B1HoOraA5Ya6WgKarvrcWmSGFqVywMWxlu+FWUK65cbivV62OXsgQtnsRZpmfG/hqoBs0PucgZwHFvBRohgnBoxRVJ95PGSR+VWb2gN0PlkdIIKCkBLDO6kL3oZA/uyzJoqb/HI6nXCmCyYbccQc4/vqGtrcdgx6crK38XGykAXu8SWFd7yuEHA+BiUqW8J4lPeQ4FBSBFG9AsgMOU7A4Z88bQ==
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=uaSyDhtGvTHeVrT4IN3p8vE5r39tyrkkpkQ7ahmkb8k=; b=UnftzqI9MjGmILGEu1BW2otC1l8e3uWSRTBYtDLRXwxwGQ1gyivS3Z1BmnoJdxE848XTljmWBUc8/0zGbRmoALwx2vBv/VAujAT19xhRKJDvcJWiMFQghTkWheJJP0ijIALv3GPBoxcmUFJMZFQL5zG8EDsP6f8/E1fBNxiaELhlLOtNclM24c3R8ygD+eQbP9yZem5eL3wfQq48U4xxosENSMxd7jM2DT00BOHc49Lg/0PcXhtnDRLzYX71QYFxZFQt5GU17NGiVN4aJTO2JJlFtSN0Us3Uv/9B/83TxplsUe36amcW9lunO3drftl1bUFP6m9ySCfvI79ReahN7A==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=w0lBKP1oH7ijk0CZl0g7AwLMAcuzlWUDwDCPJeniFJUD1LDsV0PjtMnJUWMGXlw2pdPr3BaaZZ06lfIdUrfGVtLjGwQgVd49X8ZCrZxBogxiVtKkkvIlt8lb+qJQA0EC7mlXSDocMXJZUY5Hn5cYxXyWO06ove/bEzgtsTiN7k4KBSkyN1kkj6Iw8LyZcJLyhdvYdbLiuOjli8Nsm9hoZpDlGhXBuSkffRKHY9h0qV4XKW6pWVhn3c5Enmqa3jt1UdsuDDJPaiEKmMK8BvWvl6/7gOP3UeBo+wpl/NnQqDG9hmjzRvbjjXLb8WlC/i/Ivw5Q0+Y6ffciYVwtjF8LkQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vA2qBdJYENzP9GXQoF02GNcm1HzGp7ADlOcKLQn8UymPshoZVv+wRqZw8qERoNYzLUB4pG/r3445CTUwy/T8kibUwkd3l0X2RVnXed8+zXcndTkelvQNy04OsZN6C8OLU38jjyPp7fOjXSSHsP0Pu7ooaXV+gFmvft4f62TS7dPeId9bYlKTKkczMv4K0FaLPwhjcg5kh62zgoa08at7Jah7ASHOyNhBShEn/ZmeA2SPPP2c/2iROhxN3yal3MhVV+1ykWHfQTJAIc6ocJju20XwDQEIqtCLFnXWNXPi9yKrdRqKfi4TobdifC5iPHZImZYLK5OkKAWSgEv+YFEy5A==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Harry Ramsey <Harry.Ramsey@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Wed, 14 Jan 2026 11:08:54 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Thread-index: AQHchThCncyVuPEinUCTQtinTDX+lLVRgV4A
  • Thread-topic: [PATCH v3 2/6] arm/mpu: Implement vmap functions for MPU

Hi Michal,

>> 
>> +/*
>> + * Free a xen_mpumap entry given the index. A mpu region is actually 
>> disabled
>> + * when the refcount is 0 and the region type is MPUMAP_REGION_FOUND.
>> + *
>> + * @param idx                   Index of the mpumap entry.
>> + * @param region_found_type     MPUMAP_REGION_* value.
>> + * @return                      0 on success, otherwise negative on error.
>> + */
>> +static int xen_mpumap_free_entry(uint8_t idx, int region_found_type)
>> +{
>> +    ASSERT(spin_is_locked(&xen_mpumap_lock));
>> +    ASSERT(idx != INVALID_REGION_IDX);
>> +    ASSERT(MPUMAP_REGION_OVERLAP != region_found_type);
>> +
>> +    if ( MPUMAP_REGION_NOTFOUND == region_found_type )
>> +    {
>> +        printk(XENLOG_ERR "Cannot remove entry that does not exist\n");
>> +        return -EINVAL;
>> +    }
>> +
>> +    if ( xen_mpumap[idx].refcount )
>> +    {
>> +        xen_mpumap[idx].refcount -= 1;
>> +        return 0;
>> +    }
>> +
>> +    if ( MPUMAP_REGION_FOUND == region_found_type )
>> +        disable_mpu_region_from_index(idx);
>> +    else
>> +    {
>> +        printk(XENLOG_ERR "Cannot remove a partial region\n");
>> +        return -EINVAL;
>> +    }
> NIT: Try to limit the number of if/else blocks to make the code read better.
> Here you could do the following to remove one else:
>    if ( MPUMAP_REGION_FOUND != region_found_type )
>    {
>        printk(XENLOG_ERR "Cannot remove a partial region\n");
>        return -EINVAL;
>    }
> 
>    disable_mpu_region_from_index(idx);
> 
>    return 0;

Makes sense, while we are there, shall we have also a comment above that check, 
something like this:

/*
 * If we reached this point, the region is due to be destroyed, as a safety
 * check we need to ensure the API is called with the exact region, to prevent
 * destroying a region using a partial memory range.
 */

What do you think? Otherwise someone in the future might think it’s ok to move 
this check
together with the other on top.

>> 
>> 
>> void vunmap(const void *va)
>> {
>> -    BUG_ON("unimplemented");
>> +    paddr_t base = virt_to_maddr(va);
>> +
>> +    if ( destroy_xen_mapping_containing(base) )
>> +        panic("Failed to vunmap region\n");
>> }
> Looking at this series as a whole, at the end we will end up with
> vmap_contig/vunmap to contain the same implementation as map_domain_page and
> alike from the last patch. Shouldn't we define ones using the others?

We can do it, the only thing is that if vunmap fails, we will get a less 
specific error message,
if you are ok with that we will do the change.

Cheers,
Luca


 


Rackspace

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