Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2688213pxy; Tue, 3 Aug 2021 12:29:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1CPrSDSW7OIwhWaCeRuWj/N6a7q7UC/SVO/kBaf8ukaG1KrTK3ThnuizlPG+yr5b/u6Xe X-Received: by 2002:a05:6402:18c1:: with SMTP id x1mr27613699edy.145.1628018966769; Tue, 03 Aug 2021 12:29:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628018966; cv=none; d=google.com; s=arc-20160816; b=bEB+Aw1AC/KjwQceYenE47BL/z1Pyo7CFUK1LG7VwxHF0Ydcyf73X2IORdMSp+2FrJ /52RY7uart8HTtvXR/yuhXUE29pewDnFi6kTe183Kxtn4eN5Ie6zVAzRSccXh3NdbNAx /psQM9zb7LtJYgX4j0Zp3yqNr1dF1GQ1EcKa6MpVVLq/L2LWv+RQVJLwtXLf8ZiJIBA+ mAIYxMzw/tLh2tdyKmHPTqo4aBNwvH9Vzek6bVurNY3gbdGxnaF8Izn1UlAiVK+O/HzY Ha21Bp1rxzOkiP+BrfJ7OkcSNeb5iKe+dglEi8CTQP8BgvDrEcsPjcGURBi6/tch1W3R wwbw== 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:dkim-signature:dkim-filter; bh=ufOXnrjNoj2jj0kO6jzQg5CG4x+xLFn4fbpBWTIdmX0=; b=hUUW8/M34Y3/LJsEBnhwLA/9b9B5xXa6JRFfptEAL7ajEQliQSAqsn0eDOwjgtQCr8 +lUAOARZuDcVFsAeGa/u3eLH/ep6OdT/cRjkTh4qh5i6/QLyMy6myuwoGzr7HPFF9olV ORNPVI3V7tE/Ytu8XASAGbYhHYDIbUhWvCPsd5t7I3yUrL+IQq0s9ItfuHaC/eX6Oq9I TBWs4IKHQTeQENrEKPcoAMdiZyrT+FfTDacY35PMuOCVPHmtU1aYFxcL5JKRZgmQHuwb GsBG1VtbEMKNHl+qx3bicukfFbXx+bVnhvJcAHfRDhEXyL7g6Sl3n+k49S8ReG2G3Nfe 5c2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=OX10tiq7; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x20si13920584edd.553.2021.08.03.12.29.01; Tue, 03 Aug 2021 12:29:26 -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; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=OX10tiq7; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239887AbhHCT1X (ORCPT + 99 others); Tue, 3 Aug 2021 15:27:23 -0400 Received: from linux.microsoft.com ([13.77.154.182]:40726 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239877AbhHCT1X (ORCPT ); Tue, 3 Aug 2021 15:27:23 -0400 Received: from [192.168.1.115] (unknown [223.178.56.171]) by linux.microsoft.com (Postfix) with ESMTPSA id EDFA320B36E0; Tue, 3 Aug 2021 12:27:07 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com EDFA320B36E0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1628018831; bh=ufOXnrjNoj2jj0kO6jzQg5CG4x+xLFn4fbpBWTIdmX0=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=OX10tiq7r0BPbyCoVbcJjWb/k50fZHx/RdYxNchK4NRW4Su3VSgQRuV8t9tBkqyWo ojLU/CFXlv8LLCa1um144zvr3MDdxV6ay00ss+I1+mUrApYEZDVHoBZLFQMQqnMU5p jHL1/2iAHRnNbksIWXb73QDhByRCjDGY0yxgBAv4= Subject: Re: [RFC v1 8/8] mshv: add vfio bridge device To: Wei Liu , Linux on Hyper-V List Cc: virtualization@lists.linux-foundation.org, Linux Kernel List , Michael Kelley , Vineeth Pillai , Sunil Muthuswamy , Nuno Das Neves , pasha.tatashin@soleen.com, "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Dexuan Cui References: <20210709114339.3467637-1-wei.liu@kernel.org> <20210709114339.3467637-9-wei.liu@kernel.org> From: Praveen Kumar Message-ID: Date: Wed, 4 Aug 2021 00:57:03 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20210709114339.3467637-9-wei.liu@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09-07-2021 17:13, Wei Liu wrote: > + > +static int mshv_vfio_set_group(struct mshv_device *dev, long attr, u64 arg) > +{ > + struct mshv_vfio *mv = dev->private; > + struct vfio_group *vfio_group; > + struct mshv_vfio_group *mvg; > + int32_t __user *argp = (int32_t __user *)(unsigned long)arg; > + struct fd f; > + int32_t fd; > + int ret; > + > + switch (attr) { > + case MSHV_DEV_VFIO_GROUP_ADD: > + if (get_user(fd, argp)) > + return -EFAULT; > + > + f = fdget(fd); > + if (!f.file) > + return -EBADF; > + > + vfio_group = mshv_vfio_group_get_external_user(f.file); > + fdput(f); > + > + if (IS_ERR(vfio_group)) > + return PTR_ERR(vfio_group); > + > + mutex_lock(&mv->lock); > + > + list_for_each_entry(mvg, &mv->group_list, node) { > + if (mvg->vfio_group == vfio_group) { > + mutex_unlock(&mv->lock); > + mshv_vfio_group_put_external_user(vfio_group); > + return -EEXIST; > + } > + } > + > + mvg = kzalloc(sizeof(*mvg), GFP_KERNEL_ACCOUNT); > + if (!mvg) { > + mutex_unlock(&mv->lock); > + mshv_vfio_group_put_external_user(vfio_group); > + return -ENOMEM; > + } > + > + list_add_tail(&mvg->node, &mv->group_list); > + mvg->vfio_group = vfio_group; > + > + mutex_unlock(&mv->lock); > + > + return 0; > + > + case MSHV_DEV_VFIO_GROUP_DEL: > + if (get_user(fd, argp)) > + return -EFAULT; > + > + f = fdget(fd); > + if (!f.file) > + return -EBADF; Can we move these both checks above switch statement and do fdput accordingly under both case statement accordingly? > + > + ret = -ENOENT; > + > + mutex_lock(&mv->lock); > + > + list_for_each_entry(mvg, &mv->group_list, node) { > + if (!mshv_vfio_external_group_match_file(mvg->vfio_group, > + f.file)) > + continue; > + > + list_del(&mvg->node); > + mshv_vfio_group_put_external_user(mvg->vfio_group); > + kfree(mvg); > + ret = 0; > + break; > + } > + > + mutex_unlock(&mv->lock); > + > + fdput(f); > + > + return ret; > + } > + > + return -ENXIO; > +} > + > +static int mshv_vfio_set_attr(struct mshv_device *dev, > + struct mshv_device_attr *attr) > +{ > + switch (attr->group) { > + case MSHV_DEV_VFIO_GROUP: > + return mshv_vfio_set_group(dev, attr->attr, attr->addr); > + } > + > + return -ENXIO; > +} > + > +static int mshv_vfio_has_attr(struct mshv_device *dev, > + struct mshv_device_attr *attr) > +{ > + switch (attr->group) { > + case MSHV_DEV_VFIO_GROUP: > + switch (attr->attr) { > + case MSHV_DEV_VFIO_GROUP_ADD: > + case MSHV_DEV_VFIO_GROUP_DEL: > + return 0; > + } > + > + break; do we need this break statement ? If not, lets remove it. > + } > + > + return -ENXIO; > +} > + > +static void mshv_vfio_destroy(struct mshv_device *dev) > +{ > + struct mshv_vfio *mv = dev->private; > + struct mshv_vfio_group *mvg, *tmp; > + > + list_for_each_entry_safe(mvg, tmp, &mv->group_list, node) { > + mshv_vfio_group_put_external_user(mvg->vfio_group); > + list_del(&mvg->node); > + kfree(mvg); > + } > + > + kfree(mv); > + kfree(dev); We are freeing up dev. Please ignore my comment in caller patch. Thanks. > +} > + > +static int mshv_vfio_create(struct mshv_device *dev, u32 type); > + > +static struct mshv_device_ops mshv_vfio_ops = { > + .name = "mshv-vfio", > + .create = mshv_vfio_create, > + .destroy = mshv_vfio_destroy, > + .set_attr = mshv_vfio_set_attr, > + .has_attr = mshv_vfio_has_attr, > +}; Regards, ~Praveen.