Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp394594iog; Thu, 30 Jun 2022 02:57:33 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uQcF4o6hvUqxwq1KeTJB2KYH2CVfElEebbZ/WPh/LiMxzzKb1+psAJR7JeARl21bmsG6Rf X-Received: by 2002:a63:8a41:0:b0:40d:a82b:cda5 with SMTP id y62-20020a638a41000000b0040da82bcda5mr7116238pgd.610.1656583053319; Thu, 30 Jun 2022 02:57:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656583053; cv=none; d=google.com; s=arc-20160816; b=feXUrRBHQ6fqSXG+2IsdSr4D4GXAyyw7wjs/LhCJztH+3k8zBT1jq0PmkymB+iKOy7 aOouGqUAF+Wg3lWI96TrmO5c81VBMI4XhHfpgPclTL9y1o8kEqrfjC+PWBXTdY4rAdts n/dGzUtKzDUTSTxBnHnclXS+WaocEvkzjCmyt9BSZEitM/6E/J3wX1k8dFtd9khsI/QC WmD/51lrYNcARE03SYJHSd/5bJH8rq8XO7zUPFCISK3R73U57JYK/3AKRVYMsahBMUyO tYXp4hNy4ui1NewpcYCFzt8YozXYhW+mmtfQ/sJHvpZHWOnvtbfaAt5geCUiKs2ItMZH VjHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=eP1sj3XLEhD8H0WwbeboKYvAKhfYwTvFMo2H6hCECIY=; b=MSiSafLl4nVGeZP3gIhrPw46KDr7NVqsAGq9wnWU/CpAhOaLJ/vC3e+EGO247h7ctk bxrPMEFGbe5dZzwuts17In2GtFFFvRAckWgRVYPZK3P4tzli7Q3scTMZhAHez2Nd4ix7 hpAySqP5v5xiMGVlPXrMZoAc/LFEWsZfJACQWHW9cPWlp9vvGile7ePb8TaXMCIA9UoQ tm/5HcTqlpM7dJ8E4AQtzhnkTwD7m5Lf5zWs/bsnr9kmc7/b1b2yhFAtGeV2zNpUaX/L t9DS3e88tvsh2K5boyXSU5Q/3/N6Q+PtGAepA3A3aSHjZuBMRHRVD1Isryr0lwccWNY2 UIyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=FvOXx8wC; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb8-20020a17090b35c800b001ed05a3f1ecsi5476864pjb.177.2022.06.30.02.57.21; Thu, 30 Jun 2022 02:57: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=@virtuozzo.com header.s=relay header.b=FvOXx8wC; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233577AbiF3JyQ (ORCPT + 99 others); Thu, 30 Jun 2022 05:54:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230350AbiF3JyO (ORCPT ); Thu, 30 Jun 2022 05:54:14 -0400 X-Greylist: delayed 919 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 30 Jun 2022 02:54:13 PDT Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 325EC22BFB; Thu, 30 Jun 2022 02:54:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-Id:Date:Subject:From: Content-Type; bh=eP1sj3XLEhD8H0WwbeboKYvAKhfYwTvFMo2H6hCECIY=; b=FvOXx8wCxRCi G6aAQCyB2O0Rs+02kUuiNOhqdQjCy8aMvJ2S+xudaMcHf4dnMRFd50KgW6SAZzluXTcfg+3W1YX/u LnhNuu495fVk3LwJtEclMd5vuiJ2BBv3i2/EwhcDjW6+sESMkSdiFZjMYyQO9MMF3A+kpxDWf1Smp UoZdo=; Received: from [192.168.16.236] (helo=vzdev.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.94.2) (envelope-from ) id 1o6qbC-007yyH-Lu; Thu, 30 Jun 2022 11:37:09 +0200 From: Alexander Atanasov To: "Michael S. Tsirkin" , Jason Wang Cc: kernel@openvz.org, Alexander Atanasov , Thomas Gleixner , Peter Zijlstra , "Paul E. McKenney" , Marc Zyngier , Halil Pasic , Cornelia Huck , Vineeth Vijayan , Peter Oberparleiter , linux-s390@vger.kernel.org, Xuan Zhuo , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/1] virtio: Restore semantics of vq->broken in virtqueues Date: Thu, 30 Jun 2022 09:36:46 +0000 Message-Id: <20220630093651.25981-1-alexander.atanasov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 virtio: harden vring IRQ (8b4ec69d7e09) changed the use of vq->broken. As result vring_interrupt handles IRQs for broken drivers as IRQ_NONE and not IRQ_HANDLED and made impossible to initiallize vqs before the driver is ready, i.e. in probe method. Balloon driver does this and it can not load because it fails in vqs_init with -EIO. So instead of changing the original intent ot the flag introduce a new flag vq->ready which servers the purpose to check of early IRQs and restore the behaviour of the vq->broken flag. Signed-off-by: Alexander Atanasov --- drivers/virtio/virtio_ring.c | 20 ++++++++++++++------ include/linux/virtio.h | 2 +- include/linux/virtio_config.h | 10 +++++----- 3 files changed, 20 insertions(+), 12 deletions(-) Cc: Thomas Gleixner Cc: Peter Zijlstra Cc: "Paul E. McKenney" Cc: Marc Zyngier Cc: Halil Pasic Cc: Cornelia Huck Cc: Vineeth Vijayan Cc: Peter Oberparleiter Cc: linux-s390@vger.kernel.org Cc: Xuan Zhuo diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 13a7348cedff..dca3cc774584 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -100,6 +100,9 @@ struct vring_virtqueue { /* Other side has made a mess, don't try any more. */ bool broken; + /* the queue is ready to handle interrupts */ + bool ready; + /* Host supports indirect buffers */ bool indirect; @@ -1688,7 +1691,8 @@ static struct virtqueue *vring_create_virtqueue_packed( vq->we_own_ring = true; vq->notify = notify; vq->weak_barriers = weak_barriers; - vq->broken = true; + vq->broken = false; + vq->ready = false; vq->last_used_idx = 0; vq->event_triggered = false; vq->num_added = 0; @@ -2134,7 +2138,10 @@ irqreturn_t vring_interrupt(int irq, void *_vq) return IRQ_NONE; } - if (unlikely(vq->broken)) { + if (unlikely(vq->broken)) + return IRQ_HANDLED; + + if (unlikely(!vq->ready)) { dev_warn_once(&vq->vq.vdev->dev, "virtio vring IRQ raised before DRIVER_OK"); return IRQ_NONE; @@ -2180,7 +2187,8 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, vq->we_own_ring = false; vq->notify = notify; vq->weak_barriers = weak_barriers; - vq->broken = true; + vq->broken = false; + vq->ready = false; vq->last_used_idx = 0; vq->event_triggered = false; vq->num_added = 0; @@ -2405,7 +2413,7 @@ EXPORT_SYMBOL_GPL(virtio_break_device); * (probing and restoring). This function should only be called by the * core, not directly by the driver. */ -void __virtio_unbreak_device(struct virtio_device *dev) +void __virtio_device_ready(struct virtio_device *dev) { struct virtqueue *_vq; @@ -2414,11 +2422,11 @@ void __virtio_unbreak_device(struct virtio_device *dev) struct vring_virtqueue *vq = to_vvq(_vq); /* Pairs with READ_ONCE() in virtqueue_is_broken(). */ - WRITE_ONCE(vq->broken, false); + WRITE_ONCE(vq->ready, true); } spin_unlock(&dev->vqs_list_lock); } -EXPORT_SYMBOL_GPL(__virtio_unbreak_device); +EXPORT_SYMBOL_GPL(__virtio_device_ready); dma_addr_t virtqueue_get_desc_addr(struct virtqueue *_vq) { diff --git a/include/linux/virtio.h b/include/linux/virtio.h index d8fdf170637c..538c5959949a 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -131,7 +131,7 @@ void unregister_virtio_device(struct virtio_device *dev); bool is_virtio_device(struct device *dev); void virtio_break_device(struct virtio_device *dev); -void __virtio_unbreak_device(struct virtio_device *dev); +void __virtio_device_ready(struct virtio_device *dev); void virtio_config_changed(struct virtio_device *dev); #ifdef CONFIG_PM_SLEEP diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index 49c7c32815f1..35cf1b26e05a 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h @@ -259,21 +259,21 @@ void virtio_device_ready(struct virtio_device *dev) /* * The virtio_synchronize_cbs() makes sure vring_interrupt() - * will see the driver specific setup if it sees vq->broken + * will see the driver specific setup if it sees vq->ready * as false (even if the notifications come before DRIVER_OK). */ virtio_synchronize_cbs(dev); - __virtio_unbreak_device(dev); + __virtio_device_ready(dev); /* - * The transport should ensure the visibility of vq->broken + * The transport should ensure the visibility of vq->ready * before setting DRIVER_OK. See the comments for the transport * specific set_status() method. * * A well behaved device will only notify a virtqueue after * DRIVER_OK, this means the device should "see" the coherenct - * memory write that set vq->broken as false which is done by + * memory write that set vq->ready as true which is done by * the driver when it sees DRIVER_OK, then the following - * driver's vring_interrupt() will see vq->broken as false so + * driver's vring_interrupt() will see vq->true as true so * we won't lose any notification. */ dev->config->set_status(dev, status | VIRTIO_CONFIG_S_DRIVER_OK); -- 2.25.1