From mboxrd@z Thu Jan 1 00:00:00 1970 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 9BC1FD1CDC6 for ; Tue, 9 Dec 2025 11:47:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1181512.1504551 (Exim 4.92) (envelope-from ) id 1vSwBo-0007ue-Qh; Tue, 09 Dec 2025 11:47:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1181512.1504551; Tue, 09 Dec 2025 11:47:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vSwBo-0007uX-Nr; Tue, 09 Dec 2025 11:47:32 +0000 Received: by outflank-mailman (input) for mailman id 1181512; Tue, 09 Dec 2025 11:47:31 +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 1vSwBn-0007u8-8t for xen-devel@lists.xenproject.org; Tue, 09 Dec 2025 11:47:31 +0000 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [2a00:1450:4864:20::534]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d6710b27-d4f4-11f0-9cce-f158ae23cfc8; Tue, 09 Dec 2025 12:47:28 +0100 (CET) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-641977dc00fso6772231a12.1 for ; Tue, 09 Dec 2025 03:47:28 -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-647b4121eb6sm13824315a12.26.2025.12.09.03.47.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 Dec 2025 03:47:27 -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: d6710b27-d4f4-11f0-9cce-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765280848; x=1765885648; 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=2dbP/Ei4BMUdrCYo3EdbJe8BBHowxkgRf3kv2cnV+ww=; b=dT4/DYoaqVcGN5JMkBcrFIhgfpKmHOIvhXoc8GdjA7uDs7hlNlv5zTy6NXNqYCIPCg v6ayGYDfMTbraoqFOlr89gklX+qGtnJrQ8+sTJLRN5nSkjaeLCokgONYjTuPCisSmG7w DaJHy6vxlnprTf/SYHLnpgcBEud+dCpepsJZTOI3eo+d4PQ8emUwy4bD75QA0VKBp0wi X3J5mpxfHhygDjZm8wHcncCfoCD9MbRsnyy2yML0sf/b3FC/2zrCIKKCRNFZauVUYo6V xiEtF0V5koTPc1q9UXB0KenjfG0sReMX3nIqr5mJ5J42cvQnLSP6Osml+KfwDt5SOZdM 2OFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765280848; x=1765885648; 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=2dbP/Ei4BMUdrCYo3EdbJe8BBHowxkgRf3kv2cnV+ww=; b=YUSyD5qd/EG3gdn94veUWRC5HmP6CPEWF3YDXwMm4LvitfkfwF1dq8RkI9aRmgrn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Fx4zKR/juMxhVIrkP6DW3dPUelN9vKIgkHG7Lrj6bunXwjjetUQ+TY1A== X-Received: by 2002:a05:6402:518c:b0:640:7529:b8c7 with SMTP id 4fb4d7f45d1cf-6491a2d0516mr8056264a12.1.1765280847752; Tue, 09 Dec 2025 03:47:27 -0800 (PST) Message-ID: <021bdde7-ea62-447f-a788-dc31c6a930bd@gmail.com> Date: Tue, 9 Dec 2025 12:47:26 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 11/19] xen/riscv: implement p2m_set_range() 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: <5f2812bb3b82ba1f9178eb00f68a85388f862f09.1763986955.git.oleksii.kurochko@gmail.com> <8b95ccca-7924-4cf8-818a-094782c6bbea@suse.com> Content-Language: en-US From: Oleksii Kurochko In-Reply-To: <8b95ccca-7924-4cf8-818a-094782c6bbea@suse.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 12/8/25 5:52 PM, Jan Beulich wrote: > On 24.11.2025 13:33, Oleksii Kurochko wrote: >> @@ -28,6 +36,77 @@ unsigned char get_max_supported_mode(void) >> return max_gstage_mode.mode; >> } >> >> +static inline unsigned int calc_offset(const struct p2m_domain *p2m, >> + const unsigned int lvl, >> + const paddr_t gpa) >> +{ >> + unsigned int off = (gpa >> P2M_GFN_LEVEL_SHIFT(lvl)) & >> + P2M_TABLE_OFFSET(p2m, lvl); >> + >> + /* >> + * For P2M_ROOT_LEVEL, `offset` ranges from 0 to 2047, since the root >> + * page table spans 4 consecutive 4KB pages. >> + * We want to return an index within one of these 4 pages. >> + * The specific page to use is determined by `p2m_get_root_pointer()`. >> + * >> + * Example: if `offset == 512`: >> + * - A single 4KB page holds 512 entries. >> + * - Therefore, entry 512 corresponds to index 0 of the second page. >> + * >> + * At all other levels, only one page is allocated, and `offset` is >> + * always in the range 0 to 511, since the VPN is 9 bits long. >> + */ >> + return off & (PAGETABLE_ENTRIES - 1); >> +} >> + >> +#define P2M_MAX_ROOT_LEVEL 5 >> + >> +#define P2M_BUILD_LEVEL_OFFSETS(p2m, var, addr) \ >> + unsigned int var[P2M_MAX_ROOT_LEVEL] = {-1}; \ > What use is this initializer? Slot 0 ... I wanted a way to detect if something mistakenly tries to access an uninitialized array element, and using -1 would help distinguish whether an element was truly uninitialized or if calc_offset() simply returned 0. However, you’re right, it doesn’t work because only Slot 0 is initialized with -1. So... > >> + BUG_ON(P2M_ROOT_LEVEL(p2m) >= P2M_MAX_ROOT_LEVEL); \ >> + for ( unsigned int i = 0; i <= P2M_ROOT_LEVEL(p2m); i++ ) \ >> + var[i] = calc_offset(p2m, i, addr); > ... is guaranteed to be written to, afaics. With this simplified (or an > explanation given for why it is needed) ... I will just drop an initializer and let var[] to be initialized with 0s. > Acked-by: Jan Beulich Thanks. ~ Oleksii