Received: by 2002:ac0:de83:0:0:0:0:0 with SMTP id b3csp1318228imk; Mon, 4 Jul 2022 00:04:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1scYfO4kYgULW6HReMI2M4YTLDmRHOX/O3ovE6ERH2jXJb9joQIizG9r19fttWRQXh7ZLrl X-Received: by 2002:a17:906:9245:b0:726:3b57:1046 with SMTP id c5-20020a170906924500b007263b571046mr27808065ejx.221.1656918260754; Mon, 04 Jul 2022 00:04:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656918260; cv=none; d=google.com; s=arc-20160816; b=J/9Bqe20kySNYna0Qh1yoPtxrNmCSzgmsUZqqA/VJhz+aCStNyrIRo6H2fZKgAytJp kPj2QZrDtdqTzWG2QygFclmlUCct0WhTdhJlSDsO81eu0MIPr+8h3H2Q0+x8GxOxtNOc +NB5ggmZO70K9mXhsCf1bD14BpkJo2JUaflFLAC6oOdh2XTRnVYh0pdgdRu6LTloATVz 15DGoKDIv9Qd69Hoy/4MpYacub9P9pXxBOfA/IudS3oZMs4V9pMh8JAEsXjTehm1mDWd zZno3XZAQ1V4tKP0eZtrgJfbtqEXcNIuJqkurw9j9+yG8lvAFPvVRLUqMPMlpYkN6GE0 tkyA== 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=QKFiYOhVLexNLZAnyygH6JGx6im3hhRGTkcpFvcfiv0=; b=Ui8b3rzuKee1yWOL/nxYUZ324I/ph9WeVIP25Zi1fk1cD5a+D3q48QF7aSqymEfmbc yBosPnWndaS+WlF8ThzMvSd9pZhCtsOhobqhjZ64MCgv4ywsblFF0OJAhxc96Ykuo/JZ 1fTpI27k74OZaOmvFBsMl+kEMzrax/O2t/UKFuryxXwyjFcMQvSYYkOiTDf5sRh2arp8 Iipls831vLAu/CN+Eu0wJybvrp1ZiGwNO5Ruf3zK93sfYtGYpkdjzMzYf/VD9HzCQHDy r8xGCAnx4dsjwn7Of2tsjW107PTJM+TATqZG3BdtuEHIsfQzILVyHbAWm1xfUyxqiHTm HWIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="M4fHphM/"; 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 qk37-20020a1709077fa500b006fe4d195c19si19535994ejc.546.2022.07.04.00.03.55; Mon, 04 Jul 2022 00:04:20 -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="M4fHphM/"; 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 S232901AbiGDHAy (ORCPT + 99 others); Mon, 4 Jul 2022 03:00:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232637AbiGDHAw (ORCPT ); Mon, 4 Jul 2022 03:00:52 -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 5BE312DC2 for ; Mon, 4 Jul 2022 00:00:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656918050; 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=QKFiYOhVLexNLZAnyygH6JGx6im3hhRGTkcpFvcfiv0=; b=M4fHphM/2q+qW6AOPJSc5mh5jU9NR56MlYMu3kQ/tIrzh7zZOPd5vE+gKGlBvAlDfrguc5 Ur0gPhwCEZVTyT10SSyMBp4rWtZlStTwDEsXo4VQw4UXSqmbFcXDq9R/k8LuHmfcQLBBgl Ebw6tGR9lFjBh4Cach60RQDv/xJc2n4= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-226-mfQDXdSdMuKJKJrtn4ERKA-1; Mon, 04 Jul 2022 03:00:49 -0400 X-MC-Unique: mfQDXdSdMuKJKJrtn4ERKA-1 Received: by mail-wr1-f71.google.com with SMTP id w12-20020adf8bcc000000b0021d20a5b24fso1182228wra.22 for ; Mon, 04 Jul 2022 00:00:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=QKFiYOhVLexNLZAnyygH6JGx6im3hhRGTkcpFvcfiv0=; b=uxPGJqwoQRhQLmpSwpNAaHhVkKie36T1ECcbUBQj6o1fDCkNxFsgZgNhtUUOnaYj94 vcX5PYZAL4zqEY3qvAu5JaVcLw0ECmftAWmmH30A73lfCQNQzkY1rQvYhtH81bEN06z1 mCggk7xOgJStonthra/TM2CxH8QoI9a7+6+b4n+i5Kr8755mFMqdfiUiQ2BIe1QoWNuj TRSth6Ted+45dR1Ter4Nf+p4Fm+tUebqmPlhqPhxWXwbMM2tj6QM/UOT3pZNVyB5DZmb NzRdAFR9xcOiVgyIN7qI2dWo0HDtJffp3LjXv7eEcG2822B1x4rmIM3CV9kGAX8+EgIe b5HA== X-Gm-Message-State: AJIora+cmrFEVoMYjOYqMESdDJhtOKrqJda/iraoear9BlCdkFTGZODT Nr8MVx8hPLv24tcIcJb/PqX5/VS9YiVIm8/Dg5OQULYllc6iT+qRzGk31sgRHtqomv4tgdsVnu8 ohi7eNSUQxb/jQoYqnEVbMBEO X-Received: by 2002:a5d:5050:0:b0:21b:a348:7c0 with SMTP id h16-20020a5d5050000000b0021ba34807c0mr24643673wrt.184.1656918048109; Mon, 04 Jul 2022 00:00:48 -0700 (PDT) X-Received: by 2002:a5d:5050:0:b0:21b:a348:7c0 with SMTP id h16-20020a5d5050000000b0021ba34807c0mr24643655wrt.184.1656918047895; Mon, 04 Jul 2022 00:00:47 -0700 (PDT) Received: from redhat.com ([2.55.3.188]) by smtp.gmail.com with ESMTPSA id o15-20020a05600c510f00b003971fc23185sm14891356wms.20.2022.07.04.00.00.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 00:00:47 -0700 (PDT) Date: Mon, 4 Jul 2022 03:00:42 -0400 From: "Michael S. Tsirkin" To: Jason Wang 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 Subject: Re: [PATCH V3] virtio: disable notification hardening by default Message-ID: <20220704025850-mutt-send-email-mst@kernel.org> References: <20220629022223-mutt-send-email-mst@kernel.org> <20220629030600-mutt-send-email-mst@kernel.org> <20220629044514-mutt-send-email-mst@kernel.org> <20220630043219-mutt-send-email-mst@kernel.org> <20220704021950-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.8 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=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 Mon, Jul 04, 2022 at 02:40:16PM +0800, Jason Wang wrote: > On Mon, Jul 4, 2022 at 2:22 PM Michael S. Tsirkin wrote: > > > > On Mon, Jul 04, 2022 at 12:23:27PM +0800, Jason Wang wrote: > > > > So if there are not examples of callbacks not ready after kick > > > > then let us block callbacks until first kick. That is my idea. > > > > > > Ok, let me try. I need to drain my queue of fixes first. > > > > > > Thanks > > > > If we do find issues, another option is blocking callbacks until the > > first add. A bit higher overhead as add is a more common operation > > but it has even less of a chance to introduce regressions. > > So I understand that the case of blocking until first kick but if we > block until add it means for drivers: > > virtqueue_add() > virtio_device_ready() > virtqueue_kick() > > We probably enlarge the window in this case. > > Thanks Yes but I don't know whether any drivers call add before they are ready to get a callback. The main thing with hardening is not to break drivers. Primum non nocere and all that. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >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 > > > > > > > > > > > > > > > > Let's leave remove alone for now. I am close to 100% sure we have *lots* > > > > > > > > of issues around it, but while probe is unavoidable remove can be > > > > > > > > avoided by blocking hotplug. > > > > > > > > > > > > > > Unbind can trigger this path as well. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > 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 > > > > > > > > > > > > > > > > patches you posted deal with DRIVER_OK spec compliance. > > > > > > > > I do not see patches for kicks before callbacks are ready to run. > > > > > > > > > > > > > > Yes. > > > > > > > > > > > > > > Thanks > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > MST > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >