Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp546147ybb; Fri, 20 Mar 2020 04:00:30 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtd7Wy4wOmgIFp3W3+9gMLx2bfRWMiOv6nheCtJ+ND5yYCspKL+y94O3vOTYy1gq72+RT52 X-Received: by 2002:a05:6830:1b6f:: with SMTP id d15mr6327483ote.285.1584702030174; Fri, 20 Mar 2020 04:00:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584702030; cv=none; d=google.com; s=arc-20160816; b=nXGW7AyvcJi17TFc+eQ+NZcyVAXeS/CKev6dMtYBwa+wh3cTBQKxxIQnGiPe9gDdTY J4Tz6qCMvMEnoPKwprJJJsFobfdGMzYSiMlXxoyQWL252qzfcZ2TjKUJzfHDL9VkWpjk vSPkHMOvugTAaFdd60wW+YhLuZieeOgzwVcLWGrTGjv7JVJPiv1zJtsqPiw6xvYXH9Oj ur/uUxJkXYUI0MQeWdRwcgcR9IQLECe24kxeovsNrHxDl92oYc3k9i33DCsuIhHbt3v8 JUJ/p0E9Lb2CtuZYrax8Hw/hqwM1ou/6KkfU4w61rO0URRwbSRKGgVTuEi+lLte2DsF1 yk5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=JBGzd1fiCYIMs0yXGqTi6J4Cg8iQgyHBNWCz5d+cCxM=; b=hkSe4hJhji6MvzSyb8yEC99MNM33jk3sGM/iG6c1b7FxoR6AYB5osDPH9+XO1EhXEp ibRLv2w/cSHYfn8kI1SwtFmIjhh1coxWJq+fyhbUDDqIfu2WfiJecrBwzEundROgMdsi pSdotx6MIoEdyXXxQGkNyMePT1Cf52PfBDlHil7ZJnbq4M2WQsAFVOq69Gs1govn8E5H MSwxlmhIEyKlnTX0lMGXEjoS6PWl1/c6mh9hIouZ2PMcDbx63e21kKjJfPiOwrlH/C6D SLVEdk/l8jcKw9TGOWJnSC6YC/x5KvddO4updNhSDvNV1tASrUalWNX/IAQq+00VKrj3 cg5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f50si2825087otf.139.2020.03.20.04.00.17; Fri, 20 Mar 2020 04:00:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727197AbgCTK7I (ORCPT + 99 others); Fri, 20 Mar 2020 06:59:08 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:34541 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726805AbgCTK7H (ORCPT ); Fri, 20 Mar 2020 06:59:07 -0400 Received: by mail-oi1-f196.google.com with SMTP id j5so6050111oij.1; Fri, 20 Mar 2020 03:59:05 -0700 (PDT) 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=JBGzd1fiCYIMs0yXGqTi6J4Cg8iQgyHBNWCz5d+cCxM=; b=QSRMgd5q/1n7036elxXzPGURwccLrpWQkNYkFlA9lyisF9PSvlcz9R7uwdz0BFQiSn MpMIiIDwykmOFZXeD9scfzwBVtr04YsRSuxqxpAO9daTwH8r6Yk5QK2aK6cq7+OVoNIf 8Bic8lYRjii0Dny8UpwZguzX5Ri36+lYgdW8rByMzk4HSG65coiHbjVKYOipiIywaixL gyBoGgWPEsHz4eQIPnUkA/QyLsiUhA/7a6qY93BMH7Dvky/11fwkslxtwuFh273J9Sas v0aYMxaA0ESGXnKyot81MqZxIzto/mhMUReAZO5/YqBnLRDESncjkU4m5msC4njEeLm2 BSDA== X-Gm-Message-State: ANhLgQ2pdLZMd1sR17D3QPWTwN6m5Kk3JCnlA33jd/8U77t/xA5wnZhM m4xkxI3VRJFTq0lDvwSmBlqLkgz+giSv7I0Rq18= X-Received: by 2002:aca:ad93:: with SMTP id w141mr6082546oie.54.1584701944814; Fri, 20 Mar 2020 03:59:04 -0700 (PDT) MIME-Version: 1.0 References: <20200320093125.23092-1-brgl@bgdev.pl> In-Reply-To: <20200320093125.23092-1-brgl@bgdev.pl> From: Geert Uytterhoeven Date: Fri, 20 Mar 2020 11:58:53 +0100 Message-ID: Subject: Re: [PATCH] gpiolib: don't call sleeping functions with a spinlock taken To: Bartosz Golaszewski Cc: Linus Walleij , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , Bartosz Golaszewski Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Bartosz, On Fri, Mar 20, 2020 at 10:31 AM Bartosz Golaszewski wrote: > From: Bartosz Golaszewski > > We must not call pinctrl_gpio_can_use_line() with the gpio_lock taken > as it takes a mutex internally. Let's move the call before taking the > spinlock and store the return value. > > This isn't perfect - there's a moment between calling > pinctrl_gpio_can_use_line() and taking the spinlock where the situation > can change but it isn't a regression either: previously this part wasn't > protected at all and it only affects the information user-space is > seeing. > > Reported-by: Geert Uytterhoeven > Fixes: d2ac25798208 ("gpiolib: provide a dedicated function for setting lineinfo") > Signed-off-by: Bartosz Golaszewski Thanks for your patch! > --- a/drivers/gpio/gpiolib.c > +++ b/drivers/gpio/gpiolib.c > @@ -1154,8 +1154,19 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc, > struct gpioline_info *info) > { > struct gpio_chip *chip = desc->gdev->chip; > + bool ok_for_pinctrl; > unsigned long flags; > > + /* > + * This function takes a mutex so we must check this before taking > + * the spinlock. > + * > + * FIXME: find a non-racy way to retrieve this information. Maybe a > + * lock common to both frameworks? > + */ > + ok_for_pinctrl = pinctrl_gpio_can_use_line( > + chip->base + info->line_offset); Note that this is now called unconditionally, while before it was only called if all previous steps in the ||-pipeline failed. > + > spin_lock_irqsave(&gpio_lock, flags); > > if (desc->name) { > @@ -1182,7 +1193,7 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc, > test_bit(FLAG_USED_AS_IRQ, &desc->flags) || > test_bit(FLAG_EXPORT, &desc->flags) || > test_bit(FLAG_SYSFS, &desc->flags) || > - !pinctrl_gpio_can_use_line(chip->base + info->line_offset)) > + !ok_for_pinctrl) > info->flags |= GPIOLINE_FLAG_KERNEL; > if (test_bit(FLAG_IS_OUT, &desc->flags)) > info->flags |= GPIOLINE_FLAG_IS_OUT; Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds