Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1279515imm; Tue, 22 May 2018 01:14:28 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpsf6Npi9vq56XkQkiz+HT2iYQSyOt4yXZNQnPry8V0CpGaICU3yC0GGLplUng9ouG+Hujq X-Received: by 2002:a62:9fca:: with SMTP id v71-v6mr23190255pfk.233.1526976868375; Tue, 22 May 2018 01:14:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526976868; cv=none; d=google.com; s=arc-20160816; b=TvIj3cpQ6u8VCJZXydf5r5HbS7XkTvE8DjgR9aCi3eKtKItVZaY4onvFwKspTArYFj nHXijb9Sk4JARfbFdG3fhLiaQVsYj106FJEIjq5FzXJ8OGLrluMe/rT+A/a/H5N+9oXo S5aFrFC7vruc3z5aaVHy8Zp7yTlBhDBBq2HlWndVtGHN01f7qigAnFxM7qSWxjKYq7u4 8JYzzNmEesaqxIYIRS8aslAHhCZgAI5I1Anp5B7/SsJwXp4kfW5BjG9OqHSilDhsezsh FAc11BJ44oPcd/nqxq5MPgZJPMg8mgBeoMFADN+ZjIBLzktdkVTs2bo5jGjMxvth9yHp XIqA== 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=xQrQBRw/azauPYCIbA7aqTmFqguDBcTLNApuymcFzqk=; b=JbRl5XmFGuti411SxWwn2cvKvJllZGkxHxEg/czO3qquoNiNw8pA8OJpL2PhL4ZyyK i9LpZzIvKEYua+/mBXUTJd72E5qPRj757WPrUsfrMUHbsXKpcE2+yFkr6C6kNWiZKVDo kVII/zJGNmyhT84RVjPAU6CdRXAHQQq2uYG4lN6K5S/Cz2bG0MWEWluzV0vyuGr2TsJe hg85qx2MRtT1sfLrtPzsjzMxjqjU6kpqDAMxp5M8J1LaiDsUBuWfedUDpNquQUcdvIj0 g5h/ROOKo5NxqWfSQ+xnweJ9OlwjLdcRdTNMr2P0pegms1yphPmy19pSgpwUQSivSnuU VCyA== 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 v10-v6si16699957plz.190.2018.05.22.01.14.13; Tue, 22 May 2018 01:14:28 -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 S1751324AbeEVINy (ORCPT + 99 others); Tue, 22 May 2018 04:13:54 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40382 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751024AbeEVINw (ORCPT ); Tue, 22 May 2018 04:13:52 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 79DD57D85E; Tue, 22 May 2018 08:13:51 +0000 (UTC) Received: from gondolin (dhcp-192-222.str.redhat.com [10.33.192.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 993116B581; Tue, 22 May 2018 08:13:48 +0000 (UTC) Date: Tue, 22 May 2018 10:13:46 +0200 From: Cornelia Huck To: Alex Williamson Cc: kwankhede@nvidia.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, pasic@linux.ibm.com Subject: Re: [PATCH v4 1/2] vfio/mdev: Check globally for duplicate devices Message-ID: <20180522101346.3442e1af.cohuck@redhat.com> In-Reply-To: <20180518191025.3187.29141.stgit@gimli.home> References: <20180518190145.3187.7620.stgit@gimli.home> <20180518191025.3187.29141.stgit@gimli.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.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 22 May 2018 08:13:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 22 May 2018 08:13:51 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 Fri, 18 May 2018 13:10:25 -0600 Alex Williamson wrote: > When we create an mdev device, we check for duplicates against the > parent device and return -EEXIST if found, but the mdev device > namespace is global since we'll link all devices from the bus. We do > catch this later in sysfs_do_create_link_sd() to return -EEXIST, but > with it comes a kernel warning and stack trace for trying to create > duplicate sysfs links, which makes it an undesirable response. > > Therefore we should really be looking for duplicates across all mdev > parent devices, or as implemented here, against our mdev device list. > Using mdev_list to prevent duplicates means that we can remove > mdev_parent.lock, but in order not to serialize mdev device creation > and removal globally, we add mdev_device.active which allows UUIDs to > be reserved such that we can drop the mdev_list_lock before the mdev > device is fully in place. > > Two behavioral notes; first, mdev_parent.lock had the side-effect of > serializing mdev create and remove ops per parent device. This was > an implementation detail, not an intentional guarantee provided to > the mdev vendor drivers. Vendor drivers can trivially provide this > serialization internally if necessary. Second, review comments note > the new -EAGAIN behavior when the device, and in particular the remove > attribute, becomes visible in sysfs. If a remove is triggered prior > to completion of mdev_device_create() the user will see a -EAGAIN > error. While the errno is different, receiving an error during this > period is not, the previous implementation returned -ENODEV for the > same condition. Furthermore, the consistency to the user is improved > in the case where mdev_device_remove_ops() returns error. Previously > concurrent calls to mdev_device_remove() could see the device > disappear with -ENODEV and return in the case of error. Now a user > would see -EAGAIN while the device is in this transitory state. > > Signed-off-by: Alex Williamson > --- > Documentation/vfio-mediated-device.txt | 5 ++ > drivers/vfio/mdev/mdev_core.c | 102 +++++++++++--------------------- > drivers/vfio/mdev/mdev_private.h | 2 - > 3 files changed, 42 insertions(+), 67 deletions(-) Reviewed-by: Cornelia Huck I think it is better to deal with any possible vendor driver implications on top of this (I still believe that vfio-ccw is fine).