Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1290815pxk; Thu, 10 Sep 2020 11:38:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIcSCD8XVaE2KhzXwbRWoUnz3gF7m/XDUfTP658FCSax3gKEc4Hcej6UTgiUZO6V9wqQso X-Received: by 2002:a17:907:270f:: with SMTP id w15mr10762631ejk.141.1599763129634; Thu, 10 Sep 2020 11:38:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599763129; cv=none; d=google.com; s=arc-20160816; b=bxuqkDTb1agJhPZ6bJ+vN4FtgHKC+YED0rd995Nf/kU7cuIiVUkunZwTtwyiKJa+RU BXdLhZ7Qw6DzBxRwzhmdkfSrX496+HXwUeGW7BTsWlksUJeFTTyPYRQ2fr6lZx0mITkX wmDZYIblatXm1zS3fFPgtEWl5936me2TvzgOBxhV2f8F+xXz92hBS7su6LrrDGr0oeX8 CQa4aO1CUywbzZuwxi4o0s0uEO0I4HQU24KCz7cfVlBwKJnOr5sLWNT4fGiQH5lrQXw/ qiPhVziNXrLIcX5CYFVx5mmqhHNR38GSzVcw3gZjy9olpnzv418RNwV8LuV13XPHTlaN q1JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:ironport-sdr:ironport-sdr; bh=LSZ4+2T5z6JwGTsieahhC9f8BZ79yeuEBkLpr8Ia7tU=; b=ZwMUzxNpb+mz4te8FFKSLYLZW5i+8FNsYzLxfYmDJXn53KY5a1hc1nZSq+HPp0Kdgy TZfle3WEDOjzM7sA2wIx6Uc93OdawZGA7pEaWWzSPPXJKNMnZJCZbdxO2Mk0EEGIzBz4 gkY/uRXfqH9m9Aj23cHQ7dgfYlnLE6kWtKfs635E7bOF3UlK+qX0X3uFJsPMBrQ98m16 FUeqc7r5bJPY+qiez/RkhGNT8GSmZKKy/rS4B1biAB8QStcDPy4cCTKPu+IWtTWq9wod YavRydvEmGZqnD9T3rTv2Llv9qGMZq4CzBtcMBv+65lNWCUfYWxIU2UlfBFhRRZTqeR4 BjAg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pg3si4370615ejb.94.2020.09.10.11.38.26; Thu, 10 Sep 2020 11:38:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727041AbgIJSfl (ORCPT + 99 others); Thu, 10 Sep 2020 14:35:41 -0400 Received: from mga12.intel.com ([192.55.52.136]:2108 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726920AbgIJSdr (ORCPT ); Thu, 10 Sep 2020 14:33:47 -0400 IronPort-SDR: wSYNeRRvAS+P7TZvhEhi1sEKZvUy+NQrpPGTzkFoHCspugprrZyYf8Lg1qWU7sX3uGgEO9I6L0 oY3l2gCP+Uig== X-IronPort-AV: E=McAfee;i="6000,8403,9740"; a="138128098" X-IronPort-AV: E=Sophos;i="5.76,413,1592895600"; d="scan'208";a="138128098" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2020 11:33:43 -0700 IronPort-SDR: 1a/KSLpHMr/+R7JtsXWE2hXmug66deTVdvrtfeesZwCdJX/YgF8I0vNKPFK65vrZ2aRx1LX4FP uG4HpMCpUYFQ== X-IronPort-AV: E=Sophos;i="5.76,413,1592895600"; d="scan'208";a="334266515" Received: from rchatre-mobl.amr.corp.intel.com (HELO [10.209.150.7]) ([10.209.150.7]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2020 11:33:42 -0700 Subject: Re: [PATCH v3 06/17] virt: acrn: Introduce VM management interfaces To: Greg Kroah-Hartman , Shuo A Liu Cc: linux-kernel@vger.kernel.org, x86@kernel.org, "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Sean Christopherson , Yu Wang , Zhi Wang , Zhenyu Wang References: <20200909090836.46762-1-shuo.a.liu@intel.com> <20200909090836.46762-7-shuo.a.liu@intel.com> <20200909094516.GB607744@kroah.com> <20200910061900.GI13723@shuo-intel.sh.intel.com> <20200910162810.GB1265411@kroah.com> From: Reinette Chatre Message-ID: Date: Thu, 10 Sep 2020 11:33:30 -0700 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20200910162810.GB1265411@kroah.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Shuo and Greg, On 9/10/2020 9:28 AM, Greg Kroah-Hartman wrote: > On Thu, Sep 10, 2020 at 02:19:00PM +0800, Shuo A Liu wrote: >> On Wed 9.Sep'20 at 11:45:16 +0200, Greg Kroah-Hartman wrote: >>> On Wed, Sep 09, 2020 at 05:08:25PM +0800, shuo.a.liu@intel.com wrote: ... >>>> /** >>>> * struct acrn_vm - Properties of ACRN User VM. >>>> + * @dev: The struct device this VM belongs to >>>> + * @list: Entry within global list of all VMs >>>> * @vmid: User VM ID >>>> + * @vcpu_num: Number of virtual CPUs in the VM >>>> + * @flags: Flags (ACRN_VM_FLAG_*) of the VM. This is VM flag management >>>> + * in HSM which is different from the &acrn_vm_creation.vm_flag. >>>> */ >>>> struct acrn_vm { >>>> - u16 vmid; >>>> + struct device *dev; >>>> + struct list_head list; >>>> + u16 vmid; >>>> + int vcpu_num; >>>> + unsigned long flags; >>>> }; >>>> >>>> +struct acrn_vm *acrn_vm_create(struct acrn_vm *vm, >>>> + struct acrn_vm_creation *vm_param); >>>> +int acrn_vm_destroy(struct acrn_vm *vm); >>>> + >>>> #endif /* __ACRN_HSM_DRV_H */ >>>> diff --git a/drivers/virt/acrn/hsm.c b/drivers/virt/acrn/hsm.c >>>> index 28a3052ffa55..bc85a3c14f87 100644 >>>> --- a/drivers/virt/acrn/hsm.c >>>> +++ b/drivers/virt/acrn/hsm.c >>>> @@ -19,6 +19,8 @@ >>>> >>>> #include "acrn_drv.h" >>>> >>>> +static struct miscdevice acrn_dev; >>>> + >>>> /* >>>> * When /dev/acrn_hsm is opened, a 'struct acrn_vm' object is created to >>>> * represent a VM instance and continues to be associated with the opened file >>>> @@ -34,14 +36,77 @@ static int acrn_dev_open(struct inode *inode, struct file *filp) >>>> return -ENOMEM; >>>> >>>> vm->vmid = ACRN_INVALID_VMID; >>>> + vm->dev = get_device(acrn_dev.this_device); >>> >>> You are grabbing a reference on a static structure? >> >> acrn_dev is static, but acrn_dev.this_device is not. > > But you don't control that device, the misc device core does. > >>> >>> Ugh, who reviewed this code before it was sent out??? >> >> This part was just newly added according to your suggestion.. Please >> refer to >> https://lore.kernel.org/lkml/1946bf48-fda7-20e0-246d-93414a1a67f5@intel.com/ > > What you were doing there was wrong, and what you are doing here is just > odd. > > Step back please, and describe exactly what you are trying to do. And > then explain how grabbing a reference to the device reference count for > the misc device is going to help solve that issue. > From what I understand this current path was entered after Greg's original suggestion from https://lore.kernel.org/lkml/20200828102704.GB1470435@kroah.com to replace the pr_xxx() calls with the more informative dev_xxx() ones. Perhaps all that is needed to follow the original suggestion is to replace the pr_xxx() calls with dev_xxx(acrn_dev.this_device, ...) ? (An example of this is drivers/input/serio/userio.c and some others) The device (acrn_dev.this_device) can be trusted to exist for the lifetime of the driver since it is removed on module unload where the misc device is unregistered. Reinette