Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2351002pxa; Mon, 17 Aug 2020 07:36:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMBiKPXGAJJy0tKme5obINggOLANXPMKrKZ2bXjrrfNUu4wGat1obcgDr7ayuWeSElwbcc X-Received: by 2002:aa7:d3d9:: with SMTP id o25mr15625263edr.362.1597674973182; Mon, 17 Aug 2020 07:36:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597674973; cv=none; d=google.com; s=arc-20160816; b=XLjxMtBlQo4vc6zRibuVTWtvzlrNBynIC/bohNpq6cjta185o2YYbybytlfzio3Hsx Br+lVR4BMVy0uLuR8h04fO0j/fyN+Q3Zr5efiSCcNvOpRs97uB5zIQ1xaNLDc2FV0Yat yBhtG6WL5Ks5MHtfsYqX3YunxTiRq2wiZ816iyDzfD68jN7uZsyBKY2JGTU81b1AKLiU pO0uKYc8zpAhRepG+VQrEKLMxKtkT9qPJ0feu8CzzNYVePjpTTt9X/r1CATQyxXUc6AW ogA+/dnuSnurRInWcOijFfmA0uST/JGdP8NEOw1EC6ZEi8HC7zWsYWYzXP23YV1+R67E 8vkQ== 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=4xCxql3rFXOrYwsJnruwiMml2YFmKU3isYfeanIkWcA=; b=zOKxe3erKofQEL3J+cjKVKtoGVQscLNFdnYiarp35gBMdCUL3jDB735MdyXzIoOBIP Rksq2EDlH3IZDeSvUTS11hVS9LZ7Ev42VgPIo1/Mfp2X0OnfrzgTn91RLdO8UqTFDk0c zdcBL6CpdsJ89WdlCx8lD2FwxzPOniM+o+pTE+1saejK1eThM+zI3hOtmGml/Kx5Nxh5 q8zYxu0WOa/UBcpYf9xK7DrOyKtiW9f+WLhcs8YPJlqmuahTTgwosPkhJAfIE/w43e+Q QlQhJjt3hgLI+FylJ74xeC6UdT6aVdP+fg5+tnmggs6VUghPbJzyETAQlo7pb2FWqcq3 dMTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="e2VC/nDU"; 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 va27si11713789ejb.575.2020.08.17.07.35.50; Mon, 17 Aug 2020 07:36:13 -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="e2VC/nDU"; 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 S1728916AbgHQOca (ORCPT + 99 others); Mon, 17 Aug 2020 10:32:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728791AbgHQOc1 (ORCPT ); Mon, 17 Aug 2020 10:32:27 -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 82FCFC061342 for ; Mon, 17 Aug 2020 07:32:26 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id a5so15238551wrm.6 for ; Mon, 17 Aug 2020 07:32:26 -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=4xCxql3rFXOrYwsJnruwiMml2YFmKU3isYfeanIkWcA=; b=e2VC/nDUrcTrPiLe8Rsn9RLZlW4rcYA2Jl5mIjWssD4VC0ZsKSwazLp8W5LLAaUaQj phEwXCaxN15zdXIHVkVdQueXA7BSoUMC0zP4wxhkF81Dtcv5KDknoOUQjRfneCH/dG8i A0xmmSzTjChp0DTHg0RH9HZcD65eQFAjQE1SPdMLbebUyYnIzJbKT2cH4SwFYFHq9W9C QPdKnQp7eFbhQ0pEWFwCu033czTsTfQikLNWQ+0wf9674ynxvj/JUV+8zh1UaU4OLTO3 w2ZoiM/l+X1VgEo0AWO+IdM8fY/IvnQpjF22RYs8pd/4Y5fUgXJaPyurEa7kKxZpGK5+ R9Xg== 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=4xCxql3rFXOrYwsJnruwiMml2YFmKU3isYfeanIkWcA=; b=gPzL+kRdpPYH1JttqhN/1x0sViThmMF1BivrNd8d8cVTV37ph3kpQTPhf7MZBhybQx 2v4q4t4PpgP7v0MD+WNtM75ad2vFJ301JiyGbAe7SFl99M0SG4VU9/mceK/d1bKzulMQ txBEIkg2b5f2h0Z1nNInB26MCfi+voZ083TBGfV4hEc1+wx5l5+Es+6GalD22W0lSK7n aIkaIjjSgu8pRu5cc9EMwt+WnlSUpAolCiGjDaLPKuIzGteB4fw4C6UvIJTKmqMbRJt4 j83PQ9mx4KBKeN+rOG7ReP8zdvu4f/egIeGhCsidBQqVYsQlZMr7sGXkbAx6o2YsVtVC rf2g== X-Gm-Message-State: AOAM53058JxVVrqx4QmQH7fsuMwG3nkAr9FqYW27E9s7iBAUjDkHOfoo h8VnJ+Aj/na4/P7Sp1ZBOzq3ZQ== X-Received: by 2002:adf:f48d:: with SMTP id l13mr15343611wro.43.1597674745210; Mon, 17 Aug 2020 07:32:25 -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 d23sm30698956wmd.27.2020.08.17.07.32.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2020 07:32:24 -0700 (PDT) Date: Mon, 17 Aug 2020 15:32:22 +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: <20200817143222.x524v6xqw5hvzvjs@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 07:53:55PM +0530, Sumit Garg wrote: > On Mon, 17 Aug 2020 at 19:27, Doug Anderson wrote: > > > > Hi, > > > > On Mon, Aug 17, 2020 at 5:27 AM Sumit Garg wrote: > > > > > > 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); > > > > Wait, howzat work? There's a single global variable that you stash > > the "sched_work" into with no locking? What if two people schedule > > work at the same time? > > This API is intended to be invoked from NMI context only, so I think > there will be a single user at a time. How can you possibly know that? This is library code, not a helper in a driver. Daniel. > And we can make that explicit > as well: > > +/* Schedule work via irq work queue */ > +bool irq_work_schedule(struct work_struct *sched_work) > +{ > + if (in_nmi()) { > + 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); > + } > + > + return false; > +} > +EXPORT_SYMBOL_GPL(irq_work_schedule); > > -Sumit > > > > > -Doug