Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1143982iog; Thu, 30 Jun 2022 18:28:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sYZC5FddLlx1JaOlaDTxngjaDaubf5YkKWsYXnDcaqzS4cGdXEwp2p4WWC4qAG03G+hHKX X-Received: by 2002:a17:902:f54e:b0:16a:75a9:9a39 with SMTP id h14-20020a170902f54e00b0016a75a99a39mr17106141plf.70.1656638880626; Thu, 30 Jun 2022 18:28:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656638880; cv=none; d=google.com; s=arc-20160816; b=DUKqilOByCSlos8/RELzRwZi64ohSIZVSCEtQBEVUtAr/Y39uJYh+wQ6iCqipywohY q0yOOlwOhGgHuf9zQ0B+vdmiVDcQCbQCKArWBwqf2WmsTusfSEOM9MfPghFmGc2QYv2T aUlDi80px2uFo6pfVlytWPsTErQc9xP87G9y/nEGpS6oBBlJchVtfDvshZzk68C0o3Zr cwO4dUtPXxhpml4ibiMSfbQC75oaVd6PbWUerl6zPo2ujhub/n5ecz7qTwq2K81wpuYK 6JWIN0REAcXJl6UcoKNKrkgWAy8FuczA01UkiIfawqdnnXawUW6tdi2AlXE8SUm1xVWO GHZg== 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=2KH53Wl1gr5UMbynLfVT+FjBM4ZDGlsSeHT6iWm6OnU=; b=QvfRpMqLJhX6M7m8lVufJI8M4hra37zoFgCJxLEPHYozJx6pvFxmpR9FzMMMHXMiVI waU0eygPvNFgqSmwREvN05MNazqvL1/cFYoCZBTPSavhyPomMPgh7E9s7R1/CSC1QgZE mGuWFAnMnb2H1vPqZmpHdR69iUD4gDX+C7p+HK6KBAj0AN5VF4TsLKCjR8z8X0i5zxRQ uHbXrcB5n8Alf/5ET6eRm66LWiNmo1PjhVDWCI4z3rQH2GVeDfbcjtCCusiO1cL2HWry zb57dI1zcovMI6CqBUHfg/IaPryaKspT/FdpE5qT2dtKiFkvT7WPWT92F6N08NSUsFit VY6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bRdviL9T; 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 o5-20020a170903300500b001674c1a3475si22670814pla.126.2022.06.30.18.27.49; Thu, 30 Jun 2022 18:28:00 -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=@redhat.com header.s=mimecast20190719 header.b=bRdviL9T; 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 S231751AbiGABWd (ORCPT + 99 others); Thu, 30 Jun 2022 21:22:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232650AbiGABWb (ORCPT ); Thu, 30 Jun 2022 21:22:31 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2F4955A2CB for ; Thu, 30 Jun 2022 18:22:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656638550; 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=2KH53Wl1gr5UMbynLfVT+FjBM4ZDGlsSeHT6iWm6OnU=; b=bRdviL9TDbL6BeBKnbyhb4tpyRgCxiQEsZFnuxvVhybI3jLOmm2/RfRiESovHgHV8d99Ie AuQBHX29ZIBCI3Pc+q3jfZZ2qtailWwSYwtYO8PHjiUlCuzEE8CbYocdSDUhh+Iae6V7Cb tAJslrD1FVh5Ps/LLmhzv4kS/WLxlTc= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-279-GyrQLR1-PyaZrSSfoBcrlw-1; Thu, 30 Jun 2022 21:22:28 -0400 X-MC-Unique: GyrQLR1-PyaZrSSfoBcrlw-1 Received: by mail-lf1-f69.google.com with SMTP id p2-20020a05651212c200b004814102d512so391391lfg.1 for ; Thu, 30 Jun 2022 18:22:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2KH53Wl1gr5UMbynLfVT+FjBM4ZDGlsSeHT6iWm6OnU=; b=L9FrRwWD1l+zTKYF4tQ4yNzQkM3LL0rS3CIlcD0CseYT1uZtVTmF3EtfFEReuinDz1 sJXWU5oRgn6yq2ymFPnUEc2WjiajO1zXeUOYCKEJ/XjbN33+qI4RvtTVSPsvzsrmtLTi tYMFscpjNNr3jxU/D1MueUtNsDKsqi0iCpnzue/gLqEqQn6peZTPOhMXTQ6sxlrjLVTn Miuw5zHy//dYSh+rupcJniaG03CheG3789Fw/+G/WRgaK2+GwkGaYh5M5m04C1Wbf+xI imO6MueciNNREM6uVwzDXgND/G2lJWRn1KZooVA+ULB9Md02gcVZv8eaYqYxHhdsRLPo d0Aw== X-Gm-Message-State: AJIora+tbwIV9tRIbLEW7zyd9E78Br+kG2/KAX1vZK7Xyofi9DWJSIQx s+BoiWUjHoc6n4wz+lj7x07I1rCwy522J5Kch3BHVmdBAxdbSbGU3+FAGFee1xfMOcdQvKqgEh0 1aUzeC585NL81dg6r9VFOB3lzoRGxq6/w3E+mGk1g X-Received: by 2002:a05:6512:22c3:b0:47f:704b:3820 with SMTP id g3-20020a05651222c300b0047f704b3820mr7390619lfu.411.1656638546133; Thu, 30 Jun 2022 18:22:26 -0700 (PDT) X-Received: by 2002:a05:6512:22c3:b0:47f:704b:3820 with SMTP id g3-20020a05651222c300b0047f704b3820mr7390605lfu.411.1656638545914; Thu, 30 Jun 2022 18:22:25 -0700 (PDT) MIME-Version: 1.0 References: <20220608171334.730739-1-apatel@ventanamicro.com> <20220629174318.GB2018382@p14s> <20220630152003-mutt-send-email-mst@kernel.org> In-Reply-To: <20220630152003-mutt-send-email-mst@kernel.org> From: Jason Wang Date: Fri, 1 Jul 2022 09:22:15 +0800 Message-ID: Subject: Re: [PATCH] rpmsg: virtio: Fix broken rpmsg_probe() To: "Michael S. Tsirkin" Cc: Mathieu Poirier , Arnaud POULIQUEN , Anup Patel , Bjorn Andersson , Atish Patra , Alistair Francis , Anup Patel , linux-remoteproc@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-kernel , virtualization Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_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 On Fri, Jul 1, 2022 at 3:20 AM Michael S. Tsirkin wrote: > > On Thu, Jun 30, 2022 at 11:51:30AM -0600, Mathieu Poirier wrote: > > + virtualization@lists.linux-foundation.org > > + jasowang@redhat.com > > + mst@redhat.com > > > > On Thu, 30 Jun 2022 at 10:20, Arnaud POULIQUEN > > wrote: > > > > > > Hi, > > > > > > On 6/29/22 19:43, Mathieu Poirier wrote: > > > > Hi Anup, > > > > > > > > On Wed, Jun 08, 2022 at 10:43:34PM +0530, Anup Patel wrote: > > > >> The rpmsg_probe() is broken at the moment because virtqueue_add_inbuf() > > > >> fails due to both virtqueues (Rx and Tx) marked as broken by the > > > >> __vring_new_virtqueue() function. To solve this, virtio_device_ready() > > > >> (which unbreaks queues) should be called before virtqueue_add_inbuf(). > > > >> > > > >> Fixes: 8b4ec69d7e09 ("virtio: harden vring IRQ") > > > >> Signed-off-by: Anup Patel > > > >> --- > > > >> drivers/rpmsg/virtio_rpmsg_bus.c | 6 +++--- > > > >> 1 file changed, 3 insertions(+), 3 deletions(-) > > > >> > > > >> diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c > > > >> index 905ac7910c98..71a64d2c7644 100644 > > > >> --- a/drivers/rpmsg/virtio_rpmsg_bus.c > > > >> +++ b/drivers/rpmsg/virtio_rpmsg_bus.c > > > >> @@ -929,6 +929,9 @@ static int rpmsg_probe(struct virtio_device *vdev) > > > >> /* and half is dedicated for TX */ > > > >> vrp->sbufs = bufs_va + total_buf_space / 2; > > > >> > > > >> + /* From this point on, we can notify and get callbacks. */ > > > >> + virtio_device_ready(vdev); > > > >> + > > > > > > > > Calling virtio_device_ready() here means that virtqueue_get_buf_ctx_split() can > > > > potentially be called (by way of rpmsg_recv_done()), which will race with > > > > virtqueue_add_inbuf(). If buffers in the virtqueue aren't available then > > > > rpmsg_recv_done() will fail, potentially breaking remote processors' state > > > > machines that don't expect their initial name service to fail when the "device" > > > > has been marked as ready. > > > > > > > > What does make me curious though is that nobody on the remoteproc mailing list > > > > has complained about commit 8b4ec69d7e09 breaking their environment... By now, > > > > i.e rc4, that should have happened. Anyone from TI, ST and Xilinx care to test this on > > > > their rig? > > > > > > I tested on STm32mp1 board using tag v5.19-rc4(03c765b0e3b4) > > > I confirm the issue! > > > > > > Concerning the solution, I share Mathieu's concern. This could break legacy. > > > I made a short test and I would suggest to use __virtio_unbreak_device instead, tounbreak the virtqueues without changing the init sequence. > > > > > > I this case the patch would be: > > > > > > + /* > > > + * Unbreak the virtqueues to allow to add buffers before setting the vdev status > > > + * to ready > > > + */ > > > + __virtio_unbreak_device(vdev); > > > + > > > > > > /* set up the receive buffers */ > > > for (i = 0; i < vrp->num_bufs / 2; i++) { > > > struct scatterlist sg; > > > void *cpu_addr = vrp->rbufs + i * vrp->buf_size; > > > > This will indeed fix the problem. On the flip side the kernel > > documentation for __virtio_unbreak_device() puzzles me... > > It clearly states that it should be used for probing and restoring but > > _not_ directly by the driver. Function rpmsg_probe() is part of > > probing but also the entry point to a driver. > > > > Michael and virtualisation folks, is this the right way to move forward? > > I don't think it is, __virtio_unbreak_device is intended for core use. Can we fill the rx after virtio_device_ready() in this case? Btw, the driver set driver ok after registering, we probably get a svq kick before DRIVER_OK? Thanks > > > > > > > Regards, > > > Arnaud > > > > > > > > > > > Thanks, > > > > Mathieu > > > > > > > >> /* set up the receive buffers */ > > > >> for (i = 0; i < vrp->num_bufs / 2; i++) { > > > >> struct scatterlist sg; > > > >> @@ -983,9 +986,6 @@ static int rpmsg_probe(struct virtio_device *vdev) > > > >> */ > > > >> notify = virtqueue_kick_prepare(vrp->rvq); > > > >> > > > >> - /* From this point on, we can notify and get callbacks. */ > > > >> - virtio_device_ready(vdev); > > > >> - > > > >> /* tell the remote processor it can start sending messages */ > > > >> /* > > > >> * this might be concurrent with callbacks, but we are only > > > >> -- > > > >> 2.34.1 > > > >> >