Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4666823iob; Sun, 8 May 2022 21:13:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLv7FuDGsCI72inLXsMFy1doBunAl14VOCXV/KBQZnzOqrQzocOLzga2c2B0Esmtl1GDAP X-Received: by 2002:a17:902:7e06:b0:159:6c1:ea2b with SMTP id b6-20020a1709027e0600b0015906c1ea2bmr14170373plm.105.1652069630799; Sun, 08 May 2022 21:13:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652069630; cv=none; d=google.com; s=arc-20160816; b=vvON6PgpIdSGTOZt6YB+3Bs7RkMejHWqBsC2ZnI1OslfmkUb/N5013cIvNq89ljwJu 4iJlgAyZEw/Q9FMxbgUe0lfI7+oNCXS+B1cko78rJVH/7xfa2pOKbauIUw2djbkJ0TQM yf36EvlQPQ03zOVtiIJItqJdXNoDH8h4qKDb4WZNMcI0nQ9u8hqGRofr3VVgoojhbRzc ZszSeJd+Yx/H/Z7uHhgAhxomkbUqaWCbqDtM8ZCnO3TO6H+NzC+JSxE0dQ0tlJ7NvI1r 8r7CxmJ41a+wLnvVRlHBI1kxnGSpiTWuQoIfKr1j6VKo/yOtGGkQtauRosgQxJ96H5nW tUXw== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=YraIWaagOO06xPNgZtGKgCndWhzj8vDJW92q5HYE0L4=; b=W1HHQFkgeU01S7poFJ1D9AwZA7KiM2+5zH16zoQ3rbQkNjCJZawhSB2JT+SPvNSQqC O8orAonYj7f1ozqX9qaTvGmEnpxCfNGJjY0hfvxyGAXQiTXP0hpHZCK4gjZhlNVphhHO S36zYAt4xx/AWrlkxmWarglGWCUQ0iuP9mka0hDQf0ruWYVmlbcXpaT62nt/SkiRT95t CvaY25Y40dwYIMQRzXTalEBZbGnIPFy7IirLM4UXFzRt19+RVmSbk2Slv1oZlxIC1lrj m6QCVmyxY9BMWslahfTClMScdY/ZwZltVT3rgfU6oyaZsWDLoV2aS9Sqlwpj/Mjtqg+f gamQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fKVAPckK; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s11-20020a17090302cb00b0015cf377e71esi10357097plk.523.2022.05.08.21.13.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 21:13:50 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fKVAPckK; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8A6FE1053E3; Sun, 8 May 2022 21:11:59 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377604AbiEDTqw (ORCPT + 99 others); Wed, 4 May 2022 15:46:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377597AbiEDTqi (ORCPT ); Wed, 4 May 2022 15:46:38 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 085EB4D9EA for ; Wed, 4 May 2022 12:43:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651693381; 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=YraIWaagOO06xPNgZtGKgCndWhzj8vDJW92q5HYE0L4=; b=fKVAPckK0QFLl5rXpUg8Jwe+m9jch/CiGH6KJ4LaPNleIG6l0ffIBIhopVYxawXHY/h46T FFfxSY3sqN1CHCs/mTxKgFXPaQv62X5ZmvTynqGlHHEE8rIAvgh0x2MuLXWDBtoIhVImcb UZEvY2Z7ARhhWqU7F1uu78reXgdvtmU= Received: from mail-il1-f200.google.com (mail-il1-f200.google.com [209.85.166.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-65-w91mePy3NS6pMBTh0xJ6KQ-1; Wed, 04 May 2022 15:43:00 -0400 X-MC-Unique: w91mePy3NS6pMBTh0xJ6KQ-1 Received: by mail-il1-f200.google.com with SMTP id r20-20020a056e02109400b002cc174742c9so1238024ilj.5 for ; Wed, 04 May 2022 12:42:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:organization:mime-version:content-transfer-encoding; bh=YraIWaagOO06xPNgZtGKgCndWhzj8vDJW92q5HYE0L4=; b=fj5/88n9eQpuUbGPjhOr8TTk0HujRaKf70NSh+KMDAg0ofl2JpLPY5ONDJFPF0ewd1 SBDdsoj0C5rSOpwUBs4qOLtrTne3hMDYpzb5ORXQ4BPnFE+YgRELvrQCsSetZdaw704b gaGrZFF1AQPomJ/bexFyjqa+FpkZ9v2QyBydHgolhTr1ZinyqCcHfKXo98mcG8pRrIb0 JBVL+mvFFhQgf9bho3mL4KNnWwI/gso6c/QDc0iVLZYMOICAspX2unr653ICo8+r2sfq 0hBT72t67qinciE7n7oNgbjVhtPZOqoXdvqgAXJ+0u6dvAW854lmgCcwIgEslWchNegY 3HCQ== X-Gm-Message-State: AOAM530eziVuWf4wNksFI79xPcIAg4WnZJ35zvDo6B9MDejX76qQYMVh SjWETmm0l0Alkx3/97kbCsGnCPSHR8xMToWb64b9J9q6nEi8zeECHZBS21Ouw6/hJPhshE6LImD C45A7+KwriWYWrkLjpsv5/gUy X-Received: by 2002:a05:6638:1487:b0:328:6e36:39e4 with SMTP id j7-20020a056638148700b003286e3639e4mr9226521jak.202.1651693379404; Wed, 04 May 2022 12:42:59 -0700 (PDT) X-Received: by 2002:a05:6638:1487:b0:328:6e36:39e4 with SMTP id j7-20020a056638148700b003286e3639e4mr9226506jak.202.1651693379138; Wed, 04 May 2022 12:42:59 -0700 (PDT) Received: from redhat.com ([38.15.36.239]) by smtp.gmail.com with ESMTPSA id t17-20020a6b0911000000b0065a47e16f61sm3960876ioi.51.2022.05.04.12.42.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 12:42:58 -0700 (PDT) Date: Wed, 4 May 2022 13:42:57 -0600 From: Alex Williamson To: Abhishek Sahu Cc: Cornelia Huck , Yishai Hadas , Jason Gunthorpe , Shameer Kolothum , Kevin Tian , "Rafael J . Wysocki" , Max Gurtovoy , Bjorn Helgaas , , , , Subject: Re: [PATCH v3 6/8] vfio: Invoke runtime PM API for IOCTL request Message-ID: <20220504134257.1ecb245b.alex.williamson@redhat.com> In-Reply-To: <20220425092615.10133-7-abhsahu@nvidia.com> References: <20220425092615.10133-1-abhsahu@nvidia.com> <20220425092615.10133-7-abhsahu@nvidia.com> Organization: Red Hat MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 25 Apr 2022 14:56:13 +0530 Abhishek Sahu wrote: > The vfio/pci driver will have runtime power management support where the > user can put the device low power state and then PCI devices can go into > the D3cold state. If the device is in low power state and user issues any > IOCTL, then the device should be moved out of low power state first. Once > the IOCTL is serviced, then it can go into low power state again. The > runtime PM framework manages this with help of usage count. One option > was to add the runtime PM related API's inside vfio/pci driver but some > IOCTL (like VFIO_DEVICE_FEATURE) can follow a different path and more > IOCTL can be added in the future. Also, the runtime PM will be > added for vfio/pci based drivers variant currently but the other vfio > based drivers can use the same in the future. So, this patch adds the > runtime calls runtime related API in the top level IOCTL function itself. > > For the vfio drivers which do not have runtime power management support > currently, the runtime PM API's won't be invoked. Only for vfio/pci > based drivers currently, the runtime PM API's will be invoked to increment > and decrement the usage count. Taking this usage count incremented while > servicing IOCTL will make sure that user won't put the device into low > power state when any other IOCTL is being serviced in parallel. > > Signed-off-by: Abhishek Sahu > --- > drivers/vfio/vfio.c | 44 +++++++++++++++++++++++++++++++++++++++++--- > 1 file changed, 41 insertions(+), 3 deletions(-) > > diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c > index a4555014bd1e..4e65a127744e 100644 > --- a/drivers/vfio/vfio.c > +++ b/drivers/vfio/vfio.c > @@ -32,6 +32,7 @@ > #include > #include > #include > +#include > #include "vfio.h" > > #define DRIVER_VERSION "0.3" > @@ -1536,6 +1537,30 @@ static const struct file_operations vfio_group_fops = { > .release = vfio_group_fops_release, > }; > > +/* > + * Wrapper around pm_runtime_resume_and_get(). > + * Return 0, if driver power management callbacks are not present i.e. the driver is not Mind the gratuitous long comment line here. > + * using runtime power management. > + * Return 1 upon success, otherwise -errno Changing semantics vs the thing we're wrapping, why not provide a wrapper for the `put` as well to avoid? The only cases where we return zero are just as easy to detect on the other side. > + */ > +static inline int vfio_device_pm_runtime_get(struct device *dev) Given some of Jason's recent series, this should probably just accept a vfio_device. > +{ > +#ifdef CONFIG_PM > + int ret; > + > + if (!dev->driver || !dev->driver->pm) > + return 0; > + > + ret = pm_runtime_resume_and_get(dev); > + if (ret < 0) > + return ret; > + > + return 1; > +#else > + return 0; > +#endif > +} > + > /* > * VFIO Device fd > */ > @@ -1845,15 +1870,28 @@ static long vfio_device_fops_unl_ioctl(struct file *filep, > unsigned int cmd, unsigned long arg) > { > struct vfio_device *device = filep->private_data; > + int pm_ret, ret = 0; > + > + pm_ret = vfio_device_pm_runtime_get(device->dev); > + if (pm_ret < 0) > + return pm_ret; I wonder if we might simply want to mask pm errors behind -EIO, maybe with a rate limited dev_info(). My concern would be that we might mask errnos that userspace has come to expect for certain ioctls. Thanks, Alex > > switch (cmd) { > case VFIO_DEVICE_FEATURE: > - return vfio_ioctl_device_feature(device, (void __user *)arg); > + ret = vfio_ioctl_device_feature(device, (void __user *)arg); > + break; > default: > if (unlikely(!device->ops->ioctl)) > - return -EINVAL; > - return device->ops->ioctl(device, cmd, arg); > + ret = -EINVAL; > + else > + ret = device->ops->ioctl(device, cmd, arg); > + break; > } > + > + if (pm_ret) > + pm_runtime_put(device->dev); > + > + return ret; > } > > static ssize_t vfio_device_fops_read(struct file *filep, char __user *buf,