Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4706984rwb; Mon, 8 Aug 2022 05:56:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR52+eS14tSlaVhAZF62Mn3K8yi+D8bF9krP0f8dGfjNTxewqSFLJCEteI4nzWQ6vCrgn6y0 X-Received: by 2002:a17:907:75e7:b0:730:bc2f:b26a with SMTP id jz7-20020a17090775e700b00730bc2fb26amr13375608ejc.738.1659963393892; Mon, 08 Aug 2022 05:56:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659963393; cv=none; d=google.com; s=arc-20160816; b=ymPkVd5Hl15h8toQRLkH7w0cSF2f9crRO8T7nnR96tPp/YpeH2CpD4M0ON+Cp0Bvxo VaNZ+H5kkIrPADdwsotkPj2/XzL+ymF8UuJ1lQRQ24FEd4Tj/9l8COaUKdMdzRdb4khu MfBo1xfRfBw9T8XdeYTlYfmAe2b8yiWsEMy07h5EbRMZplW8/M21XNrMyhykECJmEIup vAvgd41Mc4s4hf46im60J9L8F+bfzQdytEaNLy4OuLFvf9IAAd6kKPAGmw9mE3JDvhLL jzSYnjeMw2NDCz3jaSpsecz2JQ/lmjUItwul17Xvubcb4T9ScUNixBN2yAzIwEZQOriG iX8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=bIkebALpaCzzfrhDIO+eiB2cWrwHJfvl0+w6H8aCeL4=; b=Mx8gztt3p0TkGW2xPkCnfS9DWfDbppRKxpa6bDUkoLY1u0KAuSRezOv3ggRUd38ppM x4c/ySr7O3VSylxiw9+zLwz1CxgtP7na8UYRvcwj/9mP9+4jYn+LeIPo1oFk/A0zdt68 zcJhfAkv06YH69obw60RPMlgCV9VpCHvSDpZ8b+7ltD9fm9wx3w9X3XvBWI5Tt+w4kg7 ja5yT4Jm7UEzCu2xw/ZqxntrY1AfSnY/+vo26aWfp3NSz3UsH9X2BTtKNzxm7CCaFV6j auD7BG5BOOBnsYE6DxdEE5cUrZItD2LLsu/Kf0F4OAtHif32WGL9eLiWG03X31ZOTf6+ 4T/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EdXW0FF4; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bt20-20020a0564020a5400b0043df915305fsi6215505edb.119.2022.08.08.05.56.09; Mon, 08 Aug 2022 05:56:33 -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=@redhat.com header.s=mimecast20190719 header.b=EdXW0FF4; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242936AbiHHMqC (ORCPT + 99 others); Mon, 8 Aug 2022 08:46:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235645AbiHHMp7 (ORCPT ); Mon, 8 Aug 2022 08:45:59 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 86E43D8C for ; Mon, 8 Aug 2022 05:45:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659962757; 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: in-reply-to:in-reply-to:references:references; bh=bIkebALpaCzzfrhDIO+eiB2cWrwHJfvl0+w6H8aCeL4=; b=EdXW0FF4JjeuO0Ej4xVDjjq/v3j87qBmjgQSvTtYWfdyeeNUhaU/vRAxDi5pgL1+w70wt8 DXC0CjtgUpfn2bixxrw3eVqt4+Z3G9nckJupPYpcFm90qMXK0aGzZDwQD46wUr/3pT32fN IcFQIiZO4iBnHVbW1toMFA2j1Q07l9E= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-656-K-tcVbbeMvadQcWCfNjAXw-1; Mon, 08 Aug 2022 08:45:56 -0400 X-MC-Unique: K-tcVbbeMvadQcWCfNjAXw-1 Received: by mail-wm1-f70.google.com with SMTP id r5-20020a1c4405000000b003a534ec2570so1490043wma.7 for ; Mon, 08 Aug 2022 05:45:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=bIkebALpaCzzfrhDIO+eiB2cWrwHJfvl0+w6H8aCeL4=; b=jZ0dC+bKmDpTZw/DxEx0lR4Cvh7JYAQBeRrPxNe+U2Zck2sH3CJ1IhHINwoTBYR20Y WAklq6X/c6rDKrEx0hqDeVv5B6K5B2CHEKN00GO1FSuoH/4t8hkpTCMp6olXwTXA+oyc 8nhmWGCtZeAUG1uHewCnUia2s9Twz2ivK+Ye5MEVaFXug9CnhpFEuZiAVby1jW4KJDrq lwLiFB5uxeI1bQDVm5vQi33nkvGZ9oGf4NvjLSRljIZupPiS5Gss4QvE+cgbZ0zxlAzc 1MrkdECkN1XGNAURqI3SW/LqU3fwmjv7eD2Nrn7odTFObIJJ/4t65UTrc+p8BPSyiA8x AmvA== X-Gm-Message-State: ACgBeo3YOcnN7WonQN1TMKA2X+Y9QSm8YukS/sQKOZUWwgVnKFWSQs9T rfknZ5IfbgUlKQAKxlAZ0Yb0K6s+OCekLphlxDcEW3qbS/TOo62QBAnCJ9uMkjRSWdFknIXnMCt jePq1tAiodhABb6BXFSVYom4z X-Received: by 2002:adf:edc1:0:b0:21d:7157:f4aa with SMTP id v1-20020adfedc1000000b0021d7157f4aamr11472384wro.454.1659962755060; Mon, 08 Aug 2022 05:45:55 -0700 (PDT) X-Received: by 2002:adf:edc1:0:b0:21d:7157:f4aa with SMTP id v1-20020adfedc1000000b0021d7157f4aamr11472372wro.454.1659962754783; Mon, 08 Aug 2022 05:45:54 -0700 (PDT) Received: from redhat.com ([2.52.21.123]) by smtp.gmail.com with ESMTPSA id m8-20020a5d56c8000000b00222d4dfcdffsm1715765wrw.87.2022.08.08.05.45.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Aug 2022 05:45:53 -0700 (PDT) Date: Mon, 8 Aug 2022 08:45:48 -0400 From: "Michael S. Tsirkin" To: Will Deacon Cc: stefanha@redhat.com, jasowang@redhat.com, torvalds@linux-foundation.org, ascull@google.com, maz@kernel.org, keirf@google.com, jiyong@google.com, kernel-team@android.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, crosvm-dev@chromium.org Subject: Re: IOTLB support for vhost/vsock breaks crosvm on Android Message-ID: <20220808083958-mutt-send-email-mst@kernel.org> References: <20220805181105.GA29848@willie-the-truck> <20220807042408-mutt-send-email-mst@kernel.org> <20220808101850.GA31984@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220808101850.GA31984@willie-the-truck> X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_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, Aug 08, 2022 at 11:18:50AM +0100, Will Deacon wrote: > Hi Michael, > > On Sun, Aug 07, 2022 at 09:14:43AM -0400, Michael S. Tsirkin wrote: > > Will, thanks very much for the analysis and the writeup! > > No problem, and thanks for following up. > > > On Fri, Aug 05, 2022 at 07:11:06PM +0100, Will Deacon wrote: > > > So how should we fix this? One possibility is for us to hack crosvm to > > > clear the VIRTIO_F_ACCESS_PLATFORM flag when setting the vhost features, > > > but others here have reasonably pointed out that they didn't expect a > > > kernel change to break userspace. On the flip side, the offending commit > > > in the kernel isn't exactly new (it's from the end of 2020!) and so it's > > > likely that others (e.g. QEMU) are using this feature. > > > > Exactly, that's the problem. > > > > vhost is reusing the virtio bits and it's only natural that > > what you are doing would happen. > > > > To be precise, this is what we expected people to do (and what QEMU does): > > > > > > #define QEMU_VHOST_FEATURES ((1 << VIRTIO_F_VERSION_1) | > > (1 << VIRTIO_NET_F_RX_MRG) | .... ) > > > > VHOST_GET_FEATURES(... &host_features); > > host_features &= QEMU_VHOST_FEATURES > > VHOST_SET_FEATURES(host_features & guest_features) > > > > > > Here QEMU_VHOST_FEATURES are the bits userspace knows about. > > > > Our assumption was that whatever userspace enables, it > > knows what the effect on vhost is going to be. > > > > But yes, I understand absolutely how someone would instead just use the > > guest features. It is unfortunate that we did not catch this in time. > > > > > > In hindsight, we should have just created vhost level macros > > instead of reusing virtio ones. Would address the concern > > about naming: PLATFORM_ACCESS makes sense for the > > guest since there it means "whatever access rules platform has", > > but for vhost a better name would be VHOST_F_IOTLB. > > We should have also taken greater pains to document what > > we expect userspace to do. I remember now how I thought about something > > like this but after coding this up in QEMU I forgot to document this :( > > Also, I suspect given the history the GET/SET features ioctl and burned > > wrt extending it and we have to use a new when we add new features. > > All this we can do going forward. > > Makes sense. The crosvm developers are also pretty friendly in my > experience, so I'm sure they wouldn't mind being involved in discussions > around any future ABI extensions. Just be aware that they _very_ recently > moved their mailing lists, so I think it lives here now: > > https://groups.google.com/a/chromium.org/g/crosvm-dev > > > But what can we do about the specific issue? > > I am not 100% sure since as Will points out, QEMU and other > > userspace already rely on the current behaviour. > > > > Looking at QEMU specifically, it always sends some translations at > > startup, this in order to handle device rings. > > > > So, *maybe* we can get away with assuming that if no IOTLB ioctl was > > ever invoked then this userspace does not know about IOTLB and > > translation should ignore IOTLB completely. > > There was a similar suggestion from Stefano: > > https://lore.kernel.org/r/20220806105225.crkui6nw53kbm5ge@sgarzare-redhat > > about spotting the backend ioctl for IOTLB and using that to enable > the negotiation of F_ACCESS_PLATFORM. Would that work for qemu? Hmm I would worry that this disables the feature for old QEMU :( > > I am a bit nervous about breaking some *other* userspace which actually > > wants device to be blocked from accessing memory until IOTLB > > has been setup. If we get it wrong we are making guest > > and possibly even host vulnerable. > > And of course just revering is not an option either since there > > are now whole stacks depending on the feature. > > Absolutely, I'm not seriously suggesting the revert. I just did it locally > to confirm the issue I was seeing. > > > Will I'd like your input on whether you feel a hack in the kernel > > is justified here. > > If we can come up with something that we have confidence in and won't be a > pig to maintain, then I think we should do it, but otherwise we can go ahead > and change crosvm to mask out this feature flag on the vhost side for now. > We mainly wanted to raise the issue to illustrate that this flag continues > to attract problems in the hope that it might inform further usage and/or > spec work in this area. > > In any case, I'm happy to test any kernel patches with our setup if you > want to give it a shot. Thanks! I'm a bit concerned that the trick I proposed changes the configuration where iotlb was not set up from "access to memory not allowed" to "access to all memory allowed". This just might have security implications if some application assumed the former. And the one Stefano proposed disables IOTLB for old QEMU versions. > > Also yes, I think it's a good idea to change crosvm anyway. While the > > work around I describe might make sense upstream I don't think it's a > > reasonable thing to do in stable kernels. > > I think I'll prepare a patch documenting the legal vhost features > > as a 1st step even though crosvm is rust so it's not importing > > the header directly, right? > > Documentation is a good idea regardless, so thanks for that. Even though > crosvm has its own bindings for the vhost ioctl()s, the documentation > can be reference or duplicated once it's available in the kernel headers. > > Will So for crosvm change, I will post the documentation change and you guys can discuss? -- MST