From patchwork Fri Oct 20 16:15:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 156223 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1168681vqb; Fri, 20 Oct 2023 09:16:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFZdjzF9eTPGnsR+bighVedLpgQAJx0ZbjJP/ya/3MivqnyPUFVWQr4QHL76s9sPBaczIEk X-Received: by 2002:a05:6a00:150a:b0:68e:3772:4e40 with SMTP id q10-20020a056a00150a00b0068e37724e40mr2407939pfu.3.1697818581010; Fri, 20 Oct 2023 09:16:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697818580; cv=none; d=google.com; s=arc-20160816; b=dEf4DYMKpc6AWeYEjaMrO3ZphPlgSUFQKnls0yXdNcI/JkO4f+mBLsGXwH/mR7Jd66 Qj7bR4YE6oeV72tBT1pEt/9PKP6Ksa5HO7mfNM8IHmiE63ZjW7htO2Cs5k2IWlKrn448 /XHvIpjl9ym1yVcaoxKIQm4hA5swGhwS0nH9a/9H6TJgGO3XeEIgnNu/e4xHEIzLqoo/ 6aT5NdsGSMqLrgSi3KG9Fyinte65ArvT4zeVOsl+kWJBAe0Ekg3L2dxYhy1K0J6w/vyx XiuUQGcCPG5rFkn6usuRSGMaAvZ1By4+2cVPSr0QVTIliGCdtj/squMeX1Z1olNlry6C irRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OW6M6axVm5EebrjONkYC4l2vPrYg1mjhksi3LsyyGRs=; fh=hRowg7FHjFkNvsaqzIhvo3cvY/I4Cr+L17V0ykyMVw0=; b=GhpeKgeXnA2Kn7Ma2e0HKB6yDC2jJKsYJffuRfxrB+311Ct8/ophASpuVwul18kJ5o fcjA7FCLqtjOLmDYUzUQX1yywLrO3uNGjUU38b4X2P3HTAREpmsA7MKgv62fLdfFFHjW QihuptZFL7WLwvATfEkAst3H5bTjBZfraiamRIlSwm0EOu73mtp+fL4tnYw/sZlmZahg xA6Guu7U1vJaCc8FV2QVReu95lkByISVvINXm96JExyuqmTl3U+tDCspO/zlFUwmSg15 6yF0bBRNyf2miaLOHs18GKujVATwwLpyuZMRZcXb57FCkr+eyWL92JRyid6gI9flJHMg TP+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=EMC1XQKN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id d20-20020a056a00199400b006bdfb718e04si2301789pfl.338.2023.10.20.09.16.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 09:16:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=EMC1XQKN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id F1A0D836B4F0; Fri, 20 Oct 2023 09:16:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377864AbjJTQQJ (ORCPT + 26 others); Fri, 20 Oct 2023 12:16:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229814AbjJTQQB (ORCPT ); Fri, 20 Oct 2023 12:16:01 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB9F8D57; Fri, 20 Oct 2023 09:15:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description; bh=OW6M6axVm5EebrjONkYC4l2vPrYg1mjhksi3LsyyGRs=; b=EMC1XQKNq6loHyWtwUrjbzwmwV cAgfQRMd4tmkJ8vfgqiDsAHkfDsIEKFYNphoGgZltm07MeMmeMyO41dK4BLYlKHBUnL8cqRNJUffv zVUHHvzr6M4MMJHsTleqmotIfBWN5RE5+FHp2NiKmK8ql6L7KcoxAfQIzazUnV+8qIv//5YmJyAH9 OxkBx/FtKdKWlxLO5fHYVYMBiLVYGrhC5A2L6h+uGalAtARfBXqSpuBlQovufA2ZACvU44sInMHHX saBDt/gndB0Jsk/Udp6oA3ydy0qG4OQ/poadbKKrrsFCSauxFUH/o6H3FX9ha6MDCtAaqPZVCLSsN QtrjJRcw==; Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qts9v-00BAsE-0Q; Fri, 20 Oct 2023 16:15:36 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qts9s-001UOW-0m; Fri, 20 Oct 2023 17:15:32 +0100 From: David Woodhouse To: Juergen Gross , xen-devel@lists.xenproject.org Cc: Greg Kroah-Hartman , Jiri Slaby , Roger Pau Monne , Stefano Stabellini , Dawei Li , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Paul Durrant Subject: [PATCH v2 1/3] hvc/xen: fix event channel handling for secondary consoles Date: Fri, 20 Oct 2023 17:15:27 +0100 Message-Id: <20231020161529.355083-2-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231020161529.355083-1-dwmw2@infradead.org> References: <20231020161529.355083-1-dwmw2@infradead.org> MIME-Version: 1.0 Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by desiato.infradead.org. See http://www.infradead.org/rpr.html X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 20 Oct 2023 09:16:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780291816378533952 X-GMAIL-MSGID: 1780291816378533952 From: David Woodhouse The xencons_connect_backend() function allocates a local interdomain event channel with xenbus_alloc_evtchn(), then calls bind_interdomain_evtchn_to_irq_lateeoi() to bind to that port# on the *remote* domain. That doesn't work very well: (qemu) device_add xen-console,id=con1,chardev=pty0 [ 44.323872] xenconsole console-1: 2 xenbus_dev_probe on device/console/1 [ 44.323995] xenconsole: probe of console-1 failed with error -2 Fix it to use bind_evtchn_to_irq_lateeoi(), which does the right thing by just binding that *local* event channel to an irq. The backend will do the interdomain binding. This didn't affect the primary console because the setup for that is special — the toolstack allocates the guest event channel and the guest discovers it with HVMOP_get_param. Fixes: fe415186b4 ("xen/console: harden hvc_xen against event channel storms") Signed-off-by: David Woodhouse Reviewed-by: Juergen Gross Cc: stable@vger.kernel.org --- drivers/tty/hvc/hvc_xen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c index 98764e740c07..f24e285b6441 100644 --- a/drivers/tty/hvc/hvc_xen.c +++ b/drivers/tty/hvc/hvc_xen.c @@ -433,7 +433,7 @@ static int xencons_connect_backend(struct xenbus_device *dev, if (ret) return ret; info->evtchn = evtchn; - irq = bind_interdomain_evtchn_to_irq_lateeoi(dev, evtchn); + irq = bind_evtchn_to_irq_lateeoi(evtchn); if (irq < 0) return irq; info->irq = irq; From patchwork Fri Oct 20 16:15:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 156222 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1168667vqb; Fri, 20 Oct 2023 09:16:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhLix1SnHhn5DZnvciO1hzjzsV5cVwKNELQz+QT4d93yL1hjA2U9z8l3jtTIwnlXOYNSDR X-Received: by 2002:a17:90b:1e12:b0:27d:d9a:be8b with SMTP id pg18-20020a17090b1e1200b0027d0d9abe8bmr3390954pjb.6.1697818580430; Fri, 20 Oct 2023 09:16:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697818580; cv=none; d=google.com; s=arc-20160816; b=oWKJOw+Ork6wr6DwXbYEqXlRNIoJ4PmS/gOD8JDqF7QX8cxo0kHKicrOy3gcLciEsh D2y5zxo2jQSpW9C3Fhk+V13WZNRiAoKVNDnrroerJobDM6O5owR20S/HDS5js0ZAJx6J 6N9jMgVj/LUR7jE6/Gy0Ho5uPQC1TM1UCAzs3cqlJznyWGpfKKIO/1zlr6ATEyeUClDj slRAGirrEbCPnjqQC+20HspgXR8wImPZZFALxn/5vfJoENVab80Z/QyxlobOjqXHZHrG cMGvqcCfOZvfEHP+Tjxhx7nTUMjd/5dnNSvI0kF9RlCrWY3Mxc31l4gtihOmJpBr0xyc 5NpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=I4hMGAn3CCXbvIhFniLsRuw1X84vM7LzNgk6oVf6hDo=; fh=hRowg7FHjFkNvsaqzIhvo3cvY/I4Cr+L17V0ykyMVw0=; b=yjFZCHIGWhVdNGFSTZhjcNneHJf7hRVNE8//mxwvLBJ1UeGadX2LNMxX5gpq5mamv2 qA9Gzfb0cckXyhwdh4eqwvtPILXmGlXi13z6YJ6+OJ4xi7yGfgPfKZNIMTKqgayBcbj6 3XA1bSkqXWaCCUgRB2a+UDryAUfMMJLrY2qBJ/nUGfjWIUo/JLwNcxw38Zou5TH2qddo H/to0ZwrxO7hF/cyPJA9nIFOhtihqrwVVd0wQZB0qH2YzWttmpkGRiBLpKSmM6exV9gD 1hCF+XWtMbyLGc83YssrhNNpEgaFp64YofMafRopYnfXb+3lBetD+aWpLy7acly8OZR6 Ue7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=g6XL6KrL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id np3-20020a17090b4c4300b0027d3ed58c04si2397023pjb.173.2023.10.20.09.16.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 09:16:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=g6XL6KrL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 8CCB38301528; Fri, 20 Oct 2023 09:16:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229738AbjJTQP4 (ORCPT + 26 others); Fri, 20 Oct 2023 12:15:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229733AbjJTQPy (ORCPT ); Fri, 20 Oct 2023 12:15:54 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 921C6114; Fri, 20 Oct 2023 09:15:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description; bh=I4hMGAn3CCXbvIhFniLsRuw1X84vM7LzNgk6oVf6hDo=; b=g6XL6KrLFvXCVI21u1A5KeupFv +QFnHNBtXPSX2WGx/qzbR8hAv15UjjS3G7GeUcRbT6Gzod96JethLXROgfY3uc2SU169IvhiZdRGh PQGKjDFv0/nWu/OIs7h5I+YdQjcKmWPq6iD07vRG6QQQEc9KMRwcxd9MEFfDm+JhqgzS/494qQBHg cmRRbbr+caoCft14R2moMfBDrzAlzzoBVVkfYfN3hN7MnKJVzuTCxV7GKaf92411iUcMwW41EdBZu LzyJ/6kNrv4xSgCoDDiOqDloTvQ2En//Zuw6p8kbzieBn/ZS50xuBKNEiKD53bPkfqRtyRa8Wwy2S MoYvVmXQ==; Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qts9u-00E44C-84; Fri, 20 Oct 2023 16:15:34 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qts9s-001UOZ-13; Fri, 20 Oct 2023 17:15:32 +0100 From: David Woodhouse To: Juergen Gross , xen-devel@lists.xenproject.org Cc: Greg Kroah-Hartman , Jiri Slaby , Roger Pau Monne , Stefano Stabellini , Dawei Li , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Paul Durrant Subject: [PATCH v2 2/3] hvc/xen: fix error path in xen_hvc_init() to always register frontend driver Date: Fri, 20 Oct 2023 17:15:28 +0100 Message-Id: <20231020161529.355083-3-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231020161529.355083-1-dwmw2@infradead.org> References: <20231020161529.355083-1-dwmw2@infradead.org> MIME-Version: 1.0 Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 20 Oct 2023 09:16:17 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780291815703296370 X-GMAIL-MSGID: 1780291815703296370 From: David Woodhouse The xen_hvc_init() function should always register the frontend driver, even when there's no primary console — as there may be secondary consoles. (Qemu can always add secondary consoles, but only the toolstack can add the primary because it's special.) Signed-off-by: David Woodhouse Reviewed-by: Juergen Gross Cc: stable@vger.kernel.org --- drivers/tty/hvc/hvc_xen.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c index f24e285b6441..4a768b504263 100644 --- a/drivers/tty/hvc/hvc_xen.c +++ b/drivers/tty/hvc/hvc_xen.c @@ -588,7 +588,7 @@ static int __init xen_hvc_init(void) ops = &dom0_hvc_ops; r = xen_initial_domain_console_init(); if (r < 0) - return r; + goto register_fe; info = vtermno_to_xencons(HVC_COOKIE); } else { ops = &domU_hvc_ops; @@ -597,7 +597,7 @@ static int __init xen_hvc_init(void) else r = xen_pv_console_init(); if (r < 0) - return r; + goto register_fe; info = vtermno_to_xencons(HVC_COOKIE); info->irq = bind_evtchn_to_irq_lateeoi(info->evtchn); @@ -622,6 +622,7 @@ static int __init xen_hvc_init(void) } r = 0; + register_fe: #ifdef CONFIG_HVC_XEN_FRONTEND r = xenbus_register_frontend(&xencons_driver); #endif From patchwork Fri Oct 20 16:15:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 156221 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1168646vqb; Fri, 20 Oct 2023 09:16:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHr/4+2zYJ8pSpWDHC9JpFFMTWEZFpWHev4tBLAt/PGkYocPYTpEnnKP46/NVyLBePoLgyT X-Received: by 2002:a17:90a:bf12:b0:27d:73e5:c2c7 with SMTP id c18-20020a17090abf1200b0027d73e5c2c7mr2048231pjs.3.1697818579469; Fri, 20 Oct 2023 09:16:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697818579; cv=none; d=google.com; s=arc-20160816; b=uvipfUiTMrn6h/+JS5Cf00hFPqUcNd47IHBdP2hEUOKEORx3vx+g1m6pQT84BhMbBm SyvLTQUGboHs4Ibyi2Z6OVQR2NtlwPoup906FNHuFyI3hkyezYyky+2aVKVNSahHtjeR /EC7S6HkTV8EF4mLwbnXzs8dT0O/lVZ051h/dQ3liIkrQa1RzlKpDKDVENI5HN5EZwZ5 cCY5uKZ3VtwnWyfA+zeoP0uwwVDW5UZ5jutLP9dSc1QMfyvaUuFIK2PqH4qX2bbUvG4u OoDgCXXWT3jCEP0xNKfpRCZF/NHW9EkCf8NEJhdcE6BCQzSMz7CbFuhIvGW3b4ZYkBWk 33dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tKr5NCYEWPmX5deg+2Ptja2Fo3YNlvlkNEh9wJh6ZDg=; fh=hRowg7FHjFkNvsaqzIhvo3cvY/I4Cr+L17V0ykyMVw0=; b=SBta1C7WDUkNfAz5DUCb/1WzgaiA3pZrpo9Y8F1Y9RLf4sI93HuCEGPxh84ADMi2J4 gc9XYpwQx5EQSfoG8G9pC2DzBODwsNyFV/yj89TAR4ZDLMPWw0qrvtQ8I5lVY3AT2/UP HBGyCK/A5nfiYWHq9prS7r5yI3xoQuzQseE5jqzbWPXGVptngd1ih6TsiJqTYp/GxbGF ZqQAMyGyuNNNLsAAoP09V3xp7klukBkeOBCsVSwRjH0DXQQR5JdDP1ztOCmlWoQSg9BL H/DVB1jz0iYLsPH4XcFjtuYsRUf14sbHtNMq9jAV4rgil5WCd0aLJoJ8pMqV1vHTjWDK VCHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ERnIsojr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id p2-20020a17090a4f0200b0027383ac5ebcsi2209891pjh.130.2023.10.20.09.16.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 09:16:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ERnIsojr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 49798836B4EB; Fri, 20 Oct 2023 09:16:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377853AbjJTQQG (ORCPT + 26 others); Fri, 20 Oct 2023 12:16:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229799AbjJTQP6 (ORCPT ); Fri, 20 Oct 2023 12:15:58 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78DCD1A8; Fri, 20 Oct 2023 09:15:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=tKr5NCYEWPmX5deg+2Ptja2Fo3YNlvlkNEh9wJh6ZDg=; b=ERnIsojrkc5WLnr34IDZQWQKrG wFzlSNa4uSGkth0zeh9LHdVk5FXd6R1LgmCBut8RlHh4SGdWnzA22SU/ejGMiigfeW+6R5k7l2fg2 0uiPSrmfiUIoAU5Q2qVPTTjT2kI+9So4NYm2If5BnDiMQZk7Rt7YUcegC1ffCiPYVpfP+E6Imy9hV i2YFd5mM2Jc+985Yim+drAaCsJdkxvZKx7L2lWkn8w4S+76vvn2Jy23msUjaZ2EOVxJJfAY6wkfgh GDrxLxeDVf77oL1C2C89fPb2hRzeM7pGCmELvA/wEZqdkqmaffpDBxTbaPsfNHSm8zNZg6XsaeLtV M17Mpk1w==; Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qts9u-00E44E-8P; Fri, 20 Oct 2023 16:15:34 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qts9s-001UOc-1F; Fri, 20 Oct 2023 17:15:32 +0100 From: David Woodhouse To: Juergen Gross , xen-devel@lists.xenproject.org Cc: Greg Kroah-Hartman , Jiri Slaby , Roger Pau Monne , Stefano Stabellini , Dawei Li , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Paul Durrant Subject: [PATCH v2 3/3] hvc/xen: fix console unplug Date: Fri, 20 Oct 2023 17:15:29 +0100 Message-Id: <20231020161529.355083-4-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231020161529.355083-1-dwmw2@infradead.org> References: <20231020161529.355083-1-dwmw2@infradead.org> MIME-Version: 1.0 Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 20 Oct 2023 09:16:17 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780291814650747106 X-GMAIL-MSGID: 1780291814650747106 From: David Woodhouse On unplug of a Xen console, xencons_disconnect_backend() unconditionally calls free_irq() via unbind_from_irqhandler(), causing a warning of freeing an already-free IRQ: (qemu) device_del con1 [ 32.050919] ------------[ cut here ]------------ [ 32.050942] Trying to free already-free IRQ 33 [ 32.050990] WARNING: CPU: 0 PID: 51 at kernel/irq/manage.c:1895 __free_irq+0x1d4/0x330 It should be using evtchn_put() to tear down the event channel binding, and let the Linux IRQ side of it be handled by notifier_del_irq() through the HVC code. On which topic... xencons_disconnect_backend() should call hvc_remove() *first*, rather than tearing down the event channel and grant mapping while they are in use. And then the IRQ is guaranteed to be freed by the time it's torn down by evtchn_put(). Since evtchn_put() also closes the actual event channel, avoid calling xenbus_free_evtchn() except in the failure path where the IRQ was not successfully set up. However, calling hvc_remove() at the start of xencons_disconnect_backend() still isn't early enough. An unplug request is indicated by the backend setting its state to XenbusStateClosing, which triggers a notification to xencons_backend_changed(), which... does nothing except set its own frontend state directly to XenbusStateClosed without *actually* tearing down the HVC device or, you know, making sure it isn't actively in use. So the backend sees the guest frontend set its state to XenbusStateClosed and stops servicing the interrupt... and the guest spins for ever in the domU_write_console() function waiting for the ring to drain. Fix that one by calling hvc_remove() from xencons_backend_changed() before signalling to the backend that it's OK to proceed with the removal. Tested with 'dd if=/dev/zero of=/dev/hvc1' while telling Qemu to remove the console device. Signed-off-by: David Woodhouse Cc: stable@vger.kernel.org Reviewed-by: Juergen Gross --- drivers/tty/hvc/hvc_xen.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c index 4a768b504263..34c01874f45b 100644 --- a/drivers/tty/hvc/hvc_xen.c +++ b/drivers/tty/hvc/hvc_xen.c @@ -377,18 +377,21 @@ void xen_console_resume(void) #ifdef CONFIG_HVC_XEN_FRONTEND static void xencons_disconnect_backend(struct xencons_info *info) { - if (info->irq > 0) - unbind_from_irqhandler(info->irq, NULL); - info->irq = 0; + if (info->hvc != NULL) + hvc_remove(info->hvc); + info->hvc = NULL; + if (info->irq > 0) { + evtchn_put(info->evtchn); + info->irq = 0; + info->evtchn = 0; + } + /* evtchn_put() will also close it so this is only an error path */ if (info->evtchn > 0) xenbus_free_evtchn(info->xbdev, info->evtchn); info->evtchn = 0; if (info->gntref > 0) gnttab_free_grant_references(info->gntref); info->gntref = 0; - if (info->hvc != NULL) - hvc_remove(info->hvc); - info->hvc = NULL; } static void xencons_free(struct xencons_info *info) @@ -553,10 +556,23 @@ static void xencons_backend_changed(struct xenbus_device *dev, if (dev->state == XenbusStateClosed) break; fallthrough; /* Missed the backend's CLOSING state */ - case XenbusStateClosing: + case XenbusStateClosing: { + struct xencons_info *info = dev_get_drvdata(&dev->dev);; + + /* + * Don't tear down the evtchn and grant ref before the other + * end has disconnected, but do stop userspace from trying + * to use the device before we allow the backend to close. + */ + if (info->hvc) { + hvc_remove(info->hvc); + info->hvc = NULL; + } + xenbus_frontend_closed(dev); break; } + } } static const struct xenbus_device_id xencons_ids[] = { @@ -616,7 +632,7 @@ static int __init xen_hvc_init(void) list_del(&info->list); spin_unlock_irqrestore(&xencons_lock, flags); if (info->irq) - unbind_from_irqhandler(info->irq, NULL); + evtchn_put(info->evtchn); kfree(info); return r; }