Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp523959pxb; Thu, 21 Jan 2021 12:54:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJybkLLez998houl1EULVM/mwS6WPTEeTXQ3KLMNOFbd7I3uXqO7OxDRH4LJjLMyZ4RKE+NF X-Received: by 2002:a05:6402:2288:: with SMTP id cw8mr760496edb.161.1611262457438; Thu, 21 Jan 2021 12:54:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611262457; cv=none; d=google.com; s=arc-20160816; b=T4Eo8lUszGrvVH33fiVv3PHNKFUxAA9J9SquTa1iXwBef2ayA2zAfe0iWtXQBQwk43 zx3zQpSq01U1gFTdPadXLYJoYYw0exZ1lnvc4x5FpsWkT/i+6G0McnimWFGMXMXvEnzs 2zr7ZmI235pcNCZIn8wE6qY2nY8UEqk67ebYHIQGrNExjp06RQbp6621BBWBJu4gE4YU 7dgqe8M1excrwuNdGff6nOkcU8ux7ethRvVwWbUvILWuM9f/nZrii8rO5pLWImpxQv+r xQsb/prAW7S9UvmSF1aqugkchbYp1H1iwKTJGz7OGgz4qfLAe2WqJa7zk/uirbBNLqti 43gQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=MtA/rotM7LM+Bn3G3T+jNqr3eNcqPFdB3Dx8FJkKl8I=; b=a+zU74hPegETj0z33Nz/rDfnlrVWFmPM1kfkXSfXlO6EHW9DYXIErrw+8Doq9ds/7o qoCzVDV+PHZwHIagELYvE4Hxowe64p3XoBryh+mJO4Y53U/WOoqcgN4BG1kQhPnyyJiw TXnjbP33/KXDSvG4emtqPcQBOdmhvGDWCIGPNyd2m0zSlW0YgQCN9dwdefhxRhndc+hN bJXPyagdJYmfsRZkTHHs9/XM0Ocg+/ns2EfGCeLe5XygxXBe1DckZtei7Vxm1P05EEmy nbRIlrYtRhKS9fGPz6erZOV57payI7gl+832HQq7iUmnhkpqTRI78sgxBBdG6a655lC4 S+Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=V5LG2mMB; 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 y4si2828176edw.240.2021.01.21.12.53.52; Thu, 21 Jan 2021 12:54:17 -0800 (PST) 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=V5LG2mMB; 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 S1726644AbhAUUvy (ORCPT + 99 others); Thu, 21 Jan 2021 15:51:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48468 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725779AbhAUUvx (ORCPT ); Thu, 21 Jan 2021 15:51:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611262226; 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=MtA/rotM7LM+Bn3G3T+jNqr3eNcqPFdB3Dx8FJkKl8I=; b=V5LG2mMBvO2PyQjJJzFNVcfZUc8JQL/54TJ3rfdwtP1xBePzUVYpqHPCS2ITY6UzegmuUt Dk/Zb8c2GZi9Nc04o5zV6/n1AiQrN/q98LeZo5yj3SkMHsaIMVMIpBkpBdlLHnbSKepuXL jVUionR/T4/cSHg8Q3R0MxIl9SYGifE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-7-Sl9xzLQdMp-zP7fumoqVkA-1; Thu, 21 Jan 2021 15:50:24 -0500 X-MC-Unique: Sl9xzLQdMp-zP7fumoqVkA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5B5C6800D55; Thu, 21 Jan 2021 20:50:22 +0000 (UTC) Received: from omen.home.shazbot.org (ovpn-112-255.phx2.redhat.com [10.3.112.255]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2CEF61F55; Thu, 21 Jan 2021 20:50:21 +0000 (UTC) Date: Thu, 21 Jan 2021 13:50:21 -0700 From: Alex Williamson To: Niklas Schnelle Cc: Matthew Rosato , cohuck@redhat.com, pmorel@linux.ibm.com, borntraeger@de.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, gerald.schaefer@linux.ibm.com, linux-s390@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 4/4] vfio-pci/zdev: Introduce the zPCI I/O vfio region Message-ID: <20210121135021.0eb7e873@omen.home.shazbot.org> In-Reply-To: <90d99da8-02cf-e051-314b-2ab192f8fd57@linux.ibm.com> References: <1611086550-32765-1-git-send-email-mjrosato@linux.ibm.com> <1611086550-32765-5-git-send-email-mjrosato@linux.ibm.com> <90d99da8-02cf-e051-314b-2ab192f8fd57@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 20 Jan 2021 14:21:59 +0100 Niklas Schnelle wrote: > On 1/19/21 9:02 PM, Matthew Rosato wrote: > > Some s390 PCI devices (e.g. ISM) perform I/O operations that have very > .. snip ... > > + > > +static size_t vfio_pci_zdev_io_rw(struct vfio_pci_device *vdev, > > + char __user *buf, size_t count, > > + loff_t *ppos, bool iswrite) > > +{ > ... snip ... > > + /* > > + * For now, the largest allowed block I/O is advertised as PAGE_SIZE, > > + * and cannot exceed a page boundary - so a single page is enough. The > > + * guest should have validated this but let's double-check that the > > + * request will not cross a page boundary. > > + */ > > + if (((region->req.gaddr & ~PAGE_MASK) > > + + region->req.len - 1) & PAGE_MASK) { > > + return -EIO; > > + } > > + > > + mutex_lock(&zdev->lock); > > I plan on using the zdev->lock for preventing concurrent zPCI devices > removal/configuration state changes between zPCI availability/error > events and enable_slot()/disable_slot() and /sys/bus/pci/devices//recover. > > With that use in place using it here causes a deadlock when doing > "echo 0 > /sys/bus/pci/slots//power from the host for an ISM device > attached to a guest. > > This is because the (soft) hot unplug will cause vfio to notify QEMU, which > sends a deconfiguration request to the guest, which then tries to > gracefully shutdown the device. During that shutdown the device will > be accessed, running into this code path which then blocks on > the lock held by the disable_slot() code which waits on vfio > releasing the device. > > Alex may correct me if I'm wrong but I think instead vfio should > be holding the PCI device lock via pci_device_lock(pdev). There be dragons in device_lock, which is why we have all the crude try-lock semantics in reset paths. Don't use it trivially. Device lock is not necessary here otherwise, the device is bound to a driver and has an open userspace file descriptor through which the user is performing this access. The device can't be removed without unbinding the driver, which can't happen while the user still has open files to it. Thanks, Alex