From patchwork Fri Nov 11 14:27:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng(Mike)" X-Patchwork-Id: 18857 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp781652wru; Fri, 11 Nov 2022 06:46:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf7kcPoi1+OSEhhFRPnfk20Ykhfgy0w91HUh6yjYyGwICT/oUJhXCENf/bPQLgx3t2an02HB X-Received: by 2002:a17:906:3547:b0:7aa:40ea:faae with SMTP id s7-20020a170906354700b007aa40eafaaemr2052263eja.551.1668178019447; Fri, 11 Nov 2022 06:46:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668178019; cv=none; d=google.com; s=arc-20160816; b=NJlqWJG3IJBK0x5tq8zRvs1IINxBw7VhjMnK1vAQKhPF8DgYGqertUJcySNsU1Zkyt O2DdanvIypqNR7AqqXRK67WlXl0M4D1nKGLel6SxKtZ7Ldutp78eU5amJG8wrNU7mpOf Yvxs7ResGn0WitfHSTVpRvmJIaHDPnjCjh1IGvGmwIDTcJ5UVAnXIt1OeHna5+bQ9SQF qSIpDo6BPcU+gOt4lxuwFWN4d8wm5be61ZzjnFmUcTM1Glr1ToShv2Ww4gSMmpntIfNG EekX5WCAMu9I1Hzt2HJ9kcbnLtruI0+OCtPTS8Q0VPh494uJfNoKU/vnMEYPw2oZCZul O69g== 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=paWB6LA4tvd+J1mXniXlZAfOslSPztEcV2p7IKlUSqs=; b=jC6bo7iOFlh/GlGf2okg+xZ1+7IyNVGrEgYfdGzJPf/bxP+WbnVh8tvl81Qnbp+urB 2hAJ44qyYbaoEEpnO/wXIw1viJXYA/jThvWWtc38uppCRUAmCN5ZaTteW6aae+ilSfkc V1BX8/z9+OjoGuYBHN22ncc7m7N+7ZzqND+dpXTXzEVpBWogYHDIrRB4XKWBCwtUVJ29 x6LZ5CzbKIlg7IFnXPAgq+VG+cjRrMoFg/1sQscU3YUv6/EWjzklRv44aPEAxHugmFuK T0cglCfAJtVA7L+GWQXSRpZKKlVnQTPUeUcvGXzJS0OedKV2nIr4EZD2l3uvVKCaDaRp RvbQ== 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 k26-20020aa7d2da000000b00461c43d1113si2052750edr.569.2022.11.11.06.46.34; Fri, 11 Nov 2022 06:46:59 -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 S234416AbiKKO1h (ORCPT + 99 others); Fri, 11 Nov 2022 09:27:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231261AbiKKO1a (ORCPT ); Fri, 11 Nov 2022 09:27:30 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 257E11AD; Fri, 11 Nov 2022 06:27:29 -0800 (PST) Received: from kwepemi100025.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N81Hg1GfHzmVpr; Fri, 11 Nov 2022 22:27:11 +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:26 +0800 From: "Longpeng(Mike)" To: CC: , , , , , , , , Longpeng Subject: [RFC 1/4] pci/sriov: extract sriov_numvfs common helper Date: Fri, 11 Nov 2022 22:27:19 +0800 Message-ID: <20221111142722.1172-2-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?1749211434961563077?= X-GMAIL-MSGID: =?utf-8?q?1749211434961563077?= From: Longpeng Extract a common helper to set sriov nums. Signed-off-by: Longpeng --- drivers/pci/iov.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 952217572113..3b441cd92960 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -406,23 +406,9 @@ static ssize_t sriov_numvfs_show(struct device *dev, return sysfs_emit(buf, "%u\n", num_vfs); } -/* - * num_vfs > 0; number of VFs to enable - * num_vfs = 0; disable all VFs - * - * Note: SRIOV spec does not allow partial VF - * disable, so it's all or none. - */ -static ssize_t sriov_numvfs_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static int sriov_numvfs_common(struct pci_dev *pdev, u16 num_vfs) { - struct pci_dev *pdev = to_pci_dev(dev); int ret = 0; - u16 num_vfs; - - if (kstrtou16(buf, 0, &num_vfs) < 0) - return -EINVAL; if (num_vfs > pci_sriov_get_totalvfs(pdev)) return -ERANGE; @@ -471,6 +457,28 @@ static ssize_t sriov_numvfs_store(struct device *dev, exit: device_unlock(&pdev->dev); + return ret; +} + +/* + * num_vfs > 0; number of VFs to enable + * num_vfs = 0; disable all VFs + * + * Note: SRIOV spec does not allow partial VF + * disable, so it's all or none. + */ +static ssize_t sriov_numvfs_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct pci_dev *pdev = to_pci_dev(dev); + int ret; + u16 num_vfs; + + if (kstrtou16(buf, 0, &num_vfs) < 0) + return -EINVAL; + + ret = sriov_numvfs_common(pdev, num_vfs); if (ret < 0) return ret; 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 */ }; /** From patchwork Fri Nov 11 14:27:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng(Mike)" X-Patchwork-Id: 18861 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp782198wru; Fri, 11 Nov 2022 06:48:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf5lwRXc2OpGq771V7zJZhCFvV+7y9/8NmVRLqv8RyrlrjPzBRnwiDGACxDNP9ZVV7xcOUrR X-Received: by 2002:a17:906:950d:b0:78d:9b4f:44ee with SMTP id u13-20020a170906950d00b0078d9b4f44eemr2002142ejx.679.1668178080589; Fri, 11 Nov 2022 06:48:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668178080; cv=none; d=google.com; s=arc-20160816; b=sqUa3K1Acp2aLbi/+d/bedLIunPvNyoDl+dZSvXybnSPeqybYXSp4pLhRrS8fNkrTj 7GWAo/ix2nKMxzBnqQy+KmpFHVtaPSp7hxTttdPUHgjj7qEbNkMoHqk8IaW9Vx06/d3r oPKEfmKhguE6Ma3oxzrGFoMzLh9lMWBUiMU9iUnky65+7tztGseXCSyV8Xo//y2kyVvT Djs/Nf9X1+L7KAY7HNPAWmN8cmecHMiVo2prJbgsLwizc3IzlkY+Cjqe/AdzeuEgFTuU Pm92O6eQE7uO5AcOPZCxeyEiAmYR5MSZOrIKx4VPJElCms/RxQeynQGqgjazbwQTpKyV bUwQ== 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=1oCABg660WSt5sn1EaDKLL7HG+a/ppG27crV3lx/j20=; b=eRNAHyscF3PKRdKY6bBGmjqUfdHuxybgACkZ7yNxYZnh19zC1A7gcUJDbclxB5eAmY /FOKaLUwTSSBSWnMip4Oun+N+CSrYRmG7vxTIBAU0QrYbmItCRRUYIFid5iVjEB09B2+ awJ1/KafOpyrvwq+BWpzc6jlZcaPVv0mvjSSG3WYQCkFAyWrztLY5inRKn6NeVNTuQIh hoMZXN4UYUDUtY0gityhZtQ+jgcdCjMuuepbht8JBHCogpoGO4CDkpjQajn8NPDxOsMr M6VePsZ++YflIuunrDYV30YnyzBRjbJsMr6xgNtQc8nUOc7Anqk6iX9fUIIZDbP0Dk7n 69/w== 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 a91-20020a509ee4000000b0045c9904fdafsi2363271edf.74.2022.11.11.06.47.36; Fri, 11 Nov 2022 06:48:00 -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 S234581AbiKKO1w (ORCPT + 99 others); Fri, 11 Nov 2022 09:27:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232851AbiKKO1c (ORCPT ); Fri, 11 Nov 2022 09:27:32 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79A47C12; Fri, 11 Nov 2022 06:27:31 -0800 (PST) Received: from kwepemi100025.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N81HV1c9rzHvp9; Fri, 11 Nov 2022 22:27:02 +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 3/4] pci/sriov: add sriov_numfs_no_scan interface Date: Fri, 11 Nov 2022 22:27:21 +0800 Message-ID: <20221111142722.1172-4-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?1749211499017070988?= X-GMAIL-MSGID: =?utf-8?q?1749211499017070988?= From: Longpeng Add sriov_numfs_no_scan interface, we can enable the sriov without adding all VFs immediately. For example: echo 16 > /sys/bus/pci/devices/0000\:65\:00.0/sriov_numvfs_no_scan ( Enable 16 VFs, but not add it to the system. ) Signed-off-by: Longpeng --- drivers/pci/iov.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 886489aae0de..cb24d4b60e0d 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -491,6 +491,68 @@ static ssize_t sriov_numvfs_store(struct device *dev, return count; } +static ssize_t sriov_numvfs_no_scan_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct pci_dev *pdev = to_pci_dev(dev); + int ret; + u16 num_vfs; + + if (kstrtou16(buf, 0, &num_vfs) < 0) + return -EINVAL; + + device_lock(&pdev->dev); + /* Clear the flag when disabling VFs */ + pdev->no_vf_scan = num_vfs ? 1 : 0; + device_unlock(&pdev->dev); + + ret = sriov_numvfs_common(pdev, num_vfs); + if (ret < 0) + goto fail; + + if (!num_vfs) + return count; + + /* + * Special case: set the same num_vfs again. + */ + if (test_bit(0, pdev->sriov->vf_bitmap)) + return count; + + /* + * Default to enabling VF0, we need to read some config registers that are the + * same across all associated VFs. See pci_read_vf_config_common(). + */ + ret = pci_iov_add_virtfn(pdev, 0); + if (ret < 0) { + int rc; + + rc = sriov_numvfs_common(pdev, 0); + if (rc < 0) + pci_warn(pdev, "Roll back to SR-IOV disabled state failed, %d\n", rc); + + goto fail; + } + + return count; + +fail: + device_lock(&pdev->dev); + if (pdev->no_vf_scan) + pdev->no_vf_scan = 0; + device_unlock(&pdev->dev); + + return ret; +} + +static ssize_t sriov_numvfs_no_scan_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return sriov_numvfs_show(dev, attr, buf); +} + static ssize_t sriov_offset_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -544,6 +606,7 @@ static ssize_t sriov_drivers_autoprobe_store(struct device *dev, static DEVICE_ATTR_RO(sriov_totalvfs); static DEVICE_ATTR_RW(sriov_numvfs); +static DEVICE_ATTR_RW(sriov_numvfs_no_scan); static DEVICE_ATTR_RO(sriov_offset); static DEVICE_ATTR_RO(sriov_stride); static DEVICE_ATTR_RO(sriov_vf_device); @@ -552,6 +615,7 @@ static DEVICE_ATTR_RW(sriov_drivers_autoprobe); static struct attribute *sriov_pf_dev_attrs[] = { &dev_attr_sriov_totalvfs.attr, &dev_attr_sriov_numvfs.attr, + &dev_attr_sriov_numvfs_no_scan.attr, &dev_attr_sriov_offset.attr, &dev_attr_sriov_stride.attr, &dev_attr_sriov_vf_device.attr, From patchwork Fri Nov 11 14:27:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng(Mike)" X-Patchwork-Id: 18860 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp782122wru; Fri, 11 Nov 2022 06:47:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf58/hvnIfesExXDq185kf2tqOvIPO1KRTCwaIbieQauTZ0D2M3y3/r6iRtTHpU+VWOxx3U7 X-Received: by 2002:a17:907:c68a:b0:78d:860b:788f with SMTP id ue10-20020a170907c68a00b0078d860b788fmr1986548ejc.561.1668178071420; Fri, 11 Nov 2022 06:47:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668178071; cv=none; d=google.com; s=arc-20160816; b=QAzrcpNu0rPDddVlHHauhrTcv5tHM3RxAe8Y9oCtUu0XD5mLOC9evOmnOcG9QKmMlB GACop9BHat244+5z//5h6FnPOc8tR/gtiMOeHyQJO2WjRROu9nK1i2d26/Fk00z/c9Fp RMSM+Cl88V2fS+FpvAk9Qv752x84AZ43wFLOHioMabdG91bHuDJqRAJP08ML+6968cLy GOQtQEDLazMRq1ptP2D/RJDiIq9XWNnmUEsq5lHDmZ0zCgCWAruWD1Cn3kcesBY/WY83 Ww78CAyWhCaPAwgWo5W54bGQJrfdNfC7vib41jsN6OFu72CsclC9uR1NH14s89ZZGcDj nThQ== 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=3/C1aL8+PvRjILigbqt9duU/DTbl295v1z+uX4u48m0=; b=oyqSyCWSN5L3YAXz2pexHVXSxi+fFu6Le+bJfFA30+jDN/gVu7YdsdFatW2K56e5uv R9XiEHhJ6dlSizYRoS7rKY9Lp+nbiUTTEQ9ozY/8JcvO1YIrLPBnyT0UBAvzmeJDlW+Z qj5/JekWAgXFbOHt55PEHSKt4+GAA6WQUIzO3kx+UBKJnVhAmm1mw7LAjfK/cNRlnBKM qIPC+Xmz3Z2GqEZbD3DNeL/49GPr7vkanEwF3hldbeRa9V8NRmzoZcP5+rGzxmtjCCRc GEhWWB34QeS3GLV3PxyUk7R96o/Xi9Y4qZejp5dBUPCYKf8/IMS5kMMLkhHjyCwAJacA ckTA== 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 o22-20020a509b16000000b00462e23be64fsi2013242edi.578.2022.11.11.06.47.27; Fri, 11 Nov 2022 06:47:51 -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 S234552AbiKKO1u (ORCPT + 99 others); Fri, 11 Nov 2022 09:27:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232372AbiKKO1b (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 418F1BB4; Fri, 11 Nov 2022 06:27:31 -0800 (PST) Received: from kwepemi100025.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N81Ck5sMrzbngJ; Fri, 11 Nov 2022 22:23:46 +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:28 +0800 From: "Longpeng(Mike)" To: CC: , , , , , , , , Longpeng Subject: [RFC 4/4] pci/sriov: add sriov_scan_vf_id interface Date: Fri, 11 Nov 2022 22:27:22 +0800 Message-ID: <20221111142722.1172-5-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?1749211489053449435?= X-GMAIL-MSGID: =?utf-8?q?1749211489053449435?= From: Longpeng The users can add a specific VF through the sriov_scan_vf_id interface. For example: echo 4 > /sys/bus/pci/devices/0000\:65\:00.0/sriov_scan_vf_id ( Add VF4 into the system. ) Signed-off-by: Longpeng --- drivers/pci/iov.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index cb24d4b60e0d..2b585b3a9ad8 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -553,6 +553,51 @@ static ssize_t sriov_numvfs_no_scan_show(struct device *dev, return sriov_numvfs_show(dev, attr, buf); } +static ssize_t sriov_scan_vf_id_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct pci_dev *pdev = to_pci_dev(dev); + u16 vf_id; + ssize_t ret; + + if (kstrtou16(buf, 0, &vf_id) < 0) + return -EINVAL; + + device_lock(&pdev->dev); + + if (!pdev->sriov->num_VFs) { + ret = -ENOENT; + goto exit; + } + + if (vf_id >= pdev->sriov->num_VFs) { + ret = -ENODEV; + goto exit; + } + + if (test_bit(vf_id, pdev->sriov->vf_bitmap)) { + ret = -EEXIST; + goto exit; + } + + device_unlock(&pdev->dev); + + /* Already scanned VF0 when enabling VFs */ + if (vf_id == 0) + return count; + + ret = pci_iov_add_virtfn(pdev, vf_id); + if (ret < 0) + return ret; + + return count; + +exit: + device_unlock(&pdev->dev); + return ret; +} + static ssize_t sriov_offset_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -607,6 +652,7 @@ static ssize_t sriov_drivers_autoprobe_store(struct device *dev, static DEVICE_ATTR_RO(sriov_totalvfs); static DEVICE_ATTR_RW(sriov_numvfs); static DEVICE_ATTR_RW(sriov_numvfs_no_scan); +static DEVICE_ATTR_WO(sriov_scan_vf_id); static DEVICE_ATTR_RO(sriov_offset); static DEVICE_ATTR_RO(sriov_stride); static DEVICE_ATTR_RO(sriov_vf_device); @@ -616,6 +662,7 @@ static struct attribute *sriov_pf_dev_attrs[] = { &dev_attr_sriov_totalvfs.attr, &dev_attr_sriov_numvfs.attr, &dev_attr_sriov_numvfs_no_scan.attr, + &dev_attr_sriov_scan_vf_id.attr, &dev_attr_sriov_offset.attr, &dev_attr_sriov_stride.attr, &dev_attr_sriov_vf_device.attr,