Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4340246rwo; Tue, 25 Jul 2023 04:50:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlFECT5DuHneQjMCTFJK0hi4fzJ6Fo+llYp2iavtn50wJTlyLUILpNKDdNrWU0i4JPkXDUbZ X-Received: by 2002:a17:907:7711:b0:987:f6d6:572c with SMTP id kw17-20020a170907771100b00987f6d6572cmr5238780ejc.25.1690285806818; Tue, 25 Jul 2023 04:50:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1690285806; cv=pass; d=google.com; s=arc-20160816; b=Z7Suf9ltxhVOtiAwG71Ii8t4aR7kqk0Y0hFrdicUntOvXFPXTL+BzeNPToGS8EDdBX 8FWhKhk4Vp8/R3TSv+6Ee2VStGnmMLt/kL80aZ+0x8AcOoSya3qTUSXSM89+Ia0LW8Ku 8H0CXNYIkIP2oHoxMwqKwjgtrEWZxhDJVVIBePleMexOElLquDgnhTabPcAYW4ByDATi m883qB+wpU4fxF8w3Kgari/S7xaSJWXkOAIcssSLZvuqMUfVkCJfkMi2MdDFQyXhV5gL PIcVU+6oiASFHL+tD1bhodVvka9u0IJiicjUS4LHNwXaswfcYLaDEJZvdlee1LELbBAV YpUA== 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=0Rq3oo6dG5NtyjCqzeaOhQmL6y9md63CI+T7ceOBsFk=; fh=ZNABukW+04P2RLLF7vAMOIeS2yeRyiT75oMbjQ53F2k=; b=PX98KchWUPDpUtMogkCJnKyvis2LSKSV9NO9WfSx5eEPGfKghZZ5gJsj+P2Rpr7KRk wcjXaXRO71yaBVpRpTbOJwPq+bZDzOgQ+Io691/aHGKXOQ6t/QJ1tRwXNMwR6zEpbOnL 8EjrHnXxBaHS7p91RE/9MGZshxtq5vIP7Z35I45n5IlQOJSCoEVVqKJtY3tzYLI2ukT4 JUIk5WW0K7Qw8aSyQGPwrh44r3Y0dV8NkZUVpNR/MyEZXGT62o6wydsflbuB/3VPPY7d Np2g019/+NbVzJgvvMYA7J7WhpqSPCbEK9Qh1grHPAt3OMaA4TkingOlBdnWUfMguMV4 XEvw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=HWFUg6qd; 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 o7-20020a170906860700b0099302549616si7985636ejx.805.2023.07.25.04.49.42; Tue, 25 Jul 2023 04:50:06 -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=HWFUg6qd; 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 S234921AbjGYLj4 (ORCPT + 99 others); Tue, 25 Jul 2023 07:39:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234881AbjGYLjz (ORCPT ); Tue, 25 Jul 2023 07:39:55 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2074.outbound.protection.outlook.com [40.107.244.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D13E811B; Tue, 25 Jul 2023 04:39:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YHCgUMnwpKaopgL+JwQr/5EvbyV2Urq4aL6ebjzy44BQVvnCgEfn1kcUyK7RFdb3v371QAJ419pNzEJtkvCFREwNgDear3725EPtjRc+rhojl9QWLXpxRfFDhJ1VgcLnPtQ9R3Fvvbr5+S7ZQhdkiVpUnf+TZJDnstgUS6F8uMiLBsjwFGCkWniwCHuyN64wOTqLEyCXjQUJZtBgJWVlXaB6AZQZyJbc1OW9J85fJXCqdwc65nSRkVW5ssN+B0odya4+ISzISdp6ccUOqx3AgSqFBtLYKld/UjBcM7OenTD34Uc2igI9pKn3M9XQwVed2/oSJIc5o48xset6LefoXg== 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=0Rq3oo6dG5NtyjCqzeaOhQmL6y9md63CI+T7ceOBsFk=; b=I19+g6YuzMcyjzLvqXM8uyckmq/qq3xJOjkjJrT2rPOEA8ZsHnHREHGyEFd31LYX8SigpXr82jIpW/lQf7ynZlxlAHLl5F1u720zMvmHr37tGkK08RI7AS9Y3xi2DFb3Qiout65xqeUdY4wh81gpzH2Q1HVl5/g4ttBCIWCVKB2NnUlx+oT8WkJbTfT62mDbtpN5ry93AyvTv/pNzRqy7tpdfWDj+Qa8aVkbqUJF+q21Rbfy8HFgOIQc13hCppRQav9cp52GmOM9kuk9QrAzjFW5WB+Jnd7eCfqX1zQmIid4VoBtIRzKCbxAjqq/K++DFbHu/CMkFPjrqDgjQfHNJw== 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=0Rq3oo6dG5NtyjCqzeaOhQmL6y9md63CI+T7ceOBsFk=; b=HWFUg6qd3/YB6CqUlJAdDdrku2vZozLsFnCuB919yRG7EmZtbQ1DbzJhK6HcjenfMJSb3v9exxHr7DW9gkbS4tHDQHvQUrm2CY+n8/5aJnTTqkiVtjdnvnxt/a7KwEtAxNUaKfBQ2lRcKnst/ZbHTaRrht1L/aLPxkUUXWaQZqCI8oS70chiM+3gBECzLx4XF8m/dP4wFwiTHijb5AdN6MXKRalEWvqHuSjUZ1S6un0U1K0PuHHQO+g7ZOJD9cdoLjhayK1mhlZ4YHjeBtqRtaHDHMgVJDUL0wjbgBLCeVBlBO5Aud5WFEhECCN+HqhC2XRnizqG5tnokC35/R084w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by PH0PR12MB8030.namprd12.prod.outlook.com (2603:10b6:510:28d::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.32; Tue, 25 Jul 2023 11:39:52 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6609.032; Tue, 25 Jul 2023 11:39:52 +0000 Date: Tue, 25 Jul 2023 08:39:51 -0300 From: Jason Gunthorpe To: Benjamin Herrenschmidt Cc: Lorenzo Pieralisi , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, alex.williamson@redhat.com, osamaabb@amazon.com, linux-pci@vger.kernel.org, Clint Sbisa , catalin.marinas@arm.com, maz@kernel.org Subject: Re: VFIO (PCI) and write combine mapping of BARs Message-ID: References: <2838d716b08c78ed24fdd3fe392e21222ee70067.camel@kernel.crashing.org> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: BLAPR03CA0066.namprd03.prod.outlook.com (2603:10b6:208:329::11) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|PH0PR12MB8030:EE_ X-MS-Office365-Filtering-Correlation-Id: ca050d60-a27d-475e-9ac9-08db8d03dc46 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: g4kfOMAUNjHmP+1uJAphXxSAXubL+Wc9hsFKWUwomfYWsokmoM/eRpshwVkalGW9zIuUzG63IpEcjgvnvcsVp6/6sczMuC1i46Dsxxazw4RWXz2cg9TdMC7Ea9Zwi3Q1s8RLtzWgF92X8Hx0jqOw6NHBgkPwjmQUWBHnayKq8xsjg6atqphRaxWbbxDQprma5afM9LdnNFennnZNhf06obWgBSdpWfEr3XcM9ISuny+rtLIy07u/TTSBTLpi90P5WDylXjSy7XVmyqwgkLMJTyn1LzywGnUmQF5yDoIwd0OF4W2Aui/E7IH/lnAaYS91JwwT2I0dHDj+vw2yB/vzz7dgjmutuZoUApAlCrVpVgKIONDG9x2KeRc8niaIpymUeAIgdfGihf14Ni36D9yQrUhSFHFS5FW9CgvG1oyqD9Uc/5vC4im/4zd3N2smqIUjXi8YP68cAMywuSVhalet+LJ/AD4TzXfwGQBRZXD36XbcGR5zrsC6F/jUj0qO+Ddsl6IalczUYzJ2GQdZRErAuJZ6pvMURMoNLq3/hy7q+O989MkzKjY/5pqghUPs3+p4Sa4DWIER+rCBwl735RsHzLejszyIvvTaBR8p0Au1xBY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(346002)(376002)(396003)(136003)(366004)(451199021)(26005)(186003)(6506007)(5660300002)(36756003)(8676002)(8936002)(7416002)(2906002)(2616005)(86362001)(38100700002)(6916009)(4326008)(316002)(66946007)(66556008)(66476007)(478600001)(6512007)(6486002)(41300700001)(54906003)(67856001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?CBcXgRrjIDB4Gppv7rz0tF0WJyBS5v6v2Mair4S3RsUC6wqspUi03n5Czu/R?= =?us-ascii?Q?Lk877nlq9WI1h4m951yA7B+JVSoRDSHXopnSvoYLNwNOpMLtfuXgMIB+4D8O?= =?us-ascii?Q?rY+P8v4mJ93Hrm4S3UsxZaw3PrxoT3WebqRSWIU1wjhtlTMngS60CyDXtoiF?= =?us-ascii?Q?1+JiBx+lIU/z0J0kH9PCL+DgYuAt/lhyPd2llgcxlNs66QoMO6ikVfsVqbxI?= =?us-ascii?Q?MgSm/vFzOHWSzDtJyolc/jxQFHbwkker+lkoMTH7kNMx7ni9wqPhBKffRT5w?= =?us-ascii?Q?CfSS67sfMpAQJqFraDFgE7y0Se+4qEeXcD6/fFXG6xzFCXhAI8rfXnqhE/Tt?= =?us-ascii?Q?j2mw/G9LOQe1St6TNFSKIL8pp4T97LK6bDAI3wUTh7Go9npB4sHQJuvD7ywM?= =?us-ascii?Q?D1tLSBaj7sbHs0NU55PAd0vowaKLj7Ynu5OwAWRvy99XoZZF+h3v/QmSaJWV?= =?us-ascii?Q?Rn/HoBkpy/Nht9fynuj341+IA/afflA1XVrwaJCUDlWOfPG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7h90TpP1KmbSSb3us1pfBFgCqSlGupBe99yF5qU5p1FGRffvkJZ1?= =?us-ascii?Q?Le3LSBL7++8XYqZiiUMRXMbMPZjFA3LivGXfMfX/sUP+LA03ig365DnemrlZ?= =?us-ascii?Q?9qbRPUp6pamZxbdIIGCXGjI3n5AAB28hULuBSkPXgBwgs+vjbCUYkbG9MWHB?= =?us-ascii?Q?X3tqGzN1OH+gmZQI5oOqN1XQwbb3J8JUMYJMaZ5L?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ca050d60-a27d-475e-9ac9-08db8d03dc46 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2023 11:39:52.4458 (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: nxKk3DwDh3suPpYy1D5aLGcqiKAS3ycBERNS90Rp37KgQwBu/x+oyVdq0ayBFMNI X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB8030 X-Spam-Status: No, score=-1.1 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_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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, Jul 25, 2023 at 04:15:39PM +1000, Benjamin Herrenschmidt wrote: > > Assuming this is for #2, I think VFIO has fallen into a bit of a trap > > by allowing userspace to form the mmap offset. I've seen this happen > > in other subsystems too. It seems like a good idea then you realize > > you need more stuff in the mmap space and become sad. > > > > Typically the way out is to covert the mmap offset into a cookie where > > userspace issues some ioctl and then the ioctl returns an opaque mmap > > offset to use. > > > > eg in the vfio context you'd do some 'prepare region for mmap' ioctl > > where you could specify flags. The kernel would encode the flags in > > the cookie and then mmap would do the right thing. Adding more stuff > > is done by enhancing the prepare ioctl. > > > > Legacy mmap offsets are kept working. > > This indeed what I have in mind. IE. VFIO has legacy regions and add-on > regions though the latter is currently only exploited by some drivers > that create their own add-on regions. My proposal is to add an ioctl to > create them from userspace as "children" of an existing driver-provided > region, allowing to set different attributes for mmap. I wouldn't call it children, you are just getting a different mmap cookie for the same region object. > In the current VFIO the implementation is *entirely* in vfio_pci_core > for PCI and entirely in vfio_platform_common.c for platform, so while > the same ioctls could be imagined to create sub-regions, it would have > to be completely implemented twice unless we do a lot of heavy lifting > to move some of that region stuff into common code. The machinery for managing the mmap cookies should be in common code Jason