Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp913232iog; Thu, 30 Jun 2022 12:42:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1suIbWUW5g1AxHo7dvWdOr08c+EYRbKZuo1MxMmkn8CjUA1Z+Mk6VxrsHWKwRTuxibxVhuP X-Received: by 2002:a17:902:7290:b0:16b:b6b5:7e6c with SMTP id d16-20020a170902729000b0016bb6b57e6cmr1898796pll.116.1656618166444; Thu, 30 Jun 2022 12:42:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656618166; cv=none; d=google.com; s=arc-20160816; b=CLR2m6WcIk3WJKdM9/Jjmoprcl2E47fVheeTTXEwJ9jSkTik1cA0efc/fqz7L+6YNh oQQGVGycuRwkxQUsdf30WRxQzdhgimLMLv4KeFYZf5xnLaetd+3alQ2e9582eI4JaUsb P2265lP0Mduku9XCFtGrL2jPRjeiD5NoIFPAugtNzFezphNwBw1FRNrXTQd3oyf2MBUw /pZhWWRBiAMk5nMXM9cGJiXzpl4jIKroYWGqwmBvF37Aog+xkm0GV0zif8QE1JwQ6++r s7iR794CHYEMecCYZ5HhRnkvXONp91yjaOl9U7uQsBgUnnhhvBTGZnYSdSrt8cfXmtqU GFsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=6CjSS5d5sjNHdItcbvsvU/YpM2uPYuOWoAxR2J1g4bg=; b=jfsneezOIEys90HpSxBbgqnBLpWaTDmDd5qYQfQwYZ31y0647T+Lno+15j1e0i+AXE W++ZzYK4F7/T2jihmX2IRRML41d4rsHkHw9HwpMIwQma0Q8qguGZHchYGOd9tMBF3bpk TS18keXopTqEXHm2lPJ2Hksk0REEGWXu+1z8lAag5ohTrVF/r+lBKuFx2BU8uz5k3XUY EKXDAQBgsaIhReHBeYOhff2m9EIxhmU7tQ7yKhvmJiN9FfIY9e0SSqIVpkt9SiECtbc5 Aq9Sa8Ne5lG1bSXqJQ117PAJ2aNhJ/ZVoJ/i83Okj4Jvp6WEwnvjg9qLlgxXVEqqziMS +2qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BubFn39a; 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 z2-20020a170903018200b0016a1e17f2casi6856548plg.1.2022.06.30.12.42.32; Thu, 30 Jun 2022 12:42:46 -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=BubFn39a; 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 S236340AbiF3TUx (ORCPT + 99 others); Thu, 30 Jun 2022 15:20:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235373AbiF3TUv (ORCPT ); Thu, 30 Jun 2022 15:20:51 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 84D4142A16 for ; Thu, 30 Jun 2022 12:20:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656616849; 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=6CjSS5d5sjNHdItcbvsvU/YpM2uPYuOWoAxR2J1g4bg=; b=BubFn39aEU+qTu9xXfMnqcJSvBbEdB8hy8Bvjmo/zRGZbURbgZd6kJ+ChbdwW3iwubOvVZ lPBjIq8RBAYXCt1Y2VjOjgS99dZWB3PNpKv+kNw8ygD2NEvMUvAgacTq78j+WNwXjvm9Au ikI/e08upEF2ujPyc3YK8G72VnScv+o= 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.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-584-bDOBM2WiMFKR12ILmuELmQ-1; Thu, 30 Jun 2022 15:20:48 -0400 X-MC-Unique: bDOBM2WiMFKR12ILmuELmQ-1 Received: by mail-wm1-f72.google.com with SMTP id c185-20020a1c35c2000000b0039db3e56c39so1834706wma.5 for ; Thu, 30 Jun 2022 12:20:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6CjSS5d5sjNHdItcbvsvU/YpM2uPYuOWoAxR2J1g4bg=; b=7+jEdjPhmoKOYyXhOdaoJEs75IQPNnkD6ZBV1F1pmG8BCoDZvsgwpKU/P9YbaXj4SQ BN3ONV3cSWdb7GANQC30BuAn0T37TayawzUacS8QdAW5ORXUGbxfwOBF937qXdJd2Zm8 Pha7bK7+MaTww+i0cNC5oahKSuJC985ZdljIKCHemNkGsqBz4q56kaXbsJTgUSeQZF5C p38wwJlf+Gwr9RH1TbT033tKG/pxUz+mZv0TVR8qLBMphtYNeBupMXoWYucPSxXG6RVY D4g141gKJlDUIeDDDG9mhe//kjNx8LjfsTBqm/qi2MUrsg3vVDnnPMPc+b1N9sN7SKa8 nIDw== X-Gm-Message-State: AJIora8gqrSE5Q5oGyJPS9SRLOS4kluerRVu8GiX8tkqIOJaI6Y1joh9 ihNbQ0XsQG+uNtat7i6+YfgNKSV7cwhy9u/rWEYqBCOjgiGxNAKa9s2rBU1ma3Ykw/UvDCBvhXX 0gvVMwQ2KgOPbKoQwYXbzLp+x X-Received: by 2002:a5d:66cc:0:b0:21b:8f5e:875b with SMTP id k12-20020a5d66cc000000b0021b8f5e875bmr10265284wrw.51.1656616846864; Thu, 30 Jun 2022 12:20:46 -0700 (PDT) X-Received: by 2002:a5d:66cc:0:b0:21b:8f5e:875b with SMTP id k12-20020a5d66cc000000b0021b8f5e875bmr10265260wrw.51.1656616846615; Thu, 30 Jun 2022 12:20:46 -0700 (PDT) Received: from redhat.com ([2.55.35.209]) by smtp.gmail.com with ESMTPSA id q3-20020a1c4303000000b003a03185231bsm7512645wma.31.2022.06.30.12.20.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 12:20:46 -0700 (PDT) Date: Thu, 30 Jun 2022 15:20:42 -0400 From: "Michael S. Tsirkin" To: Mathieu Poirier Cc: Arnaud POULIQUEN , Jason Wang , Anup Patel , Bjorn Andersson , Atish Patra , Alistair Francis , Anup Patel , linux-remoteproc@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: Re: [PATCH] rpmsg: virtio: Fix broken rpmsg_probe() Message-ID: <20220630152003-mutt-send-email-mst@kernel.org> References: <20220608171334.730739-1-apatel@ventanamicro.com> <20220629174318.GB2018382@p14s> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 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. > > > > 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 > > >>