[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [XEN PATCH 3/4] xen/include: add pure and const attributes


  • To: Simone Ballarin <simone.ballarin@xxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 23 Oct 2023 15:34:46 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fMLjx89QHNR1E+jgaLS4qyOoGIaRXeLbh2j3ZcXFmDs=; b=HToIVGsZxgmGzubPPJTitr8vwA2sm1AqV8GnQlEd790VqVlSNy/t9CEGgcsVX3cJhC3HKQKTTInswyhVxLX10OKOvKCy8F3YkE6mEsaXyOO9infmOGEh1C/coHwDK0Sjj6TUVI7lFeD7lTDBo7cVgbTm28hqWLpOdy557SEaca8m/kCL707UkFdAKDuHz3Ooy/WWWrCNu7Xl4VCvxiuJULdoDojEzTYjU3Sl/NgH1fw+8FxSd31I96DPLvMyqhZtUof8ovfFO+mEKVcpfza9taeZuXE2dYvYed1jGQvAC6PdlCPICcDn8jCRUsK1J3n413pFcw2ZsxcZh2a7QZH/Bw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BetW6GXQaQI+hlNDorO/JYYyoM25eqogEG96FCn0lNkRw1QOvy9b7tOgSx1g9VeG6b5x+LG0sN0GSUnDd3FstY+zieucvNxB+p4LJfW1G1hEC5V/pQQzL97M1XUvPpXxC6cYUd/+FkwymjyIjYxCcI+ZjOBRwxk6/4cmuf0+MMgYLLP8p2IHFsX02tKWaNRw91t7ulyekKFtdfGM/zxd4sizbBxdnRK+v1JF8wsS59QRhUMKCfNvybnqALJ15UTxZ8lr1WtiAxtHyoukXfsv7839B2eUXhjWsSsgt7g+BuvzanSW0yGhG2zLWfNB9VO0afqqx/dr4IVwvqmPoo6y9A==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: consulting@xxxxxxxxxxx, sstabellini@xxxxxxxxxx, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Mon, 23 Oct 2023 13:34:58 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 18.10.2023 16:18, Simone Ballarin wrote:
> Add const and pure attributes to address reports
> of MISRA C:2012 Rule 13.1: Initializer lists shall
> not contain persistent side effects
> 
> Add pure attribute to function pdx_to_pfn.
> Add const attribute to functions generated by TYPE_SAFE.
> 
> These functions are used in initializer lists: adding
> the attributes ensures that no effect will be performed
> by them.

Adding the attribute does, according to my understanding, ensure nothing.
The compiler may (but isn't required to) diagnose wrong uses of the
attributes, but it may also make use of the attributes (on the
declaration) without regard to the attribute potentially being wrongly
applied. Since further for inline functions the compiler commonly infers
attributes from the expanded code (discarding the attribute), the only
thing achieved here is a documentation aspect, I think.

> --- a/xen/include/xen/pdx.h
> +++ b/xen/include/xen/pdx.h
> @@ -164,7 +164,7 @@ static inline unsigned long pfn_to_pdx(unsigned long pfn)
>   * @param pdx Page index
>   * @return Obtained pfn after decompressing the pdx
>   */
> -static inline unsigned long pdx_to_pfn(unsigned long pdx)
> +static inline __attribute_pure__ unsigned long pdx_to_pfn(unsigned long pdx)
>  {
>      return (pdx & pfn_pdx_bottom_mask) |
>             ((pdx << pfn_pdx_hole_shift) & pfn_top_mask);

Taking this as an example for what I've said above: The compiler can't
know that the globals used by the functions won't change value. Even
within Xen it is only by convention that these variables are assigned
their values during boot, and then aren't changed anymore. Which makes
me wonder: Did you check carefully that around the time the variables
have their values established, no calls to the functions exist (which
might then be subject to folding)?

Additionally - what about the sibling function pfn_to_pdx()?

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.