Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp52690pxj; Thu, 10 Jun 2021 14:35:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwedr9JPGWMlCwAsJ1Rk/ArzW3Ua4DfSSF8O8s67tEanzX6BvgHFgXNj0MVu8BA1FcUyNnS X-Received: by 2002:a17:907:2165:: with SMTP id rl5mr511699ejb.98.1623360905714; Thu, 10 Jun 2021 14:35:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623360905; cv=none; d=google.com; s=arc-20160816; b=b7G1qopZuJMcAt2ZGN8bSX3Q59A0vi5kof1t5ml8JlOCa736zXYhtjKk+3Lq3xR+aF 6nsrZJ+0FJdWnq2mvFogygk9oot3ohy4BSoW5CYVDRY64xxJqVX9GYtqdPWqiNFd95QJ u52QLorBsM3d2GX9UUyvq2hzTuQ2jVgsnNeG6FJCDsKL3JabJjyEuzxl/u70w2nI1GSv 20fFqY/bTU9LJ8yOTiNzNkdLPZCqApTV5tRCAqXO00G6j/s+ADo3GsXvn7pmKkRt19+h Ys2eDSUCVh2uJgRogEHuunMJJ9BtAy2fqatqib5JwI8HqB26aKTXB6C4ni0rWRHBAAxm Fl2w== 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=Mc0t7dqVDGu20ZDgp1J77BZzzR8pf6dBx6PMN3sIo8c=; b=vJ972mkSDWFOtik890DxBLt4OooiZG0RVTOdhCQMBOTdsNwO/WRa6Lhy3rmSC2Qinc oSrsBQlEC33jo2R6dFeqWQyw7YNIcipM1/P80o7TOMAoFiempDB7Vhn1qxud4lw9YDb6 +gK79CAu1OGitkHmYpf1pkeTGCJcleowTvM6HOfnZMJ+hzPWrJOpsim5oPWrIjMDRduk onbF4SD4NvxSVvXS517avFUNm8V6qZXBGRIOpeCFMuJUDWhxzf01L7qsMNpecLrfZVAd X2w60zguqVrSX4k07HnjKeA1vzkdcKNDQd2Pt6ZJrjWjFGAed477Df7IIgpXzSwJhvga lNvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aOEIplv0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y11si3132146edt.542.2021.06.10.14.34.41; Thu, 10 Jun 2021 14:35:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aOEIplv0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230083AbhFJVc1 (ORCPT + 99 others); Thu, 10 Jun 2021 17:32:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230211AbhFJVc1 (ORCPT ); Thu, 10 Jun 2021 17:32:27 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF72DC061574 for ; Thu, 10 Jun 2021 14:30:20 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id a19so3693259ljq.12 for ; Thu, 10 Jun 2021 14:30:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Mc0t7dqVDGu20ZDgp1J77BZzzR8pf6dBx6PMN3sIo8c=; b=aOEIplv0pyoO+2D1enYzTH7rRMUM5qf5y/qVUZMMn97grwASNtzDCe6NqISGYiZMo/ ukksvEVMwqEiLXlOk7Xqes3HVR1NjBClrE1UmSQ+glzsnFi3+RbYzGF78dSlKpLFU0JZ fdTr/eSTmYpuSXZulL5tGXRJG/I0jBiZbkhkcpdSROdkYtLEck/4uALoj6p0onaq315m JtShyX4vbRX1kL2eW4pFO5ne3PKIMIIoI3VPqWTXEo3+d3M4W6uXg7lVNw/lt/VjhUrE 6A8O8GSKAnoiX+g/msiwrr/WSJCOVPblDBUfbeD3OI0es+O8CDxB3CEA+scJZ1LWc7dI gSOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Mc0t7dqVDGu20ZDgp1J77BZzzR8pf6dBx6PMN3sIo8c=; b=ZcUtASK7jCigG9MIdVHLSXcIlWYn+b82QRnvFOa/SkAOfrt8n3Q3C0rInPYiFiAM1o NmgcAChW4WylSEId/7j6UllhF+3hKfe57i9wO6oCtY+hXIsdHlavozAegnk4yxAW2iRt hNPQ0JulCQrcsbxkEtJYFK/OydMJbBekXGTX7GSZL8C25x9kkCDd7fH64Mo8yoBPVymS ylHVbbf3NIu8I2piIRUe1neeAMOLo/UGxwwZyCbrP1IARAUPpA1uIkzFlxY554/BgMId vmE1/0SRig05C9UrGqereAkIybNZhQnGplbrMgbYDydKDj+rnBlw2B6cUNnPEdrJzRjX BOEw== X-Gm-Message-State: AOAM531FlmamiFuXvoFLW9PPA1cfbkvLvks4I/S60MIH4SAvpOOxY/YO h6sezRc2sxNCXxJ2ETX9iJMt6pbkeKo4gDDtRXm+Ew== X-Received: by 2002:a2e:22c3:: with SMTP id i186mr433222lji.273.1623360618946; Thu, 10 Jun 2021 14:30:18 -0700 (PDT) MIME-Version: 1.0 References: <911941d4bf19f18abdc9700abca9f26b3c04c343.1623326176.git.viresh.kumar@linaro.org> In-Reply-To: <911941d4bf19f18abdc9700abca9f26b3c04c343.1623326176.git.viresh.kumar@linaro.org> From: Linus Walleij Date: Thu, 10 Jun 2021 23:30:07 +0200 Message-ID: Subject: Re: [PATCH V3 2/3] gpio: virtio: Add IRQ support To: Viresh Kumar , Marc Zyngier , Thomas Gleixner Cc: Bartosz Golaszewski , "Enrico Weigelt, metux IT consult" , Viresh Kumar , "Michael S. Tsirkin" , Jason Wang , Vincent Guittot , Bill Mills , =?UTF-8?B?QWxleCBCZW5uw6ll?= , stratos-dev@op-lists.linaro.org, "open list:GPIO SUBSYSTEM" , linux-kernel , Stefan Hajnoczi , "Stefano Garzarella --cc virtualization @ lists . linux-foundation . org" , virtualization@lists.linux-foundation.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Viresh! thanks for this interesting patch! On Thu, Jun 10, 2021 at 2:16 PM Viresh Kumar wrote: > This patch adds IRQ support for the virtio GPIO driver. Note that this > uses the irq_bus_lock/unlock() callbacks since the operations over > virtio can sleep. > > Signed-off-by: Viresh Kumar > drivers/gpio/gpio-virtio.c | 256 ++++++++++++++++++++++++++++++- > include/uapi/linux/virtio_gpio.h | 15 ++ You also need to select GPIOLIB_IRQCHIP in the Kconfig entry for the gpio-virtio driver, because you make use of it. > +static void virtio_gpio_irq_mask(struct irq_data *d) > +{ > + struct gpio_chip *gc = irq_data_to_gpio_chip(d); > + struct virtio_gpio *vgpio = gpio_chip_to_vgpio(gc); > + struct vgpio_line *line = &vgpio->lines[d->hwirq]; > + > + line->masked = true; > + line->masked_pending = true; > +} > + > +static void virtio_gpio_irq_unmask(struct irq_data *d) > +{ > + struct gpio_chip *gc = irq_data_to_gpio_chip(d); > + struct virtio_gpio *vgpio = gpio_chip_to_vgpio(gc); > + struct vgpio_line *line = &vgpio->lines[d->hwirq]; > + > + line->masked = false; > + line->masked_pending = true; > +} This looks dangerous in combination with this: > +static void virtio_gpio_interrupt(struct virtqueue *vq) > +{ (...) > + local_irq_disable(); > + ret = generic_handle_irq(irq); > + local_irq_enable(); Nominally slow IRQs like those being marshalled over virtio should be nested, handle_nested_irq(irq); but are they? Or are they just quite slow not super slow? If a threaded IRQF_ONESHOT was requested the IRQ core will kick the thread and *MASK* this IRQ, which means it will call back to your .irq_mask() function and expect it to be masked from this point. But the IRQ will not actually be masked until you issue your callbacks in the .irq_bus_sync_unlock() callback right? So from this point until .irq_bus_sync_unlock() get called and actually mask the IRQ, it could be fired again? I suppose the IRQ handler is reentrant? This would violate the API. I would say that from this point and until you sync you need a spinlock or other locking primitive to stop this IRQ from fireing again, and a spinlock will imply local_irq_disable() so this gets really complex. I would say only using nesting IRQs or guarantee this some other way, one way would be to specify that whatever is at the other side of virtio cannot send another GPIO IRQ message before the last one is handled, so you would need to send a specific (new) VIRTIO_GPIO_REQ_IRQ_ACK after all other messages have been sent in .irq_bus_sync_unlock() so that the next GPIO IRQ can be dispatched after that. (Is this how messaged signalled interrupts work? No idea. When in doubt ask the IRQ maintainers.) Thanks, Linus Walleij