Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp368046pxm; Wed, 2 Mar 2022 17:31:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJyJlLI8GtM0ibTwcgAqJHpvbwtpDAwbZu5uTXObMLMAbZNTcXRWaQSfa0+Q8PTggQKK6cYc X-Received: by 2002:a17:903:2289:b0:151:9612:b339 with SMTP id b9-20020a170903228900b001519612b339mr6186716plh.108.1646271117177; Wed, 02 Mar 2022 17:31:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646271117; cv=none; d=google.com; s=arc-20160816; b=jg4boaVSCTbQVKpZyWrkmdsssVH7GYtqtpXcQfLrP66DBLY2HRbGdtoQ3z8TT7U79d Zkrr2rZ4rbTX7SCEByBd+m6MGtU7m5+ktfTlCPFYpcaHkcua7dthXZeofNGo3QZN8c+g hEXAHWJ8TJ5Ctmlb4+oYR/UyxuD/3gEhS3OjdVDOeSes1okDXUT88lolMc92xWEzphFq kB3Evl88aOg5tyWWkVbszA2yiVbo2neiGd/8qzAsDMvHkaUm38GazzSdKeMUi9Wg/L9Y lPJRcHmWsTst8XctxVPHwYMXAnhn84HZfdiRqtuAKHTre0F8seHX0uzdE4QKHkGHrngt Lbow== 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:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-filter; bh=0A9U3/A1+sfRyujc9HpaWZgG2Yh/DJChDIAh5jtJwK8=; b=vI0izobi9INL7vxZ7UzS2lb7YRJdI/IbSCiczENVX59vLCM0kDkVBnbVBfTYM9RQMy WIqbUhV0kkAhBeCL9RWwto9lYdjZQI1/71uZlGX0C/gjJQBt/HBMM6j2tBfGSU2yfrtW fdfxj0RY0j+dnh96ciRfDtS2DlB19ZCWAftru0hReHdoadn24Q+hXcVmakEpgN3x8lDy 6JyGf0BjPO0/DJYZCLbA0i2uzNUSHgPlV9u7v51I0voU4Z8+ST39rbnddXKrF9cCLPe3 MiGgnACwKHimSJ6/Y1tIfwyd0ReseGncyRcEfxKNqboVtiaNwZrmCAgYvJy3PFXS/HoX vxBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=DizS9EAj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y5-20020a1709029b8500b0014f9a608b16si612489plp.537.2022.03.02.17.31.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 17:31:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=DizS9EAj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 93939A66F6; Wed, 2 Mar 2022 17:09:28 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231196AbiCCBKK (ORCPT + 99 others); Wed, 2 Mar 2022 20:10:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231169AbiCCBKH (ORCPT ); Wed, 2 Mar 2022 20:10:07 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EBA332D1F5; Wed, 2 Mar 2022 17:09:22 -0800 (PST) Received: from [192.168.1.17] (unknown [192.182.151.181]) by linux.microsoft.com (Postfix) with ESMTPSA id 7389920B7178; Wed, 2 Mar 2022 17:09:22 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7389920B7178 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1646269762; bh=0A9U3/A1+sfRyujc9HpaWZgG2Yh/DJChDIAh5jtJwK8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=DizS9EAjkuOlxzJb2WrrLVIGurQ+MgGe6Hq5pB62M48Xc3JusNC/qzQfHkD5sm65U 355H29NJ7MUufUpRbdXJLkFG/kTdd9QT1OthG6rNaz3o0CXqK+VQMqrhSdX/rwtfos JjqKGFqvZxt0RJam1K4Mu+IR49pL12o2XWiznzT8= Message-ID: Date: Wed, 2 Mar 2022 17:09:21 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH v3 02/30] drivers: hv: dxgkrnl: Driver initialization and loading Content-Language: en-US To: Greg KH , Wei Liu Cc: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, spronovo@microsoft.com, spronovo@linux.microsoft.com References: <719fe06b7cbe9ac12fa4a729e810e3383ab421c1.1646163378.git.iourit@linux.microsoft.com> <739cf89e71ff72436d7ca3f846881dfb45d07a6a.1646163378.git.iourit@linux.microsoft.com> <20220301222321.yradz24nuyhzh7om@liuwe-devbox-debian-v2> From: Iouri Tarassov In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=no 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 3/1/2022 11:53 PM, Greg KH wrote: > On Tue, Mar 01, 2022 at 10:23:21PM +0000, Wei Liu wrote: > > > > +struct dxgglobal *dxgglobal; > > > > > > No, make this per-device, NEVER have a single device for your driver. > > > The Linux driver model makes it harder to do it this way than to do it > > > correctly. Do it correctly please and have no global structures like > > > this. > > > > > > > This may not be as big an issue as you thought. The device discovery is > > still done via the normal VMBus probing routine. For all intents and > > purposes the dxgglobal structure can be broken down into per device > > fields and a global structure which contains the protocol versioning > > information -- my understanding is there will always be a global > > structure to hold information related to the backend, regardless of how > > many devices there are. > > Then that is wrong and needs to be fixed. Drivers should almost never > have any global data, that is not how Linux drivers work. What happens > when you get a second device in your system for this? Major rework > would have to happen and the code will break. Handle that all now as it > takes less work to make this per-device than it does to have a global > variable. > > > I definitely think splitting is doable, but I also understand why Iouri > > does not want to do it _now_ given there is no such a model for multiple > > devices yet, so anything we put into the per-device structure could be > > incomplete and it requires further changing when such a model arrives > > later. > > > > Iouri, please correct me if I have the wrong mental model here. > > > > All in all, I hope this is not going to be a deal breaker for the > > acceptance of this driver. > > For my reviews, yes it will be. > > Again, it should be easier to keep things in a per-device state than > not as the proper lifetime rules and the like are automatically handled > for you. If you have global data, you have to manage that all on your > own and it is _MUCH_ harder to review that you got it correct. Hi Greg, I do not really see how the driver be written without the global data. Let's review the design. Dxgkrnl acts as the aggregator of all virtual compute devices, projected by the host. It needs to do operations, which do not belong to a particular compute device. For example, cross device synchronization and resource sharing. A PCI device device is created for each virtual compute device. Therefore, there should be a global list of objects and a mutex to synchronize access to the list. A VMBus channel is offered by the host for each compute device. The list of the VMBus channels should be global. A global VMBus channel is offered by the host. The channel does not belong to any particular compute device, so it must be global. IO space is shared by all compute devices, so its parameters should be global. Dxgkrnl needs to maintain a list of processes, which opened compute device objects. Dxgkrnl maintains private state for each process and when a process opens the /dev/dxg device, Dxgkrnl needs to find if the process state is already created by walking the global process list. Now, where to keep this global state? It could be kept in the /dev/dxg private device structure. But this structure is not available when, for example, dxg_pci_probe_device() or dxg_probe_vmbus() is called. Can there be multiple /dev/dxg devices? No. Because the /dev/dxg device represents the driver itself, not a particular compute device. I am not sure what design model you have in mind when saying there should be no global data. Could you please explain keeping in mind the above requirements? Thanks Iouri