Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1287675pxj; Fri, 4 Jun 2021 10:24:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwV+F1ul2oZzdwiqaTLFx8CswSP3RpBboMF1U2aVrtee2YzsVeTe03LiSVG3pmFrQ26KG5r X-Received: by 2002:a17:906:4f91:: with SMTP id o17mr5215178eju.219.1622827475777; Fri, 04 Jun 2021 10:24:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1622827475; cv=pass; d=google.com; s=arc-20160816; b=M1J8UTuFU5DY6nRRpZvFcJFvC9mvxJZfPXq3cOtx8D2+jm4RB7jveVIghDPZLonwWK pq86uWo54XlEbI/LG87csxtqsSZVaVwKmVnf5x1WlvdPjMRO/TL+5wGL5x6HPVIYv4Ku JOIHWUijOpnAsfx0CZ/quXhndtHesSEwedpw4egAS29gvUtNYpQwovt0+3rbbrtHK6Wl J2AV1g6oikoLZquVgNHGuqCZLx+0ongZfL2hw9U13Et8pIqhDSAwsF5jFn8udGFTgC7W Eywj73y+6ox1t/3VEdFnA1Ee5mszwl3D1P5SIoroNrda/24/+5kCAZTiSdJztpU+EezB X2OA== 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=rCyH/0zz9hxT6Ak2VCMJeBgWPNLqosG0jZISCbP6zrM=; b=xa4bOcOJmS4iToZuUx+7lUf1JJ/TRKk9LzAR39wNVt06PbeMocm/v7dVKaVJlXvR+l a/YepjFnH7ovDUBSBVa9R5WUCm9UsELhv/FwfcPp2RqNdpMy2wo+fTqNBZ7N2djPieUM v5KcYthZi4EL9e6N9WlA+d1BbmlfYXL4xU6dSd+XBwNjlLi/cOuq2PTBH4SkCV09d+jv X6dvvC3R+o++scf7JbpHDGcO2k+bnNteyURYzAiVe6QEu+4I6RqH4ZQfGo1Rq01SjUUY P5WEQ+0OUf7wYBI4dxCG0m8I/9erjLF8y3WkD52hv702v4GimPhsgNfSp7HHhrFSKHts FxzQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=ER4YCcqm; 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 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=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l6si5019575edt.207.2021.06.04.10.24.07; Fri, 04 Jun 2021 10:24:35 -0700 (PDT) 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=@Nvidia.com header.s=selector2 header.b=ER4YCcqm; 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 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=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230353AbhFDRX5 (ORCPT + 99 others); Fri, 4 Jun 2021 13:23:57 -0400 Received: from mail-bn8nam11on2058.outbound.protection.outlook.com ([40.107.236.58]:4449 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229675AbhFDRX4 (ORCPT ); Fri, 4 Jun 2021 13:23:56 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OivIECnRZx7L5hidVPuI7O6IJbsJm6uTISf00auvCTnFVboxn8Hb5Z2I7r/L4RYtEKf8PXlTuVSU+pb1/h498E7VWT+pddSG1BP7vZl+UkxPp2lx1pWSPAiQTaDUCdeT3RqYnh8lz8X8GfCRyIk6uOAloGjLhD9An8Xo9tqIPsspLyoiz+bcxYPf78GnX+PVY4HiGHmApwn75yhMQ96rHteIkfskcnZxuOy29v4z6Zk1H7EVnrsM00FWb0I4XBjJvWtJ8FHJ88mlSLXIZwBS3CWDFGeiNnocgdPz6n6mgRv+Jjszfzcw3/zrcHTgR1KG4ogavY1k4Ucie3QlXwjGfQ== 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-SenderADCheck; bh=rCyH/0zz9hxT6Ak2VCMJeBgWPNLqosG0jZISCbP6zrM=; b=BNnmCRPLPbFMdsmYdT7lwAkGADD+KWlZmGQ4/sawHxp76iPP2ASOt+Yyh3mig9vjW/RaJwI2yI2InAoAy1h8+JYJDhdrV/hDlzHe76hpT0ufvPhbpZI7Wj5MllMcZ/4rzoD1iXDsQNspZ7uvMX/22xq/gCspvsOTiIsjrjzGlZdHT++byzGH2Ib/O6m/f5mhc8DBdsPboU96UX2AuERneg0J+NkOhO8TsQ6ApPe1HPqi6vQIxL1WuvLD/yn3fX9LqPuxIVsaIBus9uQzRNI4mLlUFiCn1lTEMna/MVRABqUrMtHcgaGjkwZThAXzo6wjqYuUmkgKJU8g4pIgd+6MtQ== 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=rCyH/0zz9hxT6Ak2VCMJeBgWPNLqosG0jZISCbP6zrM=; b=ER4YCcqmCGB//UVvFgH2l2ZCArSw/nZ7CWT4lSvUSwyVG3f7IwAzGlaMJazxzaDQuwuYR6HvRFOgrnRrT8c7yKUhvv9ZMfaE+zQ0phZNBTF2eDJmCNp7B76n/ljifJc5+cHwCl+6O07YMydmFTMF7uEUZQhStkDDX9JR/AzZ96uOCtsODsoPV24is0s23XJrz6wEWh+K667n/P2dcL2/kfA186iLNtmea0FSf/RqKnHDKJOUWmN8FdMwhDTCf+X3qU8jAwOiubFGDGB959OfLp5KAKhkYpSipmrpIdhWLJNpmCc5rswYP2ZICWMEJ9tnXxBXmuPs7nTKn2/jbMO5Tg== Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL1PR12MB5269.namprd12.prod.outlook.com (2603:10b6:208:30b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.22; Fri, 4 Jun 2021 17:22:08 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e%6]) with mapi id 15.20.4195.024; Fri, 4 Jun 2021 17:22:08 +0000 Date: Fri, 4 Jun 2021 14:22:07 -0300 From: Jason Gunthorpe To: Paolo Bonzini Cc: Alex Williamson , "Tian, Kevin" , Jean-Philippe Brucker , "Jiang, Dave" , "Raj, Ashok" , "kvm@vger.kernel.org" , Jonathan Corbet , Robin Murphy , LKML , "iommu@lists.linux-foundation.org" , David Gibson , Kirti Wankhede , David Woodhouse , Jason Wang Subject: Re: [RFC] /dev/ioasid uAPI proposal Message-ID: <20210604172207.GT1002214@nvidia.com> References: <20210603201018.GF1002214@nvidia.com> <20210603154407.6fe33880.alex.williamson@redhat.com> <20210604122830.GK1002214@nvidia.com> <20210604092620.16aaf5db.alex.williamson@redhat.com> <815fd392-0870-f410-cbac-859070df1b83@redhat.com> <20210604155016.GR1002214@nvidia.com> <30e5c597-b31c-56de-c75e-950c91947d8f@redhat.com> <20210604160336.GA414156@nvidia.com> <2c62b5c7-582a-c710-0436-4ac5e8fd8b39@redhat.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2c62b5c7-582a-c710-0436-4ac5e8fd8b39@redhat.com> X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: BL0PR02CA0057.namprd02.prod.outlook.com (2603:10b6:207:3d::34) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by BL0PR02CA0057.namprd02.prod.outlook.com (2603:10b6:207:3d::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.21 via Frontend Transport; Fri, 4 Jun 2021 17:22:08 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lpDWJ-001liB-Jt; Fri, 04 Jun 2021 14:22:07 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 620ee070-9405-4a52-71ee-08d9277d483c X-MS-TrafficTypeDiagnostic: BL1PR12MB5269: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0mnauDbJ6KnVnuCWGbJlELLI3isnWntFp5RexKKdyI/fZAnBVR1TY75/ppVRxKw7RWu+tJNz11AtYKBOAvMtjDhtgB6E/b0cURPvBQ8rgfzyfiLic6bvUP4M9vtYe5VTLO1A94hJLm9jnA6gODV7iwMgQPb8cquGQNHRqop3jTtMGZLVk6opBXEEgLYawgn3wTNUGoaxOE27rh5G0fZHJAwyGbnikKkJaLm32ImXFU/4rpkaMzvJVzquOvWlESB10VyMVOnkW1z8qIgwYqN60UbWzYahxrWay3NlFWpTAuDgTm9L0wyFkM7IfJYNbsei0j9WKv6980c49QBCtCMo39iZkOwShCE1HPUDnOlGIYj3rSi0g1UjtI7i2/aUgDB9HNGxJtwdNGZ5Q3Tw3qU5qWeSt9mJAy/DelyuUqttbvUOxqmwaWUacoHIVm7wTlPZy2IpjJ0gCxTDAS8PNVxnaTv2rNrbPe9QyDBPMcSkyGO5wDNSQUOiWjjofZnCd/iTfwy2P8DqkEVbzvWE+5FRSb3kBSKzFMC1/GPXoZ9bT9Oh/8RD6iOSzpufzsOmQ/BSlOTd7prPF+zKyjMT1H3zgZKbbcJcFAa04nAR1ps90Qg= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR12MB5506.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(346002)(366004)(396003)(376002)(39860400002)(54906003)(1076003)(38100700002)(426003)(66556008)(66476007)(4326008)(5660300002)(186003)(66946007)(316002)(53546011)(478600001)(26005)(6916009)(36756003)(86362001)(9786002)(7416002)(9746002)(83380400001)(8676002)(2906002)(2616005)(33656002)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?YE/ZarSi3clbZWc4AHwHYODFCdLDJBm5Nles3SZOgIm515LeUNfESPFsi5uT?= =?us-ascii?Q?Tj9Qa5hdggK+r5Nr22pIeRn+JATGo0BxueKVXvrKfATiXZ3YCNfkAG1m8Bkw?= =?us-ascii?Q?1BoXZtdHP9h3eo8DrSdZh9PL1jLYVcXoIyEFc7SYUpI7BSYFWcgdK4nYMRet?= =?us-ascii?Q?D/iRZGpfnnr4SgFZpzMJUCqJ5tNfEpJSb71gjJyvLQDJt9Ufa7nd8mcHDFSF?= =?us-ascii?Q?Orw/XyW6lHonGwNvP49371gTcYwjfmPSImA4AIhEY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8VDNnfykCkMzZGhTcLFr0MKQPiRorp3VKy6lYbCaoGMu25WcFG8+p2A6biK?= =?us-ascii?Q?PBEGWSW3ULDQFNao5ndclumk9fpx/12BSlJuMyUZWadzS+ygviW7MTJq9fl9?= =?us-ascii?Q?12RIxuHJnoIQH5oK96hwn4G3mlYi0dzip6+/AlxSQvm+N93yviK94eSvbTtt?= =?us-ascii?Q?EtqbaBS0i7trUfJ3+uiMEexQ?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 620ee070-9405-4a52-71ee-08d9277d483c X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jun 2021 17:22:08.7306 (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: wMuK0vTK1MrIC75I5tQZkEebS9jAKNa7CEwFQPKXtQ5LzWuJ8yWtFLJmt4i92H1d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5269 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 04, 2021 at 06:10:51PM +0200, Paolo Bonzini wrote: > On 04/06/21 18:03, Jason Gunthorpe wrote: > > On Fri, Jun 04, 2021 at 05:57:19PM +0200, Paolo Bonzini wrote: > > > I don't want a security proof myself; I want to trust VFIO to make the right > > > judgment and I'm happy to defer to it (via the KVM-VFIO device). > > > > > > Given how KVM is just a device driver inside Linux, VMs should be a slightly > > > more roundabout way to do stuff that is accessible to bare metal; not a way > > > to gain extra privilege. > > > > Okay, fine, lets turn the question on its head then. > > > > VFIO should provide a IOCTL VFIO_EXECUTE_WBINVD so that userspace VFIO > > application can make use of no-snoop optimizations. The ability of KVM > > to execute wbinvd should be tied to the ability of that IOCTL to run > > in a normal process context. > > > > So, under what conditions do we want to allow VFIO to giave a process > > elevated access to the CPU: > > Ok, I would definitely not want to tie it *only* to CAP_SYS_RAWIO (i.e. > #2+#3 would be worse than what we have today), but IIUC the proposal (was it > yours or Kevin's?) was to keep #2 and add #1 with an enable/disable ioctl, > which then would be on VFIO and not on KVM. At the end of the day we need an ioctl with two arguments: - The 'security proof' FD (ie /dev/vfio/XX, or /dev/ioasid, or whatever) - The KVM FD to control wbinvd support on Philosophically it doesn't matter too much which subsystem that ioctl lives, but we have these obnoxious cross module dependencies to consider.. Framing the question, as you have, to be about the process, I think explains why KVM doesn't really care what is decided, so long as the process and the VM have equivalent rights. Alex, how about a more fleshed out suggestion: 1) When the device is attached to the IOASID via VFIO_ATTACH_IOASID it communicates its no-snoop configuration: - 0 enable, allow WBINVD - 1 automatic disable, block WBINVD if the platform IOMMU can police it (what we do today) - 2 force disable, do not allow BINVD ever vfio_pci may want to take this from an admin configuration knob someplace. It allows the admin to customize if they want. If we can figure out a way to autodetect 2 from vfio_pci, all the better 2) There is some IOMMU_EXECUTE_WBINVD IOCTL that allows userspace to access wbinvd so it can make use of the no snoop optimization. wbinvd is allowed when: - A device is joined with mode #0 - A device is joined with mode #1 and the IOMMU cannot block no-snoop (today) 3) The IOASID's don't care about this at all. If IOMMU_EXECUTE_WBINVD is blocked and userspace doesn't request to block no-snoop in the IOASID then it is a userspace error. 4) The KVM interface is the very simple enable/disable WBINVD. Possessing a FD that can do IOMMU_EXECUTE_WBINVD is required to enable WBINVD at KVM. It is pretty simple from a /dev/ioasid perpsective, covers todays compat requirement, gives some future option to allow the no-snoop optimization, and gives a new option for qemu to totally block wbinvd no matter what. Jason