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

Re: [PATCH v4 4/7] arm/mpu: Provide access to the MPU region from the C code


  • To: "Orzel, Michal" <Michal.Orzel@xxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Tue, 6 May 2025 08:45:10 +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=5ky/vAF+1Bjeyis2x8vdk9xTxAD3UbJzPp2bnjUseFU=; b=w10mMxh+I6Nx9XVZOC3ddiH4HFrqee4cEyEMpqXXX4ymyqED+Vm8d7DbGSCyjsnySg8YZAMcCXZFAeyZpfomeTDnn9XQFagvREovp+1Ix01ajh2Nnd7oeIKO4YUA66kHHoH3174z2pLrYyI6YHNKUSlkhxQknlUFppgu3BUSiHexR/E6uw4W4HEhJXjpwcnMAnwr/NQouQmCXHRcnV0IeGmavzD9LCzErKokqhB+i02H/wqBYcRrgpf8/N3Zlv4e2VeoYevXWnc4D5ahdz3VzzPYaGP4yriJBdoNyosJ/TqrD2MElojywkl44L1OOhSr9Wg9DWAEaiDfWgwsPMIVzg==
  • 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=5ky/vAF+1Bjeyis2x8vdk9xTxAD3UbJzPp2bnjUseFU=; b=Inl7HnorQsNiSPTN67DBRyHtPAzihQWV1msh2mebRKYxcEp6YOPg24pVI6dyyQx9sQWeTpLRL/oLDyvEYtkPAwD4XE7LZelqXAk1Lvpl4EhaUYYlV1phXcQF9V/O4jfDKeU/RW1owwtAL6l/GD4HQDmRfshKl0s3GEeNTgVtZiqGZ1/cApUJc47/rutm3QIK0W6M6qjkYz+8Z8y8auOT0zHvJHHq2CPMsvqndGQT7WJQR+AEaqOEXJZs0VWjoaQqIYfyxlUt7mKbf+iUKjsgf/5zC07RjYk8QEtngWHMpcTgSej97DYkkVSQ74Se4fhO/esJImPeTwKTCIePevZArA==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=ls37upRf30SHWYX3Ae5mQN5UTsqis5ywK1bZocZ6RdePav/XMQilX213qKIXjaVZ5VFh5ActA5oIftnPo9xyPUHQnJ+jAPKC0KWlBqrPu+r9cfTFupgzfoCaJyoGPh30wWNFv1Hlx093iCK23V8Y4dbGK58XJ7ugOxBTWtl9iiu1kaJYbLfHKghO8wFnx6z0rT+Vb77UbnSh+Vhfl4gCapeD7gJvYSLVwXMURzEtw++VzzCW0GyBHc1sG6w9Fx1B58IB8vj0p22vbE0bSyYiftJBuoilP7vpfsSzDw9DxdywIKkEQwgBGQv/Scb5FDOXpZjJIycfKBdCC1zfYZiXnA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tXpUJaACgdRTGXbpBkw/0X0GaqFUIvReSdFB9WlCPG5NkI4gpHwfNt7scW+G1xmLu64N3iTM4mlUhRQn08s5rsRijJ950jlS+rNoTra6sd31y0a9ZPSgpq9HI7ERvE7hq0jtu8x+2aNiAQ8ZvOPaiS4O3nHqf/+RuowgspfZ4ShBpeIG6Cy65kAZ6KxtAEPqcVLbweoBoVRqykXk+0HYrZwo+C22tfkbhS9FJDSZ3T8kOASXuBfc9Cgku/3SgXaJR47lnctFyNrHnAJIhOzze1ZapopSVum8DPTTo6ZiHojL27MHIY2vY75638nal6IlM8bvY3yeCW6A173nKnlBFQ==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: "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: Tue, 06 May 2025 08:46:36 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Thread-index: AQHbuRpwLITrbiULPkuuL8oh5S0krbPD902AgAFcswA=
  • Thread-topic: [PATCH v4 4/7] arm/mpu: Provide access to the MPU region from the C code

Hi Michal,

>> 
>> diff --git a/xen/arch/arm/include/asm/mpu.h b/xen/arch/arm/include/asm/mpu.h
>> index 1368b2eb990f..40a86140b6cc 100644
>> --- a/xen/arch/arm/include/asm/mpu.h
>> +++ b/xen/arch/arm/include/asm/mpu.h
>> @@ -17,6 +17,7 @@
>> #define MPU_REGION_SHIFT  6
>> #define MPU_REGION_ALIGN  (_AC(1, UL) << MPU_REGION_SHIFT)
>> #define MPU_REGION_MASK   (~(MPU_REGION_ALIGN - 1))
>> +#define MPU_REGION_RES0   (0xFFFFULL << 48)
> This does not look like a common macro. It's arm64 specific.
> Also, it looks like you use it in macros that are common too.

Yes right, I’ll move that into asm/arm64/mpu.h

>> 
>> +/*
>> + * Reads the MPU region with index 'sel' from the HW.
> If you use @foo style, you should use @sel here.
> But IMO this comment does not bring any usefulness.
> The name of the helper and parameter description is enough.
> 
>> + *
>> + * @pr_read: mpu protection region returned by read op.
>> + * @sel: mpu protection region selector
>> + */
>> +extern void read_protection_region(pr_t *pr_read, uint8_t sel);
>> +
>> +/*
>> + * Writes the MPU region with index 'sel' to the HW.
>> + *
>> + * @pr_write: const mpu protection region passed through write op.
> No need to say const in parameter description
> 
>> + * @sel: mpu protection region selector
> Same here.

I’ll modify these above

>> 
>> diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c
>> index 9eab09ff2044..40ccf99adc94 100644
>> --- a/xen/arch/arm/mpu/mm.c
>> +++ b/xen/arch/arm/mpu/mm.c
>> @@ -8,6 +8,8 @@
>> #include <xen/sizes.h>
>> #include <xen/types.h>
>> #include <asm/mpu.h>
>> +#include <asm/mpu/mm.h>
>> +#include <asm/sysregs.h>
>> 
>> struct page_info *frame_table;
>> 
>> @@ -26,6 +28,35 @@ DECLARE_BITMAP(xen_mpumap_mask, MAX_MPU_REGION_NR) \
>> /* EL2 Xen MPU memory region mapping table. */
>> pr_t __section(".data.page_aligned") xen_mpumap[MAX_MPU_REGION_NR];
>> 
>> +#ifdef CONFIG_ARM_64
>> +/*
>> + * The following are needed for the case generators 
>> GENERATE_WRITE_PR_REG_CASE
> It's read a bit odd. Perhaps remove 'generators' word and use 'cases:'

ok

>> 
>> 
>> +#ifdef CONFIG_ARM_64
>> +/*
>> + * Armv8-R supports direct access and indirect access to the MPU regions 
>> through
>> + * registers, indirect access involves changing the MPU region selector, 
>> issuing
> s/registers,/registers:/ and perhaps use bullet points
> 
>> + * an isb barrier and accessing the selected region through specific 
>> registers;
>> + * instead direct access involves accessing specific registers that points 
>> to
>> + * a specific MPU region, without changing the selector (in some cases) and
> What do you mean by "in some cases"?

what I had in mind was that eventually you’ll need to change the selector at 
some point,
like arm64 every 16 regions or on arm32 from region 32 onwards, but maybe I can 
simplify
and remove this part.

> 
>> + * issuing barriers because of that.
>> + * For Arm64 the PR{B,L}AR_ELx (for n=0) and PR{B,L}AR<n>_ELx, n=1..15, are 
>> used
> If for n==0 you used (), why not following the same style for 1..15?
> It all improves readability of such long comments.
> 
>> + * for the direct access to the regions selected by 
>> PRSELR_EL2.REGION<7:4>:n, so
>> + * 16 regions can be directly access when the selector is multiple of 16, 
>> giving
> s/access/accessed/
> s/is multiple/is a multiple/

ok all the above

Cheers,
Luca

 


Rackspace

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