Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp132659ioo; Wed, 25 May 2022 23:23:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZPVgkno2nHVxd/BAnWgK7/4MdmFFQ7UDOn3sCnafbXk6ef0BNIAuyH/YsgYN8fiQyCa8s X-Received: by 2002:a17:907:3fa2:b0:6fe:d043:3fd1 with SMTP id hr34-20020a1709073fa200b006fed0433fd1mr18493304ejc.700.1653546228952; Wed, 25 May 2022 23:23:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1653546228; cv=pass; d=google.com; s=arc-20160816; b=ULa6LwWKYf/LM0eXDnXMIO+o7hbP3ANh+4lxzIXdqbXYa2TeptonDNogBASAe2MYzq s01JMkHqD0juHtZDQ6xfxHkvGm7syDjDKd3YZL7Q+nd3PV9yy+Rnz1znXS1ftCaoqGfu RnfvXjDp/bPkJU6XvtDbxMMFCP0nLS0JYwYxJ9BIbn2Scs6ZKDp5yaZRVsJ7rQSDmQTV 0/jEtXtYYA3UD9hRXNjPlMCfe5YYF+tnY4NbWvqqXDsx+/jP/Ah9zFIIfayFVNBA/PtH XnzxMa0unsyq3ynIKgp49DZzuGzuBycNlbb4FYbk5AUH05rB5lRiKadKGEvWi/NYWVrc FeYQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:in-reply-to:content-disposition :references:message-id:subject:cc:to:from:date:dkim-signature; bh=aeRNnXTazBsLlfXDKYpe5iuwgRHbkxLQ+nvMcQDvtOg=; b=Bfh02NWcRs1WdbxsP+wb2lGDihr8SqPp7FDuoQv67IgWyWrvdmpNPtzIO9M4HDmxaU xylgp4aGGyEA9J1F7xY1To4AzX6T3HsEg1LzUoHV9fSuSX8ZKPEmhePddsK6ZcxTgDWV OfnYx/tZvwCE3mj/4DSXgZx9uCIuz+bsXUMhofcdz/CWF+w7kV60Nzzq3ZyahOMjsYqV UWYjomQjnJmKjVLeM9z2+wHD8Nyf77b5uj43vz2jxGsrbPlsnZqONSpD5fvJHt/B0AK6 OJj1zHqCUff0wkPuNRcMdUqXeMrLEsgrWvEeV8yJ7nfEkhxwVYSeISTc7zILoAnGqRM8 Fh2A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=DoyXQ66o; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sc5-20020a1709078a0500b006feb6ce49c9si760510ejc.935.2022.05.25.23.23.21; Wed, 25 May 2022 23:23:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=DoyXQ66o; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241859AbiEXVIX (ORCPT + 99 others); Tue, 24 May 2022 17:08:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241787AbiEXVIV (ORCPT ); Tue, 24 May 2022 17:08:21 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2081.outbound.protection.outlook.com [40.107.236.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31FCB3DDF9; Tue, 24 May 2022 14:08:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J4KopruvZ5F+27OWdlDsi9d0hTKLfZ1DwBkZHO6XnvQW9bsb/iUENZlGGjBPlaimdvb99i0f92aqmCZ4nB57oF0weER/ZOU39tX1O0zFeTBkUYa2uLyjBqtfvvu21LVdUwjIf21IKlzy4tQk34pKt8kNvf/BFb+gFRE9T+JYWnjbUxDBjJmImJJwYqsMK2ih1J2pusL7s/GziwyX0KU5kKGMAp8jvzOlrl7et68F4FskXrwAj/vCNYEapOj3ieSk9Z3C3dioab2SazPXit2f3pl98WETEcK+EnCiuQ08GgcwkVbU0QwuFv6QSIEqit2yD925x37U5tVKKu1KNfzjeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aeRNnXTazBsLlfXDKYpe5iuwgRHbkxLQ+nvMcQDvtOg=; b=YdVyU48//lv3miKMzOTBi6ZRRQcz2hfz/WaNHGaps7zTdXzMemj952VpO93TaaoEltRo5ftRhAwLHhpWm7AQEOnPeVdw+IQbey9vyN5+tQ4dt7y4GZypQ+9poGkoFbq3uiMZqPAroLAVwsxOJOcxncLo3wDnCetprq8SnTAUZolDHS0cMmW4qWTXXcSpyH9PcZH0z44xmpuD3XcvOxoxzrahvepNgI0zYCG2jBbuL0l0tn5BGKGu0DEx8+RHAX5t2YmoyQXZioxzzlQaNB0eEn8UKBmwXUCFT9pe59Gn1yinSxZFJhUdKfeTK+mmVffusbosV1USlhMwGfq1KQwt8g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aeRNnXTazBsLlfXDKYpe5iuwgRHbkxLQ+nvMcQDvtOg=; b=DoyXQ66o+j4759zPF2NTP9aBbEZuKcbmrqM9W63nynr9goZWTXo7e1nHldf/TRilyS2rph1UCLl5HRl02A8+h2JvB90WBz26dDxGZwr80SD4kDAPVUW7jEmOFJzZYM9ce7aM+2Delpbfd9rmzwy0Wyt2aLUV0DjVDcPl7Hm7xM/gH/9ExXL+aenD3NjpszzbLjx9proo4W5wy/7qx9RbfRmqKeuFvzbswNHYLFKr2KObXwWqD/66ovAj4W13K0tCrs6UPyFl+8Owu0Ty76EQtw4bN1D5m+dv/8q/qDuQGUNIiv0FCxHIRkUPh7GP8edS5SAh1wlFBaASCmRNDoamLw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) by BN6PR1201MB0100.namprd12.prod.outlook.com (2603:10b6:405:59::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.17; Tue, 24 May 2022 21:08:17 +0000 Received: from MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::2484:51da:d56f:f1a5]) by MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::2484:51da:d56f:f1a5%7]) with mapi id 15.20.5293.013; Tue, 24 May 2022 21:08:17 +0000 Date: Tue, 24 May 2022 18:08:15 -0300 From: Jason Gunthorpe To: Matthew Rosato Cc: linux-s390@vger.kernel.org, alex.williamson@redhat.com, cohuck@redhat.com, schnelle@linux.ibm.com, farman@linux.ibm.com, pmorel@linux.ibm.com, borntraeger@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, gerald.schaefer@linux.ibm.com, agordeev@linux.ibm.com, svens@linux.ibm.com, frankja@linux.ibm.com, david@redhat.com, imbrenda@linux.ibm.com, vneethv@linux.ibm.com, oberpar@linux.ibm.com, freude@linux.ibm.com, thuth@redhat.com, pasic@linux.ibm.com, pbonzini@redhat.com, corbet@lwn.net, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: Re: [PATCH v8 17/22] vfio-pci/zdev: add open/close device hooks Message-ID: <20220524210815.GB1343366@nvidia.com> References: <20220524185907.140285-1-mjrosato@linux.ibm.com> <20220524185907.140285-18-mjrosato@linux.ibm.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220524185907.140285-18-mjrosato@linux.ibm.com> X-ClientProxiedBy: BL1PR13CA0438.namprd13.prod.outlook.com (2603:10b6:208:2c3::23) To MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8b23888e-f848-425e-c439-08da3dc985eb X-MS-TrafficTypeDiagnostic: BN6PR1201MB0100:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sItI+OmaqXnNi2A5z4C9we0tvTRNSy/VODd1bdhHrw1GgNunaiKa5IOZbPH2vpCuDyvrRjqDMFHIBgkEENmojbwVjabeqlKyzXosUI+lPgsLdUQ102V9zVNZ1WnN3h49GX3/oTkvoD0efP6/yHiUpYJsYn6VJszqf+DBqNrtlg3pLlD2ULTpjblk0seVCK9ery3TObs7qikTt/umHco4HXuhNEMJL/Cx907OIKXngZHUNizB0rsYV78JLknGAERvMwhZFmEb92USYulLyzdeQGUyqD5c8w6Zbmt/mb3aA1LyQPbyxmtCwfSANhAjwBF1WL4ykhQSv/HylyQCdacJi1BjSo8BwRx2gC8lFtza3pHFxR5XBPRaV1Ub1ZSkpPI6owoR8cPPY58bAVboP7WAghmHnxop3M8YaO9M2uHy7XDPfhByUnWEw06PTAdJ6fS2o7ZjKVCv7tYmMAU+PMwcObUwzT5P4Z6w4B4q8Ecpzs+nAq3oRqCe/KpV2jyjsF1+Xsogum+8eVDRfoG07Px2U9BIzoXk4c3mYz0CgHMfEoj6fc2cA+OtmlK55PRaoqcuCo+sNadBPF/MgUVhtIjp0O1n4dnl5mKoDbRZgfhtNmggtZyeFIIWJD3AKHsv8X4w6gwyzJswoTAxlDJ2oWCxjQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR12MB4192.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(2616005)(8936002)(6486002)(1076003)(6512007)(26005)(86362001)(2906002)(6506007)(66476007)(33656002)(7416002)(508600001)(5660300002)(186003)(38100700002)(83380400001)(36756003)(66556008)(6916009)(4326008)(66946007)(316002)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?9h3Remy3aRyettyY/wHDmL1h8Tnw9WcH98+tu0qxPh10Nn9gNuoDsZ4kH/rz?= =?us-ascii?Q?YCQyR2yFjJWlqfev2cvBlSManSPnKPts5f0imoAal3x7GdgJlVVq0z96WGMm?= =?us-ascii?Q?EXxHwwkdGUW0hnWfwz2SEMRwklQMTv+z5tw6+4m6DSjFbMF2JOHcWCMfMT8Q?= =?us-ascii?Q?lQLwJyC2gHCTIZKTgN+HQ5WJ1CL5QMY/jBkA6ubhf5aHopWhhEBevvXR5H2H?= =?us-ascii?Q?4sAIpQne4w4WEz2egqHNjQvLMa8ENDnT22Q6TE9lPQvK2WM4bIvDc9g5YAyT?= =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jFbxKg7l8ZeHxysHWz/InXAGm+6GBrjQ2?= =?us-ascii?Q?eATe8iEm+QD8QBo77VpiF8WRmhFLI2phOumQbpRxxynRCXjoHGDnTd3S62DY?= =?us-ascii?Q?0hA6SBECxKaGSAHQZvK704oD02jBpI2NfDOH7igHKB1wcsN5w4wVOHTTLt2J?= =?us-ascii?Q?w5x8kRCfKh4LHF7cOUN4nk5/d2ig+PAG8m5pLIphMECmXD5CSUUh/mMva7Nv?= =?us-ascii?Q?ABxNeLehOe9HOIdWYHMaNNFEhjJ2LujtcBYc1sqsn1xPsCXS4Rt8OyAAXT2B?= =?us-ascii?Q?9RjL+OFlRnLmEdewy1poShrMYqIOvexbc2qmJ/vab4Oy6IRJoDbB3qozeDUk?= =?us-ascii?Q?BG0irrEakZSJwMB6sRdDUyPgjpnKTBmEi2JDyDHpRcCBykZA8aHk6ecih8M/?= =?us-ascii?Q?GxRMA1fxuk7IloNReGKOsIZ571JsjuE3E3ryRAYfFqR6AQpfSrAV8ZjahJ4p?= =?us-ascii?Q?7Q61G9md+ODcW63GvwPCg82JHzI85Y9W5Rwvc+cFitvOfyGeJooXwV/4ngxf?= =?us-ascii?Q?aKOY8nz+Kf0NyL0+Yp98jsJkQKFjTWpfKAcQstSWlILhZMxUA1Cq5D0aJriN?= =?us-ascii?Q?/Bm+q3w+uQ=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8b23888e-f848-425e-c439-08da3dc985eb X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4192.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2022 21:08:17.3387 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xEXuXPd60kGGE2yrgX8aWbhykT9WcKMg/fZv6bCynDJ1juj0mWNR5VNADF6TaqZD X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1201MB0100 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no 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 Tue, May 24, 2022 at 02:59:02PM -0400, Matthew Rosato wrote: > During vfio-pci open_device, pass the KVM associated with the vfio group > (if one exists). This is needed in order to pass a special indicator > (GISA) to firmware to allow zPCI interpretation facilities to be used > for only the specific KVM associated with the vfio-pci device. During > vfio-pci close_device, unregister the notifier. > > Signed-off-by: Matthew Rosato > arch/s390/include/asm/pci.h | 2 ++ > drivers/vfio/pci/vfio_pci_core.c | 11 ++++++++++- > drivers/vfio/pci/vfio_pci_zdev.c | 27 +++++++++++++++++++++++++++ > include/linux/vfio_pci_core.h | 12 ++++++++++++ > 4 files changed, 51 insertions(+), 1 deletion(-) > > diff --git a/arch/s390/include/asm/pci.h b/arch/s390/include/asm/pci.h > index 85eb0ef9d4c3..67fbce1ea0c9 100644 > +++ b/arch/s390/include/asm/pci.h > @@ -5,6 +5,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -195,6 +196,7 @@ struct zpci_dev { > struct s390_domain *s390_domain; /* s390 IOMMU domain data */ > struct kvm_zdev *kzdev; > struct mutex kzdev_lock; > + struct notifier_block nb; /* vfio notifications */ This is obsolete now right? Same for the #include ? > @@ -418,6 +424,9 @@ void vfio_pci_core_disable(struct vfio_pci_core_device *vdev) > > vdev->needs_reset = true; > > + if (vfio_pci_zdev_release(vdev)) > + pci_info(pdev, "%s: Couldn't restore zPCI state\n", __func__); > + > /* > * If we have saved state, restore it. If we can reset the device, > * even better. Resetting with current state seems better than > diff --git a/drivers/vfio/pci/vfio_pci_zdev.c b/drivers/vfio/pci/vfio_pci_zdev.c > index ea4c0d2b0663..d0df85c8b204 100644 > +++ b/drivers/vfio/pci/vfio_pci_zdev.c > @@ -11,6 +11,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -136,3 +137,29 @@ int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev, > > return ret; > } > + > +int vfio_pci_zdev_open(struct vfio_pci_core_device *vdev) > +{ > + struct zpci_dev *zdev = to_zpci(vdev->pdev); > + > + if (!zdev) > + return -ENODEV; > + > + if (!vdev->vdev.kvm) > + return 0; > + > + return kvm_s390_pci_register_kvm(zdev, vdev->vdev.kvm); > +} > + > +int vfio_pci_zdev_release(struct vfio_pci_core_device *vdev) > +{ > + struct zpci_dev *zdev = to_zpci(vdev->pdev); Keeping these functions named open_device/close_device wouuld probably be clearer > + if (!zdev) > + return -ENODEV; > + > + if (!vdev->vdev.kvm) > + return 0; > + > + return kvm_s390_pci_unregister_kvm(zdev); > +} Again this cannot fail, you should make it return void, not ignore the failure - or at least push the ignoring the failure down to the place that is causing this. Otherwise it looks fine to me, thanks Jason