Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2156764iof; Tue, 7 Jun 2022 21:39:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzG4+N789XOhA4TI0qcU+4wf0z3D8Q/E2MJ6hdKExZwh19p6eJhb9mTQdLwt23B2qpLKrEZ X-Received: by 2002:a17:90b:4a03:b0:1e8:4b95:677f with SMTP id kk3-20020a17090b4a0300b001e84b95677fmr24233388pjb.85.1654663167389; Tue, 07 Jun 2022 21:39:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654663167; cv=none; d=google.com; s=arc-20160816; b=zryLi/mXT98ExKRkAUVUu0zgnh15slZoK9AmpYAyVHPtj0bl+7GzNvQJya/j55oykw ChZCEE9OARtel52esHPSl/X6LBvsKiTczp1pF10vUD5Z6g5fyFAWHa8zMpFFXFm71ojq Klu/QQumZReZZuGPnXevkv8mzW5yyZMrRtXtVfuQH1tN/ms5EuLv8UrtXuN73cmN8Aye lsPxovOdzrPjPffWBs+3K4BeJ2pkDqUC4bHDXWAd6nfSqRHTbzmCTOhx7ddB9DrNW3py a18kueqFoqw3N/zQJWL/0DBbiUQGnlF3D+eO+Oa3zjuwhupLz0kI416LNteX/vOEEB6h sGFw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=L38G9gQLJnu71wKjbgGgqrcT2wsss8qVoZkNX0NYex4=; b=Rh2hWRy534dg0U791hGXTWHpYhBb/OCCuvXN4gcguwGaUtmMqIwKFA3ZNIyP4+uWaa n7IWTTB/5FmNfk+InruXoccDMJuhDwBjKf5EHnxMvSgAAtsecJA3uYMMZOpLriuNdLsn U1LMDF9T4kaptX0tEd5SALkxRZ1grbrX/NYnCveD1Pqu1ujcSrGdpPpItBt3FxD0+Cfh bxgwT0ixQiDyacSdM23Zv61dKqjPIy+GUCRJdv3RhLPBJENA1QDLxFfENPn6noiF9KOt uMbItNbUQNaCsJGeBmVcLLvI3N6j4FFTQJ/zzZQeUWnbBmLMInxLwYU8HPocIvBPbBUC ezCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bNm5uATO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d10-20020a170902ceca00b00161739962ffsi30036361plg.163.2022.06.07.21.39.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:39:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bNm5uATO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3B3BA27CD78; Tue, 7 Jun 2022 21:07:18 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380885AbiFGVmc (ORCPT + 99 others); Tue, 7 Jun 2022 17:42:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378690AbiFGUwX (ORCPT ); Tue, 7 Jun 2022 16:52:23 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E90BF6146; Tue, 7 Jun 2022 11:42:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8245AB82182; Tue, 7 Jun 2022 18:42:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECDA5C385A2; Tue, 7 Jun 2022 18:42:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654627367; bh=5W7m88KiTZvHvoWjyOt0GpGQuUxzdpHJkRGENQfNYDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bNm5uATOucfBJ9wWIqyvwlEihts0v15j13QYm/aF4eQb0kMFqoQstA+NvXFRLidpT qAGusUmZttG4xyJBrYSTBQUOH9/dCG5Cr7dMDQthtAw/62O5XON4KNfRtaCUKJapK6 GLOLneMm5QYmV7XJOlwPrO5lfoy/i6KnMKVjYcYc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johannes Berg , Richard Weinberger Subject: [PATCH 5.17 714/772] um: virtio_uml: Fix broken device handling in time-travel Date: Tue, 7 Jun 2022 19:05:06 +0200 Message-Id: <20220607165010.083869783@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164948.980838585@linuxfoundation.org> References: <20220607164948.980838585@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Johannes Berg commit af9fb41ed315ce95f659f0b10b4d59a71975381d upstream. If a device implementation crashes, virtio_uml will mark it as dead by calling virtio_break_device() and scheduling the work that will remove it. This still seems like the right thing to do, but it's done directly while reading the message, and if time-travel is used, this is in the time-travel handler, outside of the normal Linux machinery. Therefore, we cannot acquire locks or do normal "linux-y" things because e.g. lockdep will be confused about the context. Move handling this situation out of the read function and into the actual IRQ handler and response handling instead, so that in the case of time-travel we don't call it in the wrong context. Chances are the system will still crash immediately, since the device implementation crashing may also cause the time- travel controller to go down, but at least all of that now happens without strange warnings from lockdep. Fixes: c8177aba37ca ("um: time-travel: rework interrupt handling in ext mode") Cc: stable@vger.kernel.org Signed-off-by: Johannes Berg Signed-off-by: Richard Weinberger Signed-off-by: Greg Kroah-Hartman --- arch/um/drivers/virtio_uml.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) --- a/arch/um/drivers/virtio_uml.c +++ b/arch/um/drivers/virtio_uml.c @@ -63,6 +63,7 @@ struct virtio_uml_device { u8 config_changed_irq:1; uint64_t vq_irq_vq_map; + int recv_rc; }; struct virtio_uml_vq_info { @@ -148,14 +149,6 @@ static int vhost_user_recv(struct virtio rc = vhost_user_recv_header(fd, msg); - if (rc == -ECONNRESET && vu_dev->registered) { - struct virtio_uml_platform_data *pdata; - - pdata = vu_dev->pdata; - - virtio_break_device(&vu_dev->vdev); - schedule_work(&pdata->conn_broken_wk); - } if (rc) return rc; size = msg->header.size; @@ -164,6 +157,21 @@ static int vhost_user_recv(struct virtio return full_read(fd, &msg->payload, size, false); } +static void vhost_user_check_reset(struct virtio_uml_device *vu_dev, + int rc) +{ + struct virtio_uml_platform_data *pdata = vu_dev->pdata; + + if (rc != -ECONNRESET) + return; + + if (!vu_dev->registered) + return; + + virtio_break_device(&vu_dev->vdev); + schedule_work(&pdata->conn_broken_wk); +} + static int vhost_user_recv_resp(struct virtio_uml_device *vu_dev, struct vhost_user_msg *msg, size_t max_payload_size) @@ -171,8 +179,10 @@ static int vhost_user_recv_resp(struct v int rc = vhost_user_recv(vu_dev, vu_dev->sock, msg, max_payload_size, true); - if (rc) + if (rc) { + vhost_user_check_reset(vu_dev, rc); return rc; + } if (msg->header.flags != (VHOST_USER_FLAG_REPLY | VHOST_USER_VERSION)) return -EPROTO; @@ -369,6 +379,7 @@ static irqreturn_t vu_req_read_message(s sizeof(msg.msg.payload) + sizeof(msg.extra_payload)); + vu_dev->recv_rc = rc; if (rc) return IRQ_NONE; @@ -412,7 +423,9 @@ static irqreturn_t vu_req_interrupt(int if (!um_irq_timetravel_handler_used()) ret = vu_req_read_message(vu_dev, NULL); - if (vu_dev->vq_irq_vq_map) { + if (vu_dev->recv_rc) { + vhost_user_check_reset(vu_dev, vu_dev->recv_rc); + } else if (vu_dev->vq_irq_vq_map) { struct virtqueue *vq; virtio_device_for_each_vq((&vu_dev->vdev), vq) {