Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 70AFDC7EE2A for ; Wed, 25 Jun 2025 14:16:02 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1024961.1400716 (Exim 4.92) (envelope-from ) id 1uUQul-0003JM-Ft; Wed, 25 Jun 2025 14:15:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1024961.1400716; Wed, 25 Jun 2025 14:15:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uUQul-0003JF-CC; Wed, 25 Jun 2025 14:15:51 +0000 Received: by outflank-mailman (input) for mailman id 1024961; Wed, 25 Jun 2025 14:15:49 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uUQuj-0003J6-KA for xen-devel@lists.xenproject.org; Wed, 25 Jun 2025 14:15:49 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2060e.outbound.protection.outlook.com [2a01:111:f403:2414::60e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e2c2eab5-51ce-11f0-b894-0df219b8e170; Wed, 25 Jun 2025 16:15:47 +0200 (CEST) Received: from PH8PR12MB7326.namprd12.prod.outlook.com (2603:10b6:510:216::7) by DM4PR12MB5866.namprd12.prod.outlook.com (2603:10b6:8:65::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8857.25; Wed, 25 Jun 2025 14:15:42 +0000 Received: from PH8PR12MB7326.namprd12.prod.outlook.com ([fe80::6d76:9c33:d230:8264]) by PH8PR12MB7326.namprd12.prod.outlook.com ([fe80::6d76:9c33:d230:8264%4]) with mapi id 15.20.8857.022; Wed, 25 Jun 2025 14:15:42 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e2c2eab5-51ce-11f0-b894-0df219b8e170 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=t/jtHwp2ltemq7fKVS9aCx3NakRwA8j/mAgTQQlRunvX41vX9eIS6JSQzYwyKkHTAfQo6EUgzKFY4lArKYMjYv+LU2eJRP13kmfnc6OeB39bpEC3/0PTCRyZ2A+VSlSaPDrkRzDWKLl7w2UD23XKv6HtFc3FGwejKCvJo0Cel6aA7DPQv4B9fOhlKqc2N+zz0L1QWR3VwqhPNykstv2X70UmTYn4j2cTm28pp2VXRw1jhD7yxg2qzcK1luEo/qbrt5H/Kj9ayguJUlr8QNNl1gt6QGvhtWrlRBLNEFPPNA7p4jLSASzKrpKOk9ZilJvsVN+30lD0DBqnr7LeFjLwnw== 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=CYgPdWRnj0mClzlnmlH/ZXSxxYpCMH3YEgd7+AiGMKI=; b=IggMYjkk7fRiKdeQ9IJZR/S6gclS1UrT+G/7VD5KB+IDsbW0JccFfwxOASmhyN/pfJhG6revEAYVnE03Xffm3g+ibrG1wtfb+VAkuaPiHOZtEfZEz3mhH5B34x7Gu+MOROw7pOh44jwpXwYig0TxlQyPS5eTf7/WS+bshRuUyC+LX2XFQbuC6i9DrrYbdguLCegfIbn7azkmyqhEkoAjnmzVK8tbgKxzbKrmg9uNrPjPWi4xfRZSBB7pXi49gYQFDE685JaIBvLp3CTK9JZM/ZqZc91rC/Jq43G/l+5988okQUZi6rbAOwFWzXpreLTISroGlC5hZDNEZKaEmsa5mw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CYgPdWRnj0mClzlnmlH/ZXSxxYpCMH3YEgd7+AiGMKI=; b=n2xGXEO6xJUwTwApL5SxXMhTp8XzqyxD/B1A5akExb15zt/gj1z33sOSI+uxrgjqAxQH2FK3w72KLrpuuQlEEZQX4LFEwFdjlacY3BuZSzBrqp0i1NSfkTdCsgQic1ufJ0aKWX3ZnfxKzXuztI3icCJLPY1aTGbQqZCXGlhfXhI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Message-ID: Date: Wed, 25 Jun 2025 15:15:37 +0100 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/6] arm/mpu: Populate a new region in Xen MPU mapping table Content-Language: en-GB To: Hari Limaye , xen-devel@lists.xenproject.org Cc: luca.fancellu@arm.com, Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Wei Chen References: <840ec219278c2fcb4f8592303eb671b5271b0a95.1750411205.git.hari.limaye@arm.com> From: Ayan Kumar Halder In-Reply-To: <840ec219278c2fcb4f8592303eb671b5271b0a95.1750411205.git.hari.limaye@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: DU7PR01CA0022.eurprd01.prod.exchangelabs.com (2603:10a6:10:50f::10) To PH8PR12MB7326.namprd12.prod.outlook.com (2603:10b6:510:216::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH8PR12MB7326:EE_|DM4PR12MB5866:EE_ X-MS-Office365-Filtering-Correlation-Id: c8ff1683-6f25-4b09-56de-08ddb3f2c48a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|366016|1800799024|7053199007; X-Microsoft-Antispam-Message-Info: =?utf-8?B?aTdoa2dQOGVuRzZadWhVRzIrclZIOEVnc2QyTkY3VXRqSW9MUXM2L1ZzQjJo?= =?utf-8?B?Qzl5ak95UHhNTTd6TUx4UHpNQ3FmQlNiNnB6YmdmKzRUbko5NWYxNmdOU1hD?= =?utf-8?B?YTJZYVJMdGgzZGVSUm91YXVlbzNqK0R2bitDQ0JibHZ3TEIybmhHV2lSZ3JB?= =?utf-8?B?bEVHNENZY0lGU1BzQ2lKNzZUb3ZSaUhXT093WWlQTGh1UkNucmVzTDVneWhG?= =?utf-8?B?WXpmVGJSZWRVNXV1Zm1mV1JYT01NQmthZCtNLzJxQ0ZhUW0rRDNYUThJcENM?= =?utf-8?B?bXdPaXRITURuSkNTUEVYblN4MWVFU3dFZ29USlJxZDNLdDZrSWR1NEtHUjRr?= =?utf-8?B?dmZmMXdrL29HKzRSV2Vpalp0SCs3RlRzQndTZjlOWTdlNTlHWXQ2NlZGZU9N?= =?utf-8?B?dWFSZCtSd2dpcnVFRXRDdDdaWTNPWVlTeU5pbVhJSWxicDl3cUtzalc2TjVT?= =?utf-8?B?cmNJNzNUbk1OcUF5a3VVVGtJZmU0ZXlDR2NoWEp1NjQzY3l6bGZhVjdkanpu?= =?utf-8?B?MTJKNEVuTW1zQlVQWHl0NjQrSFV5NWpsSjNQUWxnUWprVE5sM3lpMExkY1Bw?= =?utf-8?B?VmplbDBsSTZZdXBFbGpHZ05pQ1hZOXcrMUFKQWgzbDBkWXVYVUVQME9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M3V4Z0c0WnNK?= =?utf-8?B?cFdsb0RySFVYanlwaGhKOWVnbXVwbVAwZ1NHajVZN2pEdk1XMUluMUlXWVBZ?= =?utf-8?B?MUdZTSt2M01UM2VVaGMrV0VZVW55anVmeXlyRDdjL1dvdXduYVBWMlVsTFV5?= =?utf-8?B?RWcyb1pydVRGU0xETGp3U09WcmtVSU1KRkp2ZWN1K0lDZ0k2WExNZWl5T3Fp?= =?utf-8?B?dGVMZ2hlTFI2ODdrNk82N0tBaC9ud0wxUXM2YldNZVFRNDljOTlZUEJnb2dZ?= =?utf-8?B?ckZvUEs0U1N2ZEZmQUpqS0tJTU94dlkzTElyYzVJY0tkR2tQeDJVVG9XWHEv?= =?utf-8?B?clQ2RWxYcW1USGlOOUFibHBRZ0xScWphbmRJbnJrOXF4VCtwZE5pdGxjUVIy?= =?utf-8?Q?o8bSoTasp0M=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR12MB7326.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(366016)(1800799024)(7053199007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?ckxwekg2SXc0Y1lJZDdyWUNOMVhYLzRmSUhkekdmdGUwcFpQaFI2b25rRFZI?= =?utf-8?B?RTRwRk5nSGNDdGFqcHJGYWJsdnIzQjdrS1FQcEZlZ1ErVjlGWHBDMjdodHNk?= =?utf-8?B?R09lUUdCMEhaNDF2enJmNWQ0VjgwbXEzcjNFSHRrQUthUG1CV3h5SUxQZWdZ?= =?utf-8?B?WFUzeWY2UFlMaW96dUtNME9MdGVYNVpmZjVNQnlCSDZSbEdLUTgyM0FsT0Zi?= =?utf-8?B?MXd0MFRIdm40Z1l3UXNHUXFnd1djeUlqUFVMT2dwWmdFVUJKYktGM0hWVzlu?= =?utf-8?B?SVdwU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6WHZI?= =?utf-8?Q?ANCNNiwsKQJ+tXf9fC16qU4o5?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c8ff1683-6f25-4b09-56de-08ddb3f2c48a X-MS-Exchange-CrossTenant-AuthSource: PH8PR12MB7326.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2025 14:15:42.0251 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4PeCl8+ITDqDQgRGmGTHTBi1F+DbNOmQJ0dM0YnCIS22FHHJmovN5ej2pwy25TogP1hZ8sehcbmI529kNec7Gg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5866 Hi Hari, Some questions. On 20/06/2025 10:49, Hari Limaye wrote: > CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email. > > > From: Penny Zheng > > Introduce map_pages_to_xen() that is implemented using a new helper, > xen_mpumap_update(), which is responsible for updating Xen MPU memory > mapping table(xen_mpumap), including creating a new entry, updating > or destroying an existing one, it is equivalent to xen_pt_update in MMU. > > This commit only implements populating a new entry in Xen MPU memory mapping > table(xen_mpumap). > > Signed-off-by: Penny Zheng > Signed-off-by: Wei Chen > Signed-off-by: Luca Fancellu > Signed-off-by: Hari Limaye > --- > xen/arch/arm/include/asm/mpu/mm.h | 12 ++++ > xen/arch/arm/mpu/mm.c | 96 +++++++++++++++++++++++++++++++ > 2 files changed, 108 insertions(+) > > diff --git a/xen/arch/arm/include/asm/mpu/mm.h b/xen/arch/arm/include/asm/mpu/mm.h > index a0f0d86d4a..f0f41db210 100644 > --- a/xen/arch/arm/include/asm/mpu/mm.h > +++ b/xen/arch/arm/include/asm/mpu/mm.h > @@ -64,6 +64,7 @@ static inline void context_sync_mpu(void) > * The following API requires context_sync_mpu() after being used to modify MPU > * regions: > * - write_protection_region > + * - xen_mpumap_update > */ > > /* Reads the MPU region (into @pr_read) with index @sel from the HW */ > @@ -72,6 +73,17 @@ void read_protection_region(pr_t *pr_read, uint8_t sel); > /* Writes the MPU region (from @pr_write) with index @sel to the HW */ > void write_protection_region(const pr_t *pr_write, uint8_t sel); > > +/* > + * Maps an address range into the MPU data structure and updates the HW. > + * Equivalent to xen_pt_update in an MMU system. > + * > + * @param base Base address of the range to map (inclusive). > + * @param limit Limit address of the range to map (exclusive). > + * @param flags Flags for the memory range to map. > + * @return 0 on success, negative on error. > + */ > +int xen_mpumap_update(paddr_t base, paddr_t limit, unsigned int flags); > + > /* > * Creates a pr_t structure describing a protection region. > * > diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c > index 15197339b1..1de28d2120 100644 > --- a/xen/arch/arm/mpu/mm.c > +++ b/xen/arch/arm/mpu/mm.c > @@ -6,6 +6,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -41,6 +42,8 @@ DECLARE_BITMAP(xen_mpumap_mask, MAX_MPU_REGION_NR) \ > /* EL2 Xen MPU memory region mapping table. */ > pr_t __cacheline_aligned __section(".data") xen_mpumap[MAX_MPU_REGION_NR]; > > +static DEFINE_SPINLOCK(xen_mpumap_lock); > + > static void __init __maybe_unused build_assertions(void) > { > /* > @@ -176,6 +179,99 @@ int mpumap_contain_region(pr_t *table, uint8_t nr_regions, paddr_t base, > return MPUMAP_REGION_NOTFOUND; > } > > +/* > + * Allocate a new free EL2 MPU memory region, based on bitmap xen_mpumap_mask. > + * @param idx Set to the index of the allocated EL2 MPU region on success. > + * @return 0 on success, otherwise -ENOENT on failure. > + */ > +static int xen_mpumap_alloc_entry(uint8_t *idx) > +{ > + ASSERT(spin_is_locked(&xen_mpumap_lock)); > + > + *idx = find_first_zero_bit(xen_mpumap_mask, max_mpu_regions); > + if ( *idx == max_mpu_regions ) > + { > + printk(XENLOG_ERR "mpu: EL2 MPU memory region mapping pool exhausted\n"); > + return -ENOENT; > + } > + > + set_bit(*idx, xen_mpumap_mask); > + return 0; > +} > + > +/* > + * Update the entry in the MPU memory region mapping table (xen_mpumap) for the > + * given memory range and flags, creating one if none exists. > + * > + * @param base Base address (inclusive). > + * @param limit Limit address (exclusive). > + * @param flags Region attributes (a combination of PAGE_HYPERVISOR_XXX) > + * @return 0 on success, otherwise negative on error. > + */ > +static int xen_mpumap_update_entry(paddr_t base, paddr_t limit, > + unsigned int flags) > +{ > + uint8_t idx; > + int rc; > + > + ASSERT(spin_is_locked(&xen_mpumap_lock)); > + > + rc = mpumap_contain_region(xen_mpumap, max_mpu_regions, base, limit, &idx); > + if ( (rc < 0) || (rc > MPUMAP_REGION_NOTFOUND) ) if ( !(rc == MPUMAP_REGION_NOTFOUND) ) <<-- Does it read better ? > + return -EINVAL; > + > + /* We are inserting a mapping => Create new region. */ > + if ( flags & _PAGE_PRESENT ) Why do we need to check for this flag ? Or where have we set it. If we have reached here, doesn't it mean that the region does not exist. So we need to create one. > + { > + rc = xen_mpumap_alloc_entry(&idx); > + if ( rc ) > + return -ENOENT; > + > + xen_mpumap[idx] = pr_of_addr(base, limit, flags); > + > + write_protection_region(&xen_mpumap[idx], idx); > + } > + > + return 0; > +} > + > +int xen_mpumap_update(paddr_t base, paddr_t limit, unsigned int flags) > +{ > + int rc; > + > + if ( flags_has_rwx(flags) ) > + { > + region_printk("Mappings should not be both Writeable and Executable\n"); > + return -EINVAL; > + } > + > + if ( !IS_ALIGNED(base, PAGE_SIZE) || !IS_ALIGNED(limit, PAGE_SIZE) ) > + { > + region_printk("base address 0x%"PRIpaddr", or limit address 0x%"PRIpaddr" is not page aligned\n", > + base, limit); > + return -EINVAL; > + } > + > + spin_lock(&xen_mpumap_lock); > + > + rc = xen_mpumap_update_entry(base, limit, flags); > + > + spin_unlock(&xen_mpumap_lock); > + > + return rc; > +} > + > +int map_pages_to_xen(unsigned long virt, mfn_t mfn, unsigned long nr_mfns, > + unsigned int flags) > +{ > + int rc = xen_mpumap_update(mfn_to_maddr(mfn), > + mfn_to_maddr(mfn_add(mfn, nr_mfns)), flags); > + if ( !rc ) > + context_sync_mpu(); > + > + return rc; > +} > + > void __init setup_mm(void) > { > BUG_ON("unimplemented"); Rest look good to me. - Ayan > -- > 2.34.1 > >