Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp1521127pxb; Fri, 18 Feb 2022 09:25:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJyMcilyPdyTCjOmBON96Jv45h8lLPxLrcS837+xVj3PihiKRJ40z8u9Pri5BTwWaolc5xfr X-Received: by 2002:a17:906:954b:b0:6ce:a859:71f8 with SMTP id g11-20020a170906954b00b006cea85971f8mr7174676ejy.380.1645205132528; Fri, 18 Feb 2022 09:25:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645205132; cv=none; d=google.com; s=arc-20160816; b=WcywZOvkopdQhmg3tcQSkFj2wUiMSNLZP9B/VxNlOh0xCrvpyvJm6BnyCi3erJifLU ibI/1vArBsmyo+50F4vJAyh2KLEOdkGJJsWArjUDrEwRoIXFjwbp11Vdg84rgV5KQaNG Fqy6P5uI5yvVMMKfAJSbkakGNVLeYpILAYPHK1yvl1EEngrddZF8zc0YY8qLfDK/YQfw 45qgbuW6oruty2jPvcpYDyVUDZIrcbYEutxZgn7iTRWUSBh1zMoQ3lSIJ7m8eDz6q21p CmSpbq/o1RyNNqdyWdEhR66fovVQMEfgWhDP8spoFeBhoV8pep60QTZXEV/wzt/jb1jY eOFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=4ldn/wyFUYS9oX2H4KZV4SRGFhvLNkEJlNBHlweSE44=; b=e3yka/c+nEiWVycH2jBMAARuFE8BVLeg1uc5oTsc8K1gxVEAZcEKJycg7rGGP1xk9u te7I9NnDFtYDSrswx+iVMq6zI3jcqDoh7djj69kfgGmotFY9Sv1uhH26C5ifThZPIMT3 2zkCf5pefq/l+3RRyY5HAGRjwkOYb9sx0TvpbcvJj+Otlb7Gz7bweH7WVLiKO1yuK3Vu 9k4dzqmI1/9heSvkzQBe7sPYIiWS8368CvrVI7fb/W/3BjHlnRDeLJRYKY2sCPigBTKf YPAGQNezWn2ouV3gGTVJYGGuPsXN3WsHXykQO0cJxQCrnT4u/9xp2peuzLV9nORxM5n1 y6Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZGJ6uKfo; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id er26si3734390edb.307.2022.02.18.09.25.08; Fri, 18 Feb 2022 09:25:32 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZGJ6uKfo; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236470AbiBRO4n (ORCPT + 99 others); Fri, 18 Feb 2022 09:56:43 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:50236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236354AbiBRO42 (ORCPT ); Fri, 18 Feb 2022 09:56:28 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 883D9593A4 for ; Fri, 18 Feb 2022 06:56:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645196164; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4ldn/wyFUYS9oX2H4KZV4SRGFhvLNkEJlNBHlweSE44=; b=ZGJ6uKfop4GVTHnZqrhHQhp3RCzj2MiKOFHTiwphtj1caj4hla0uu227MojdUTUJLInGS3 ABPX0tVStqI+JMidxPy2rY7UJySDx9KawhaTQMv44hiZq+edczVIeYdTwNxlvG7pkW3PIb d3eZNS/cJ86gYyTXvc1fZnqreDcmLnw= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-611--KoJPLJSPeGI16TeMqEKYQ-1; Fri, 18 Feb 2022 09:56:02 -0500 X-MC-Unique: -KoJPLJSPeGI16TeMqEKYQ-1 Received: by mail-qv1-f70.google.com with SMTP id a12-20020a056214062c00b0042c2f3fca04so9039108qvx.21 for ; Fri, 18 Feb 2022 06:56:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=4ldn/wyFUYS9oX2H4KZV4SRGFhvLNkEJlNBHlweSE44=; b=gN/MFE6ewNweUOPQ252YTshjOcOX1HJpAmQ4mhgN9w+YyLTmSMGleWpeDzJUfOlSfa wB1WBB0MFfYRkJscX8WTG9pPX6lzVQuAtYLfXw4SLFIF2GoYJSQ7jLqI96vntb8oxaAq 7Cm3obQhze2yzWCJ1tWPpC/eMsDbEAR33D4O1I6CnQ9PxPY0g/KRFsowB43TK+i4ZwlU IBPpWmxfsAt2wOe2wqrFcnc4Si/QbYEzMz7CYxKatPXNIjrLLFFv2vGcf8XJtt5jjb5R CCKI+OVO6avrpiH3BumXfyls8Dba8nvD7ea558OE3owhTJC/IawJegp1SeLQ2cZ71X5H A5cQ== X-Gm-Message-State: AOAM53126OnUhPqALnXTxf/LZGXwprTJTL7dii945a7JezlRx7SOv6Tb xQP2Hc+sqNGcRJzJkD/xNhcpJFSw0MqXS6oU9gYD7DgklUZgUAzrqgJuMYPpn+CqyfIfeYyU2lL xoVY11TJd9msmb+YRIAvkS7s6 X-Received: by 2002:ac8:5c8f:0:b0:2dd:b404:bd94 with SMTP id r15-20020ac85c8f000000b002ddb404bd94mr1693189qta.50.1645196161891; Fri, 18 Feb 2022 06:56:01 -0800 (PST) X-Received: by 2002:ac8:5c8f:0:b0:2dd:b404:bd94 with SMTP id r15-20020ac85c8f000000b002ddb404bd94mr1693178qta.50.1645196161706; Fri, 18 Feb 2022 06:56:01 -0800 (PST) Received: from localhost.localdomain (024-205-208-113.res.spectrum.com. [24.205.208.113]) by smtp.gmail.com with ESMTPSA id w3sm25923138qta.13.2022.02.18.06.56.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Feb 2022 06:56:01 -0800 (PST) Subject: Re: [PATCH v1 4/7] fpga: dfl: fix VF creation when ports have no local BAR space To: "Zhang, Tianfei" , "Wu, Hao" , "mdf@kernel.org" , "Xu, Yilun" , "linux-fpga@vger.kernel.org" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" Cc: "corbet@lwn.net" , Matthew Gerlach References: <20220214112619.219761-1-tianfei.zhang@intel.com> <20220214112619.219761-5-tianfei.zhang@intel.com> From: Tom Rix Message-ID: <1281cbc7-7a1f-da84-3713-0d81982379ab@redhat.com> Date: Fri, 18 Feb 2022 06:55:58 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On 2/18/22 12:14 AM, Zhang, Tianfei wrote: > >> -----Original Message----- >> From: Tom Rix >> Sent: Tuesday, February 15, 2022 11:51 PM >> To: Zhang, Tianfei ; Wu, Hao ; >> mdf@kernel.org; Xu, Yilun ; linux-fpga@vger.kernel.org; >> linux-doc@vger.kernel.org; linux-kernel@vger.kernel.org >> Cc: corbet@lwn.net; Matthew Gerlach >> Subject: Re: [PATCH v1 4/7] fpga: dfl: fix VF creation when ports have no local >> BAR space >> >> >> On 2/14/22 3:26 AM, Tianfei zhang wrote: >>> From: Matthew Gerlach >>> >>> When a port is not connected to the same PCIe endpoint as the FME, the >>> port does not need to be released before being virtualized. Fix VF >>> creation code to handle this new use >> Similar, how does this fit in with iofs, this looks like it would not be valid for the >> existing cards > IOFS introducing multiple methods for PR and AFU access. > 1. Legacy Model. > 2. Micro-Personas in AFU. > 3. Multiple VFs per PR slot. > > For 1 and 2 model, there are 1:1 mapping between Port device and PR slot (or entire AFU). In virtualization, > it should release the Port device firstly and then assign to VM. In this models, the DFL driver will track that > the number of port devices has released (cdev->released_port_num in dfl_fpga_cdev_config_ports_vf() function) > are equal with the numbers of SRIOV or not. But in model 3, it has multiple VFs per PR slot, and assign the VF to VM > without release the port device, so the tracking mechanism of cdev->released_port_num is not workable on new If ->release_port_num is not workable, then it needs to be generalized. Refactor to handle all the cases. Tom > model. This patch want to handle this new model during VF creation. > >>> case. >>> >>> Signed-off-by: Matthew Gerlach >>> Signed-off-by: Tianfei Zhang >>> --- >>> drivers/fpga/dfl.c | 11 +++++++++-- >>> 1 file changed, 9 insertions(+), 2 deletions(-) >>> >>> diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c index >>> 26f8cf890700..cfc539a656f0 100644 >>> --- a/drivers/fpga/dfl.c >>> +++ b/drivers/fpga/dfl.c >>> @@ -1705,15 +1705,22 @@ >> EXPORT_SYMBOL_GPL(dfl_fpga_cdev_config_ports_pf); >>> int dfl_fpga_cdev_config_ports_vf(struct dfl_fpga_cdev *cdev, int num_vfs) >>> { >>> struct dfl_feature_platform_data *pdata; >>> - int ret = 0; >>> + int ret = 0, port_count = 0; >>> >>> mutex_lock(&cdev->lock); >>> + >>> + list_for_each_entry(pdata, &cdev->port_dev_list, node) { >>> + if (pdata->dev) >> This looks wrong, >> >> pdata->dev is dereferenced below, if there is a case were (!pdata->dev) >> here there would be crash later. >> >>> + continue; >>> + port_count++; >> how does this work when only some of the ports are handled in the new way ? > This code want to handle the " Multiple VFs per PR slot" model as I mentioned above. > In new model, the port_count want to count that how many port devices have released. > This code looks not good readability, I try to re-write it. > >> Tom >> >>> + } >>> + >>> /* >>> * can't turn multiple ports into 1 VF device, only 1 port for 1 VF >>> * device, so if released port number doesn't match VF device number, >>> * then reject the request with -EINVAL error code. >>> */ >>> - if (cdev->released_port_num != num_vfs) { >>> + if (port_count && cdev->released_port_num != num_vfs) { >>> ret = -EINVAL; >>> goto done; >>> }