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

Re: [PATCH v2 3/6] arm/mpu: Implement free_init_memory for MPU systems


  • To: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • From: "Orzel, Michal" <michal.orzel@xxxxxxx>
  • Date: Tue, 13 Jan 2026 12:54:30 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=arm.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • 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=nWFwnq/uGaUTjhyQQzwUypW8vL6iA0epU0MrIm4lGiM=; b=ykryeajqrI9xTrhL/VVUTBuMrpBbp/tp1rpofrHVzf2FC19ByLFxvx+rcV8lSA+gXI61mWRjNOY/S4J2KFrJ9c4eFxzmSs5UdUjwv6dIPfFafJfZK4D40OMHROL3L1xyATaArl+IPaNfARx0PV9jLjtu5P9Q1Th+f+kaOcIalBmIPzy4Re5Q0dIMfa5kLx3tSxT+RjAPt324omNBJO33PFzGvRrg9SB6O2xA7yHWL8XqzBkGOzXbMQ9Aub0pzeyrWx48Pkeb5uMIVXptl5m56vVWM2Ot8iipGm4VLVGFmvozEbbP0A2zbys/4YyVpF5rRrV+zEIVrpbch3T38E+2cw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uCaP90a0wJtCnN+o6vkhcnmtBK9T+iv2rR+I5phwrPWULPWru+pug0Np2MQD6Rp7d9HslcMFsVbkbaz8P1D4ghRKFSHsOiLP4p+YNdvnh3rK1TpJeMwD8EBy2FlVLR4tS5w1CUN6PrRK21z6NlCrhpnVo6BSYdQZeV06RwvkpQjPBAFqnRzUoOWy3gaekycjvyhVVp5MWcO90Erqr6KKXjDoQvxQ/ZG+o4XkY7pcOCaBWIe3Y2HqwRCEDLQfDFFvMhdOVXLKmabaf8nph477T5ydeF2d1ej1rBOEfjJzODZ0I6oTGTNAjRPui4Du9rkAxAQDVPe3ivz5qEvrPG68PA==
  • Cc: Harry Ramsey <Harry.Ramsey@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Penny Zheng <Penny.Zheng@xxxxxxx>, "Stefano Stabellini" <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, "Bertrand Marquis" <Bertrand.Marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Wei Chen <Wei.Chen@xxxxxxx>, Hari Limaye <Hari.Limaye@xxxxxxx>
  • Delivery-date: Tue, 13 Jan 2026 11:54:49 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 13/01/2026 12:13, Luca Fancellu wrote:
> Hi Michal,
> 
>>>
>>> -static bool is_mm_attr_match(pr_t *region, unsigned int attributes)
>>> +static int is_mm_attr_match(pr_t *region, unsigned int attributes)
>>> {
>>>     if ( region->prbar.reg.ro != PAGE_RO_MASK(attributes) )
>>> -    {
>>> -        printk(XENLOG_WARNING
>>> -               "Mismatched Access Permission attributes (%#x instead of 
>>> %#x)\n",
>>> -               region->prbar.reg.ro, PAGE_RO_MASK(attributes));
>>> -        return false;
>>> -    }
>>> +        return MPU_ATTR_RO_MISMATCH;
>>>
>>>     if ( region->prbar.reg.xn != PAGE_XN_MASK(attributes) )
>>> -    {
>>> -        printk(XENLOG_WARNING
>>> -               "Mismatched Execute Never attributes (%#x instead of 
>>> %#x)\n",
>>> -               region->prbar.reg.xn, PAGE_XN_MASK(attributes));
>>> -        return false;
>>> -    }
>>> +        return MPU_ATTR_XN_MISMATCH;
>> Later below you don't seem to differentiate between MPU_ATTR_RO_MISMATCH and
>> MPU_ATTR_XN_MISMATCH. Therefore I would suggest to keep them as one to 
>> simplify
>> the code.
>>
>>>
>>>     if ( region->prlar.reg.ai != PAGE_AI_MASK(attributes) )
>>> -    {
>>> -        printk(XENLOG_WARNING
>>> -               "Mismatched Memory Attribute Index (%#x instead of %#x)\n",
>>> -               region->prlar.reg.ai, PAGE_AI_MASK(attributes));
>>> -        return false;
>>> -    }
>>> +        return MPU_ATTR_AI_MISMATCH;
>>>
>>> -    return true;
>>> +    return 0;
>>> }
>>>
>>> /* Map a frame table to cover physical addresses ps through pe */
>>> @@ -357,12 +342,45 @@ static int xen_mpumap_update_entry(paddr_t base, 
>>> paddr_t limit,
>>>     */
>>>     if ( flags_has_page_present && (rc >= MPUMAP_REGION_FOUND) )
>>>     {
>>> -        if ( !is_mm_attr_match(&xen_mpumap[idx], flags) )
>>> +        int attr_match = is_mm_attr_match(&xen_mpumap[idx], flags);
>>> +
>>> +        /* We do not support modifying AI attribute. */
>>> +        if ( MPU_ATTR_AI_MISMATCH == attr_match )
>>>         {
>>> -            printk("Modifying an existing entry is not supported\n");
>>> +            printk(XENLOG_ERR
>>> +                   "Modifying memory attribute is not supported\n");
>>>             return -EINVAL;
>>>         }
>>>
>>> +        /*
>>> +         * Permissions RO and XN can be changed only by the full region.
>>> +         * Permissions that match can continue and just increment refcount.
>>> +         */
>>> +        if ( MPU_ATTR_RO_MISMATCH == attr_match ||
>> Enlcose in brackets () || ()
>>
>>> +             MPU_ATTR_XN_MISMATCH == attr_match )
>>> +        {
>>> +            if ( rc == MPUMAP_REGION_INCLUSIVE )
>>> +            {
>>> +                printk(XENLOG_ERR
>>> +                       "Cannot modify partial region permissions\n");
>>> +                return -EINVAL;
>>> +            }
>>> +
>>> +            if ( xen_mpumap[idx].refcount != 0 )
>>> +            {
>>> +                printk(XENLOG_ERR
>>> +                       "Cannot modify memory permissions for a region 
>>> mapped multiple times\n");
>> Memory permission? Here you are checking for XN/RO.
> 
> Right, is it better “memory attributes”?
Yet in a if() block for MPU_ATTR_AI_MISMATCH == attr_match you already have the
same message.

~Michal

> 
>>
>>> +                return -EINVAL;
>>> +            }
>>> +
>>> +            /* Set new permission */
>>> +            xen_mpumap[idx].prbar.reg.ro = PAGE_RO_MASK(flags);
>>> +            xen_mpumap[idx].prbar.reg.xn = PAGE_XN_MASK(flags);
>> Here you always change both, that's why there is no need to provide two 
>> separate
>> macros as I mentioned above.
> 
> good point.
> 
> Cheers,
> Luca
> 




 


Rackspace

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