Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1930863imm; Tue, 22 May 2018 11:40:17 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq1CQaDbGjtd57HaM48dLHYQEG+Yf5DnF3B+WLjJ3Rtvfx+8TCLk9tK9CsOLZnludNMhWOH X-Received: by 2002:a63:b907:: with SMTP id z7-v6mr20335275pge.9.1527014416990; Tue, 22 May 2018 11:40:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527014416; cv=none; d=google.com; s=arc-20160816; b=fK2PpbChF9OydXJXEBh1ZZIJL44SRHoIolde619DPZiw1GaFCa92nTMedyVNclG5G6 pavvQ0B+IN3AIPzFBDXMbHvuJxlM62XKtqf2zaFFeMEQo3vCMKDSR2EsOPQ2DKmIeQrU rVFm/UO1WduL+kn92XF9rRWUbcHTx9yk/HMNl4Uh47UrxPgguHK+kT982E9mtbuZfoBX c538PB7Z7ekye8gp6QRAZzEt8x/vQWeZtCrlWmA3CCQrG3WrLj33g50JDaEe8+0f/eW5 rkFtVxZBHwbK+iQwWFglxElQRAQi/SQud/JSVqeTL2SL2sdC7pLdKiEZXj0Oo5yEOlnb sxfg== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=rzLsWqeawG4KK+bWng7s3XZwoh7iayc8xAZiM4eMzdY=; b=yo3u2oexA7cFlS/w3drnVo5ITZp32UmhPXLSGTfE0GdT2WrdRETYTn2PUy4qQlNB86 15rgs/FQ1u+GX0yt0PBdvzB1hLWHQv6Va+ig26C4j/FOrZQMaavwGmxf2nNJ/AEW1Let zlo+zBq98VAGKSADk3rvFs7KywJqtz8I9fbCZzIBBtrsFTQzLmtIseB9qqwluEuOcD3C irJpXubyC1EsfVDPo8GLX5cbycQI2VKV0B35JIem+c4KtjG0QJTv9nBPjbdFjzvAP7fc t8p3X+ASX2gLe3FHIxEji/cPd9caEJlGyrwTs266BVew1FxOw4ktavOjxF9sFj4WiYPS aALA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f16-v6si16974003pfe.291.2018.05.22.11.40.02; Tue, 22 May 2018 11:40:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751605AbeEVSib (ORCPT + 99 others); Tue, 22 May 2018 14:38:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54642 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751319AbeEVSia (ORCPT ); Tue, 22 May 2018 14:38:30 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 400A73078AA1; Tue, 22 May 2018 18:38:30 +0000 (UTC) Received: from w520.home (ovpn-116-135.phx2.redhat.com [10.3.116.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD2BA1C950; Tue, 22 May 2018 18:38:29 +0000 (UTC) Date: Tue, 22 May 2018 12:38:29 -0600 From: Alex Williamson To: Halil Pasic Cc: kwankhede@nvidia.com, Dong Jia , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, cohuck@redhat.com Subject: Re: [PATCH v4 0/2] vfio/mdev: Device namespace protection Message-ID: <20180522123829.4e758646@w520.home> In-Reply-To: References: <20180518190145.3187.7620.stgit@gimli.home> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 22 May 2018 18:38:30 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 22 May 2018 19:17:07 +0200 Halil Pasic wrote: > From vfio-ccw perspective I join Connie's assessment: vfio-ccw should > be fine with these changes. I'm however not too deeply involved with > the mdev framework, thus I don't feel comfortable r-b-ing. That results > in > Acked-by: Halil Pasic > for both patches. > > While at it I have would like to ask about the semantics and intended > use of the mdev interfaces. > > static int vfio_ccw_sch_probe(struct subchannel *sch) > { > > /* HALIL: 8< Not so interesting stuff happens here. >8 */ This was interesting: private->state = VFIO_CCW_STATE_NOT_OPER; > ret = vfio_ccw_mdev_reg(sch); > if (ret) > goto out_disable; > /* > * HALIL: > * This might be racy. Somewhere in vfio_ccw_mdev_reg() the create attribute > * is made available (it calls mdev_register_device()). For instance create will > * attempt to decrement private->avail which is initialized below. I fail to > * understand how is this well synchronized. > */ > INIT_WORK(&private->io_work, vfio_ccw_sch_io_todo); > atomic_set(&private->avail, 1); > private->state = VFIO_CCW_STATE_STANDBY; > > return 0; > > out_disable: > cio_disable_subchannel(sch); > out_free: > dev_set_drvdata(&sch->dev, NULL); > kfree(private); > return ret; > } > > Should not initialization of go before mdev_register_device(), and then rolled > back if necessary if mdev_register_device() fails? > > In practice it does not seem very likely that userspace can trigger > mdev_device_create() before vfio_ccw_sch_probe() finishes so it should > not be a practical problem. But I would like to understand how synchronization > is supposed to work. > > [Added Dong Jia, maybe he is also able to answer my question.] vfio_ccw_mdev_create() requires that private->state is not VFIO_CCW_STATE_NOT_OPER but vfio_ccw_sch_probe() explicitly sets state to this value before calling vfio_ccw_mdev_reg(), so a create should return -ENODEV if racing with parent registration. Is there something else that I'm missing? Thanks, Alex