Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1009611pxb; Thu, 4 Feb 2021 02:49:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYOSjvqnBJ03n+DdmYzqskuHcx6ER4DTKYZfTTug0J85Gno2d7fEazaLBiHW2VJxHa0pv5 X-Received: by 2002:a17:906:9ad3:: with SMTP id ah19mr7399400ejc.37.1612435775041; Thu, 04 Feb 2021 02:49:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612435775; cv=none; d=google.com; s=arc-20160816; b=NWjBlaKDDosuMTF1CWYtM1uh7BWBJFMjrwslf5VHb4Ain8SCW5m+fPZkv/6zbNGZEm kxfJO8//b4+MV9lyKxBsybykLQB9phTkWVHaXLxIm9mAW8grtITNZ+5wSrfntdkgKmHM Ng+l9ZPmWv9YuqMiUWlketYoruitjznsH1bNGRz+x1gMCREPhsGNgF1rt32PZ8Gp29tC bhlhAKrWLS3XCy9O+7FTthi96w7IwR+BKWLaDgXFALB9OHjsw/K7ASGB0CMo/sUUjajQ JM2+djzUCaNk492qcopFtr9z7rUTL1uH+BTYSvU71T/EV4xoabRalYMzsg8VpSitCApP 43rA== 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 :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:subject:from; bh=Mu6QWsEgsYHeV8ecNMXta39UeUjFmBFojhK/55bOwUE=; b=ihI0nLl+emR+a9wPsdBO1ueMFUfuZCnyUzSREpLoX7Tk98dNYqgW1eERfDXZSLeBSJ 1YrOpJr4z0P7+Ov4+y4mmxy9T4z08eT8us6AIpkjqk4elZbPAmDtV2Zu8YpaNDC0Q2Hc EkdsQ8xzItMMO1W+ou9UTESzvcfcG+rlYzagMBjULy+sF8tBhQIwu3R9Bp15I1Dod2lG xnHQOCd1p1vmMtk4ItOSuqVztwMsEcQk144KaWoNZDbKrwMcra8jkJ4Wsc8W4A/PWIpX 3MUo8WNGOIp08ukjfaG4+VNgKVCviQ39TwjaTWa++mm2vI8ZU1gt10An9BdEqWcsXlXl PVHQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bw14si3000497ejb.201.2021.02.04.02.49.10; Thu, 04 Feb 2021 02:49:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235475AbhBDKre (ORCPT + 99 others); Thu, 4 Feb 2021 05:47:34 -0500 Received: from frasgout.his.huawei.com ([185.176.79.56]:2494 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234873AbhBDKr2 (ORCPT ); Thu, 4 Feb 2021 05:47:28 -0500 Received: from fraeml715-chm.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4DWZrz0RChz67kVn; Thu, 4 Feb 2021 18:43:15 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml715-chm.china.huawei.com (10.206.15.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Thu, 4 Feb 2021 11:46:46 +0100 Received: from [10.210.168.183] (10.210.168.183) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Thu, 4 Feb 2021 10:46:41 +0000 From: John Garry Subject: Re: PCI MSI issue with reinserting a driver To: Marc Zyngier CC: Thomas Gleixner , Zhou Wang , References: <87o8h3lj0n.wl-maz@kernel.org> <8a54fdd0-950b-f801-e83d-750aef73ab3c@huawei.com> <4848792ce8c9ed7490e2205281a3cbda@kernel.org> <28c56995-501a-880b-e6dd-ac76b8290c2c@huawei.com> <3d3d0155e66429968cb4f6b4feeae4b3@kernel.org> Message-ID: Date: Thu, 4 Feb 2021 10:45:12 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.1.2 MIME-Version: 1.0 In-Reply-To: <3d3d0155e66429968cb4f6b4feeae4b3@kernel.org> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.210.168.183] X-ClientProxiedBy: lhreml719-chm.china.huawei.com (10.201.108.70) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/02/2021 17:23, Marc Zyngier wrote: >> >> Before: >>  In free path, we have: >>      its_irq_domain_free(nvecs = 27) >>        bitmap_release_region(count order = 5 == 32bits) >> >> Current: >>  In free path, we have: >>      its_irq_domain_free(nvecs = 1) for free each 27 vecs >>        bitmap_release_region(count order = 0 == 1bit) > > Right. I was focusing on the patch and blindly ignored the explanation > at the top of the email. Apologies for that. Yeah, it was a distraction. > > I'm not overly keen on handling this in the ITS though, and I'd rather > we try and do it in the generic code. How about this (compile tested > only)? > > diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c > index 6aacd342cd14..cfccad83c2df 100644 > --- a/kernel/irq/irqdomain.c > +++ b/kernel/irq/irqdomain.c > @@ -1399,8 +1399,19 @@ static void irq_domain_free_irqs_hierarchy(struct > irq_domain *domain, >          return; > >      for (i = 0; i < nr_irqs; i++) { > -        if (irq_domain_get_irq_data(domain, irq_base + i)) > -            domain->ops->free(domain, irq_base + i, 1); > +        int n ; > + > +        /* Find the largest possible span of IRQs to free in one go */ > +        for (n = 0; > +             ((i + n) < nr_irqs && > +              irq_domain_get_irq_data(domain, irq_base + i + n)); > +             n++); > + > +        if (!n) > +            continue; > + > +        domain->ops->free(domain, irq_base + i, n); > +        i += n; >      } >  } That fixed my problem. For my benefit, if MSIs must be allocated in power of 2, could we check a flag for the dealloc method? Like, if MSI domain, then do as before 4615fbc3788d. But I'm not sure on the specific scenario which that commit fixed. Or even whether you want specifics like that in core code. Thanks, John