From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD91C337688 for ; Sat, 25 Apr 2026 15:10:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777129852; cv=none; b=pkyQJc1nOkUQa1K0+6EWzB0A3xz1KxY+/O8m86r5TvVCCuByd8YxHkdgthmCw2aZ2Y3oYNcwxCwEMCC8ujP1UglbwwXd8wi8wNM3QTMTrWTtrKrjqdIKgJk4hS2qXzKGPZH3m75EQjIlJQEqAFVjWXbpRdsDr0RSt8SHjYS7YLU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777129852; c=relaxed/simple; bh=7OmRKB5lte2dq7kRW48MLu51Z2dEntMVGgXISah2S/I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sNBrFLmegJKG2YKfSDonkX2rXkifi20UcFxj2EaTrOEKT97T8oZZaHKsx2cM3G7Xnfy+0GibNZ6D9QBKmcMxntcnXwzdfxFfnl7o0w2qzalcBgKH0y4iP+SCs43OG7Usgqtqi4SCRAVgvWqkCgCZTCw/gfTgg8jVQ2pcCo9z8/Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=cOZFgIfV; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=eoIGRCXR; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cOZFgIfV"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="eoIGRCXR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777129849; 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=ferbHEmpI+lNfISIiYNW9cZesuyd3hPcOYBw4/4sikc=; b=cOZFgIfV5KwUs7gwF0P9LfaTA20yjWanjhkgXurKvqnzO20xnYEnxonQBKwLJVfE+HOn2d 8QcMcMy7BPVoKRi6IsCaVMqper/vxmiU9DLW81pwv7b023j4cx0ky0kcfoGHAqjy52XSku Pf/j8C9A4isrFTLevS1HfPY4nu57HP8= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-145-3xgwjEziPOWaZb-ZZQQkWg-1; Sat, 25 Apr 2026 11:10:48 -0400 X-MC-Unique: 3xgwjEziPOWaZb-ZZQQkWg-1 X-Mimecast-MFC-AGG-ID: 3xgwjEziPOWaZb-ZZQQkWg_1777129847 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-488d8deb75fso72358475e9.3 for ; Sat, 25 Apr 2026 08:10:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1777129847; x=1777734647; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ferbHEmpI+lNfISIiYNW9cZesuyd3hPcOYBw4/4sikc=; b=eoIGRCXRzuO4q4+z2gi8hd6bkVjIRsioPelzuGTd7wxWIzInTy6HqXETiyqwFx86/x k6siyJ/+1sdvDs+yeJy8iWBflhZQWUCP5CujY56MJ/omSLfoxWuC6qs4GCgXcT60aTIP jlC8e5/AWenJL8YrXrIxuEc227OZQX9nGMc0BHJRxW5IAj6zo+Wt0JifoDfQbwyivmHq NXCMrtxQwRtZl+InoD1IxWketJQfl+t5GGBIHm4rg95qc/g27Mw6x+b3fQTFkFtfHyqz Yv5UaV/7uhB7bJWVz38UUMAiKusg6K+kohQZHD/iqkKwCt98qhWuw2irANxxAxR/WxjO tbAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777129847; x=1777734647; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ferbHEmpI+lNfISIiYNW9cZesuyd3hPcOYBw4/4sikc=; b=icGIEYK4Ecuc0izNN6RrX1gnTnymkGe3HcReNIlIMCHjoY2fMWeykq1hONnDF/Yqk6 K9yW/nB/9g+fq/FOhoTu5nDWrOY6A8qwDXw8hnQbjPi8yjb6Px8iN6Vg6ZMqxUq+VI3u Mjgu5OlNqKugXkBayXiOtZOo/pqC+8rTSuKSTbxAz9SHWLX21r4e0go9M3uAY2llM12a iaaU1bGakjr/jmMC+tlo4Lh5y1Gdl0q/fX4S26eGIyAaPeEJdYxt/R1z5xYX/zhBWlAm LOYxXx9lGbUAewTokMSAb+iHFJdQ33T499IgKYAspvvDQDquBtHj/DeVxZKBfy5DEoKk Dt9w== X-Forwarded-Encrypted: i=1; AFNElJ+NrIIjgFW71QwM+U4wEh86h8nxGn9O33moIpZ+quCTacE+nd90tzqNXiRlNICBdUmFzQLmvfXOIB0cFXo=@vger.kernel.org X-Gm-Message-State: AOJu0YzWzkt5OecpWVMrrkuHhKwyNIcsU/mJirlcb3grDRQiME2tXDY7 K34EaYLCz17T/CWGtlrFPAzIay5YQ3rfYZ4jms1qJdQ6280R9jOeuZDg/ntaDvJ8OHExrHg77Qk qomOsqoYj4h+pE4LIgcGuU3ivf5P73LgpYz1sWg77ZGpr5ZFY+UPOKTS4p2vwJqPMFg== X-Gm-Gg: AeBDiesQT3b6hBVRn5tFn8xlq8XDwWKmL88/ekRGXZFbEz5QUvRDNCn6dzq6cA28gwt ACXAqTiLCBYQ76/C4QuUKSiM4QnTguSDRPy4UHn/zmknUttjFNXcXX2FU/6weR2LE/m94wzx5iJ IMNzpd/R+IlOpcfxWM0ITk2/aAsOdtUTj4I10Wt3doGCDoO4EtXZzZHEs+9fUpY3BkHbRa1CpGz 2FH2ZBqLeRJdogPkbLeFsHh8llwL0/IDo3POG4EYF++ZPQIJ7KChMX2H2DgltxAgBOBk8TMbFQU AOqh+LTpYvfwx2fp7BGBfsb2u6qwY9ZvoCCC8PEsQpU3yOQJlzZ6Xb44tsQI9i7hID0BgGhyTD1 SGTt1WAT/RSzGWc7tFoWevE5/ X-Received: by 2002:a05:600c:3e1a:b0:489:1ca2:eafd with SMTP id 5b1f17b1804b1-4891ca2ee65mr375230875e9.11.1777129847293; Sat, 25 Apr 2026 08:10:47 -0700 (PDT) X-Received: by 2002:a05:600c:3e1a:b0:489:1ca2:eafd with SMTP id 5b1f17b1804b1-4891ca2ee65mr375230665e9.11.1777129846820; Sat, 25 Apr 2026 08:10:46 -0700 (PDT) Received: from redhat.com ([147.235.221.19]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488fb7a06f3sm242530465e9.22.2026.04.25.08.10.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Apr 2026 08:10:46 -0700 (PDT) Date: Sat, 25 Apr 2026 11:10:43 -0400 From: "Michael S. Tsirkin" To: physicalmtea Cc: Peter Hilber , jasowang@redhat.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] virtio: rtc: tear down old virtqueues before restore Message-ID: <20260425110857-mutt-send-email-mst@kernel.org> References: <20260425070840.488634-1-physicalmtea@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260425070840.488634-1-physicalmtea@gmail.com> On Sat, Apr 25, 2026 at 03:08:40PM +0800, physicalmtea wrote: > From: JiaJia > > virtio_device_restore() resets the device and restores the negotiated > features before calling ->restore(). viortc_freeze() intentionally > leaves the existing virtqueues in place so the alarm queue can still > wake the system, but viortc_restore() immediately calls > viortc_init_vqs() without first deleting those old queues. > > If virtqueue reinitialization fails on virtio-pci, the transport error > path can run vp_del_vqs() against a newly allocated vp_dev->vqs array > while vdev->vqs still contains the old virtqueues. vp_del_vqs() then > looks up queue state through the new array and can dereference a NULL > info pointer in vp_del_vq(), crashing the guest kernel during restore. > > This can also happen during a non-faulty reinitialization, when one of > the vp_find_vqs_msix() attempts is unsuccessful before a later attempt > would succeed. > > Delete the stale virtqueues before rebuilding them. If restore fails > before virtio_device_ready(), reuse the remove path to stop the device. > Once the device is ready, return errors directly instead of deleting the > virtqueues again. > > Fixes: 0623c7592768 ("virtio_rtc: Add module and driver core") > Signed-off-by: JiaJia Sorry is this just the 1st name or the 1st and the last name? I think it's preferred to have the full name here. > Reviewed-by: Peter Hilber > --- > v3: > - Add Fixes tag. > - Add Peter's Reviewed-by tag. > - Clarify commit message regarding reinitialization scenarios. > > Apologies for missing the Fixes tag, and thanks for catching that! > I've also updated the commit message to include the scenario you > mentioned. > > drivers/virtio/virtio_rtc_driver.c | 28 ++++++++++++++++++++-------- > 1 file changed, 20 insertions(+), 8 deletions(-) > > diff --git a/drivers/virtio/virtio_rtc_driver.c b/drivers/virtio/virtio_rtc_driver.c > index a57d5e06e..4419735b0 100644 > --- a/drivers/virtio/virtio_rtc_driver.c > +++ b/drivers/virtio/virtio_rtc_driver.c > @@ -1257,6 +1257,15 @@ static int viortc_init_vqs(struct viortc_dev *viortc) > return 0; > } > > +static void __viortc_remove(struct viortc_dev *viortc) > +{ > + struct virtio_device *vdev = viortc->vdev; > + > + viortc_clocks_deinit(viortc); > + virtio_reset_device(vdev); > + vdev->config->del_vqs(vdev); > +} > + > /** > * viortc_probe() - probe a virtio_rtc virtio device > * @vdev: virtio device > @@ -1282,7 +1291,7 @@ static int viortc_probe(struct virtio_device *vdev) > > ret = viortc_init_vqs(viortc); > if (ret) > - return ret; > + goto err_reset_vdev; > > virtio_device_ready(vdev); > > @@ -1329,10 +1338,7 @@ static void viortc_remove(struct virtio_device *vdev) > { > struct viortc_dev *viortc = vdev->priv; > > - viortc_clocks_deinit(viortc); > - > - virtio_reset_device(vdev); > - vdev->config->del_vqs(vdev); > + __viortc_remove(viortc); > } > > static int viortc_freeze(struct virtio_device *dev) > @@ -1353,9 +1359,11 @@ static int viortc_restore(struct virtio_device *dev) > bool notify = false; > int ret; > > + dev->config->del_vqs(dev); > + > ret = viortc_init_vqs(viortc); > if (ret) > - return ret; > + goto err_remove; > > alarm_viortc_vq = &viortc->vqs[VIORTC_ALARMQ]; > alarm_vq = alarm_viortc_vq->vq; > @@ -1364,7 +1372,7 @@ static int viortc_restore(struct virtio_device *dev) > ret = viortc_populate_vq(viortc, alarm_viortc_vq, > VIORTC_ALARMQ_BUF_CAP, false); > if (ret) > - return ret; > + goto err_remove; > > notify = virtqueue_kick_prepare(alarm_vq); > } > @@ -1372,8 +1380,12 @@ static int viortc_restore(struct virtio_device *dev) > virtio_device_ready(dev); > > if (notify && !virtqueue_notify(alarm_vq)) > - ret = -EIO; > + return -EIO; > + > + return 0; > > +err_remove: > + __viortc_remove(viortc); > return ret; > } > > -- > 2.34.1