From patchwork Fri Nov 11 14:27:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng(Mike)" X-Patchwork-Id: 18858 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp781781wru; Fri, 11 Nov 2022 06:47:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf4OdufUaUGQcVmia/Y2InEl0+eUEfomLo9+vevwLJVj8oDkXnl/xl74hFcXwYMHzL3UNaNV X-Received: by 2002:a17:907:6d06:b0:73d:67ae:5f6 with SMTP id sa6-20020a1709076d0600b0073d67ae05f6mr2065994ejc.583.1668178037968; Fri, 11 Nov 2022 06:47:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668178037; cv=none; d=google.com; s=arc-20160816; b=Bxvo3sSU3V2zSuovUVe7beDMxPxvuav5LrH4mR9t+3ywSCXWY8UjgnWtPgfj0gML+R 3CqylR8EAy22j7QFGOwKk2dqsaEhnyyNT5+PfAiEWU4m4pUmlKNm7fkNtnqKpecxDFG1 YJPAE3lWgpMBRtYs53ErUywFDG7g4vAj5YU8qN3XuBRYxUnKIwzSIuIXJU47z97rNAR7 iUnwsqHaRUk6v/TFn0raaeJpe9armOGA8hOpMGnXvErPNqPzJ9EVS1/JSZ+rvFa/JQid /ESQTGQUxmHhDKi3PEdxSnvpq0tnNUohjiA41GSqH4UrWhiIq4kfiFgdn04lYB0gjBls ZcPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=bhAgXLkbb8Kh50RQcLMNjhrqTKmDToHp1bLDHIQvUds=; b=J7AoPQJATi63v9HXghEc15s3ht3Ubd/6wJk6gMdk5X7hzuot8GfsppsN+8Ajz07YH6 wF91S9LC3zTHlurS1OPk1b9EdD6vx+kTkguQofCx7OlZHTxoimcoFUUcVYHYsuUSI/zt fTfgX1Spoo3u9zoIV02BdqwxTMuJHLR8fTowjgSIMflxbn+s5mRdjQdjIDlxRXDeEseU t8bZxpHW9LOxMpc2zhr9NI0VgpQDokZODrUu5TuBx3qJr0Q9LWLlkjjmgsi6YLt0dOYp p0u/aimXOvGWsbAaPDQheapcnKqK7/Uq6g02DQIsNSKZD/kp3WKDmDJFm16hGorR+gFS TH8Q== 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:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k9-20020a17090646c900b0077bd074d50bsi1582809ejs.105.2022.11.11.06.46.53; Fri, 11 Nov 2022 06:47:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234533AbiKKO1l (ORCPT + 99 others); Fri, 11 Nov 2022 09:27:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231911AbiKKO1b (ORCPT ); Fri, 11 Nov 2022 09:27:31 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D96B1BA; Fri, 11 Nov 2022 06:27:29 -0800 (PST) Received: from kwepemi100025.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N81Cj0yfKzbng6; Fri, 11 Nov 2022 22:23:45 +0800 (CST) Received: from DESKTOP-27KDQMV.china.huawei.com (10.174.148.223) by kwepemi100025.china.huawei.com (7.221.188.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 11 Nov 2022 22:27:27 +0800 From: "Longpeng(Mike)" To: CC: , , , , , , , , Longpeng Subject: [RFC 2/4] pci/sriov: add vf_bitmap to mark the vf id allocation Date: Fri, 11 Nov 2022 22:27:20 +0800 Message-ID: <20221111142722.1172-3-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20221111142722.1172-1-longpeng2@huawei.com> References: <20221111142722.1172-1-longpeng2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.148.223] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi100025.china.huawei.com (7.221.188.158) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749211454274189371?= X-GMAIL-MSGID: =?utf-8?q?1749211454274189371?= From: Longpeng Add a bitmap to mark the vf id allocation, the can be use to avoid the repeated allocations. Signed-off-by: Longpeng --- drivers/pci/iov.c | 13 +++++++++++++ drivers/pci/pci.h | 1 + 2 files changed, 14 insertions(+) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 3b441cd92960..886489aae0de 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -341,6 +341,8 @@ int pci_iov_add_virtfn(struct pci_dev *dev, int id) pci_bus_add_device(virtfn); + __set_bit(id, iov->vf_bitmap); + return 0; failed1: @@ -357,6 +359,7 @@ void pci_iov_remove_virtfn(struct pci_dev *dev, int id) { char buf[VIRTFN_ID_LEN]; struct pci_dev *virtfn; + struct pci_sriov *iov; virtfn = pci_get_domain_bus_and_slot(pci_domain_nr(dev->bus), pci_iov_virtfn_bus(dev, id), @@ -364,6 +367,9 @@ void pci_iov_remove_virtfn(struct pci_dev *dev, int id) if (!virtfn) return; + iov = pci_physfn(dev)->sriov; + __clear_bit(id, iov->vf_bitmap); + sprintf(buf, "virtfn%u", id); sysfs_remove_link(&dev->dev.kobj, buf); /* @@ -791,6 +797,11 @@ static int sriov_init(struct pci_dev *dev, int pos) if (!iov) return -ENOMEM; + rc = -ENOMEM; + iov->vf_bitmap = bitmap_zalloc(total, GFP_KERNEL); + if (!iov->vf_bitmap) + goto free_iov; + nres = 0; for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { res = &dev->resource[i + PCI_IOV_RESOURCES]; @@ -853,6 +864,7 @@ static int sriov_init(struct pci_dev *dev, int pos) res->flags = 0; } +free_iov: kfree(iov); return rc; } @@ -864,6 +876,7 @@ static void sriov_release(struct pci_dev *dev) if (dev != dev->sriov->dev) pci_dev_put(dev->sriov->dev); + bitmap_free(dev->sriov->vf_bitmap); kfree(dev->sriov); dev->sriov = NULL; } diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index b1ebb7ab8805..a76d4ff83886 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -301,6 +301,7 @@ struct pci_sriov { u16 subsystem_device; /* VF subsystem device */ resource_size_t barsz[PCI_SRIOV_NUM_BARS]; /* VF BAR size */ bool drivers_autoprobe; /* Auto probing of VFs by driver */ + unsigned long *vf_bitmap; /* Allocated VFs */ }; /**