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 D4E14D3C53D for ; Wed, 10 Dec 2025 12:44:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1182911.1505721 (Exim 4.92) (envelope-from ) id 1vTJYS-0003N2-Dg; Wed, 10 Dec 2025 12:44:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1182911.1505721; Wed, 10 Dec 2025 12:44:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vTJYS-0003Mv-B7; Wed, 10 Dec 2025 12:44:28 +0000 Received: by outflank-mailman (input) for mailman id 1182911; Wed, 10 Dec 2025 12:44:27 +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 1vTJYR-0003Mp-IJ for xen-devel@lists.xenproject.org; Wed, 10 Dec 2025 12:44:27 +0000 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [2a00:1450:4864:20::52d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f510f13e-d5c5-11f0-9cce-f158ae23cfc8; Wed, 10 Dec 2025 13:44:24 +0100 (CET) Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-640e9f5951aso1379572a12.1 for ; Wed, 10 Dec 2025 04:44:24 -0800 (PST) Received: from [192.168.1.6] (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6496db4d839sm2203256a12.21.2025.12.10.04.44.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 10 Dec 2025 04:44:23 -0800 (PST) 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: f510f13e-d5c5-11f0-9cce-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765370664; x=1765975464; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=lAwvMfCMhh5cdxo7JU3Ky1Pa6SEDggGx0ky1nAkrQxo=; b=h9yZD1T2JJAUyhWLJNZJA4I3noPYQ7G6zfo1GmEcCDTd89fl3lNo7BCm6XbO+lZnPD cRZPH7ORGlHTYZobXOZZl37xQdEE+7G8FxUcIoLmPx7fnPQ5W2nJpbIItXlZnbH89T8w 1ofmdAAYvkT8w6ZBOi4zIs8pX0esUE5sgYqdIMxeVK8CS7KwOLYvQ2hwB5LnQqT0f71/ InqRQ7+HLGPxQ30gEyFmAB3KWIPhXUZvvsiln4jHRmSfq593QM5dST4nspxx6mll1HxL Cm4FT/sullkQeczbeqF8jh1XpJcpVSD+7EbmsymgmI327gE4vSdfhHDrKnEwVR13r9N8 eN8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765370664; x=1765975464; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lAwvMfCMhh5cdxo7JU3Ky1Pa6SEDggGx0ky1nAkrQxo=; b=UFHmg9zHgyLLGRuJOSn0C/tCIjaYp+QBctHT83KYyXb1lSYp5af1Cdi46zpz2yQ588 s8PPnQjSMkk3zm/X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6uFQjnDoLdUedLmCrogrsDr8juo9Lw+zGQ== X-Received: by 2002:aa7:d612:0:b0:640:abb1:5eff with SMTP id 4fb4d7f45d1cf-64963f319c4mr3300732a12.8.1765370663859; Wed, 10 Dec 2025 04:44:23 -0800 (PST) Message-ID: Date: Wed, 10 Dec 2025 13:44:22 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 19/19] xen/riscv: introduce metadata table to store P2M type To: Jan Beulich Cc: Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Julien Grall , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , xen-devel@lists.xenproject.org References: <2c41da84b3e7fb0f6e6c3c856bff6edaf9e1d505.1763986955.git.oleksii.kurochko@gmail.com> <889df78f-7196-4b44-9558-fb83f432e18a@suse.com> <36be69fb-9362-43a4-8308-1e62be60d27f@gmail.com> <621089a4-d946-46ce-a3cf-4d0938d4a39a@suse.com> Content-Language: en-US From: Oleksii Kurochko In-Reply-To: <621089a4-d946-46ce-a3cf-4d0938d4a39a@suse.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 12/10/25 8:06 AM, Jan Beulich wrote: > On 09.12.2025 18:09, Oleksii Kurochko wrote: >> On 12/9/25 2:47 PM, Jan Beulich wrote: >>> On 24.11.2025 13:33, Oleksii Kurochko wrote: >>>> + *md_pg = p2m_alloc_page(p2m); >>>> + if ( !*md_pg ) >>>> + { >>>> + printk("%pd: can't allocate metadata page\n", p2m->domain); >>>> + domain_crash(p2m->domain); >>>> + >>>> + return; >>>> + } >>>> + } >>>> + } >>>> + >>>> + if ( *md_pg ) >>>> + metadata = __map_domain_page(*md_pg); >>>> + >>>> + if ( t >= p2m_first_external ) >>>> + { >>>> + metadata[ctx->index].type = t; >>>> + >>>> + t = p2m_ext_storage; >>>> + } >>>> + else if ( metadata ) >>>> + metadata[ctx->index].type = p2m_invalid; >>>> + >>>> + pte->pte |= MASK_INSR(t, P2M_TYPE_PTE_BITS_MASK); >>>> + >>>> + unmap_domain_page(metadata); >>>> } >>> Just to mention (towards future work): Once a metadata page goes back to be >>> entirely zero-filled, it could as well be hooked off and returned to the pool. >>> Not doing so may mean detaining an unused page indefinitely. >> Won’t that already happen when p2m_free_table() is called? > Well, that's when both page table and metadata table are freed. But what if a > leaf page table is moving back to holding all p2m_ram_rw mappings? Then the > metadata page is unused, but will remain allocated. Good point... This could be a rather expensive operation, since in the code: + else if ( metadata ) + metadata[ctx->index].type = p2m_invalid; we would have to check all other metadata entries to determine whether they are (p2m_invalid) or not, and return the page to the pool. It would be nice to have something like metadata.used_entries_num, but the entire page is used for type entries. As an option, we could reserve 8 bits to store a counter of the number of used entries in the metadata page, and then use metadata[0].used_entries_num to check whether it is zero. If it is zero, we could simply return the metadata page to the pool in the “else if (metadata)” case mentioned above. How bad is this idea? Any better suggestions? ~ Oleksii