Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp314049iog; Wed, 29 Jun 2022 00:13:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uMgXbnaCdGkUPqhqoCq9+UvezzdjoqU4MqFRFh6Y86p7DRoj6lHQ2dd/dKS3KfDP3Qz8Zt X-Received: by 2002:a17:90b:314c:b0:1ed:442c:117e with SMTP id ip12-20020a17090b314c00b001ed442c117emr2326733pjb.160.1656486792141; Wed, 29 Jun 2022 00:13:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656486792; cv=none; d=google.com; s=arc-20160816; b=obGlKHFy0eGcyPggaiDoau63CXhcq4E/gXT4tYyVHO/QtSET4CWjMsnz3QQgsYoRim 5WF840YaKU379NL11BF/YT5eCAhZCwxzGBc3/RlyfMzSDW/6V66TcpcNb5SjCfETw2FR /Tb6mikRIuFE6ip8ewAmQ0aQsz3pgOpeln6Wlfnb87Uzt/MxBNrGjkGyliej90iTzhNo GqXMA2Cvt6qw6H3ybINLIHklb4bDIlHAwFY+KRGPf91OQiKzW4Sv8tvhOhGyoBkanIQT ONLd3deTcCTZHsAjLKlGAcDRM5QM4gFTf7a9hueMe3Pm1xn6SQnnDA0ez2L+nnG9UYI9 o5QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=zdxtwKfDBaNyVyUEwFBhab9Yx2tZ8QjJF8+weaWqn/c=; b=SzvzhvBduOiZIBhrYo60xu0cDQ0DiSi4cSTS0+0pHzbdaLr+ufyLo8Kspen7OLNTHA eg+99KYnkbhMRRejW3y+h5rnNjFbiAaFdccM26ZCAv8G7SyCqInTr98Y9CmBFQMHbz+4 4xUL2c1hKpc5AJIkhLWm1NNWcMLSPJIZk4dtwPaaeuK8YntrPoTp6PLVwACF/DAAZrnv UNtzZWW1nP/TNxXd59g2/HHVrzkrAXCNDdLOvPyOijCJ18SJ0YjMNU+FPXhTM5YMOeBY qwDhShedVRbgdYKuikXquQgMTxOer0mCMoD4gKpJt1lxrALRkqf34dTKUestJTXHqAzH yzNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ToTgXsZS; 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 a27-20020a634d1b000000b003db947d50fcsi1365745pgb.174.2022.06.29.00.12.59; Wed, 29 Jun 2022 00:13:12 -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=ToTgXsZS; 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 S233048AbiF2HEq (ORCPT + 99 others); Wed, 29 Jun 2022 03:04:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232983AbiF2HEb (ORCPT ); Wed, 29 Jun 2022 03:04:31 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3B82F3DDFE for ; Wed, 29 Jun 2022 00:02:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656486156; 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=zdxtwKfDBaNyVyUEwFBhab9Yx2tZ8QjJF8+weaWqn/c=; b=ToTgXsZS671YGgIzo+dcwgyXjCHiPS+ugvC+cbTvhnwvAGl+DpoCnYKBp/5Fr1vWgYf27B oepz9xz9Sga5A3LWz4y/cu4Zbw3GJzNqTBZF09G3gZz7aEIoA4dLYeqaix2OhaPEzx90ad 9S4WNyiOYuprCJwU2FZNqtUojhF4tW0= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-63-3WrwMTWVM6-PrPxHFDOAcA-1; Wed, 29 Jun 2022 03:02:34 -0400 X-MC-Unique: 3WrwMTWVM6-PrPxHFDOAcA-1 Received: by mail-lj1-f198.google.com with SMTP id m8-20020a2eb6c8000000b0025aa0530107so1977439ljo.6 for ; Wed, 29 Jun 2022 00:02:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zdxtwKfDBaNyVyUEwFBhab9Yx2tZ8QjJF8+weaWqn/c=; b=6HVtSXDxfuYS7BFjVnsxHw7lRGZJiGlcTIsRYudyarxlGq/FkZRPHHpdXSlnS4BWIF TLmLnH38jTQt643kPeRPeMC08IvPpcA9Q0SMSfkhd1UkfRRJ8Q9U85PpizznuFG8IgIy Tf9YJKQVnQUXLpdDOW7qeRR1bgIqSFJ5bOIOv54e9VCD+4Pm7NiCsGnlxBtm+8ox6KEz hZ0ionpORSjyeMP30/GfR7mtt9RHd5JXLFREZmfewQAbYug9e520r99IwDZAAjdTJngO DXqRmSS/h6p7g4kWyeE+xfiRNaBAgdEW5y7aA0PjNda2aWsmHbZpDs7VTrAmUVl61ILl UA7Q== X-Gm-Message-State: AJIora+68wA/nZJpGbFNaKlSTLkEikPfepdopKkV1oj/VMv5uCFViO9H ORSVFj3fQgcvvM1TrX7lReNdHcokPKUF01l/CFHhPbVZTw3egceuT0XjN0gxfb+oYJLeOk4k5Kx OJiLPX5tvdO1F/3QLoLT98wktbJ66LisCAyrx1Z/G X-Received: by 2002:a05:6512:3b8e:b0:481:1a75:452 with SMTP id g14-20020a0565123b8e00b004811a750452mr1169818lfv.238.1656486152746; Wed, 29 Jun 2022 00:02:32 -0700 (PDT) X-Received: by 2002:a05:6512:3b8e:b0:481:1a75:452 with SMTP id g14-20020a0565123b8e00b004811a750452mr1169793lfv.238.1656486152366; Wed, 29 Jun 2022 00:02:32 -0700 (PDT) MIME-Version: 1.0 References: <20220624022622-mutt-send-email-mst@kernel.org> <20220627024049-mutt-send-email-mst@kernel.org> <20220627053820-mutt-send-email-mst@kernel.org> <20220628004614-mutt-send-email-mst@kernel.org> <20220629022223-mutt-send-email-mst@kernel.org> In-Reply-To: <20220629022223-mutt-send-email-mst@kernel.org> From: Jason Wang Date: Wed, 29 Jun 2022 15:02:21 +0800 Message-ID: Subject: Re: [PATCH V3] virtio: disable notification hardening by default To: "Michael S. Tsirkin" Cc: Cornelia Huck , Halil Pasic , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , linux-s390@vger.kernel.org, virtualization , kvm , linux-kernel , Ben Hutchings , David Hildenbrand Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Wed, Jun 29, 2022 at 2:31 PM Michael S. Tsirkin wrote: > > On Wed, Jun 29, 2022 at 12:07:11PM +0800, Jason Wang wrote: > > On Tue, Jun 28, 2022 at 2:17 PM Jason Wang wrote: > > > > > > On Tue, Jun 28, 2022 at 1:00 PM Michael S. Tsirkin wrote: > > > > > > > > On Tue, Jun 28, 2022 at 11:49:12AM +0800, Jason Wang wrote: > > > > > > Heh. Yea sure. But things work fine for people. What is the chance > > > > > > your review found and fixed all driver bugs? > > > > > > > > > > I don't/can't audit all bugs but the race between open/close against > > > > > ready/reset. It looks to me a good chance to fix them all but if you > > > > > think differently, let me know > > > > > > > > > > > After two attempts > > > > > > I don't feel like hoping audit will fix all bugs. > > > > > > > > > > I've started the auditing and have 15+ patches in the queue. (only > > > > > covers bluetooth, console, pmem, virtio-net and caif). Spotting the > > > > > issue is not hard but the testing, It would take at least the time of > > > > > one release to finalize I guess. > > > > > > > > Absolutely. So I am looking for a way to implement hardening that does > > > > not break existing drivers. > > > > > > I totally agree with you to seek a way without bothering the drivers. > > > Just wonder if this is possbile. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > The reason config was kind of easy is that config interrupt is rarely > > > > > > > > vital for device function so arbitrarily deferring that does not lead to > > > > > > > > deadlocks - what you are trying to do with VQ interrupts is > > > > > > > > fundamentally different. Things are especially bad if we just drop > > > > > > > > an interrupt but deferring can lead to problems too. > > > > > > > > > > > > > > I'm not sure I see the difference, disable_irq() stuffs also delay the > > > > > > > interrupt processing until enable_irq(). > > > > > > > > > > > > > > > > > > Absolutely. I am not at all sure disable_irq fixes all problems. > > > > > > > > > > > > > > > > > > > > > > Consider as an example > > > > > > > > virtio-net: fix race between ndo_open() and virtio_device_ready() > > > > > > > > if you just defer vq interrupts you get deadlocks. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > I don't see a deadlock here, maybe you can show more detail on this? > > > > > > > > > > > > What I mean is this: if we revert the above commit, things still > > > > > > work (out of spec, but still). If we revert and defer interrupts until > > > > > > device ready then ndo_open that triggers before device ready deadlocks. > > > > > > > > > > Ok, I guess you meant on a hypervisor that is strictly written with spec. > > > > > > > > I mean on hypervisor that starts processing queues after getting a kick > > > > even without DRIVER_OK. > > > > > > Oh right. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > So, thinking about all this, how about a simple per vq flag meaning > > > > > > > > "this vq was kicked since reset"? > > > > > > > > > > > > > > And ignore the notification if vq is not kicked? It sounds like the > > > > > > > callback needs to be synchronized with the kick. > > > > > > > > > > > > Note we only need to synchronize it when it changes, which is > > > > > > only during initialization and reset. > > > > > > > > > > Yes. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > If driver does not kick then it's not ready to get callbacks, right? > > > > > > > > > > > > > > > > Sounds quite clean, but we need to think through memory ordering > > > > > > > > concerns - I guess it's only when we change the value so > > > > > > > > if (!vq->kicked) { > > > > > > > > vq->kicked = true; > > > > > > > > mb(); > > > > > > > > } > > > > > > > > > > > > > > > > will do the trick, right? > > > > > > > > > > > > > > There's no much difference with the existing approach: > > > > > > > > > > > > > > 1) your proposal implicitly makes callbacks ready in virtqueue_kick() > > > > > > > 2) my proposal explicitly makes callbacks ready via virtio_device_ready() > > > > > > > > > > > > > > Both require careful auditing of all the existing drivers to make sure > > > > > > > no kick before DRIVER_OK. > > > > > > > > > > > > Jason, kick before DRIVER_OK is out of spec, sure. But it is unrelated > > > > > > to hardening > > > > > > > > > > Yes but with your proposal, it seems to couple kick with DRIVER_OK somehow. > > > > > > > > I don't see how - my proposal ignores DRIVER_OK issues. > > > > > > Yes, what I meant is, in your proposal, the first kick after rest is a > > > hint that the driver is ok (but actually it could not). > > > > > > > > > > > > > and in absence of config interrupts is generally easily > > > > > > fixed just by sticking virtio_device_ready early in initialization. > > > > > > > > > > So if the kick is done before the subsystem registration, there's > > > > > still a window in the middle (assuming we stick virtio_device_ready() > > > > > early): > > > > > > > > > > virtio_device_ready() > > > > > virtqueue_kick() > > > > > /* the window */ > > > > > subsystem_registration() > > > > > > > > Absolutely, however, I do not think we really have many such drivers > > > > since this has been known as a wrong thing to do since the beginning. > > > > Want to try to find any? > > > > > > Yes, let me try and update. > > > > This is basically the device that have an RX queue, so I've found the > > following drivers: > > > > scmi, mac80211_hwsim, vsock, bt, balloon. > > Looked and I don't see it yet. Let's consider > ./net/vmw_vsock/virtio_transport.c for example. Assuming we block > callbacks until the first kick, what is the issue with probe exactly? We need to make sure the callback can survive when it runs before sub system registration. > > > > > > > > >I couldn't ... except maybe bluetooth > > > > but that's just maintainer nacking fixes saying he'll fix it > > > > his way ... > > > > > > > > > And during remove(), we get another window: > > > > > > > > > > subsysrem_unregistration() > > > > > /* the window */ > > > > > virtio_device_reset() > > > > > > > > Same here. > > > > Basically for the drivers that set driver_ok before registration, > > I don't see what does driver_ok have to do with it. I meant for those driver, in probe they do() virtio_device_ready() subsystem_register() In remove() they do subsystem_unregister() virtio_device_reset() for symmetry > > > so > > we have a lot: > > > > blk, net, mac80211_hwsim, scsi, vsock, bt, crypto, gpio, gpu, i2c, > > iommu, caif, pmem, input, mem > > > > So I think there's no easy way to harden the notification without > > auditing the driver one by one (especially considering the driver may > > use bh or workqueue). The problem is the notification hardening > > depends on a correct or race-free probe/remove. So we need to fix the > > issues in probe/remove then do the hardening on the notification. > > > > Thanks > > So if drivers kick but are not ready to get callbacks then let's fix > that first of all, these are racy with existing qemu even ignoring > spec compliance. Yes, (the patches I've posted so far exist even with a well-behaved device). Thanks > > > -- > MST >