From nobody Thu Dec 18 09:44:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1765904173; cv=none; d=zohomail.com; s=zohoarc; b=QXU0KxKZ3JxQqyyZdrjJOlPKDgFLokUdN6LnD/GuRyqEBo+brO2erAkcH2i2GZyDEU7l2eEOrMkfd57YpiOiYxzBGxWgguEbA1chqJn6EkLEV485MWp5QMd2rqEemaaQGeL3vwS0MLCVW568rZU0LnKBfvGMtpG56MHXJZ2Mbrg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765904173; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tZGIljp4NNyE+7irjY7l3LzV9kUxh2j7lezf++r0RAg=; b=ArOv2lDB7/o2OEryfnxH8t7DyNAxeYAENvWv8ExNPJwywufUO8Qt9iUYqRCVPWwKDH1nb7T7SqsSHGB1cWe2MJYU/gkLXtkxedNj4jaC41cCQc+iNjN0UQCBQkiaD7CJEWNWMfk4RSE0LT6GGLRAp0tasI80T85SsfQq8B13RE8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1765904173035171.11749801152894; Tue, 16 Dec 2025 08:56:13 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1188145.1509402 (Exim 4.92) (envelope-from ) id 1vVYKz-0007A6-5E; Tue, 16 Dec 2025 16:55:49 +0000 Received: by outflank-mailman (output) from mailman id 1188145.1509402; Tue, 16 Dec 2025 16:55:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vVYKz-00079M-1i; Tue, 16 Dec 2025 16:55:49 +0000 Received: by outflank-mailman (input) for mailman id 1188145; Tue, 16 Dec 2025 16:55:47 +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 1vVYKx-0006gk-Lu for xen-devel@lists.xenproject.org; Tue, 16 Dec 2025 16:55:47 +0000 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [2a00:1450:4864:20::52a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 10823d82-daa0-11f0-9cce-f158ae23cfc8; Tue, 16 Dec 2025 17:55:45 +0100 (CET) Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-64198771a9bso6813009a12.2 for ; Tue, 16 Dec 2025 08:55:45 -0800 (PST) Received: from fedora (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8003cb349csm63169766b.68.2025.12.16.08.55.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Dec 2025 08:55:44 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 10823d82-daa0-11f0-9cce-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765904145; x=1766508945; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tZGIljp4NNyE+7irjY7l3LzV9kUxh2j7lezf++r0RAg=; b=m6gfNd+TS2Owo8epdafEFMeugy1YWlMbFDO7tayX4AzV9Nu9AxLWwxkgDpdCd6BckB EgjYOveP6o/6fnzr/PGCR4NZKgzJf2Rgok4zMc9NwaGn4HqFA3wxFbz6p16yRNozyVnU 5unlpxfXNYeL6ziDpWvrMJHehUHf1VKPwAdt8Lf+j7QsTdRZmi/yNRFGr1XnbVnonSEm I7JMf77aV2gNSogqQL660iOO3W/Leeqy3iVgmkC9Uzoql+wyZjmtMIgjMC+OQqjjOt3t xjGURDhRI2Gz0Nih5YoDhwC6hgPJyPfddMeVIQFjPv60ZnnkEd/O2eMaD2rnDMqnV1R+ mkYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765904145; x=1766508945; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=tZGIljp4NNyE+7irjY7l3LzV9kUxh2j7lezf++r0RAg=; b=qmTYj8H5h4VhUGVuGkFESw1UZBRQd7WBoBPGABFrCesFb622wcjksupGfEQaV38Upi tqdcgVF4Xc0YVpP8jmbR7JvktceJQ8H0tQcqx+0sLclaDxPj3AMTUaVo2IuoaWJBGglt MuN+yjupO4SJ9QfdHCz8BYkJKapRdfKu7nU31DOLpENOIhpO+MJ+jFA5fBqPvQiaOOof HDVtjowdl8kIsJRUeR8iOnMtvuGcAnnQ+CexbBVTodFQ+2El5yhQ8qFtdKnZXMwcFopf EpfoUpYsmY25YwxD8KOIv4HT9hHLbRYaVqQ9tPXtMxnKRF4dMinS3JIFT/ZbJBUCmCN1 vtLQ== X-Gm-Message-State: AOJu0Yxmc1FQNFRfGY/1Ag8Pth68Kd9/RqzXGniHQ079lJ3Rb1jS3Wsp RhkiNZ6ml/md4fh4WDBNWB+LpaQxrGBkfzmyuNYv7Wr2sy9LT5mc2iIE/ipq6Q== X-Gm-Gg: AY/fxX6s8WhltoJ3vlg8HOWfj0z9bgQjhgLBuLPBaxSzF62Xvh3ds+giPdFYwqUWWPR ka/jtgAlO6/8tGEsT80u14o727DtEsx2HepWCgay90tkRig/E2YVZYkHBG/vaaoq6UndoRzgtsp BtcI5djys0VFZej5GZvZ+rSotYHhrILKEpUgPoeJID7HsErZ7/2BM+eG3CBw1z0sQRCrkgISgdB 36mS2PsaHxUHNjmT3XW4/uLMPl/MTY6JmDub/Rp4FSbMswXQptk94lNCOiKNfNRqS5JrWzB+Peu HyFEJhxK56kZqpYyIYoWw6iRpXUB/N0IvLkLJas0foI8MEt6jyF2EAYCHZvkzuGCYly+qEq2asX ZtxqtezHeoqcaAA8eQSH7WuyFb0I+CfyvR3K8TrFz5cunWkjLNE30NaY7aQB325FNmGSoD2U0m+ V/Sws/eMHZiu+I30L+4SY9hiTxnCfn7VVmR0CMRWPhZYRj4qJhx+c= X-Google-Smtp-Source: AGHT+IE9H0v/6/3gcQGvq55aH+rbLFfzKNhgLrlYXMXVGe1fUuPnIp9idn/scP4+DQ/TZZkoQaYdpg== X-Received: by 2002:a17:906:c113:b0:b73:9be1:33ec with SMTP id a640c23a62f3a-b7d236193aamr1474539366b.9.1765904144666; Tue, 16 Dec 2025 08:55:44 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v7 03/19] xen/riscv: introduce things necessary for p2m initialization Date: Tue, 16 Dec 2025 17:55:13 +0100 Message-ID: <81cf2f714dc7310ad19e77b72c18cc4438f81641.1765879052.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1765904175809154100 Content-Type: text/plain; charset="utf-8" Introduce the following things: - Update p2m_domain structure, which describe per p2m-table state, with: - lock to protect updates to p2m. - pool with pages used to construct p2m. - back pointer to domain structure. - p2m_init() to initalize members introduced in p2m_domain structure. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in V6-7: - Nothing changed. Only rebase. --- Changes in V5: - Acked-by: Jan Beulich . --- Changes in V4: - Move an introduction of clean_pte member of p2m_domain structure to the patch where it is started to be used: xen/riscv: add root page table allocation - Add prototype of p2m_init() to asm/p2m.h. --- Changes in V3: - s/p2m_type/p2m_types. - Drop init. of p2m->clean_pte in p2m_init() as CONFIG_HAS_PASSTHROUGH is going to be selected unconditionaly. Plus CONFIG_HAS_PASSTHROUGH isn't ready to be used for RISC-V. Add compilation error to not forget to init p2m->clean_pte. - Move defintion of p2m->domain up in p2m_init(). - Add iommu_use_hap_pt() when p2m->clean_pte is initialized. - Add the comment above p2m_types member of p2m_domain struct. - Add need_flush member to p2m_domain structure. - Move introduction of p2m_write_(un)lock() and p2m_tlb_flush_sync() to the patch where they are really used: xen/riscv: implement guest_physmap_add_entry() for mapping GFNs to MFN - Add p2m member to arch_domain structure. - Drop p2m_types from struct p2m_domain as P2M type for PTE will be stored differently. - Drop default_access as it isn't going to be used for now. - Move defintion of p2m_is_write_locked() to "implement function to map me= mory in guest p2m" where it is really used. --- Changes in V2: - Use introduced erlier sbi_remote_hfence_gvma_vmid() for proper implement= ation of p2m_force_tlb_flush_sync() as TLB flushing needs to happen for each p= CPU which potentially has cached a mapping, what is tracked by d->dirty_cpum= ask. - Drop unnecessary blanks. - Fix code style for # of pre-processor directive. - Drop max_mapped_gfn and lowest_mapped_gfn as they aren't used now. - [p2m_init()] Set p2m->clean_pte=3Dfalse if CONFIG_HAS_PASSTHROUGH=3Dn. - [p2m_init()] Update the comment above p2m->domain =3D d; - Drop p2m->need_flush as it seems to be always true for RISC-V and as a consequence drop p2m_tlb_flush_sync(). - Move to separate patch an introduction of root page table allocation. --- xen/arch/riscv/include/asm/domain.h | 5 +++++ xen/arch/riscv/include/asm/p2m.h | 33 +++++++++++++++++++++++++++++ xen/arch/riscv/p2m.c | 20 +++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/xen/arch/riscv/include/asm/domain.h b/xen/arch/riscv/include/a= sm/domain.h index aac1040658..e688980efa 100644 --- a/xen/arch/riscv/include/asm/domain.h +++ b/xen/arch/riscv/include/asm/domain.h @@ -5,6 +5,8 @@ #include #include =20 +#include + struct vcpu_vmid { uint64_t generation; uint16_t vmid; @@ -24,6 +26,9 @@ struct arch_vcpu { =20 struct arch_domain { struct hvm_domain hvm; + + /* Virtual MMU */ + struct p2m_domain p2m; }; =20 #include diff --git a/xen/arch/riscv/include/asm/p2m.h b/xen/arch/riscv/include/asm/= p2m.h index 3776b98303..239f90622e 100644 --- a/xen/arch/riscv/include/asm/p2m.h +++ b/xen/arch/riscv/include/asm/p2m.h @@ -3,17 +3,48 @@ #define ASM__RISCV__P2M_H =20 #include +#include +#include +#include =20 #include =20 #define paddr_bits PADDR_BITS =20 +/* Get host p2m table */ +#define p2m_get_hostp2m(d) (&(d)->arch.p2m) + struct gstage_mode_desc { unsigned char mode; unsigned int paging_levels; char name[8]; }; =20 +/* Per-p2m-table state */ +struct p2m_domain { + /* + * Lock that protects updates to the p2m. + */ + rwlock_t lock; + + /* Pages used to construct the p2m */ + struct page_list_head pages; + + /* Back pointer to domain */ + struct domain *domain; + + /* + * P2M updates may required TLBs to be flushed (invalidated). + * + * Flushes may be deferred by setting 'need_flush' and then flushing + * when the p2m write lock is released. + * + * If an immediate flush is required (e.g, if a super page is + * shattered), call p2m_tlb_flush_sync(). + */ + bool need_flush; +}; + /* * List of possible type for each page in the p2m entry. * The number of available bit per page in the pte for this purpose is 2 b= its. @@ -97,6 +128,8 @@ static inline bool arch_acquire_resource_check(struct do= main *d) void guest_mm_init(void); unsigned char get_max_supported_mode(void); =20 +int p2m_init(struct domain *d); + #endif /* ASM__RISCV__P2M_H */ =20 /* diff --git a/xen/arch/riscv/p2m.c b/xen/arch/riscv/p2m.c index 4e84acaafd..a6e2456f54 100644 --- a/xen/arch/riscv/p2m.c +++ b/xen/arch/riscv/p2m.c @@ -3,6 +3,10 @@ #include #include #include +#include +#include +#include +#include #include =20 #include @@ -103,3 +107,19 @@ void __init guest_mm_init(void) */ local_hfence_gvma_all(); } + +int p2m_init(struct domain *d) +{ + struct p2m_domain *p2m =3D p2m_get_hostp2m(d); + + /* + * "Trivial" initialisation is now complete. Set the backpointer so t= he + * users of p2m could get an access to domain structure. + */ + p2m->domain =3D d; + + rwlock_init(&p2m->lock); + INIT_PAGE_LIST_HEAD(&p2m->pages); + + return 0; +} --=20 2.52.0