Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp646941rwi; Wed, 19 Oct 2022 00:41:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Ez03tceeuULr1UJSuX0lAc1p4yc9TX9Yh8V06gZUpF2uF+49OKz984biDI7810FVpkPlP X-Received: by 2002:a05:6402:d43:b0:459:b4a:18b5 with SMTP id ec3-20020a0564020d4300b004590b4a18b5mr6272308edb.171.1666165272616; Wed, 19 Oct 2022 00:41:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666165272; cv=none; d=google.com; s=arc-20160816; b=aTGlAlHNK6p1olz6EQabKkH7cY08rNYwCKW0CcbKl/fNT6J4F/uiv293U1HSWVsZVb BHxWQvLQQeL7C/y+TjRX6CpO2fqdVJfj781JV2MLZ6Lfv8fltg3mMCUdai8wP930RyBa YsRUz5atSrCparVLItCc/Rt85PN3sPr6WEgODyXBgYyFxvSOl+iMMm/3LDzjr2hwHKVF sNB87CpOMdaRm2ElNwGNlDAYvhCmoQqUZE5oKULMOgz+fxGGk81JRQk3odYMNsLjjQ1j HmW6EigYFtdCFEQRKTCHiQdkCenvt2mpax2pyQkl0kbsA2msayHrIQUKDehcHawmb8wt q34A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=ajumC9SUgMLnQf9+mELsYyk6alPOjWrTVfdCXFDfkNY=; b=La4Y5QJGaE6vvqPGf2Eyj5nlWzQzRHtjzT2rtLBeEn5s5m4K+1h/F0NoDlRRW4YTf0 g2K/KSrqc0bElGSuOu4gXSDjJ0V7GT0NlLqQ4Wdk9944reLqDgIfM2HRZo1IXexTxoFj 7uullCCRcOyGPWo+rHHkVhMZyCMu4qYwixIqyLCSQBrJccvfh21dGzTt31MUQubQLSZj GMJvZdki+RichVrBKMxmpBTdF6ovwMXOnuXroH0Rwt0EDkRLLg/kxNCqXekso83dmWZE 2JXKd6pxsMVJ3+ITO+oW/eHVJ1lzUXbiJEZXtYiK7zG/8sZad333z+qz/Cy/oiVK/MdW 3eoA== 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 z4-20020a056402274400b00447eb58b921si15986159edd.38.2022.10.19.00.40.47; Wed, 19 Oct 2022 00:41:12 -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 S229971AbiJSHSM (ORCPT + 99 others); Wed, 19 Oct 2022 03:18:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229872AbiJSHSH (ORCPT ); Wed, 19 Oct 2022 03:18:07 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CDD574E1B for ; Wed, 19 Oct 2022 00:18:02 -0700 (PDT) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Mshp05zszzJn5w; Wed, 19 Oct 2022 15:15:20 +0800 (CST) Received: from kwepemm600005.china.huawei.com (7.193.23.191) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 19 Oct 2022 15:17:46 +0800 Received: from [10.67.103.158] (10.67.103.158) by kwepemm600005.china.huawei.com (7.193.23.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 19 Oct 2022 15:17:45 +0800 Subject: Re: [Linuxarm] [PATCH 1/2] hisi_acc_vfio_pci: Add debugfs to migration driver To: Jason Gunthorpe CC: John Garry , , , , , References: <20221014025757.39415-1-liulongfang@huawei.com> <20221014025757.39415-2-liulongfang@huawei.com> <42d12308-4777-47a7-a1ae-50dfada050cf@huawei.com> <7c041671-71bf-d558-d47a-70296fe5c30e@huawei.com> <9826a418-4a14-aa4a-9eb8-6faf3e43c8e3@huawei.com> From: liulongfang Message-ID: Date: Wed, 19 Oct 2022 15:17:44 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.103.158] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600005.china.huawei.com (7.193.23.191) 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/18 20:01, Jason Gunthorpe Wrote: > On Tue, Oct 18, 2022 at 03:06:43PM +0800, liulongfang wrote: >> On 2022/10/17 20:11, Jason Gunthorpe Wrote: >>> On Mon, Oct 17, 2022 at 05:20:34PM +0800, liulongfang wrote: >>>> On 2022/10/14 17:20, John Garry wrote: >>>>> On 14/10/2022 03:57, Longfang Liu wrote: >>>>>> +static void hisi_acc_vf_debugfs_init(struct hisi_acc_vf_core_device *hisi_acc_vdev) >>>>>> +{ >>>>>> +    struct pci_dev *vf_pdev = hisi_acc_vdev->vf_dev; >>>>>> +    struct device *dev = &vf_pdev->dev; >>>>>> +    int ret; >>>>>> + >>>>>> +    if (!atomic_read(&hisi_acc_root_ref)) >>>>>> +        hisi_acc_debugfs_root = debugfs_create_dir("hisi_vfio_acc", NULL); >>>>>> +    atomic_inc(&hisi_acc_root_ref); >>>>>> + >>>>> >>>>> This looks totally racy, such that I wonder why even bother using an atomic for hisi_acc_root_ref. >>>> >>>> >>>> When enabling VF, it is possible for multiple VMs to enable VF at the same time. The atomic variable >>>> is used to ensure that only one "hisi_vfio_acc" is created. When other VFs are enabled, >>>> it will not be created again, but will be used directly. >>> >>> It is still completely racy. Use a lock >>> Um! I understand your previous solution. Since we did not put module_init() in the driver, to avoid competition, we first need to modify the module_init() interface of the driver, then put debugfs_create_dir() into module_init(), and finally put debugfs_create_file() into probe(). I will implement this way in the next version. >> >> Do you have any suggested solutions? > > If you want to keep it like this, use a lock around the creation. > > Jason > . > Thanks, Longfang