Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp579577imm; Wed, 23 May 2018 01:57:25 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoBOp5kmxRUpZpkWfGwBRBIYtkNIFzf6+WYxRTsl55T/vBifYBxyOHch97nMH82hVpw8V+Z X-Received: by 2002:a63:734f:: with SMTP id d15-v6mr1650006pgn.149.1527065845823; Wed, 23 May 2018 01:57:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527065845; cv=none; d=google.com; s=arc-20160816; b=KhgsTFdjbI6QGT5wC61RGOYBk60/wt6socvMNj37YCHOTNyUxbteE2IdJjkVDlcXDQ b7iK8FmDLlFgc9KO2ve0mIs6RJH/7FnGpkIYHtUGZdS3GCTXI6UBtWTX27dUUCVfwmZm evSU4GIc9pOyQiO9T4oA//Htk/K3NkfvpT0ZjSyp5dy+Q67wKk1IoizE3mDR0d1My+eb U7AzhxdRTCTK9HtKZiIimxSREIHIvp0KotQufClqsJ9AblP0LlM1S8Hzc4MfOzjlTi6F wS1JNTe9+g1wE1TY6kZD9vIVrJ2QjVCG1bWBqh5deSb23hi0shrY6fn7PQiEkabfyVEZ mLfg== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:arc-authentication-results; bh=0C3M0r92o2m2Wo/406TRPBl9pSLsfee0tbt0qdlQmuA=; b=O6B/Wmb95mRCsE70X+2pOoOWS7HmeCZbT+ozO/MAhaDHr6tsvQMU5c9wNXgeSP2Nun 8YJfSYbdngz0wm91ihHPwQ34Lyss5C6j1TBivzvKmF2i7/uL9H3CQ39jdDm2AqsIHkLJ XAINJ0xNiAqQAAGvMyTXlAI2bTqnygBz7cVk4PUIECk/isd9yf/HpL+CnQkM1xhGytiN o+bVtbg/9Zmbx5MJhy0Cs1amfo4USkCPQA3srpZs8L2ENAplUNONAmvk/op5nBk9Yqkq n7vo9l+9Tn0mVyq5nREDg6ibS2XIPafMqFIqDItgGKYeVrny3FRPxZCs601ctBCWfpqn iLkg== 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 e84-v6si18512417pfk.198.2018.05.23.01.57.11; Wed, 23 May 2018 01:57:25 -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 S1754513AbeEWI4x (ORCPT + 99 others); Wed, 23 May 2018 04:56:53 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49362 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754273AbeEWI4s (ORCPT ); Wed, 23 May 2018 04:56:48 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F42174023826; Wed, 23 May 2018 08:56:47 +0000 (UTC) Received: from gondolin (ovpn-117-30.ams2.redhat.com [10.36.117.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 737701117645; Wed, 23 May 2018 08:56:44 +0000 (UTC) Date: Wed, 23 May 2018 10:56:41 +0200 From: Cornelia Huck To: Alex Williamson Cc: Halil Pasic , kwankhede@nvidia.com, Dong Jia , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 0/2] vfio/mdev: Device namespace protection Message-ID: <20180523105641.0d89701b.cohuck@redhat.com> In-Reply-To: <20180522123829.4e758646@w520.home> References: <20180518190145.3187.7620.stgit@gimli.home> <20180522123829.4e758646@w520.home> Organization: Red Hat GmbH MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 23 May 2018 08:56:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 23 May 2018 08:56:48 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'cohuck@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 22 May 2018 12:38:29 -0600 Alex Williamson wrote: > 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 No, I think your understanding is correct. We move the state from NOT_OPER to STANDBY only after we're set up completely, so our create callback will simply fail early with -ENODEV. This looks fine to me.