From: Julien Grall <julien@xen.org>
To: Hongyan Xia <hx242@xen.org>, xen-devel@lists.xenproject.org
Cc: "Stefano Stabellini" <sstabellini@kernel.org>,
"Wei Liu" <wl@xen.org>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Ian Jackson" <ian.jackson@eu.citrix.com>,
"George Dunlap" <george.dunlap@citrix.com>,
"Julien Grall" <julien.grall@arm.com>,
"Tamas K Lengyel" <tamas@tklengyel.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>,
"Roger Pau Monné" <roger.pau@citrix.com>
Subject: Re: [Xen-devel] [PATCH 16/17] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN
Date: Mon, 23 Mar 2020 12:26:59 +0000 [thread overview]
Message-ID: <502bd95a-a36f-5e77-ee48-a5ad2045480e@xen.org> (raw)
In-Reply-To: <7017afd81363e61996b8645fce566679fc500ab3.camel@xen.org>
Hi,
On 23/03/2020 12:11, Hongyan Xia wrote:
> On Sun, 2020-03-22 at 16:14 +0000, julien@xen.org wrote:
>> From: Julien Grall <julien.grall@arm.com>
>>
>> The first parameter of {s,g}et_gpfn_from_mfn() is an MFN, so it can
>> be
>> switched to use the typesafe.
>>
>> At the same time, replace gpfn with pfn in the helpers as they all
>> deal
>> with PFN and also turn the macros to static inline.
>>
>> Note that the return of the getter and the 2nd parameter of the
>> setter
>> have not been converted to use typesafe PFN because it was requiring
>> more changes than expected.
>>
>> Signed-off-by: Julien Grall <julien.grall@arm.com>
>>
>> ---
>> This was originally sent as part of "xen/arm: Properly disable
>> M2P
>> on Arm" [1].
>>
>> Changes since the original version:
>> - mfn_to_gmfn() is still present for now so update it
>> - Remove stray +
>> - Avoid churn in set_pfn_from_mfn() by inverting mfn and mfn_
>> - Remove tags
>> - Fix build in mem_sharing
>>
>> [1] <20190603160350.29806-1-julien.grall@arm.com>
>> ---
>> xen/arch/x86/cpu/mcheck/mcaction.c | 2 +-
>> xen/arch/x86/mm.c | 14 +++----
>> xen/arch/x86/mm/mem_sharing.c | 20 ++++-----
>> xen/arch/x86/mm/p2m-pod.c | 4 +-
>> xen/arch/x86/mm/p2m-pt.c | 35 ++++++++--------
>> xen/arch/x86/mm/p2m.c | 66 +++++++++++++++-------------
>> --
>> xen/arch/x86/mm/paging.c | 4 +-
>> xen/arch/x86/pv/dom0_build.c | 6 +--
>> xen/arch/x86/x86_64/traps.c | 8 ++--
>> xen/common/page_alloc.c | 2 +-
>> xen/include/asm-arm/mm.h | 2 +-
>> xen/include/asm-x86/grant_table.h | 2 +-
>> xen/include/asm-x86/mm.h | 12 ++++--
>> xen/include/asm-x86/p2m.h | 2 +-
>> 14 files changed, 93 insertions(+), 86 deletions(-)
>>
>>
>
> [...]
>
>> diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h
>> index abf4cc23e4..11614f9107 100644
>> --- a/xen/include/asm-arm/mm.h
>> +++ b/xen/include/asm-arm/mm.h
>> @@ -319,7 +319,7 @@ struct page_info *get_page_from_gva(struct vcpu
>> *v, vaddr_t va,
>> #define SHARED_M2P(_e) ((_e) == SHARED_M2P_ENTRY)
>>
>> /* Xen always owns P2M on ARM */
>> -#define set_gpfn_from_mfn(mfn, pfn) do { (void) (mfn), (void)(pfn);
>> } while (0)
>> +static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn) {}
>> #define mfn_to_gmfn(_d, mfn) (mfn)
>
> I do not have a setup to compile and test code for Arm, but wouldn't
> the compiler complain about unused arguments here? The marco version
> explicitly silenced compiler complaints.
The macro version does not use (void)(arg) for silencing unused
parameter. It is for evaluating (mfn) but ignore the result. A compiler
would warn without (void) because we build Xen with -Wall which include
-Wunused-value.
Xen is not used with -Wunused-parameter, so there is no concern about
unused parameters. If we ever decided to turn on -Wunused-parameter (or
-Wextra), then we will have quite a bit of code to modify (such as
callbacks not using all the parameters) to make it compile.
>
>> diff --git a/xen/include/asm-x86/grant_table.h b/xen/include/asm-
>> x86/grant_table.h
>> index 5871238f6d..b6a09c4c6c 100644
>> --- a/xen/include/asm-x86/grant_table.h
>> +++ b/xen/include/asm-x86/grant_table.h
>> @@ -41,7 +41,7 @@ static inline int
>> replace_grant_host_mapping(uint64_t addr, mfn_t frame,
>> #define gnttab_get_frame_gfn(gt, st, idx)
>> ({ \
>> mfn_t mfn_ = (st) ? gnttab_status_mfn(gt,
>> idx) \
>> : gnttab_shared_mfn(gt,
>> idx); \
>> - unsigned long gpfn_ =
>> get_gpfn_from_mfn(mfn_x(mfn_)); \
>> + unsigned long gpfn_ =
>> get_pfn_from_mfn(mfn_); \
>> VALID_M2P(gpfn_) ? _gfn(gpfn_) :
>> INVALID_GFN; \
>> })
>>
>> diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h
>> index 53f2ed7c7d..2a4f42e78f 100644
>> --- a/xen/include/asm-x86/mm.h
>> +++ b/xen/include/asm-x86/mm.h
>> @@ -500,9 +500,10 @@ extern paddr_t mem_hotplug;
>> */
>> extern bool machine_to_phys_mapping_valid;
>>
>> -static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned
>> long pfn)
>> +static inline void set_pfn_from_mfn(mfn_t mfn_, unsigned long pfn)
>> {
>> - const struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
>> + const unsigned long mfn = mfn_x(mfn_);
>> + const struct domain *d = page_get_owner(mfn_to_page(mfn_));
>> unsigned long entry = (d && (d == dom_cow)) ? SHARED_M2P_ENTRY :
>> pfn;
>>
>> if ( !machine_to_phys_mapping_valid )
>> @@ -515,11 +516,14 @@ static inline void set_gpfn_from_mfn(unsigned
>> long mfn, unsigned long pfn)
>>
>> extern struct rangeset *mmio_ro_ranges;
>>
>> -#define get_gpfn_from_mfn(mfn) (machine_to_phys_mapping[(mfn)])
>> +static inline unsigned long get_pfn_from_mfn(mfn_t mfn)
>> +{
>> + return machine_to_phys_mapping[mfn_x(mfn)];
>> +}
>
> Any specific reason this (and some other macros) are turned into static
> inline? I don't have a problem with them being inline functions but
> just wondering if there is a reason to do so.
static inline provides better safety check than macro. So we tend to
switch to static inline whenever the headers inter-dependency madness is
not interplaying.
>
>> #define mfn_to_gmfn(_d, mfn) \
>> ( (paging_mode_translate(_d)) \
>> - ? get_gpfn_from_mfn(mfn) \
>> + ? get_pfn_from_mfn(_mfn(mfn)) \
>> : (mfn) )
>>
>> #define compat_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) |
>> ((unsigned)(pfn) >> 20))
>> diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h
>> index a2c6049834..39dae242b0 100644
>> --- a/xen/include/asm-x86/p2m.h
>> +++ b/xen/include/asm-x86/p2m.h
>> @@ -505,7 +505,7 @@ static inline struct page_info
>> *get_page_from_gfn(
>> static inline gfn_t mfn_to_gfn(const struct domain *d, mfn_t mfn)
>> {
>> if ( paging_mode_translate(d) )
>> - return _gfn(get_gpfn_from_mfn(mfn_x(mfn)));
>> + return _gfn(get_pfn_from_mfn(mfn));
>> else
>> return _gfn(mfn_x(mfn));
>> }
>
> Apart from the two comments above, looks good to me.
>
> Reviewed-by: Hongyan Xia <hongyxia@amazon.com>
Thank you!
Cheers,
--
Julien Grall
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2020-03-23 12:27 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-22 16:14 [Xen-devel] [PATCH 00/17] Bunch of typesafe conversion julien
2020-03-22 16:14 ` [Xen-devel] [PATCH 01/17] xen/x86: Introduce helpers to generate/convert the CR3 from/to a MFN/GFN julien
2020-03-25 14:46 ` Jan Beulich
2020-03-28 10:14 ` Julien Grall
2020-03-30 7:38 ` Jan Beulich
2020-04-16 11:50 ` Julien Grall
2020-03-22 16:14 ` [Xen-devel] [PATCH 02/17] xen/x86_64: Convert do_page_walk() to use typesafe MFN julien
2020-03-25 14:51 ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 03/17] xen/mm: Move the MM types in a separate header julien
2020-03-25 15:00 ` Jan Beulich
2020-03-25 18:09 ` Julien Grall
2020-03-26 9:02 ` Jan Beulich
2020-03-28 10:15 ` Julien Grall
2020-03-22 16:14 ` [Xen-devel] [PATCH 04/17] xen: Convert virt_to_mfn() and mfn_to_virt() to use typesafe MFN julien
2020-03-25 15:27 ` Jan Beulich
2020-03-25 18:21 ` Julien Grall
2020-03-26 9:09 ` Jan Beulich
2020-03-28 10:33 ` Julien Grall
2020-03-22 16:14 ` [Xen-devel] [PATCH 05/17] xen/x86: Remove the non-typesafe version of pagetable_* helpers julien
2020-03-26 15:39 ` Jan Beulich
2020-03-28 10:52 ` Julien Grall
2020-03-30 7:52 ` Jan Beulich
2020-04-18 10:23 ` Julien Grall
2020-04-20 9:16 ` Jan Beulich
2020-04-20 10:10 ` Julien Grall
2020-04-20 12:14 ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 06/17] xen/x86: mm: Fix the comment on top put_page_from_l2e() to use 'mfn' julien
2020-03-26 15:51 ` Jan Beulich
2020-04-18 10:54 ` Julien Grall
2020-03-22 16:14 ` [Xen-devel] [PATCH 07/17] xen/x86: traps: Convert __page_fault_type() to use typesafe MFN julien
2020-03-26 15:54 ` Jan Beulich
2020-04-18 11:01 ` Julien Grall
2020-04-18 11:43 ` Julien Grall
2020-04-20 9:19 ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 08/17] xen/x86: traps: Convert show_page_walk() " julien
2020-03-22 16:14 ` [Xen-devel] [PATCH 09/17] xen/x86: Reduce the number of use of l*e_{from, get}_pfn() julien
2020-03-27 10:52 ` Jan Beulich
2020-03-28 10:53 ` Julien Grall
2020-03-22 16:14 ` [Xen-devel] [PATCH 10/17] xen/x86: pv: Use maddr_to_mfn(...) instead of the open-coding version julien
2020-03-27 11:34 ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 11/17] xen/x86: nested_ept: Fix typo in the message in nept_translate_l2ga() julien
2020-03-27 11:35 ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 12/17] xen/x86: p2m: Remove duplicate error message in p2m_pt_audit_p2m() julien
2020-03-27 11:35 ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 13/17] xen/x86: p2m: Reflow P2M_PRINTK()s " julien
2020-03-27 11:36 ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 14/17] xen/x86: mm: Re-implement set_gpfn_from_mfn() as a static inline function julien
2020-03-27 12:44 ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 15/17] xen/x86: p2m: Rework printk format in audit_p2m() julien
2020-03-27 12:45 ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 16/17] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN julien
2020-03-23 12:11 ` Hongyan Xia
2020-03-23 12:26 ` Julien Grall [this message]
2020-03-27 13:15 ` Jan Beulich
2020-03-28 11:14 ` Julien Grall
2020-03-30 8:10 ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 17/17] xen: Switch parameter in get_page_from_gfn to use typesafe gfn julien
2020-03-23 8:37 ` Paul Durrant
2020-03-23 10:26 ` Julien Grall
2020-03-27 13:50 ` Jan Beulich
2020-03-27 13:59 ` Julien Grall
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=502bd95a-a36f-5e77-ee48-a5ad2045480e@xen.org \
--to=julien@xen.org \
--cc=Volodymyr_Babchuk@epam.com \
--cc=andrew.cooper3@citrix.com \
--cc=george.dunlap@citrix.com \
--cc=hx242@xen.org \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=julien.grall@arm.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=tamas@tklengyel.com \
--cc=wl@xen.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).