From patchwork Wed Jan 16 15:35:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1025983 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="vk0klhZ6"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43frs420T3z9sD4 for ; Thu, 17 Jan 2019 02:36:08 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730140AbfAPPgH (ORCPT ); Wed, 16 Jan 2019 10:36:07 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:36507 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387879AbfAPPgH (ORCPT ); Wed, 16 Jan 2019 10:36:07 -0500 Received: by mail-wm1-f65.google.com with SMTP id p6so2447343wmc.1 for ; Wed, 16 Jan 2019 07:36:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6zLLpdXDNbxxW4MvbghkOOmp94mw3IDbzzKNrvQc84w=; b=vk0klhZ6jDRBn0Ys3f3UGTmN6Up/ouWL2pdlPiQfyqBhLVJvQm5L9dw6hRBMgfFpWb A3WAOlbqADlFFRIqXeqh/3qQ3++Pee62puQmiUxJ4gqabcGjQGyKIb4OK10mYj/VMu+N DNSfFLJ5mqTGsAp+g/5v5cgwVNFsImbRM8CakstEkYy41uzCqJoyJqkt6GtG6LRFN1lR lg3RM2RG6dgeJOmS1QoN62nhntZo1iCA3pzo/TKFCbiyQjgco2lcY1zj16PuMsmz56e3 xMcj9SOFk1RYcAIsAex6exLsuOMvQk7P3jUGZZl98NIqmyk7d6i44md/7u6JxW+xe8Ix Beqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6zLLpdXDNbxxW4MvbghkOOmp94mw3IDbzzKNrvQc84w=; b=crEoP/z4P5l1vLfoN40O9sYjoC3Ji3RX4z607oGUm2zF1bpwpOmvjLF07RTyPszNhm hpAoznX+zvHWQQX6Lvi7wG0ZPlBpBe5u0KvZWJiM4K0FTvNEiEWAo+3hYApys6A528na Me8RNiVH2YkjGCVcy8iBrV5dgeMF4CO8wdKFrdnWoINzsLCGL3d6ndchrUfEt/aw81wn l00FGaJ/si38ZXPo/lM+2FYdmacPQzTr8vCRqPn9QVRgQ6ojKZgQ6pjQFySzr0QuJFMg q8RmbpxBCJrcRpDYicAHKmJ4zaOAPlsJ7o9vfgzqU9PrZ7I7E0urdCVCNE9MoKuEUR2Y rpfQ== X-Gm-Message-State: AJcUukch5TPDWy6DGPcP11B3YzQ7MYVvWaSXhnFYeM+RZ/wwxbxVDInZ 8jg5R9j/ExYRoEsqIxx+zM+WDsbQNyc= X-Google-Smtp-Source: ALg8bN4lYk1t7+n8iL8pjxFjUcZcw6iucvcpn/TXQu5/FAqHYPP91x/2mNH5m5hs2VCqsahQEEmc5g== X-Received: by 2002:a1c:2c44:: with SMTP id s65mr8484233wms.80.1547652964990; Wed, 16 Jan 2019 07:36:04 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id c21sm28758364wre.71.2019.01.16.07.36.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jan 2019 07:36:03 -0800 (PST) From: Bartosz Golaszewski To: Sasha Levin Cc: Linus Walleij , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH STABLE v4.19.15] gpiolib: fix line event timestamps for nested irqs Date: Wed, 16 Jan 2019 16:35:57 +0100 Message-Id: <20190116153557.13720-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Nested interrupts run inside the calling thread's context and the top half handler is never called which means that we never read the timestamp. This issue came up when trying to read line events from a gpiochip using regmap_irq_chip for interrupts. Fix it by reading the timestamp from the irq thread function if it's still 0 by the time the second handler is called. Fixes: d58f2bf261fd ("gpio: Timestamp events in hardirq handler") Cc: stable@vger.kernel.org Signed-off-by: Bartosz Golaszewski --- Hi Sasha, this is a backport for v4.19.y series. The original patch didn't apply due to a conflict. drivers/gpio/gpiolib.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index a8e01d99919c..b3ab6c428423 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -817,7 +817,15 @@ static irqreturn_t lineevent_irq_thread(int irq, void *p) /* Do not leak kernel stack to userspace */ memset(&ge, 0, sizeof(ge)); - ge.timestamp = le->timestamp; + /* + * We may be running from a nested threaded interrupt in which case + * we didn't get the timestamp from lineevent_irq_handler(). + */ + if (!le->timestamp) + ge.timestamp = ktime_get_real_ns(); + else + ge.timestamp = le->timestamp; + level = gpiod_get_value_cansleep(le->desc); if (le->eflags & GPIOEVENT_REQUEST_RISING_EDGE