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

Re: [PATCH v4 2/5] xen/ppc: Implement bitops.h


  • To: Shawn Anastasio <sanastasio@xxxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 11 Sep 2023 15:53:18 +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=E8Rh17gKCOLUHiviCF3CCMlVIWvKkzwrCbIqhxS6hl0=; b=Y4E/jhcXuX51um/dVPexdL/DrK7JZ17ygwF71CYG/1kdRSGnIppwFp9tomeVc4wiOECa3ImaY11irIjqGEtUJRaZVCR85gxvR0aZCI13p0/Y4u5p3Izr1A83aqfraIhm9KXrJtSeZjUUilyT/buxb6brlGO93Ga27UfI145YNwVaiNqotaxPF2eVk+TggKkHctMN5Xbw7f1fxeahJYSpDbInsb0FqY55ufdksJF5WkNfx8eYp3DFhVoCmJUpUmp85KGRLntZ3q04A2+588m/yE3Hxk5DrTEjDbxZMs6l7mH4fReqZ9jLfgz7y3ihlunukeqkKnaN0kIVqOEy8sx3Zg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EKmKFPeIaTJl60wurEILfY4lmnO7ddGGzVIVjhWdL3VEjsumCjYztggWVuoeN7wwJJPg80j/1l6R5cOvF5aPIvAJmT+p8rX2Lhxdr+IimbuYqUdFcSszoE7T8cTJKf9gHgMApyEqHiwT8NT6X4U+asD956GuPXwheQo9WXeZnBggH2jtECdmpP5ZQHDq0pbjLrY2HcTJDGjwRXuhCUbkTlyjyV0hM8jrpWHxPritHRsHYuO5EHIPbypbXEeRZgcSzDCQzqm8b+3YoOKsVHkxMUr4R7HL/ldDEkaz6TnVkUWkgvRET6Bap2MRDbVtcoTEW5PEWHqyY1xffFri19d4Jw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Timothy Pearson <tpearson@xxxxxxxxxxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Mon, 11 Sep 2023 13:53:29 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 09.09.2023 00:50, Shawn Anastasio wrote:
> +/**
> + * test_bit - Determine whether a bit is set
> + * @nr: bit number to test
> + * @addr: Address to start counting from
> + */
> +static inline int test_bit(int nr, const volatile void *addr)
> +{
> +    const volatile unsigned long *p = (const volatile unsigned long *)addr;
> +    return 1 & (p[BITOP_WORD(nr)] >> (nr & (BITOP_BITS_PER_WORD - 1)));
> +}

Do you really mean unsigned long in here? (As an aside I'd also recommend
to drop the cast; I don't think it's needed for anything.)

> +static inline unsigned long test_and_clear_bits(
> +    unsigned long mask,

While apparently benign here, perhaps also better to use unsigned int.
(Looks like I even missed instances yet further up.)

> +    volatile unsigned int *p)
> +{
> +    unsigned long old, t;

I'm less certain here, because I don't know what exactly "r" permits on
ppc. (Having said that I notice that mask also is used with an "r"
constraint, so restrictions would then apply there as well. But if long
is really needed in various placed, then I would say that a comment is
warranted, perhaps next to the BITOP_* defines.)

> +    asm volatile ( PPC_ATOMIC_ENTRY_BARRIER
> +                   "1: lwarx %0,0,%3,0\n"
> +                   "andc %1,%0,%2\n"
> +                   "stwcx. %1,0,%3\n"
> +                   "bne- 1b\n"
> +                   PPC_ATOMIC_EXIT_BARRIER
> +                   : "=&r" (old), "=&r" (t)
> +                   : "r" (mask), "r" (p)
> +                   : "cc", "memory" );
> +
> +    return (old & mask);
> +}
> +
> +static inline int test_and_clear_bit(unsigned int nr,
> +                                     volatile void *addr)
> +{
> +    return test_and_clear_bits(BITOP_MASK(nr), (volatile unsigned int *)addr 
> +
> +                               BITOP_WORD(nr)) != 0;

I think this is misleading wrapping of arguments. Even if not strictly
mandated, imo if an argument doesn't fit on the rest of a line it should
start on a fresh one.

Jan



 


Rackspace

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