From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEE45C43457 for ; Mon, 19 Oct 2020 16:42:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 05C6A222B8 for ; Mon, 19 Oct 2020 16:42:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZYWCpo2B" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 05C6A222B8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 375FA6B005C; Mon, 19 Oct 2020 12:42:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D7AB6B0062; Mon, 19 Oct 2020 12:42:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 102886B0068; Mon, 19 Oct 2020 12:42:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0166.hostedemail.com [216.40.44.166]) by kanga.kvack.org (Postfix) with ESMTP id CD6076B005C for ; Mon, 19 Oct 2020 12:42:00 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 72E1D181AEF09 for ; Mon, 19 Oct 2020 16:42:00 +0000 (UTC) X-FDA: 77389242000.26.jail83_4a16b1827238 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 4B2791804B656 for ; Mon, 19 Oct 2020 16:42:00 +0000 (UTC) X-HE-Tag: jail83_4a16b1827238 X-Filterd-Recvd-Size: 6747 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Mon, 19 Oct 2020 16:41:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603125719; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2P0pw/kzhOqfVzEX3jZqFUZx91Pd6FC/rbDYJMSaPTM=; b=ZYWCpo2BIVAe4PEOMEekDrtbUG2qTKbX/NLtC6eaiu/XpJmvzMAU0QC5+Yz5KYluytXv9A TPy4QbmHgQEVsbV5Ku5kB9bqaoLNuoiUbSFBTUm3A2WizTiuucu4OkWrxtDzhurvHq3zgm gI4Lg/1e4KA8YUpaxl68Wf1mERhWW84= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-253-Cu6vSF0TMa67kRreJqzW8A-1; Mon, 19 Oct 2020 12:41:57 -0400 X-MC-Unique: Cu6vSF0TMa67kRreJqzW8A-1 Received: by mail-wm1-f70.google.com with SMTP id c204so38004wmd.5 for ; Mon, 19 Oct 2020 09:41:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=2P0pw/kzhOqfVzEX3jZqFUZx91Pd6FC/rbDYJMSaPTM=; b=k3XQJ3EnWiH3xJVotfn6euW0d9r9zSUrfGsl7LpghlcteL1PhalDZbZgs4WVAQYArT btLMMK91JdqTJ31zKhWP2N9XT0w8S/pKRx2cw5VWoeIZYpzmM9YJTVxTNvo4yrcC4Qxe ahWfxuZv/1fyyXyVbrnBqzEH7gTUmS2ZDFrd/LD9lOfX8vuODYjdQKUAku7c9XyYs/25 HOKvJpdw2h4/4rkiw7l9voJxSn5NOpG+wOL2WPKfh7dwi45Hy7kKnNEo4mui2KakYsvI 3zX00O7E8Ad8prf2Sfp7A7imWNaQsN2TPplFUJHOQIQGU3rlrIv2XC0aKsamq55CDTvy 5u4Q== X-Gm-Message-State: AOAM531dVr4JXkB6L1NdCdoygYfs8z6wIPmDmm9htwNWOKCyx/yIV+Gl NceGKNnb//2xCCz/lZBQ/NRFOzJWz0SPMWITOhHyKqiWTLusHXopu1e6mLLY0ff1Drmdw34YG1k jGR4PaEqPOzg= X-Received: by 2002:a7b:c10c:: with SMTP id w12mr53157wmi.175.1603125711452; Mon, 19 Oct 2020 09:41:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjcPNvNqsWyP0ZXdUmTiirpahsBYEQJjj/jdob5g+omUBG5HGzG6dUx96aoOXSZVVV9sNK5Q== X-Received: by 2002:a7b:c10c:: with SMTP id w12mr53127wmi.175.1603125711047; Mon, 19 Oct 2020 09:41:51 -0700 (PDT) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id 4sm324356wrp.58.2020.10.19.09.41.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Oct 2020 09:41:49 -0700 (PDT) Date: Mon, 19 Oct 2020 12:41:46 -0400 From: "Michael S. Tsirkin" To: =?utf-8?B?6LCi5rC45ZCJ?= Cc: jasowang@redhat.com, akpm@linux-foundation.org, linux-mm@kvack.org, virtualization@lists.linux-foundation.org Subject: Re: [External] Re: [RFC 3/4] vduse: grab the module's references until there is no vduse device Message-ID: <20201019123835-mutt-send-email-mst@kernel.org> References: <20201019145623.671-1-xieyongji@bytedance.com> <20201019145623.671-4-xieyongji@bytedance.com> <20201019110359-mutt-send-email-mst@kernel.org> <20201019114701-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 In-Reply-To: Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Oct 19, 2020 at 11:56:35PM +0800, =E8=B0=A2=E6=B0=B8=E5=90=89 wro= te: >=20 >=20 >=20 > On Mon, Oct 19, 2020 at 11:47 PM Michael S. Tsirkin wr= ote: >=20 > On Mon, Oct 19, 2020 at 11:44:36PM +0800, =E8=B0=A2=E6=B0=B8=E5=90=89= wrote: > > > > > > On Mon, Oct 19, 2020 at 11:05 PM Michael S. Tsirkin > wrote: > > > >=C2=A0 =C2=A0 =C2=A0On Mon, Oct 19, 2020 at 10:56:22PM +0800, Xie = Yongji wrote: > >=C2=A0 =C2=A0 =C2=A0> The module should not be unloaded if any vdu= se device exists. > >=C2=A0 =C2=A0 =C2=A0> So increase the module's reference count whe= n creating vduse > >=C2=A0 =C2=A0 =C2=A0> device. And the reference count is kept unti= l the device is > >=C2=A0 =C2=A0 =C2=A0> destroyed. > >=C2=A0 =C2=A0 =C2=A0> > >=C2=A0 =C2=A0 =C2=A0> Signed-off-by: Xie Yongji > >=C2=A0 =C2=A0 =C2=A0> --- > >=C2=A0 =C2=A0 =C2=A0>=C2=A0 drivers/vdpa/vdpa_user/vduse_dev.c | 2= ++ > >=C2=A0 =C2=A0 =C2=A0>=C2=A0 1 file changed, 2 insertions(+) > >=C2=A0 =C2=A0 =C2=A0> > >=C2=A0 =C2=A0 =C2=A0> diff --git a/drivers/vdpa/vdpa_user/vduse_de= v.c b/drivers/vdpa/ > vdpa_user/ > >=C2=A0 =C2=A0 =C2=A0vduse_dev.c > >=C2=A0 =C2=A0 =C2=A0> index 6787ba66725c..f04aa02de8c1 100644 > >=C2=A0 =C2=A0 =C2=A0> --- a/drivers/vdpa/vdpa_user/vduse_dev.c > >=C2=A0 =C2=A0 =C2=A0> +++ b/drivers/vdpa/vdpa_user/vduse_dev.c > >=C2=A0 =C2=A0 =C2=A0> @@ -887,6 +887,7 @@ static int vduse_destroy= _dev(u32 id) > >=C2=A0 =C2=A0 =C2=A0>=C2=A0 =C2=A0 =C2=A0 =C2=A0kfree(dev->vqs); > >=C2=A0 =C2=A0 =C2=A0>=C2=A0 =C2=A0 =C2=A0 =C2=A0vduse_iova_domain_= destroy(dev->domain); > >=C2=A0 =C2=A0 =C2=A0>=C2=A0 =C2=A0 =C2=A0 =C2=A0vduse_dev_destroy(= dev); > >=C2=A0 =C2=A0 =C2=A0> +=C2=A0 =C2=A0 =C2=A0module_put(THIS_MODULE)= ; > >=C2=A0 =C2=A0 =C2=A0>=C2=A0 > >=C2=A0 =C2=A0 =C2=A0>=C2=A0 =C2=A0 =C2=A0 =C2=A0return 0; > >=C2=A0 =C2=A0 =C2=A0>=C2=A0 } > >=C2=A0 =C2=A0 =C2=A0> @@ -931,6 +932,7 @@ static int vduse_create_= dev(struct > vduse_dev_config > >=C2=A0 =C2=A0 =C2=A0*config) > >=C2=A0 =C2=A0 =C2=A0>=C2=A0 > >=C2=A0 =C2=A0 =C2=A0>=C2=A0 =C2=A0 =C2=A0 =C2=A0dev->connected =3D= true; > >=C2=A0 =C2=A0 =C2=A0>=C2=A0 =C2=A0 =C2=A0 =C2=A0list_add(&dev->lis= t, &vduse_devs); > >=C2=A0 =C2=A0 =C2=A0> +=C2=A0 =C2=A0 =C2=A0__module_get(THIS_MODUL= E); > >=C2=A0 =C2=A0 =C2=A0>=C2=A0 > >=C2=A0 =C2=A0 =C2=A0>=C2=A0 =C2=A0 =C2=A0 =C2=A0return fd; > >=C2=A0 =C2=A0 =C2=A0>=C2=A0 err_fd: > > > >=C2=A0 =C2=A0 =C2=A0This kind of thing is usually an indicator of = a bug. E.g. > >=C2=A0 =C2=A0 =C2=A0if the refcount drops to 0 on module_put(THIS_= MODULE) it > >=C2=A0 =C2=A0 =C2=A0will be unloaded and the following return will= not run. > > > > > > > > Should this happen?=C2=A0 The refcount should be only decreased t= o 0 after the > > misc_device is closed? > > > > Thanks, > > Yongji > > >=20 > OTOH if it never drops to 0 anyway then why do you need to increase= it? >=20 >=20 >=20 > To prevent unloading the module in the case that the device is created,= but no > user process using it (e.g. the user process crashed).=C2=A0 >=20 > Thanks, > Yongji Looks like it can drop to 0 if that is the case then? >=20 > > > > > >=C2=A0 =C2=A0 =C2=A0> -- > >=C2=A0 =C2=A0 =C2=A0> 2.25.1 > > > > >=20 >=20