Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 871C9C433EF for ; Wed, 1 Dec 2021 16:06:22 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.236111.409532 (Exim 4.92) (envelope-from ) id 1msS7Z-00068b-Vb; Wed, 01 Dec 2021 16:06:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 236111.409532; Wed, 01 Dec 2021 16:06:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1msS7Z-00068U-Qv; Wed, 01 Dec 2021 16:06:13 +0000 Received: by outflank-mailman (input) for mailman id 236111; Wed, 01 Dec 2021 16:06:12 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1msS7Y-00067q-AJ for xen-devel@lists.xenproject.org; Wed, 01 Dec 2021 16:06:12 +0000 Received: from ppsw-32.csi.cam.ac.uk (ppsw-32.csi.cam.ac.uk [131.111.8.132]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9a1ec241-52c0-11ec-b945-1df2895da90e; Wed, 01 Dec 2021 17:06:11 +0100 (CET) Received: from hades.srcf.societies.cam.ac.uk ([131.111.179.67]:44012) by ppsw-32.csi.cam.ac.uk (ppsw.cam.ac.uk [131.111.8.136]:25) with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1msS7X-000wa5-1K (Exim 4.95) (return-path ); Wed, 01 Dec 2021 16:06:11 +0000 Received: from [192.168.1.10] (host-92-12-61-86.as13285.net [92.12.61.86]) (Authenticated sender: amc96) by hades.srcf.societies.cam.ac.uk (Postfix) with ESMTPSA id 3F4751FF79; Wed, 1 Dec 2021 16:06:11 +0000 (GMT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9a1ec241-52c0-11ec-b945-1df2895da90e X-Cam-AntiVirus: no malware found X-Cam-ScannerInfo: https://help.uis.cam.ac.uk/email-scanner-virus Message-ID: <39afb361-4047-68d1-acdd-e0838f52cb5f@srcf.net> Date: Wed, 1 Dec 2021 16:06:11 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Content-Language: en-GB To: Jan Beulich , "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= , George Dunlap References: <69b75eb5-82fe-e075-146a-28a9758da433@suse.com> From: Andrew Cooper Subject: Re: [PATCH 2/2] x86/paging: tidy paging_mfn_is_dirty() In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 01/12/2021 10:35, Jan Beulich wrote: > The function returning a boolean indicator, make it return bool. Also > constify its struct domain parameter, albeit requiring to also adjust > mm_locked_by_me(). Furthermore the function is used by shadow code only. > > Signed-off-by: Jan Beulich > > --- a/xen/arch/x86/mm/mm-locks.h > +++ b/xen/arch/x86/mm/mm-locks.h > @@ -40,7 +40,7 @@ static inline void mm_lock_init(mm_lock_ > l->unlock_level = 0; > } > > -static inline int mm_locked_by_me(mm_lock_t *l) > +static inline int mm_locked_by_me(const mm_lock_t *l) bool too? > { > return (l->lock.recurse_cpu == current->processor); > } > --- a/xen/arch/x86/mm/paging.c > +++ b/xen/arch/x86/mm/paging.c > @@ -351,14 +351,14 @@ void paging_mark_dirty(struct domain *d, > paging_mark_pfn_dirty(d, pfn); > } > > - > +#ifdef CONFIG_SHADOW_PAGING > /* Is this guest page dirty? */ > -int paging_mfn_is_dirty(struct domain *d, mfn_t gmfn) > +bool paging_mfn_is_dirty(const struct domain *d, mfn_t gmfn) > { > pfn_t pfn; > mfn_t mfn, *l4, *l3, *l2; > unsigned long *l1; > - int rv; > + bool dirty; > > ASSERT(paging_locked_by_me(d)); > ASSERT(paging_mode_log_dirty(d)); > @@ -367,36 +367,37 @@ int paging_mfn_is_dirty(struct domain *d > pfn = _pfn(get_gpfn_from_mfn(mfn_x(gmfn))); There's nothing inherently paging.c related about this function.  Thoughts on moving the implementation across, rather than #ifdef-ing it? If not, can we at least correct gmfn to mfn here and in the prototype? Alternatively, do we want to start putting things like this in a real library so we can have the toolchain figure this out automatically? > /* Invalid pages can't be dirty. */ > if ( unlikely(!VALID_M2P(pfn_x(pfn))) ) > - return 0; > + return false; > > mfn = d->arch.paging.log_dirty.top; > if ( !mfn_valid(mfn) ) These don't need to be mfn_valid().  They can be checks against MFN_INVALID instead, because the logdirty bitmap is a Xen internal structure. In response to your comment in the previous patch, this would substantially reduce the overhead of paging_mark_pfn_dirty() and paging_mfn_is_dirty(). ~Andrew