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

Re: [PATCH v3 1/3] xen/riscv: introduce setup_initial_pages


  • To: Oleksii <oleksii.kurochko@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 29 Mar 2023 14:06:42 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=C184tFCrsDO43lZbwFwhZRV6RvW9yUSnFb0tMDnXM8Y=; b=Qfql7FGlDRDDRG6H3exVftwLi7K8qHCq48IzcaWvS9kVfIVG01i4undzC5oIiFVr9LnOGkiL03l24ytOZcTOSp3r2g+G95lErX1Qyku4CupSzn0LkBqko9wa1Mdjkj5pvYbyBQlDJUpHqhQdY28YFO8CDgyosu84rXg1AsFIaLxXq1+uZr9LL8bmKk/evQ+9kFOXvozZXP1iBD/YJirtMxDpZVhCCyHjZuCEJHoOa3pPkZTYPt/YHeaFQZ2t8jJHJjrJOw6LPQcebKl9piuoq7A7NZoGGtSN+8Ba7rUlpr4Tu57LUqTzf454UPNPxwgo5SvbM69SqX/3pDnzL8+2cA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VFb8vFoGe6D3qywZ6MaMsawWhdHJP9CuQTjDxYQoKv9M5WBNbb2A6oCO7zhmeVjJYqHlPTiZFZRXNxALs2AH2hP64p74OzePpytAV2NYACYEzUa8gUWeGrss0wOwg7ZaVgtSak70aoBzMzpA2R/Bwi62etATHr0o1pHA7MHGjRHDIq6qwg7/iKosv7/apSoa7JgL3s8j0bop66svacMle8/pnNwq/n+C/ypZFkqHRzqg78E6o9rzoTXJXXR/BR0MAWIv2YkEb1WAZXjJzI01RwF9bj0XckkUo5eT9qJbdj2/zA6/2Kmo/KC1IFk2Zb2HYHMIphaTNeMYO91FVLSxtw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Julien Grall <julien@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Gianluca Guida <gianluca@xxxxxxxxxxxx>, Bob Eshleman <bobbyeshleman@xxxxxxxxx>, Alistair Francis <alistair.francis@xxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Wed, 29 Mar 2023 12:06:59 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 29.03.2023 13:43, Oleksii wrote:
> On Tue, 2023-03-28 at 17:34 +0200, Jan Beulich wrote:
>> On 27.03.2023 19:17, Oleksii Kurochko wrote:
>>> --- /dev/null
>>> +++ b/xen/arch/riscv/mm.c
>>> @@ -0,0 +1,277 @@
>>> +#include <xen/init.h>
>>> +#include <xen/kernel.h>
>>> +
>>> +#include <asm/early_printk.h>
>>> +#include <asm/config.h>
>>> +#include <asm/csr.h>
>>> +#include <asm/mm.h>
>>> +#include <asm/page.h>
>>> +#include <asm/processor.h>
>>> +
>>> +#define PGTBL_INITIAL_COUNT 8
>>
>> What does this magic number derive from? (A comment may help.)
> It can be now 4 tables as it is enough to map 2Mb. 8 it was when I
> experimented with bigger sizes of Xen binary and verified that logic of
> working with page tables works.

Since this is connected to Xen's image size as you say, I guess the
constant wants to move to a header, and then be used in an assertion
in xen.lds.S. That way one will become easily aware if/when this 2Mb
assumption breaks.

>>> +struct mmu_desc {
>>> +    unsigned long num_levels;
>>> +    uint32_t pgtbl_count;
>>
>> Nit: Style (as before please avoid fixed width types when their use
>> isn't really warranted; afaics unsigned int will do fine here and
>> elsewhere below).
> I will change it but I am not sure that I fully understand what is an
> issue with uint32_t.

The issue is simply that ./CODING_STYLE says to prefer basic types
whenever possible.

>>> +void __init setup_initial_pagetables(void)
>>> +{
>>> +    struct mmu_desc mmu_desc = { 0, 0, NULL, 0 };
>>> +
>>> +    /*
>>> +     * Access to _{stard, end } is always PC-relative
>>> +     * thereby when access them we will get load adresses
>>> +     * of start and end of Xen
>>> +     * To get linker addresses LOAD_TO_LINK() is required
>>> +     * to use
>>> +     */
>>> +    unsigned long load_start    = (unsigned long)_start;
>>> +    unsigned long load_end      = (unsigned long)_end;
>>> +    unsigned long linker_start  = LOAD_TO_LINK(load_start);
>>> +    unsigned long linker_end    = LOAD_TO_LINK(load_end);
>>> +
>>> +    if ( (linker_start != load_start) &&
>>> +         (linker_start <= load_end) && (load_start <= linker_end)
>>> ) {
>>> +        early_printk("(XEN) linker and load address ranges
>>> overlap\n");
>>> +        die();
>>> +    }
>>> +
>>> +    calc_pgtbl_lvls_num(&mmu_desc);
>>> +
>>> +    mmu_desc.pgtbl_base = stage1_pgtbl_root;
>>> +    mmu_desc.next_pgtbl = stage1_pgtbl_nonroot;
>>> +
>>> +    setup_initial_mapping(&mmu_desc,
>>> +                          linker_start,
>>> +                          linker_end,
>>> +                          load_start,
>>> +                          PTE_LEAF_DEFAULT);
>>> +
>>> +    setup_ptes_permission(&mmu_desc);
>>
>> ...: Why does this require a 2nd pass / function in the first place?
> Probably I misunderstood Julien and it setup_pte_permission can be done
> in setup_initial_mapping() but here is the reply:
> https://lore.kernel.org/xen-devel/79e83610-5980-d9b5-7994-6b0cb2b9049a@xxxxxxx/

Hmm, yes, his option 2 looks like what you've implemented. Still I
don't see why the permissions can't be got right on the first pass.

Jan



 


Rackspace

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