Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3700260pxj; Mon, 7 Jun 2021 18:23:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvj+c41QXSccBqe19UL2dlz1mCNhn2u1AY9VaQOtbeRggjQU3H7y9nfwSHp3KuwSBcd1Ut X-Received: by 2002:a05:6402:2552:: with SMTP id l18mr22918052edb.166.1623115387321; Mon, 07 Jun 2021 18:23:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623115387; cv=none; d=google.com; s=arc-20160816; b=yGZgIu1xHKfOkZkO7DrfEicQFypAcJ6j4kvaniNbNwdI2l8+NeVR36CKRmwQSLarjf CPQyllxaQLxouXdxamCzW6ei1f+TR1VzCy+EN/GW0ICBthDc1sdLsFXp3mMPa8BHuoJg rN0R+ItCMcOyOjyiveu7BdNzLITb8wtkr16Sy2TeVHCcFKyy1VlxuJBu9bEsDho0nKd7 i2JwIOk9uoGouthwtxTM4pEFH2Y/K/bllbhh1awMh65HYYLnbQJC/TmwzXBk0Do4znu4 3adS7lsKGZWMcqwKXQVBBVE8XChEzVM+mW6aG++aZSWk29LwfTu7ozVkvMgaI51GbhOD q5PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=TCwzQn65+dgzBoFvWj2wr+QLjXlAu9EeWSx0GqEzC4M=; b=TaiNbypUZOmC8rT30q+/Skw/hLexIYBSB70zmDgJUR5dfQBtch6wfRBJ4djNxij7Zz 6kE+wVh8R95M29Npl38X+83B5W0Yh1i6yc5Pu7NeqpzPhDWQIelRySvfJ2I4ZAlfyCvf minFYcL3/4tOBxW0Ph3EQeamWd6n1FM26cbqDh4MsHQIEH6bXvRmqVygpsooBUIhvW1k uTYWYbqFEr0uzHNPbGgNDl0D6uPNDoI/+MLxwqabyfPvABbMQxSbsV/d7mHKmPTc2473 Ez7OaKYHbOZsj/LPPhRvO7fRLLq4jhEPZM9oIFh02E4px8k7axvKC6QQm27No3R1xgRZ RY3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hj2ZlBF5; 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 z16si13449444ejx.706.2021.06.07.18.22.43; Mon, 07 Jun 2021 18:23:07 -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=@redhat.com header.s=mimecast20190719 header.b=hj2ZlBF5; 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 S231157AbhFHBWi (ORCPT + 99 others); Mon, 7 Jun 2021 21:22:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:36017 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230321AbhFHBWf (ORCPT ); Mon, 7 Jun 2021 21:22:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623115242; 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=TCwzQn65+dgzBoFvWj2wr+QLjXlAu9EeWSx0GqEzC4M=; b=hj2ZlBF56qdE51oVdoOYR17j6mV4SpmuNhkGRKqNRM3m2j05SbCyN9DIw1y4WYcCakJkYR m/a5IE+RZoKEQLnPtuZdIf0ORQs1fTJr/YCXFwRUYsKIJpsU6RppO34rhpqjWpe8BbzmHG 8EekV3O5u8f/b2ceS2Fayzp1LK3U2nM= Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-120-Mfmna-xiPZq4-pPzzQP85Q-1; Mon, 07 Jun 2021 21:20:41 -0400 X-MC-Unique: Mfmna-xiPZq4-pPzzQP85Q-1 Received: by mail-pf1-f200.google.com with SMTP id 9-20020a6217090000b02902ed4caf9377so2652597pfx.19 for ; Mon, 07 Jun 2021 18:20:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=TCwzQn65+dgzBoFvWj2wr+QLjXlAu9EeWSx0GqEzC4M=; b=KSq6YeUIywPiXbyKLGRavgRnbGhNnVZ5+ZI/V/PBa9zniMXK76b1is3ODogLGSqOg+ Zy938JpnGXMHgCW9J1keID6n/fp/pJvHTi0fXLipURJS7H+T650VZb3n7mjtsx0fO0s2 crK+frfxQAavy6ZKKnf3ZACQK6GgLilf+fGacCNj4AKlc7qadCXQng7IxaTLiaLGutgU eqkdf1RihXOBV+rqVoueFMqDGOimTLYb7eFa5yXMrQEmEAUOLTlaDPrQ1Jt29typwXny CEkx4fDD1Fs11dfZMvzyfS/uQ0zG7Dhr8z5c8glvi5v0U7js9w3zFG6QfKVp1DBhxhcA NR7A== X-Gm-Message-State: AOAM533NVgIiCZf6Px6qT1guq9biJ5UyDqQbRHjAPr/I7F7Z9ndrpNNr J2ZoFr/So6Mw8OOj9SdEu9bgWx2cwzMQeYk9X1/xCsHkv6MvewLMwr8SlcTFpapxfTKWEYUUDoq +Il++GpJKdur8Eey+ZPh8X/n+ X-Received: by 2002:a17:90a:c20b:: with SMTP id e11mr2002402pjt.67.1623115240161; Mon, 07 Jun 2021 18:20:40 -0700 (PDT) X-Received: by 2002:a17:90a:c20b:: with SMTP id e11mr2002339pjt.67.1623115239324; Mon, 07 Jun 2021 18:20:39 -0700 (PDT) Received: from wangxiaodeMacBook-Air.local ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id y5sm9342812pfb.19.2021.06.07.18.20.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 07 Jun 2021 18:20:38 -0700 (PDT) Subject: Re: [RFC] /dev/ioasid uAPI proposal To: Alex Williamson , Jason Gunthorpe Cc: Paolo Bonzini , "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 References: <20210604155016.GR1002214@nvidia.com> <30e5c597-b31c-56de-c75e-950c91947d8f@redhat.com> <20210604160336.GA414156@nvidia.com> <2c62b5c7-582a-c710-0436-4ac5e8fd8b39@redhat.com> <20210604172207.GT1002214@nvidia.com> <20210604152918.57d0d369.alex.williamson@redhat.com> <20210604230108.GB1002214@nvidia.com> <20210607094148.7e2341fc.alex.williamson@redhat.com> <20210607181858.GM1002214@nvidia.com> <20210607125946.056aafa2.alex.williamson@redhat.com> <20210607190802.GO1002214@nvidia.com> <20210607134128.58c2ea31.alex.williamson@redhat.com> From: Jason Wang Message-ID: <12631cf3-4ef8-7c38-73bb-649d57c0226b@redhat.com> Date: Tue, 8 Jun 2021 09:20:29 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210607134128.58c2ea31.alex.williamson@redhat.com> Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ?? 2021/6/8 ????3:41, Alex Williamson ะด??: > On Mon, 7 Jun 2021 16:08:02 -0300 > Jason Gunthorpe wrote: > >> On Mon, Jun 07, 2021 at 12:59:46PM -0600, Alex Williamson wrote: >> >>>> It is up to qemu if it wants to proceed or not. There is no issue with >>>> allowing the use of no-snoop and blocking wbinvd, other than some >>>> drivers may malfunction. If the user is certain they don't have >>>> malfunctioning drivers then no issue to go ahead. >>> A driver that knows how to use the device in a coherent way can >>> certainly proceed, but I suspect that's not something we can ask of >>> QEMU. QEMU has no visibility to the in-use driver and sketchy ability >>> to virtualize the no-snoop enable bit to prevent non-coherent DMA from >>> the device. There might be an experimental ("x-" prefixed) QEMU device >>> option to allow user override, but QEMU should disallow the possibility >>> of malfunctioning drivers by default. If we have devices that probe as >>> supporting no-snoop, but actually can't generate such traffic, we might >>> need a quirk list somewhere. >> Compatibility is important, but when I look in the kernel code I see >> very few places that call wbinvd(). Basically all DRM for something >> relavent to qemu. >> >> That tells me that the vast majority of PCI devices do not generate >> no-snoop traffic. > Unfortunately, even just looking at devices across a couple laptops > most devices do support and have NoSnoop+ set by default. I don't > notice anything in the kernel that actually tries to set this enable (a > handful that actively disable), so I assume it's done by the firmware. I wonder whether or not it was done via ACPI: " 6.2.17 _CCA (Cache Coherency Attribute) The _CCA object returns whether or not a bus-master device supports hardware managed cache coherency. Expected values are 0 to indicate it is not supported, and 1 to indicate that it is supported. All other values are reserved. ... On Intel platforms, if the _CCA object is not supplied, the OSPM will assume the devices are hardware cache coherent. " Thanks > It's not safe for QEMU to make an assumption that only GPUs will > actually make use of it. > >>>> I think it makes the software design much simpler if the security >>>> check is very simple. Possessing a suitable device in an ioasid fd >>>> container is enough to flip on the feature and we don't need to track >>>> changes from that point on. We don't need to revoke wbinvd if the >>>> ioasid fd changes, for instance. Better to keep the kernel very simple >>>> in this regard. >>> You're suggesting that a user isn't forced to give up wbinvd emulation >>> if they lose access to their device? >> Sure, why do we need to be stricter? It is the same logic I gave >> earlier, once an attacker process has access to wbinvd an attacker can >> just keep its access indefinitely. >> >> The main use case for revokation assumes that qemu would be >> compromised after a device is hot-unplugged and you want to block off >> wbinvd. But I have a hard time seeing that as useful enough to justify >> all the complicated code to do it... > It's currently just a matter of the kvm-vfio device holding a reference > to the group so that it cannot be used elsewhere so long as it's being > used to elevate privileges on a given KVM instance. If we conclude that > access to a device with the right capability is required to gain a > privilege, I don't really see how we can wave aside that the privilege > isn't lost with the device. > >> For KVM qemu can turn on/off on hot plug events as it requires to give >> VM security. It doesn't need to rely on the kernel to control this. > Yes, QEMU can reject a hot-unplug event, but then QEMU retains the > privilege that the device grants it. Releasing the device and > retaining the privileged gained by it seems wrong. Thanks, > > Alex >