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

Re: [PATCH v2] public: add RING_NR_UNCONSUMED_*() macros to ring.h


  • To: Juergen Gross <jgross@xxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 9 Dec 2021 09:48:04 +0100
  • 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=q/wjiQ0J3T6bulvXOwbJPkh8GBjSj7haCrvlH1MsovY=; b=OGfoziSVsMXQJxyqwAdLQKpGZBmMSQQUYfjMpJ3TXWTECYGIBjrRyeIyTmVMH7mAjYWiMHYzBXdzApweJdfeB2uYNryMV7uugVgbwB1sN+yY2sRJWEZDcUg62Y06SIVnQA9h9BO7opKWFobSiGm/UK2mnGx76YpvlK4t6lVoYgoMkEzGpNYELYQeV9nrvoLL8qyy7WKcHEGfqsmfR13gC5HL343gfYMuzId3yRnqGgHezXWo/5TcOblyrbc3NVUrgn8qdy4fHhKuvknKdGgg4nCLPH9sQit1xCTncPS7PSMlKx6pr7NSKDu5keCbAWkrXCvV/C5ZfEdv7o4+2559zA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P9eslVOnIQW6zN3j929pbIpWxjMwxqXW/+Fn8lemb47ALam8Bzoc+Ej7QtHmnMjxssIP322vcjoBCs0EEAf6+YQ35nZfXzAWS2M2FfzwQ/Rv+e5EvDiwAoJIUJWytqQqNX+NtmqWsFk8tBTfPeqI8OdDBnCtpg36gN6yOn9pLU/1NEwkGo8cwiArBnNFyMvqhLe9CYQGCk6s8wWDAGRZOv+Ec8jtqPKQP/6GTHoTEJ6Xp0BI+cFTo1tZ2wqnj8DPBedLaBRgaxDHcq43XqQx2L35c5OsQjSTktSudjEG7pd2q4u8VspchIC8CjWH5lSKgJ8bGrr4pU7sXxu3yABdTw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Manuel Bouyer <bouyer@xxxxxxxxxxxxxxx>, Simon Kuenzer <simon.kuenzer@xxxxxxxxx>, Paul Durrant <paul@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Thu, 09 Dec 2021 08:48:18 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 09.12.2021 08:09, Juergen Gross wrote:
> Today RING_HAS_UNCONSUMED_*() macros are returning the number of
> unconsumed requests or responses instead of a boolean as the name of
> the macros would imply.
> 
> As this "feature" is already being used, rename the macros to
> RING_NR_UNCONSUMED_*() and define the RING_HAS_UNCONSUMED_*() macros
> by using the new RING_NR_UNCONSUMED_*() macros. In order to avoid
> future misuse let RING_HAS_UNCONSUMED_*() optionally really return a
> boolean (can be activated by defining RING_HAS_UNCONSUMED_IS_BOOL).
> 
> Note that the known misuses need to be switched to the new
> RING_NR_UNCONSUMED_*() macros when using this version of ring.h.

Is this last statement stale with the introduction of
RING_HAS_UNCONSUMED_IS_BOOL?

> --- a/xen/include/public/io/ring.h
> +++ b/xen/include/public/io/ring.h
> @@ -208,11 +208,11 @@ typedef struct __name##_back_ring __name##_back_ring_t
>      (RING_FREE_REQUESTS(_r) == 0)
>  
>  /* Test if there are outstanding messages to be processed on a ring. */
> -#define RING_HAS_UNCONSUMED_RESPONSES(_r)                               \
> +#define RING_NR_UNCONSUMED_RESPONSES(_r)                                \
>      ((_r)->sring->rsp_prod - (_r)->rsp_cons)
>  
>  #ifdef __GNUC__
> -#define RING_HAS_UNCONSUMED_REQUESTS(_r) ({                             \
> +#define RING_NR_UNCONSUMED_REQUESTS(_r) ({                              \
>      unsigned int req = (_r)->sring->req_prod - (_r)->req_cons;          \
>      unsigned int rsp = RING_SIZE(_r) -                                  \
>          ((_r)->req_cons - (_r)->rsp_prod_pvt);                          \

To answer the "whether" question this was likely good enough. I wonder
though whether the use of (_r)->sring->{rsp,req}_prod doesn't require
further sanitizing of the result as it's now intended to be used as a
count - afaict the returned values could easily be beyond the number of
ring elements when the other end is misbehaving. Or if not bounding
the values here, I would say the comment in context would need
updating / extending, to tell consumers that they may not blindly use
the returned values.

Also imo all new identifiers would better have a XEN_ prefix to avoid
further growing the risk of name space clashes. But I can see how this
would result in inconsistencies with existing names.

Jan




 


Rackspace

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