Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4285026pxf; Tue, 6 Apr 2021 12:26:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxveWQ+nX3po4JSmfDorC53ICybJcqObkR3Q8q4KSuw/ZrG0sxLYSPsybqE0EEqV4DHjZ/Z X-Received: by 2002:a6b:7b05:: with SMTP id l5mr24579241iop.32.1617737181424; Tue, 06 Apr 2021 12:26:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617737181; cv=none; d=google.com; s=arc-20160816; b=pQrEkp3kgA9o/BS0Tk6QaA1L3iPwjG4B3n105rLUvM9a2fbX2HjMqYIfLmgF5wz/Ad 15OCc9Dn/BHk9qAIZdxuGXlubLZZbPO2nN+JeMJ6a4IaQN0+DLVjcdQlWEQuAeH3SUze 9beApcwlC4edW4R1F51k0fC7QAoCOdkQBbW78O/WzsVbEqsAXGAiDxo4K/lkYX2rwwnJ HkmCdq9dA5GWQz6yTmCKShV97BuhEZ8rA7tvr3SE0TzeUpJ7dubmZzhyR1mBUycSQOHg CvSjqkme/qUlGe2idZ7LUsW3xc8Cjc1pmVGaFQ/CS9xeVHTDi7EEqmg4s+foKKNamysQ j9hA== 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:from:references :cc:to:subject; bh=4KYZjErBFSQ0Gjg0mJZJpyUhCn4lw+G+vCJOz7IVDT0=; b=We7iiiYiiKMMJj9oVMztvVxcUK5QjZ1p738XPWcS2aRQN9yCeF3PGDC1hUPWri8Heg 239OgYwhldvz66wfSXVUHAwHrXF+pcagTTZeliHnk61Vi7iUWhjzkiNCB75tgMWyr6M4 nGKuxYgNiLyXyPgltdl2VifH+EdQy2PTWC9GxKE3sjGUbrB6bdyLsJlxhAsVwtSwRWsK uZNT3Tos066A5TBqmdUqVuhhxc6+EZAbOlOOsc4LPzRtqi9lO2RdGzULUffp9Z0gjnRR NgmDs6yOb3Y6O+2oUB1AKxHsrOPLlVZd7jlPTUnQ3P9U4tEE7I4Yng+L4TxRnIBIif3/ NO7Q== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s17si18361406jat.66.2021.04.06.12.26.02; Tue, 06 Apr 2021 12:26:21 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236905AbhDFJtH (ORCPT + 99 others); Tue, 6 Apr 2021 05:49:07 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:2763 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233861AbhDFJtG (ORCPT ); Tue, 6 Apr 2021 05:49:06 -0400 Received: from fraeml703-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4FF2fJ52jgz685hn; Tue, 6 Apr 2021 17:43:52 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml703-chm.china.huawei.com (10.206.15.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2106.2; Tue, 6 Apr 2021 11:48:57 +0200 Received: from [10.210.166.136] (10.210.166.136) 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; Tue, 6 Apr 2021 10:48:55 +0100 Subject: Re: PCI MSI issue with reinserting a driver To: Marc Zyngier CC: Thomas Gleixner , Zhou Wang , , "luojiaxing@huawei.com" 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> From: John Garry Message-ID: <87547f6c-2f50-7a91-c629-bbfe7c22a49b@huawei.com> Date: Tue, 6 Apr 2021 10:46:28 +0100 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.166.136] X-ClientProxiedBy: lhreml711-chm.china.huawei.com (10.201.108.62) 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: > On 2021-02-02 15:46, John Garry wrote: >> On 02/02/2021 14:48, Marc Zyngier wrote: >>>>> >>>>> Not sure. I also now notice an error for the SAS PCI driver on D06 >>>>> when nr_cpus < 16, which means number of MSI vectors allocated < >>>>> 32, so looks the same problem. There we try to allocate 16 + max(nr >>>>> cpus, 16) MSI. >>>>> >>>>> Anyway, let me have a look today to see what is going wrong. >>>>> >>>> Could this be the problem: >>>> >>>> nr_cpus=11 >>>> >>>> In alloc path, we have: >>>>     its_alloc_device_irq(nvecs=27 = 16+11) >>>>       bitmap_find_free_region(order = 5); >>>> In free path, we have: >>>>     its_irq_domain_free(nvecs = 1) and free each 27 vecs >>>>       bitmap_release_region(order = 0) >>>> >>>> So we allocate 32 bits, but only free 27. And 2nd alloc for 32 fails. >> >> [ ... ] >> >>>> Hi Marc, Just a friendly reminder on this issue. Let me know if anything required some our side. Cheers, John >>>> >>>> But I'm not sure that we have any requirement for those map bits to be >>>> consecutive. >>> >>> We can't really do that. All the events must be contiguous, >>> and there is also a lot of assumptions in the ITS driver that >>> LPI allocations is also contiguous. >>> >>> But there is also the fact that for Multi-MSI, we *must* >>> allocate 32 vectors. Any driver could assume that if we have >>> allocated 17 vectors, then there is another 15 available. >>> >>> My question still stand: how was this working with the previous >>> behaviour? >> >> Because previously in this scenario we would allocate 32 bits and free >> 32 bits in the map; but now we allocate 32 bits, yet only free 27 - so >> leak 5 bits. And this comes from how irq_domain_free_irqs_hierarchy() >> now frees per-interrupt, instead of all irqs per domain. >> >> 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. > > 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)? > > Thanks, > >         M. > > 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; >      } >  } > >