Skip to contentSkip to conversation

Argo: drop meaningless mfn_valid() check

PATCH In review Jan Beulich 2 participants 7 messages Nov 27, 2023 – Feb 5, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Argo: drop meaningless mfn_valid() check

Holding a valid struct page_info * in hands already means the referenced MFN is valid; there's no need to check that again. Convert the checking logic to a switch(), to help keeping the extra (and questionable) x86- only check in somewhat tidy shape.

---
Initially I had this (with less code churn) as

#ifdef CONFIG_X86
    if ( p2mt == p2m_ram_logdirty )
        ret = -EAGAIN;
    else
#endif
    if ( (p2mt != p2m_ram_rw) ||
         !get_page_type(page, PGT_writable_page) )
        ret = -EINVAL;

But the "else" placement seemed too ugly to me. Otoh there better wouldn't be any special casing of log-dirty here (and instead such a page be converted, perhaps right in check_get_page_from_gfn() when readonly=false), at which point the odd "else" would go away, and the if() likely again be preferable over the switch().

xen/common/argo.c +14 -5
@@ -1421,15 +1421,24 @@ find_ring_mfn(struct domain *d, gfn_t gf
         return ret;
 
     *mfn = page_to_mfn(page);
-    if ( !mfn_valid(*mfn) )
-        ret = -EINVAL;
+
+    switch ( p2mt )
+    {
+    case p2m_ram_rw:
+        if ( !get_page_and_type(page, d, PGT_writable_page) )
+            ret = -EINVAL;
+        break;
+
 #ifdef CONFIG_X86
-    else if ( p2mt == p2m_ram_logdirty )
+    case p2m_ram_logdirty:
         ret = -EAGAIN;
+        break;
 #endif
-    else if ( (p2mt != p2m_ram_rw) ||
-              !get_page_and_type(page, d, PGT_writable_page) )
+
+    default:
         ret = -EINVAL;
+        break;
+    }
 
     put_page(page);
 
#1 lore raw

Ping: [PATCH] Argo: drop meaningless mfn_valid() check

Christopher,

Quoted 6 lines · Jan Beulich

Holding a valid struct page_info * in hands already means the referenced MFN is valid; there's no need to check that again. Convert the checking logic to a switch(), to help keeping the extra (and questionable) x86- only check in somewhat tidy shape.

much like "Argo: don't obtain excess page references" (with which the one here actually also conflicts), this one is awaiting your ack or otherwise. Note that the other one has now been pending for quite a bit more than a year. I hope the same isn't going to happen here ...

Thanks, Jan

Quoted 51 lines

---
Initially I had this (with less code churn) as

#ifdef CONFIG_X86
    if ( p2mt == p2m_ram_logdirty )
        ret = -EAGAIN;
    else
#endif
    if ( (p2mt != p2m_ram_rw) ||
         !get_page_type(page, PGT_writable_page) )
        ret = -EINVAL;

But the "else" placement seemed too ugly to me. Otoh there better wouldn't be any special casing of log-dirty here (and instead such a page be converted, perhaps right in check_get_page_from_gfn() when readonly=false), at which point the odd "else" would go away, and the if() likely again be preferable over the switch().

xen/common/argo.c +14 -5
@@ -1421,15 +1421,24 @@ find_ring_mfn(struct domain *d, gfn_t gf
         return ret;
 
     *mfn = page_to_mfn(page);
-    if ( !mfn_valid(*mfn) )
-        ret = -EINVAL;
+
+    switch ( p2mt )
+    {
+    case p2m_ram_rw:
+        if ( !get_page_and_type(page, d, PGT_writable_page) )
+            ret = -EINVAL;
+        break;
+
 #ifdef CONFIG_X86
-    else if ( p2mt == p2m_ram_logdirty )
+    case p2m_ram_logdirty:
         ret = -EAGAIN;
+        break;
 #endif
-    else if ( (p2mt != p2m_ram_rw) ||
-              !get_page_and_type(page, d, PGT_writable_page) )
+
+    default:
         ret = -EINVAL;
+        break;
+    }
 
     put_page(page);
 
Reviewed-by
#2 lore raw

Re: Ping: [PATCH] Argo: drop meaningless mfn_valid() check

Quoted 10 lines · Jan Beulich

Christopher,

Quoted 6 lines · Jan Beulich

Holding a valid struct page_info * in hands already means the referenced MFN is valid; there's no need to check that again. Convert the checking logic to a switch(), to help keeping the extra (and questionable) x86- only check in somewhat tidy shape.

Quoted 5 lines

much like "Argo: don't obtain excess page references" (with which the one here actually also conflicts), this one is awaiting your ack or otherwise. Note that the other one has now been pending for quite a bit more than a year. I hope the same isn't going to happen here ...

Thanks for your patience and the reminders, appreciated and this patch can be applied.

Christopher

Quoted 55 lines

Thanks, Jan

Quoted 51 lines

---
Initially I had this (with less code churn) as

#ifdef CONFIG_X86
    if ( p2mt == p2m_ram_logdirty )
        ret = -EAGAIN;
    else
#endif
    if ( (p2mt != p2m_ram_rw) ||
         !get_page_type(page, PGT_writable_page) )
        ret = -EINVAL;

But the "else" placement seemed too ugly to me. Otoh there better wouldn't be any special casing of log-dirty here (and instead such a page be converted, perhaps right in check_get_page_from_gfn() when readonly=false), at which point the odd "else" would go away, and the if() likely again be preferable over the switch().

xen/common/argo.c +14 -5
@@ -1421,15 +1421,24 @@ find_ring_mfn(struct domain *d, gfn_t gf
         return ret;
 
     *mfn = page_to_mfn(page);
-    if ( !mfn_valid(*mfn) )
-        ret = -EINVAL;
+
+    switch ( p2mt )
+    {
+    case p2m_ram_rw:
+        if ( !get_page_and_type(page, d, PGT_writable_page) )
+            ret = -EINVAL;
+        break;
+
 #ifdef CONFIG_X86
-    else if ( p2mt == p2m_ram_logdirty )
+    case p2m_ram_logdirty:
         ret = -EAGAIN;
+        break;
 #endif
-    else if ( (p2mt != p2m_ram_rw) ||
-              !get_page_and_type(page, d, PGT_writable_page) )
+
+    default:
         ret = -EINVAL;
+        break;
+    }
 
     put_page(page);
 
#3 lore raw

Re: Ping: [PATCH] Argo: drop meaningless mfn_valid() check

Quoted 6 lines · Christopher Clark
Quoted 4 lines · Jan Beulich

Christopher,

On 27.11.2023 14:55, Jan Beulich wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

Holding a valid struct page_info * in hands already means the referenced MFN is valid; there's no need to check that again. Convert the checking logic to a switch(), to help keeping the extra (and questionable) x86- only check in somewhat tidy shape.

I'd like to hold off on this just yet, sorry -- the change does look ok as far as a transform being applied the prior logic and the necessity of the check, but with it applied, it's not obvious that it handles all the page types as best that it could there, so I'd like to look at this (and the previously submitted patch again) please.

Christopher

#4 lore raw

Re: Ping: [PATCH] Argo: drop meaningless mfn_valid() check

Quoted 15 lines · Christopher Clark
Quoted 13 lines · Christopher Clark
Quoted 10 lines · Jan Beulich

Christopher,

Quoted 6 lines · Jan Beulich

Holding a valid struct page_info * in hands already means the referenced MFN is valid; there's no need to check that again. Convert the checking logic to a switch(), to help keeping the extra (and questionable) x86- only check in somewhat tidy shape.

Quoted 7 lines
Quoted 1 line

I'd like to hold off on this just yet, sorry -- the change does look ok as far as a transform being applied the prior logic and the necessity of the check, but with it applied, it's not obvious that it handles all the page types as best that it could there, so I'd like to look at this (and the previously submitted patch again) please.

I'm puzzled: This patch merely removes a pointless check. Whatever is lacking with it in place will have been lacking before. Also can you please give a rough estimate towards when you'll be getting back on this, or ideally on both patches?

Jan

#5 lore raw

Ping: Ping: [PATCH] Argo: drop meaningless mfn_valid() check

Quoted 24 lines · Jan Beulich
Quoted 15 lines · Christopher Clark
Quoted 13 lines · Christopher Clark
Quoted 10 lines · Jan Beulich

Christopher,

Quoted 6 lines · Jan Beulich

Holding a valid struct page_info * in hands already means the referenced MFN is valid; there's no need to check that again. Convert the checking logic to a switch(), to help keeping the extra (and questionable) x86- only check in somewhat tidy shape.

Quoted 7 lines
Quoted 1 line

I'd like to hold off on this just yet, sorry -- the change does look ok as far as a transform being applied the prior logic and the necessity of the check, but with it applied, it's not obvious that it handles all the page types as best that it could there, so I'd like to look at this (and the previously submitted patch again) please.

Quoted 4 lines

I'm puzzled: This patch merely removes a pointless check. Whatever is lacking with it in place will have been lacking before. Also can you please give a rough estimate towards when you'll be getting back on this, or ideally on both patches?

Another month later: I'll give it this week, and without hearing back I'll commit what there is some time next week, with the R-b you provided.

Jan

#6 lore raw

Re: Ping: Ping: [PATCH] Argo: drop meaningless mfn_valid() check

Quoted 26 lines · Jan Beulich
Quoted 24 lines · Jan Beulich
Quoted 22 lines · Christopher Clark
Quoted 6 lines · Christopher Clark
Quoted 4 lines · Jan Beulich

Christopher,

On 27.11.2023 14:55, Jan Beulich wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

Holding a valid struct page_info * in hands already means the referenced MFN is valid; there's no need to check that again. Convert the checking logic to a switch(), to help keeping the extra (and questionable) x86- only check in somewhat tidy shape.

I'd like to hold off on this just yet, sorry -- the change does look ok as far as a transform being applied the prior logic and the necessity of the check, but with it applied, it's not obvious that it handles all the page types as best that it could there, so I'd like to look at this (and the previously submitted patch again) please.

Quoted 7 lines
Quoted 4 lines

I'm puzzled: This patch merely removes a pointless check. Whatever is lacking with it in place will have been lacking before. Also can you please give a rough estimate towards when you'll be getting back on this, or ideally on both patches?

Another month later: I'll give it this week, and without hearing back I'll commit what there is some time next week, with the R-b you provided.

Sorry for the slow communication. I'm not unaware of this but it has been difficult to provide an update on when I will be able to give it the appropriate attention.
I understand that you'd appreciate a response before next week, so I'll aim for that.

thanks,

Christopher