Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2611229pxa; Mon, 17 Aug 2020 14:18:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyM/od4jM+hH3iJKacVX0zzZ08tvR5t0WAITk6FyHv11oZ4iMFlGXf7A0LxBJZN1WkkpVFi X-Received: by 2002:a17:906:180b:: with SMTP id v11mr17793322eje.427.1597699117991; Mon, 17 Aug 2020 14:18:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597699117; cv=none; d=google.com; s=arc-20160816; b=hvuaAmcJOtz2ywanwveqMdqp+YpV/LrC0yx8oDDsgwedIpcvoAIbRF7VjK0+I3YUQS EKQ+6CD+NJSx7A1uc/tlOFl+63ap0ws4zciY03Uwme2s5GcI/w7mEghvMR2fMGQJpWcS 0OaFO3UZNK5Ak8eFQJ9L1+aC85/xoybpwiX4yNC8SyYjRHa2Bp8qJyTz3RO2icJun4ud eg9CGU8AqIFUi5+RB6ndIMiASaPqALz0nmQAtoTUR8tddO4+bzYjDVBuhFiipB0aIPhc M9jNEtUmHefmuHiTpdCgYtmCE6SiFkdyCNXsoCAlU6VI9pw8wxH+tqW+vWz55vhvM1Ic shFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=jZBiiEEprcZxIoS7kLgkj8BI5NaODguV/9YEt0JNbrs=; b=rUNQCmYNA6woS0qZEDJnhEk/qAX3MO6KdD/Hy+OSXFWGCJZdu/OtutXLzj+3rDVPMp FcG6x2yGzLQDmeYd5VNmskdAqG2Evj+mdm5cFypokHP9HmMPMPBYJzxhQLy5CwgIqGIm cDmaLKgN1lRSN4yB9Rj61JxOekv2/ULKwunI42OZJCnqAtu37GjMDOK6zM7coNRkc/Q4 WPHrRWcimIIOxjOTZ2n2G8Xjl22OGFkd1LJET4lcn5rAgTU8u6PS/5vB45+VEEfiZ9Zw WT+un6Pf/uSuoUSePESydKrcIr6beQxCuKS7eylpDshBW5CvW72r2frnhDbQo+plVwMQ 6jcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="oi/1F0No"; 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 o8si11184933edq.435.2020.08.17.14.18.15; Mon, 17 Aug 2020 14:18:37 -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="oi/1F0No"; 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 S1728967AbgHQO2w (ORCPT + 99 others); Mon, 17 Aug 2020 10:28:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728669AbgHQO2u (ORCPT ); Mon, 17 Aug 2020 10:28:50 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A0A6C061389 for ; Mon, 17 Aug 2020 07:28:50 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id r2so15234907wrs.8 for ; Mon, 17 Aug 2020 07:28:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=jZBiiEEprcZxIoS7kLgkj8BI5NaODguV/9YEt0JNbrs=; b=oi/1F0NoccxfISqtDM6MCAbKxX1wHsT+Slj0IB4Uht85/OVJZc4/mTtfWQlRQcucuQ tOl36e9Vrw9wpUkFo5sC/oUXQP6pw86tsAWPFs6z1WWJxNGsnjxmfih61u11BS2Pt9k3 9gphW+/L2Cu14UEtt4gzsopSH3RoMARg3SSrnGYuaqs3dsHaGZLrXHVxVjPBLd78B9/+ XFZliSYdHkwh/57J+ONt72l6BIJTAptctPtfnJeoe3K3Bx6+CDYoi2l/2OJJN55Nib+G FMQ7CDXrX4BYj61lntcDk3NF0tBC8Y2NEHW8jJE5elBDHA8YHQEprW5UAcSIY9UtT95t SG1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=jZBiiEEprcZxIoS7kLgkj8BI5NaODguV/9YEt0JNbrs=; b=FU9pHTBvY0SXl2ADIK7ommlvyQz3s7mufa39UCUGBC+081V0Alf4bfvukE85F7KJi1 +5+Bw10MFa1nvChw+nrwXv0/qnn0WxJgF4jpDx6JBIaj5gaa5YlpbpPEa6L7lvjzS/di MrFYQahIc3L7YJ8wDOwkmbWdzyR5NlmvtMYBoEQir16n2SOcdztHPj+bxUt5kyu3ZSM9 qcdf1ToOM5E1A0cyN+lJZGQrkz5nKMJ+/KN1hHM/xSDc+PqMloKNCRLU6i9o4s2A5nkf t/5yPGfmbdSCohWhJtZqySEPAESGkXYkE4GW36Md8LSuT5Gm8uvp4kzwWca56KcZ/CzL aVQA== X-Gm-Message-State: AOAM533J9Cj99hcKcRByv2g6rftW8fjJZCPlGURpEjbVtGN5+rU8KjqY bXSPr+7AvkE45/VbPQoRcxi3tg== X-Received: by 2002:adf:f007:: with SMTP id j7mr14748884wro.195.1597674528714; Mon, 17 Aug 2020 07:28:48 -0700 (PDT) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id n5sm30089028wrx.22.2020.08.17.07.28.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2020 07:28:48 -0700 (PDT) Date: Mon, 17 Aug 2020 15:28:46 +0100 From: Daniel Thompson To: Sumit Garg Cc: Doug Anderson , Greg Kroah-Hartman , linux-serial@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net, Jiri Slaby , Russell King - ARM Linux , Jason Wessel , LKML , Linux ARM Subject: Re: [RFC 2/5] serial: core: Add framework to allow NMI aware serial drivers Message-ID: <20200817142846.mm46yy62illrewbq@holly.lan> References: <1595333413-30052-1-git-send-email-sumit.garg@linaro.org> <1595333413-30052-3-git-send-email-sumit.garg@linaro.org> <20200814141322.lffebtamfjt2qrym@holly.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 17, 2020 at 05:57:03PM +0530, Sumit Garg wrote: > On Fri, 14 Aug 2020 at 19:43, Daniel Thompson > wrote: > > On Fri, Aug 14, 2020 at 04:47:11PM +0530, Sumit Garg wrote: > > Does it look better if you create a new type to map the two structures > > together. Alternatively are there enough existing use-cases to want to > > extend irq_work_queue() with irq_work_schedule() or something similar? > > > > Thanks for your suggestion, irq_work_schedule() looked even better > without any overhead, see below: > > diff --git a/include/linux/irq_work.h b/include/linux/irq_work.h > index 3082378..1eade89 100644 > --- a/include/linux/irq_work.h > +++ b/include/linux/irq_work.h > @@ -3,6 +3,7 @@ > #define _LINUX_IRQ_WORK_H > > #include > +#include > > /* > * An entry can be in one of four states: > @@ -24,6 +25,11 @@ struct irq_work { > void (*func)(struct irq_work *); > }; > > +struct irq_work_schedule { > + struct irq_work work; > + struct work_struct *sched_work; > +}; > + > static inline > void init_irq_work(struct irq_work *work, void (*func)(struct irq_work *)) > { > { > @@ -39,6 +45,7 @@ void init_irq_work(struct irq_work *work, void > (*func)(struct irq_work *)) > > bool irq_work_queue(struct irq_work *work); > bool irq_work_queue_on(struct irq_work *work, int cpu); > +bool irq_work_schedule(struct work_struct *sched_work); > > void irq_work_tick(void); > void irq_work_sync(struct irq_work *work); > diff --git a/kernel/irq_work.c b/kernel/irq_work.c > index eca8396..3880316 100644 > --- a/kernel/irq_work.c > +++ b/kernel/irq_work.c > @@ -24,6 +24,8 @@ > static DEFINE_PER_CPU(struct llist_head, raised_list); > static DEFINE_PER_CPU(struct llist_head, lazy_list); > > +static struct irq_work_schedule irq_work_sched; > + > /* > * Claim the entry so that no one else will poke at it. > */ > @@ -79,6 +81,25 @@ bool irq_work_queue(struct irq_work *work) > } > EXPORT_SYMBOL_GPL(irq_work_queue); > > +static void irq_work_schedule_fn(struct irq_work *work) > +{ > + struct irq_work_schedule *irq_work_sched = > + container_of(work, struct irq_work_schedule, work); > + > + if (irq_work_sched->sched_work) > + schedule_work(irq_work_sched->sched_work); > +} > + > +/* Schedule work via irq work queue */ > +bool irq_work_schedule(struct work_struct *sched_work) > +{ > + init_irq_work(&irq_work_sched.work, irq_work_schedule_fn); > + irq_work_sched.sched_work = sched_work; > + > + return irq_work_queue(&irq_work_sched.work); > +} > +EXPORT_SYMBOL_GPL(irq_work_schedule); > + This is irredeemably broken. Even if we didn't care about dropping events (which we do) then when you overwrite irq_work_sched with a copy of another work_struct, either of which could currently be enqueued somewhere, then you will cause some very nasty corruption. Daniel.