All of lore.kernel.org
 help / color / mirror / Atom feed
From: oleksii.kurochko@gmail.com
To: Jan Beulich <jbeulich@suse.com>
Cc: Alistair Francis <alistair.francis@wdc.com>,
	Bob Eshleman <bobbyeshleman@gmail.com>,
	Connor Davis <connojdavis@gmail.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Julien Grall <julien@xen.org>,
	Stefano Stabellini <sstabellini@kernel.org>,
	xen-devel@lists.xenproject.org
Subject: Re: [PATCH v7 7/8] xen/riscv: page table handling
Date: Tue, 24 Sep 2024 13:30:52 +0200	[thread overview]
Message-ID: <fc23fbd82c1495e75fc0bdcfa894cdb56262b11b.camel@gmail.com> (raw)
In-Reply-To: <6100a4e0-5bf3-4555-90ae-20624171ff79@suse.com>

On Tue, 2024-09-24 at 12:49 +0200, Jan Beulich wrote:
> On 13.09.2024 17:57, Oleksii Kurochko wrote:
> 
> 
> > @@ -68,6 +108,52 @@ static inline bool pte_is_valid(pte_t p)
> >      return p.pte & PTE_VALID;
> >  }
> >  
> > +/*
> > + * From the RISC-V spec:
> > + *   The V bit indicates whether the PTE is valid; if it is 0, all
> > other bits
> > + *   in the PTE are don’t-cares and may be used freely by
> > software.
> > + *
> > + *   If V=1 the encoding of PTE R/W/X bits could be find in Table
> > 4.5.
> 
> Please avoid using table numbers when not also specifying the precise
> doc
> version. Numbering changes, and it's table 5.5 in the doc I'm looking
> at.
> Use table names instead (also elsewhere of course).
> 
> > + *   Table 4.5 summarizes the encoding of the permission bits.
> > + *      X W R Meaning
> > + *      0 0 0 Pointer to next level of page table.
> > + *      0 0 1 Read-only page.
> > + *      0 1 0 Reserved for future use.
> > + *      0 1 1 Read-write page.
> > + *      1 0 0 Execute-only page.
> > + *      1 0 1 Read-execute page.
> > + *      1 1 0 Reserved for future use.
> > + *      1 1 1 Read-write-execute page.
> > + */
> > +inline bool pte_is_table(const pte_t p)
> 
> Missing static?
static is missed. I'll add it, thanks.

> 
> We normally omit "const" on function arguments; the frequent request
> to add
> missing const is on pointed-to types. If you still want to have it,
> ...
> 
> > +{
> > +    /*
> > +     * According to the spec if V=1 and W=1 then R also needs to
> > be 1 as
> > +     * R = 0 is reserved for future use ( look at the Table 4.5 )
> > so check
> > +     * in ASSERT that if (V==1 && W==1) then R isn't 0.
> > +     *
> > +     * PAGE_HYPERVISOR_RW contains PTE_VALID too.
> > +     */
> > +    ASSERT(((p.pte & PAGE_HYPERVISOR_RW) != (PTE_VALID |
> > PTE_WRITABLE)));
> > +
> > +    return ((p.pte & (PTE_VALID | PTE_ACCESS_MASK)) == PTE_VALID);
> > +}
> > +
> > +static inline bool pte_is_mapping(/*const*/ pte_t p)
> 
> ... I wonder why it's then commented out here.
I just experimented and missed to uncomment it. If "const" could be
omit for none pointed-to types then I prefer to drop const here and in
pte_is_table().

> > +#define XEN_TABLE_MAP_FAILED 0
> > +#define XEN_TABLE_SUPER_PAGE 1
> > +#define XEN_TABLE_NORMAL 2
> > +
> > +/*
> > + * Take the currently mapped table, find the corresponding entry,
> > + * and map the next table, if available.
> > + *
> > + * The alloc_tbl parameters indicates whether intermediate tables
> > should
> > + * be allocated when not present.
> > + *
> > + * Return values:
> > + *  XEN_TABLE_MAP_FAILED: Either alloc_only was set and the entry
> > + *  was empty, or allocating a new page failed.
> > + *  XEN_TABLE_NORMAL: next level or leaf mapped normally
> > + *  XEN_TABLE_SUPER_PAGE: The next entry points to a superpage.
> > + */
> > +static int pt_next_level(bool alloc_tbl, pte_t **table, unsigned
> > int offset)
> > +{
> > +    pte_t *entry;
> > +    mfn_t mfn;
> > +
> > +    entry = *table + offset;
> > +
> > +    if ( !pte_is_valid(*entry) )
> > +    {
> > +        if ( !alloc_tbl )
> > +            return XEN_TABLE_MAP_FAILED;
> > +
> > +        if ( create_table(entry) )
> > +            return XEN_TABLE_MAP_FAILED;
> 
> You're still losing the -ENOMEM here.
Agree, I will save the return value of create_table and return it.

> > +        rc = -EOPNOTSUPP;
> > +        goto out;
> > +    }
> > +
> > +    entry = table + offsets[level];
> > +
> > +    rc = -EINVAL;
> > +    if ( !pt_check_entry(*entry, mfn, flags) )
> > +        goto out;
> > +
> > +    /* We are removing the page */
> > +    if ( !(flags & PTE_VALID) )
> > +        /*
> > +         * there is also a check in pt_check_entry() which check
> > that
> > +         * mfn=INVALID_MFN
> > +         */
> 
> Nit: Comments are to start with a capital letter.
> 
> > +        pte.pte = 0;
> > +    else
> > +    {
> > +        /* We are inserting a mapping => Create new pte. */
> > +        if ( !mfn_eq(mfn, INVALID_MFN) )
> > +            pte = pte_from_mfn(mfn, PTE_VALID);
> > +        else /* We are updating the permission => Copy the current
> > pte. */
> > +        {
> > +            pte = *entry;
> > +            pte.pte &= ~(flags & PTE_ACCESS_MASK);
> 
> Why does "flags" need using here? Simply clearing all PTE_ACCESS_MASK
> bits
> will do, won't it? And only that will guarantee that flags which are
> to be
> clear will actually be cleared.
Agree, there is no any necessity for using "flags" here, they should be
dropped.

> 
> > +/*
> > + * If `mfn` equals `INVALID_MFN`, it indicates that the following
> > page table
> > + * update operation might be related to either:
> > + *   - populating the table (PTE_POPULATE will be set
> > additionaly),
> > + *   - destroying a mapping (PTE_VALID=0),
> > + *   - modifying an existing mapping (PTE_VALID=1).
> > + *
> > + * If `mfn` != INVALID_MFN and flags has PTE_VALID bit set then it
> > means that
> > + * inserting will be done.
> > + */
> > +static int pt_update(unsigned long virt,
> 
> Don't you have vaddr_t for variables/parameters like this one?
Yes, I have. I will update update this and re-check other places.

> 
> > +                     mfn_t mfn,
> > +                     unsigned long nr_mfns,
> > +                     unsigned int flags)
> > +{
> > +    int rc = 0;
> > +    unsigned long vfn = PFN_DOWN(virt);
> > +    unsigned long left = nr_mfns;
> > +
> > +    const mfn_t root = get_root_page();
> 
> Why the blank line between adjacent declarations?
No specific reason, just wanted to group variables by usage ( but then
it should be one blank after rc ).
But I will just drop the blank for consistency with other local
variable of other functions.

~ Oleksii



  reply	other threads:[~2024-09-24 11:31 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-13 15:57 [PATCH v7 0/8] device tree mapping Oleksii Kurochko
2024-09-13 15:57 ` [PATCH v7 1/8] xen/riscv: use {read,write}{b,w,l,q}_cpu() to define {read,write}_atomic() Oleksii Kurochko
2024-09-16  6:17   ` Jan Beulich
2024-09-13 15:57 ` [PATCH v7 2/8] xen/riscv: allow write_atomic() to work with non-scalar types Oleksii Kurochko
2024-09-16  6:25   ` Jan Beulich
2024-09-16  8:54     ` oleksii.kurochko
2024-09-13 15:57 ` [PATCH v7 3/8] xen/riscv: set up fixmap mappings Oleksii Kurochko
2024-09-16  6:32   ` Jan Beulich
2024-09-16  9:50     ` oleksii.kurochko
2024-09-13 15:57 ` [PATCH v7 4/8] xen/riscv: introduce asm/pmap.h header Oleksii Kurochko
2024-09-13 15:57 ` [PATCH v7 5/8] xen/riscv: introduce functionality to work with CPU info Oleksii Kurochko
2024-09-16  6:48   ` Jan Beulich
2024-09-16 10:07     ` oleksii.kurochko
2024-09-13 15:57 ` [PATCH v7 6/8] xen/riscv: introduce and initialize SBI RFENCE extension Oleksii Kurochko
2024-09-13 15:57 ` [PATCH v7 7/8] xen/riscv: page table handling Oleksii Kurochko
2024-09-24 10:49   ` Jan Beulich
2024-09-24 11:30     ` oleksii.kurochko [this message]
2024-09-24 13:31       ` Jan Beulich
2024-09-25 10:07         ` oleksii.kurochko
2024-09-25 14:22           ` Jan Beulich
2024-09-25 14:50             ` oleksii.kurochko
2024-09-25 14:58               ` Jan Beulich
2024-09-27  8:49                 ` oleksii.kurochko
2024-09-27  9:15                   ` Jan Beulich
2024-09-27 11:32                     ` oleksii.kurochko
2024-09-27 12:00                       ` Jan Beulich
2024-09-13 15:57 ` [PATCH v7 8/8] xen/riscv: introduce early_fdt_map() Oleksii Kurochko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fc23fbd82c1495e75fc0bdcfa894cdb56262b11b.camel@gmail.com \
    --to=oleksii.kurochko@gmail.com \
    --cc=alistair.francis@wdc.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=bobbyeshleman@gmail.com \
    --cc=connojdavis@gmail.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.