Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3185631rwb; Tue, 8 Nov 2022 01:21:39 -0800 (PST) X-Google-Smtp-Source: AMsMyM5MIYcssJWHWr38DLmv3JsTkO51wcLaUVOQw1eOglfz9Czwqb34U8ZeYRiTQ/jRxeKbnzlz X-Received: by 2002:a17:902:d18c:b0:187:1b86:daba with SMTP id m12-20020a170902d18c00b001871b86dabamr47820076plb.84.1667899299433; Tue, 08 Nov 2022 01:21:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667899299; cv=none; d=google.com; s=arc-20160816; b=jeVMaLsV9skVOaQ96aH8e/Fcd5XdIOdbYsSQb7ktF3TyRrix4Jcp8/PJ2dNcAo1wYj ou7q9VSQkrmM9sX9i/qcSVKvfcN5wqhfc/b0GMj/+3aOKIsk7RLaS7+3LVOw5QilhWqf rqAC41MMkC8n8B0qpf+LgiOK+V6BaG2fZpEWMtmhA9Nzjjr6Plh7rRfQpI4zpQgz5QjB NLIQa1cXIwrOxbrNSAkvVKks+iZ8lqtHjCyRKMA+dzsf9C+kufs2qMnKoQBUSzl6REER PvjWem2EO2y6YHiY4lzeV3PwfIaXZqTHvJOUE8TxGaQi6gHmvRq1lCRKKMENls02aT5e PPkg== 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=V76xZRdJF90cto+eNTfmdr62lIvdE2c1NcFAYSKdle4=; b=ObEB7gvIWtGskXjzQV+4ftklyOQ+JOPPH3R/UEz6CqRJyNvPYYFFzyZtDyWiMwuwSo pt7ThMtaS3Ju8h+7W8GkSXz86oGvPChrvYcDFCpTySp2fZlIq0gbNAo3wkEsKLnCscYG pahD4Bon6X11vVJHV/EGWEdXhp7bZdca/sIVy3yWY4FwFUHKXM3Z75wj7pltXFquBQi2 3s5ka9Aodu7mwngn1qftQLUmmmJnrwCU9ZLySZu96FUge5iG6LkBbsyhMyCS7mM6qBle keKjL5efd9JDKnKdO4B6JPXpvhYkBGPwnEsTmn9/01XgorB4XW8j9u5KeiXAXsL25SWP Ofcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=M+Wrl7Vn; 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 g24-20020a633758000000b00438854c876esi14116226pgn.419.2022.11.08.01.21.27; Tue, 08 Nov 2022 01:21:39 -0800 (PST) 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=M+Wrl7Vn; 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 S233668AbiKHJPJ (ORCPT + 89 others); Tue, 8 Nov 2022 04:15:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233651AbiKHJPH (ORCPT ); Tue, 8 Nov 2022 04:15:07 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C428327DD1 for ; Tue, 8 Nov 2022 01:14:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667898844; 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=V76xZRdJF90cto+eNTfmdr62lIvdE2c1NcFAYSKdle4=; b=M+Wrl7VnA3XfGnJi9Ob7CZxtP1KHuJHGsNEFTiKi6GM4mYOCPhWdLcTcKHJ75aF+oVhGBh AcQ60aDcYJW+V1mM5EkrIOaEyBf+rwNVrV8PtYX8bSzrO8EEjarkwayo5aWkBoNaSpmu4P HmaypbOycwqohhFx1wcfjyrvl3xoPiQ= Received: from mail-oo1-f71.google.com (mail-oo1-f71.google.com [209.85.161.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-26-LDM0JV4TN9eB0s2ry5ptjA-1; Tue, 08 Nov 2022 04:14:02 -0500 X-MC-Unique: LDM0JV4TN9eB0s2ry5ptjA-1 Received: by mail-oo1-f71.google.com with SMTP id x6-20020a4a2a46000000b0049ca27b1507so3487530oox.5 for ; Tue, 08 Nov 2022 01:14:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=V76xZRdJF90cto+eNTfmdr62lIvdE2c1NcFAYSKdle4=; b=yw3zJYLMnkyFx47bjL3586pJI6YSMyiZmltVJ5um/TPxCXo3KoDfryQUvYI25APex1 T8T2Ns3W/inNpILrnVc7tksYn6VcgiYWx85NOgSVWLxRTDt3KwwFNc2qkg/i+qCHaERo 2T7du1HSffclX6pOZfC2iajqGzwlXLS4zzymDAn2vZ/rF3+Vz3TyXtw6oEQbENQ3lfHg zapFp9k+QQ18AYiNQA6L1A4ayu+li3WjgRr+VKDeNeVvG3v5CItAqGjgU46z5RWfGQWo A0fohWyOjaKSMd09zjylnBEvVopOjUNdjvgeFmDUGEZFBcHLXGbXDRxulS+lsZ+mVxQt IQEQ== X-Gm-Message-State: ACrzQf2kLCO/mSHlJr+RpT/VAGW9sWqgbVSEu8HW5HSmx/ria7Yc9xQL sD5rQX7h6MdC+kqmD8bW28O3bny45t4xNbagkTiR3qFDD7S6i72Bz4K7m8P+9YRe7huJmMP0kyc 4+mcVQfqdwa4bNW54ms6uY2MwYA+eks6ZK91HbfOz X-Received: by 2002:a05:6808:181e:b0:35a:5959:5909 with SMTP id bh30-20020a056808181e00b0035a59595909mr12605627oib.35.1667898842133; Tue, 08 Nov 2022 01:14:02 -0800 (PST) X-Received: by 2002:a05:6808:181e:b0:35a:5959:5909 with SMTP id bh30-20020a056808181e00b0035a59595909mr12605616oib.35.1667898841877; Tue, 08 Nov 2022 01:14:01 -0800 (PST) MIME-Version: 1.0 References: <20221107203431.368306-1-eric.auger@redhat.com> <20221107153924-mutt-send-email-mst@kernel.org> <20221107180022-mutt-send-email-mst@kernel.org> <20221108035142-mutt-send-email-mst@kernel.org> In-Reply-To: <20221108035142-mutt-send-email-mst@kernel.org> From: Jason Wang Date: Tue, 8 Nov 2022 17:13:50 +0800 Message-ID: Subject: Re: [RFC] vhost: Clear the pending messages on vhost_init_device_iotlb() To: "Michael S. Tsirkin" Cc: Eric Auger , eric.auger.pro@gmail.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, peterx@redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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 Tue, Nov 8, 2022 at 4:56 PM Michael S. Tsirkin wrote: > > On Tue, Nov 08, 2022 at 11:09:36AM +0800, Jason Wang wrote: > > On Tue, Nov 8, 2022 at 7:06 AM Michael S. Tsirkin wrote: > > > > > > On Mon, Nov 07, 2022 at 10:10:06PM +0100, Eric Auger wrote: > > > > Hi Michael, > > > > On 11/7/22 21:42, Michael S. Tsirkin wrote: > > > > > On Mon, Nov 07, 2022 at 09:34:31PM +0100, Eric Auger wrote: > > > > >> When the vhost iotlb is used along with a guest virtual iommu > > > > >> and the guest gets rebooted, some MISS messages may have been > > > > >> recorded just before the reboot and spuriously executed by > > > > >> the virtual iommu after the reboot. Despite the device iotlb gets > > > > >> re-initialized, the messages are not cleared. Fix that by calling > > > > >> vhost_clear_msg() at the end of vhost_init_device_iotlb(). > > > > >> > > > > >> Signed-off-by: Eric Auger > > > > >> --- > > > > >> drivers/vhost/vhost.c | 1 + > > > > >> 1 file changed, 1 insertion(+) > > > > >> > > > > >> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > > > > >> index 40097826cff0..422a1fdee0ca 100644 > > > > >> --- a/drivers/vhost/vhost.c > > > > >> +++ b/drivers/vhost/vhost.c > > > > >> @@ -1751,6 +1751,7 @@ int vhost_init_device_iotlb(struct vhost_dev *d, bool enabled) > > > > >> } > > > > >> > > > > >> vhost_iotlb_free(oiotlb); > > > > >> + vhost_clear_msg(d); > > > > >> > > > > >> return 0; > > > > >> } > > > > > Hmm. Can't messages meanwhile get processes and affect the > > > > > new iotlb? > > > > Isn't the msg processing stopped at the moment this function is called > > > > (VHOST_SET_FEATURES)? > > > > > > > > Thanks > > > > > > > > Eric > > > > > > It's pretty late here I'm not sure. You tell me what prevents it. > > > > So the proposed code assumes that Qemu doesn't process device IOTLB > > before VHOST_SET_FEAETURES. Consider there's no reset in the general > > vhost uAPI, I wonder if it's better to move the clear to device code > > like VHOST_NET_SET_BACKEND. So we can clear it per vq? > > Hmm this makes no sense to me. iommu sits between backend > and frontend. Tying one to another is going to backfire. I think we need to emulate what real devices are doing. Device should clear the page fault message during reset, so the driver won't read anything after reset. But we don't have a per device stop or reset message for vhost-net. That's why the VHOST_NET_SET_BACKEND came into my mind. > > I'm thinking more along the lines of doing everything > under iotlb_lock. I think the problem is we need to find a proper place to clear the message. So I don't get how iotlb_lock can help: the message could be still read from user space after the backend is set to NULL. Thanks > > > > > > > > > BTW vhost_init_device_iotlb gets enabled parameter but ignores > > > it, we really should drop that. > > > > Yes. > > > > > > > > Also, it looks like if features are set with VIRTIO_F_ACCESS_PLATFORM > > > and then cleared, iotlb is not properly cleared - bug? > > > > Not sure, old IOTLB may still work. But for safety, we need to disable > > device IOTLB in this case. > > > > Thanks > > > > > > > > > > > > > > > > > > > > > > >> -- > > > > >> 2.37.3 > > > >