Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7751627rwi; Mon, 24 Oct 2022 20:10:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM58KotI8rTH4M+D+GvNBTKnEgbrd2yYWdDzXjNhSnG2xmRoWgBk7QNyYpgZ5d0s6ruI5xZA X-Received: by 2002:a17:907:a073:b0:78d:51c4:5b8c with SMTP id ia19-20020a170907a07300b0078d51c45b8cmr29704190ejc.355.1666667430321; Mon, 24 Oct 2022 20:10:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666667430; cv=none; d=google.com; s=arc-20160816; b=aj7xWLAhMUV8JgwsrjRrQIK5cdQI8SavL5IkUtwvYVJDHw9TVdyi/DR69UXAKtcw6l 30q41D55vWK5suBpbbOQFbeRUAf/Yr1CZ6I09BCfZ5vJERSC92p+PI8ZZe51BG0ImuZ+ tVNailR0rmiujLJ2X7yA36A6FtuUpCQmbFf7Z39n/bhhIVvWgS7qcfOgwwxhsrkAGV5U WzSHvWwOb2wvbpAnASCewdKM831G+Nidj7c979nV4AZEb82bC9WQlE5JKkfq2NhLM4PX 30SawgWhTbUyTH7Y8CXS9uc/O3QrLhFWdQyR5YsHmAeMlNd0n/3sBC4Y2TaMiNIbTx3C fRsA== 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=PVNN5A6zsgdgB+eHBndc91qyFsKzboVwnhGEbyXO3g4=; b=L4/WsRMWF9er+X+DGmiLbojeHeunGX4FlQgVqa2jiU4YuoQVb3wxNlL+vm8ziB4jRH EJtLJ7M+vhH7bq8+/aM+3+KrAMEkUo5Mbx8tqjriiSpNd/dec7LVl2Wb/Q0UmZKUuEol DVzb3X7pywxQ03VwugbMfnZblpGg5kUgp+vDEzHdRQbMlELc6tcO8f5w7Y+yFah9mOoy hFQyQUhYiN3bCR2zB1sk8trM5WofBckwqjwQ0JogHWcIeXPh70+A7D2zboEqvolSErym NV7JbGcKUM6EpyyNYii4vN2EiWSRR0Ux4O1oqxquExk1Jw7cdxnXxemxd8PsgydPNvQC XmZQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h22-20020aa7cdd6000000b00459ff7667b4si1410379edw.203.2022.10.24.20.10.05; Mon, 24 Oct 2022 20:10:30 -0700 (PDT) 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 S229940AbiJYBbw (ORCPT + 99 others); Mon, 24 Oct 2022 21:31:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229968AbiJYBbb (ORCPT ); Mon, 24 Oct 2022 21:31:31 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 559831A801; Mon, 24 Oct 2022 18:08:37 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MxDMq39y7zHvGX; Tue, 25 Oct 2022 09:08:23 +0800 (CST) Received: from dggpemm500005.china.huawei.com (7.185.36.74) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 25 Oct 2022 09:08:35 +0800 Received: from [10.69.30.204] (10.69.30.204) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 25 Oct 2022 09:08:34 +0800 Subject: Re: [Patch v9 03/12] net: mana: Handle vport sharing between devices To: Long Li , KY Srinivasan , "Haiyang Zhang" , Stephen Hemminger , Wei Liu , Dexuan Cui , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Jason Gunthorpe , Leon Romanovsky , "edumazet@google.com" , "shiraz.saleem@intel.com" , Ajay Sharma CC: "linux-hyperv@vger.kernel.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-rdma@vger.kernel.org" References: <1666396889-31288-1-git-send-email-longli@linuxonhyperv.com> <1666396889-31288-4-git-send-email-longli@linuxonhyperv.com> <05607c38-7c9f-49df-c6b2-17e35f2ecbbd@huawei.com> From: Yunsheng Lin Message-ID: <38cedbd0-b719-eab5-71bd-2677462096c5@huawei.com> Date: Tue, 25 Oct 2022 09:08:34 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.69.30.204] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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 On 2022/10/25 2:45, Long Li wrote: >>> +int mana_cfg_vport(struct mana_port_context *apc, u32 >> protection_dom_id, >>> + u32 doorbell_pg_id) >>> { >>> struct mana_config_vport_resp resp = {}; >>> struct mana_config_vport_req req = {}; >>> int err; >>> >>> + /* This function is used to program the Ethernet port in the hardware >>> + * table. It can be called from the Ethernet driver or the RDMA driver. >>> + * >>> + * For Ethernet usage, the hardware supports only one active user on >> a >>> + * physical port. The driver checks on the port usage before >> programming >>> + * the hardware when creating the RAW QP (RDMA driver) or >> exposing the >>> + * device to kernel NET layer (Ethernet driver). >>> + * >>> + * Because the RDMA driver doesn't know in advance which QP type >> the >>> + * user will create, it exposes the device with all its ports. The user >>> + * may not be able to create RAW QP on a port if this port is already >>> + * in used by the Ethernet driver from the kernel. >>> + * >>> + * This physical port limitation only applies to the RAW QP. For RC QP, >>> + * the hardware doesn't have this limitation. The user can create RC >>> + * QPs on a physical port up to the hardware limits independent of >> the >>> + * Ethernet usage on the same port. >>> + */ >>> + mutex_lock(&apc->vport_mutex); >>> + if (apc->vport_use_count > 0) { >>> + mutex_unlock(&apc->vport_mutex); >>> + return -EBUSY; >>> + } >>> + apc->vport_use_count++; >>> + mutex_unlock(&apc->vport_mutex); >>> + >>> mana_gd_init_req_hdr(&req.hdr, MANA_CONFIG_VPORT_TX, >>> sizeof(req), sizeof(resp)); >>> req.vport = apc->port_handle; >>> @@ -679,9 +714,16 @@ static int mana_cfg_vport(struct >>> mana_port_context *apc, u32 protection_dom_id, >>> >>> apc->tx_shortform_allowed = resp.short_form_allowed; >>> apc->tx_vp_offset = resp.tx_vport_offset; >>> + >>> + netdev_info(apc->ndev, "Configured vPort %llu PD %u DB %u\n", >>> + apc->port_handle, protection_dom_id, doorbell_pg_id); >>> out: >>> + if (err) >>> + mana_uncfg_vport(apc); >> >> There seems to be a similar race between error handling here and the "apc- >>> vport_use_count > 0" checking above as pointed out in v7. > > Thanks for looking into this. > > This is different to the locking bug in mana_ib_cfg_vport(). The vport sharing > between Ethernet and RDMA is exclusive, not shared. If another driver tries > to take the vport while it is being configured, it will fail immediately. It is by Suppose the following steps: 1. Ethernet driver take the lock first and do a "apc->vport_use_count++", and release the lock; 2. RDMA driver take the lock, do "apc->vport_use_count > 0" checking and return -EBUSY; 3. mana_send_request() or mana_verify_resp_hdr() return error to Ethernet driver. It seems that vport is left unused when above happens, if that is what you wanted? > design to prevent possible deadlock. I am not sure I understand the deadlock here. >