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: Fri, 27 Sep 2024 13:32:28 +0200	[thread overview]
Message-ID: <edc8bda6d7cf67b370652ea17b5d3ce462adf962.camel@gmail.com> (raw)
In-Reply-To: <c5b22604-5fa5-4034-8596-654be962ad84@suse.com>

On Fri, 2024-09-27 at 11:15 +0200, Jan Beulich wrote:
> On 27.09.2024 10:49, oleksii.kurochko@gmail.com wrote:
> > On Wed, 2024-09-25 at 16:58 +0200, Jan Beulich wrote:
> > > On 25.09.2024 16:50, oleksii.kurochko@gmail.com wrote:
> > > > On Wed, 2024-09-25 at 16:22 +0200, Jan Beulich wrote:
> > > > > On 25.09.2024 12:07, oleksii.kurochko@gmail.com wrote:
> > > > > > On Tue, 2024-09-24 at 15:31 +0200, Jan Beulich wrote:
> > > > > > > On 24.09.2024 13:30, oleksii.kurochko@gmail.com wrote:
> > > > > > > > On Tue, 2024-09-24 at 12:49 +0200, Jan Beulich wrote:
> > > > > > > > > On 13.09.2024 17:57, Oleksii Kurochko wrote:
> > > > > > > > > > +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.
> > > > > > > 
> > > > > > > That won't work very well, will it? 
> > > > > > I think it will work, just will be needed another one check
> > > > > > in
> > > > > > pt_update_entry() where pt_next_level() is called:
> > > > > >         if ( (rc == XEN_TABLE_MAP_FAILED) || (rc == -
> > > > > > ENOMEM) )
> > > > > >         ...
> > > > > 
> > > > > Yet that's precisely why I said "won't work very well":
> > > > > You're
> > > > > now
> > > > > having
> > > > > rc in two entirely distinct number spaces (XEN_TABLE_MAP_*
> > > > > and -
> > > > > E*).
> > > > > That's imo just calling for trouble down the road. Unless you
> > > > > emphasized
> > > > > this aspect pretty well in a comment.
> > > > > 
> > > > > > > Imo you need a new XEN_TABLE_MAP_NOMEM.
> > > > > > > (And then XEN_TABLE_MAP_FAILED may want renaming to e.g.
> > > > > > > XEN_TABLE_MAP_NONE).
> > > > > > I am still curious if we really need this separation. If to
> > > > > > in
> > > > > > this
> > > > > > way
> > > > > > then it should be updated the check in pt_update_entry():
> > > > > >    --- a/xen/arch/riscv/pt.c
> > > > > >    +++ b/xen/arch/riscv/pt.c
> > > > > >    @@ -165,10 +165,10 @@ static int pt_next_level(bool
> > > > > > alloc_tbl,
> > > > > > pte_t
> > > > > >    **table, unsigned int offset)
> > > > > >         if ( !pte_is_valid(*entry) )
> > > > > >         {
> > > > > >             if ( !alloc_tbl )
> > > > > >    -            return XEN_TABLE_MAP_FAILED;
> > > > > >    +            return XEN_TABLE_MAP_NONE;
> > > > > >     
> > > > > >             if ( create_table(entry) )
> > > > > >    -            return XEN_TABLE_MAP_FAILED;
> > > > > >    +            return XEN_TABLE_MAP_NOMEM;
> > > > > >         }
> > > > > >     
> > > > > >         if ( pte_is_mapping(*entry) )
> > > > > >    @@ -209,7 +209,7 @@ static int pt_update_entry(mfn_t
> > > > > > root,
> > > > > > unsigned
> > > > > >    long virt,
> > > > > >         for ( ; level > target; level-- )
> > > > > >         {
> > > > > >             rc = pt_next_level(alloc_tbl, &table,
> > > > > > offsets[level]);
> > > > > >    -        if ( rc == XEN_TABLE_MAP_FAILED )
> > > > > >    +        if ( (rc == XEN_TABLE_MAP_NONE) && (rc ==
> > > > > > XEN_TABLE_MAP_NOMEM)
> > > > > >    )
> > > > > >             {
> > > > > >                 rc = 0;
> > > > > > But the handling of XEN_TABLE_MAP_NONE and
> > > > > > XEN_TABLE_MAP_NOMEM
> > > > > > seems to
> > > > > > me should be left the same as this one part of the code
> > > > > > actually
> > > > > > catching the case when create_table() returns -ENOMEM:
> > > > > >    pt_next_level()
> > > > > >    {
> > > > > >    ...
> > > > > >                if ( flags & (PTE_VALID | PTE_POPULATE) )
> > > > > >                {
> > > > > >                    dprintk(XENLOG_ERR,
> > > > > >                            "%s: Unable to map level %u\n",
> > > > > > __func__,
> > > > > >    level);
> > > > > >                    rc = -ENOMEM;
> > > > > >                }
> > > > > 
> > > > > Except that you want to avoid "inventing" an error code when
> > > > > you
> > > > > were
> > > > > handed one. Just consider what happens to this code if
> > > > > another -
> > > > > E...
> > > > > could also come back from the helper.
> > > > I think we can drop the usage of -ENOMEM in the helper
> > > > create_table()
> > > > by returning XEN_TABLE_MAP_FAILED in case of failure, with a
> > > > redefinition of XEN_TABLE_MAP_FAILED = 1, XEN_TABLE_SUPER_PAGE
> > > > = 2,
> > > > and
> > > > XEN_TABLE_NORMAL = 3, as value 0 is used to indicate that
> > > > everything is
> > > > okay.
> > > > 
> > > > We can leave the pt_update() code as it is now:
> > > > ...
> > > >             if ( flags & (PTE_VALID | PTE_POPULATE) )
> > > >             {
> > > >                 dprintk(XENLOG_ERR,
> > > >                       "%s: Unable to map level %u\n", __func__,
> > > > level);
> > > >                 rc = -ENOMEM;
> > > >             }
> > > > ...
> > > > 
> > > > Because for the end user, it's better to receive the error code
> > > > from
> > > > xen/errno.h rather than a custom error code introduced nearby
> > > > the
> > > > helper.
> > > > 
> > > > Does it make sense?
> > > 
> > > While I think I see where you're coming from, I still don't
> > > agree.
> > > And
> > > I never suggested to bubble up some custom error indication. Up
> > > the
> > > call
> > > chain it wants to be -ENOMEM, sure. Yet keying its generation to
> > > flags & (PTE_VALID | PTE_POPULATE) is both less obvious and more
> > > fragile
> > > (towards future code changes) than keying it to rc ==
> > > XEN_TABLE_MAP_NOMEM.
> > I am not sure that (rc == XEN_TABLE_MAP_NOMEM) is equal to (flags &
> > (PTE_VALID | PTE_POPULATE) as XEN_TABLE_MAP_NOMEM miss the case
> > (flags
> > & PTE_VALID) == 0 ( removing a mapping case ) and for which should
> > be
> > returned 0 but not -ENOMEM.
> 
> The intention is quite clear: Return -ENOMEM if and only if an
> allocation
> failed. Hence why I think the XEN_TABLE_MAP_NOMEM approach is
> preferable.
Just to be sure. Do you mean the following:

diff --git a/xen/arch/riscv/pt.c b/xen/arch/riscv/pt.c
index d7eb207ddc..6cd2e595b6 100644
--- a/xen/arch/riscv/pt.c
+++ b/xen/arch/riscv/pt.c
@@ -209,24 +209,15 @@ static int pt_update_entry(mfn_t root, unsigned
long virt,
     for ( ; level > target; level-- )
     {
         rc = pt_next_level(alloc_tbl, &table, offsets[level]);
-        if ( rc == XEN_TABLE_MAP_FAILED )
+        if ( rc == XEN_TABLE_MAP_NOMEM )
         {
-            rc = 0;
-
-            /*
-             * We are here because pt_next_level has failed to map
-             * the intermediate page table (e.g the table does not
exist
-             * and the pt couldn't be allocated). It is a valid case
when
-             * removing a mapping as it may not exist in the page
table.
-             * In this case, just ignore it.
-             */
-            if ( flags & (PTE_VALID | PTE_POPULATE) )
-            {
-                dprintk(XENLOG_ERR,
-                        "%s: Unable to map level %u\n", __func__,
level);
-                rc = -ENOMEM;
-            }
+            rc = -ENOMEM;
+            goto out;
+        }
 
+        if ( rc == XEN_TABLE_MAP_NONE )
+        {
+            rc = 0;
             goto out;
         }

~ Oleksii



  reply	other threads:[~2024-09-27 11:33 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
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 [this message]
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=edc8bda6d7cf67b370652ea17b5d3ce462adf962.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.