Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3516294pxv; Sun, 4 Jul 2021 22:13:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyU4VHmnnahmKjda0xwSbcXNuCL1vl/QyXTAtLlDThYiGG675qoe+aj2ylIijJj2WDrZat9 X-Received: by 2002:a92:da05:: with SMTP id z5mr9073676ilm.133.1625462019818; Sun, 04 Jul 2021 22:13:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625462019; cv=none; d=google.com; s=arc-20160816; b=B3hryQ/0FgFCvSxOTia1u7bqgpP59reMl5s/2PNw1lfXeNAmWrYRPWAkEQ106u1wxi G2+kFI3aQq4uW9IrvYaJis9UzJanJDZrULk/CV7igG+ILvV+f7I4TdFYJWsPno3Di7iF GiudvTlLhgTdKR3qR5aq+YJ1XqNyu+ihFgsxkeUpGeieWCrVT0O6PsvdU0wbUJWFerdC UYpQFuBM3Av+94cFe4CV9z1vx3PpvbB73/OnQDvuG4aIWgpQjjuwJWAarRWfBq2hS+dF 3qrH679XZP35JOw4oqxiEvqsgBxy2SpobeeXAGp7YGUqnTJGOq4XA0iOpVuSV3/kbeA3 sKxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:from:subject:dkim-signature; bh=Budpf1Mgf5nAGlE4gIILC+M5chaMjcLyULIkUSMyGOQ=; b=GYRSKCeVRMky72PUxILZ/6U/qsKE/URdMJQYbc6pwAC2UwoneA5EP400ki4myN+oSC 2leokup/PaUdIcIzJW/ki/8mmTAnHcYUJm0kEcqWdQwz56Ysk9qZHVHP3WgCi9wN2Smy KZX9flUgkSNcKDzZb3S2v3Ta7MvGEVdj2KbcWvbk7Pt9z/U1F8r50Dme1z+5MY95HNzM op74J7Zc3T5658uXPA6KxaAX9IIJ37BjTt2uAau8WTwQUf9jXdKfs7aOa/nKwVJ9YnYe RMtNwFK95ugOwTXLHyG7NYD60jtnoRDuySuAQ6vtKhaVlpDz9SAM/7QGwFK8WZ0/zzAc 89zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="RzVE/WHo"; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h15si13943115ili.7.2021.07.04.22.13.28; Sun, 04 Jul 2021 22:13:39 -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=@redhat.com header.s=mimecast20190719 header.b="RzVE/WHo"; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229771AbhGEFOD (ORCPT + 99 others); Mon, 5 Jul 2021 01:14:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58913 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229713AbhGEFOD (ORCPT ); Mon, 5 Jul 2021 01:14:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625461886; 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=Budpf1Mgf5nAGlE4gIILC+M5chaMjcLyULIkUSMyGOQ=; b=RzVE/WHoljTfRladME/XfA6xPnsyDV8PuFoiCCdewkvruhUz5OZluiKejIONh7Fs03ITJ5 qg/XY1JDx8sCF80nRrahWxUfRmGPh/QjDsV1i/rxiCWdC7XZsOENQbi96F+Q69cJVZOBxw FHXXcGLI5nEChKOz9gDsOZ/utQviW98= Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-216-HijqptyeNduG1VZtuxdtIw-1; Mon, 05 Jul 2021 01:11:24 -0400 X-MC-Unique: HijqptyeNduG1VZtuxdtIw-1 Received: by mail-pg1-f197.google.com with SMTP id k9-20020a63d1090000b029021091ebb84cso12813717pgg.3 for ; Sun, 04 Jul 2021 22:11:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=Budpf1Mgf5nAGlE4gIILC+M5chaMjcLyULIkUSMyGOQ=; b=b+Wl3iv2DQkBB/qKvxDhyVaKg4Pe4sxNPQsKJPdAiHLpat9aUn6Cz6REdTyyPII03y KTiVD+nf9QswYimEdcX9CmYueYnot9ezd1GZw8Wsx9QWFqKprNkcIwTuwi1Ih4EUBg0A kYIb0lBbT4SZauc2v/ehUzr8dfRcOT/U/CHyrH2IrtbAyPp0I+YpT0tcrNYxHjySvEgN uCMJE+6iCX8JhxSytQMMh7HLyebVF+5zJ+tkJoojezhMlHlfyJrRoFUwb+IsxyO4So+a +Oupyj5y18BZcPGvqjCxPIy/UycVYVEHRhzqLfKPvRLGkor8XPw4vbi2nORvHhm/Xrv8 TrfQ== X-Gm-Message-State: AOAM532PH81uL/t0/81Y5hFNKjRC846k8vDBhBJry5FLZzEqoOLNW4pa FsFpc6Slg7V6iut7qCIoQXJyegJHv/O2NGhd9H8hnCY2O1hF3CXg466flN0AZVJ1CsH04F2HdtB Ebh/vzm9qJj/KAhLiRWqJ3m2IcKFlekk5KsS4UQkOZxnaBVhfrmVbW1Z+BgfW1Y7ANtr8oUHD/9 RX X-Received: by 2002:a17:902:650d:b029:129:6334:8c4a with SMTP id b13-20020a170902650db029012963348c4amr9272388plk.20.1625461883671; Sun, 04 Jul 2021 22:11:23 -0700 (PDT) X-Received: by 2002:a17:902:650d:b029:129:6334:8c4a with SMTP id b13-20020a170902650db029012963348c4amr9272365plk.20.1625461883324; Sun, 04 Jul 2021 22:11:23 -0700 (PDT) Received: from wangxiaodeMacBook-Air.local ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id r10sm12442127pga.48.2021.07.04.22.11.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 04 Jul 2021 22:11:22 -0700 (PDT) Subject: Re: [RFC PATCH] vhost-vdpa: mark vhost device invalid to reflect vdpa device unregistration From: Jason Wang To: gautam.dawar@xilinx.com Cc: martinh@xilinx.com, hanand@xilinx.com, gdawar@xilinx.com, "Michael S. Tsirkin" , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210704205205.6132-1-gdawar@xilinx.com> <3d02b8f5-0a6b-e8d1-533d-8503da3fcc4e@redhat.com> Message-ID: Date: Mon, 5 Jul 2021 13:11:18 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <3d02b8f5-0a6b-e8d1-533d-8503da3fcc4e@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2021/7/5 上午11:48, Jason Wang 写道: > > 在 2021/7/5 上午4:52, gautam.dawar@xilinx.com 写道: >>       vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); >> @@ -1091,11 +1122,13 @@ static void vhost_vdpa_remove(struct >> vdpa_device *vdpa) >>           opened = atomic_cmpxchg(&v->opened, 0, 1); >>           if (!opened) >>               break; >> -        wait_for_completion_timeout(&v->completion, >> -                        msecs_to_jiffies(1000)); >> -        dev_warn_once(&v->dev, >> -                  "%s waiting for/dev/%s to be closed\n", >> -                  __func__, dev_name(&v->dev)); >> +        if (!wait_for_completion_timeout(&v->completion, >> +                        msecs_to_jiffies(1000))) { >> +            dev_warn(&v->dev, >> +                 "%s/dev/%s in use, continue..\n", >> +                 __func__, dev_name(&v->dev)); >> +            break; >> +        } >>       } while (1); >>         put_device(&v->dev); >> +    v->dev_invalid = true; > > > Besides the mapping handling mentioned by Michael. I think this can > lead use-after-free. put_device may release the memory. > > Another fundamental issue, vDPA is the parent of vhost-vDPA device. > I'm not sure the device core can allow the parent to go away first. Or this probably means you need couple the fd loosely with the vhost-vDPA device. Thanks > > Thanks > >