Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1077619pxm; Wed, 23 Feb 2022 17:32:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJwwZj59J2ezr84OeBxxWihWhH73pe/ZrXb5ahXavN+KVmcZxgD9g7/jJKLcVrnfFfuJeId1 X-Received: by 2002:a63:1c15:0:b0:372:ffcd:4d21 with SMTP id c21-20020a631c15000000b00372ffcd4d21mr452412pgc.450.1645666333903; Wed, 23 Feb 2022 17:32:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645666333; cv=none; d=google.com; s=arc-20160816; b=slQ1IaU4t64X+NyUmMfG9y4EYdKD9qh/5Py5kUGfRqH5v9R3NHNcahMP8R+TQRNwbu gujcfScCkS/akAbTWI+bZRBam1Lt2cyu8t5nCGJda6z2HouT9+9z2/WI8BPI/p2TKaHd r2bxJRi8UO35wmdc5pu0OpK+zbJMWTXeNxO2OLf4Eh6UvafDZa8jJf1xIjB+aZHb5K8O w+L36qhxuRMbwJfSjsvh22gla/8VGVRUCZ0jVllbu1Mhu2FQxpKh629opXPnLRp2q1hy fz4OP9iPMgARj3k46GQUfufTRdmOtWflDHi9fTgzuiKDy0xPbL2bfoakC0Pjd5J78rpG GYUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=36baJ9ylSbct7WE/cHz23DfkC1LKslb3E3kbdi+UjqQ=; b=I44B0yDddG+TxZqono1QnkWpVmDfOtaRKf5rFvoD0pvzaX/3uoz4gzVBtOF4SOMgwj iR01FO55dnyySXNT3sCWv5Z+XNdtPLyl2m0xlCbPDWglNmtV3fOxckiLDMZSOQCr3tkU CMEfN0ojDeNWB/YaFjcsxh+2P+ZLoy0U85jEZZKMg3GcRlIO1GJ+obK+ldBsU2XlygSx xzotVzwiDfdjHRBviD8zNn6zZ3etKN6+TUcNEtb5auVsqALQg/xT4Lc8NSPeT+BcNCDD GTzc9oHX3PpsCg367JL+wESv0R0ku7kuBCgJgDQp7qlB+i8FANzdkX3HvTfx+KPLbJj5 Qcag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j15si1271674pfj.338.2022.02.23.17.32.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 17:32:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6D94799; Wed, 23 Feb 2022 17:11:36 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240778AbiBWVpG convert rfc822-to-8bit (ORCPT + 99 others); Wed, 23 Feb 2022 16:45:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236610AbiBWVpF (ORCPT ); Wed, 23 Feb 2022 16:45:05 -0500 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 20E8E3E5FC for ; Wed, 23 Feb 2022 13:44:36 -0800 (PST) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-27-hCb7lGpjNMCFd8pZEvh5ow-1; Wed, 23 Feb 2022 21:44:34 +0000 X-MC-Unique: hCb7lGpjNMCFd8pZEvh5ow-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.28; Wed, 23 Feb 2022 21:44:32 +0000 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.028; Wed, 23 Feb 2022 21:44:32 +0000 From: David Laight To: 'Andy Shevchenko' , Jason Gunthorpe , "linux-rdma@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Mike Marciniszyn , "Dennis Dalessandro" Subject: RE: [PATCH v1 1/1] IB/hfi1: Don't cast parameter in bit operations Thread-Topic: [PATCH v1 1/1] IB/hfi1: Don't cast parameter in bit operations Thread-Index: AQHYKOavPScLVMZqEkOT//Q3noWC2qyhqG0w Date: Wed, 23 Feb 2022 21:44:32 +0000 Message-ID: References: <20220223185353.51370-1-andriy.shevchenko@linux.intel.com> In-Reply-To: <20220223185353.51370-1-andriy.shevchenko@linux.intel.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andy Shevchenko > Sent: 23 February 2022 18:54 > > While in this particular case it would not be a (critical) issue, > the pattern itself is bad and error prone in case somebody blindly > copies to their code. It is horribly wrong on BE systems. > Don't cast parameter to unsigned long pointer in the bit operations. > Instead copy to a local variable on stack of a proper type and use. > > Fixes: 7724105686e7 ("IB/hfi1: add driver files") > Signed-off-by: Andy Shevchenko > --- > drivers/infiniband/hw/hfi1/chip.c | 29 ++++++++++++++--------------- > 1 file changed, 14 insertions(+), 15 deletions(-) > > diff --git a/drivers/infiniband/hw/hfi1/chip.c b/drivers/infiniband/hw/hfi1/chip.c > index f1245c94ae26..100274b926d3 100644 > --- a/drivers/infiniband/hw/hfi1/chip.c > +++ b/drivers/infiniband/hw/hfi1/chip.c > @@ -8286,34 +8286,33 @@ static void is_interrupt(struct hfi1_devdata *dd, unsigned int source) > irqreturn_t general_interrupt(int irq, void *data) > { > struct hfi1_devdata *dd = data; > - u64 regs[CCE_NUM_INT_CSRS]; > + DECLARE_BITMAP(pending, CCE_NUM_INT_CSRS * 64); > + u64 value; > u32 bit; > int i; > - irqreturn_t handled = IRQ_NONE; > > this_cpu_inc(*dd->int_counter); > > /* phase 1: scan and clear all handled interrupts */ > for (i = 0; i < CCE_NUM_INT_CSRS; i++) { > - if (dd->gi_mask[i] == 0) { > - regs[i] = 0; /* used later */ > - continue; > - } > - regs[i] = read_csr(dd, CCE_INT_STATUS + (8 * i)) & > - dd->gi_mask[i]; > + if (dd->gi_mask[i] == 0) > + value = 0; /* used later */ > + else > + value = read_csr(dd, CCE_INT_STATUS + (8 * i)) & dd->gi_mask[i]; > + > + /* save for further use */ > + bitmap_from_u64(&pending[BITS_TO_LONGS(i * 64)], value); > + > /* only clear if anything is set */ > - if (regs[i]) > - write_csr(dd, CCE_INT_CLEAR + (8 * i), regs[i]); > + if (value) > + write_csr(dd, CCE_INT_CLEAR + (8 * i), value); > } I think I'd leave all that alone. > /* phase 2: call the appropriate handler */ > - for_each_set_bit(bit, (unsigned long *)®s[0], > - CCE_NUM_INT_CSRS * 64) { > + for_each_set_bit(bit, pending, CCE_NUM_INT_CSRS * 64) And do something else for that loop instead. > is_interrupt(dd, bit); > - handled = IRQ_HANDLED; > - } > > - return handled; > + return IRQ_RETVAL(!bitmap_empty(pending, CCE_NUM_INT_CSRS * 64)); You really don't want to scan the bitmap again. Actually, of the face of it, you could merge the two loops. Provided you clear the status bit before calling the relevant handler I expect it will all work. David > } > > irqreturn_t sdma_interrupt(int irq, void *data) > -- > 2.34.1 - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)