Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp19313lqs; Thu, 13 Jun 2024 02:29:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVQbvVS0AZdup1HPwS2VS5HWNXT3fFcsL3cZ9W3nKUl51fodHAW6optY+ee0HqEtZG7utQmOX0EpaZ5DSVqye+HAb675Lw6e6J1ffGEXg== X-Google-Smtp-Source: AGHT+IG8jNGYmcR//Fv6y0Wrtu0hqAzcpOeWUmE4lpJxkMMPmVQjxzhd4nRPQHVNqRXoufaWidg4 X-Received: by 2002:ac8:5a87:0:b0:440:2b02:f04c with SMTP id d75a77b69052e-4415abddbdamr58265031cf.18.1718270959061; Thu, 13 Jun 2024 02:29:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718270959; cv=pass; d=google.com; s=arc-20160816; b=ym+u60jfQ0Cdi1V4Es0BZTiGjmZFLDwPhKhV1VDvyxZ8KyT5kf72XMx1C9fL0Ksf3F xQ7EEfAaBQY8sn47vUn3pdxG374kBS59bAVjr+S8TigcxL2rUxq2aiiIFCm3adtjebR6 mURocROq35gKYRYJkHIOTgIMIfktJkIqNp5jduaYugYMoRtZFNCCZ7TncdTo6u2S8wTD gICZWKSnDTk/Kled2IeuyJ8yHXXwu6QgYR8ai2kcYySUA18G8wwJ4tgYjmFk7pnXZIgX nnQE1c/12KuLUIcYMIfY8iZM1GE/JhTBcJz84t7yMCumH0qzxb50yp95rG+1wanzgz2V 9bHA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=xTL7AN68DXuCJK85qnCP9b24mcfMbuTgeoppKNKx4+E=; fh=42WPhZ4u3zLSBCZbATdYNyfZX1dL4eYdKVDcAoFJYkY=; b=TP+xFM+0UP58HKERkWqvKZ7dgZpjTGFw8tBmISfv1lQGSL2+oMN8EaEjjpdtjbYXDT ZR9eTKmdqyxIHahxIN2/XhP3LCNfANL4I2jRQOg/bcBa6zM0Xgmisy0i1dO8wIMuabXR 25BkqtWHOrGLopvBJ7U8HmxVjm+6+gmVvEYRsVO5bIne0RPU8VD6s4l4kB44syhNwFaX LGY3x+C8wnu7tkyVPRJdGNK/zgdFpwem9nTa7KWIe/UKK3aRZWtXr/25AMwf+UuqUEWW Kw2HDobnI6Y/92QZSGjMjRseFU/GMOhkXvTbwugU5c0FcmUOA40pDp4NSHdtDQmnpL42 Ay6Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=GNKFMSUW; arc=pass (i=1 dkim=pass dkdomain=bgdev-pl.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-212949-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212949-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-441f2fb9d81si10218501cf.427.2024.06.13.02.29.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 02:29:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212949-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=GNKFMSUW; arc=pass (i=1 dkim=pass dkdomain=bgdev-pl.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-212949-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212949-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9E0F11C21C91 for ; Thu, 13 Jun 2024 09:29:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EEB37140387; Thu, 13 Jun 2024 09:28:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="GNKFMSUW" Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E351213E038 for ; Thu, 13 Jun 2024 09:28:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718270925; cv=none; b=m7Wh3MuGDu/8EYBSTwPXJKLsjnrjvCKnrCXZLk457oACn6Zv07H5+Qw9nExgZhOIsNRByXMSRYGZBrO5EcS1R902g6AutfuXYINtVCxXdIDLXWOYZO8nsBnpM9o2vFrs7spTrwyJZKeri3f1noLwlIsZ7QZDnTTE8soyj5za8+0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718270925; c=relaxed/simple; bh=vG4qRDV6pQg/Th6atlB32vTGlz7L1/BU8b4zcWJlXT8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=BC0t22Vj7Jguo1nVavIePHidWfhiRq0B39hYYYlS08Jdvpy6yNbqWAK8U8cBjddVrOseFJv54BRm4W0ZfExISzsfzg7Q+f3DzraDs9Z8EUy8q3ElpelqI0EdrYWqxCji2mrJQ/DkVasbTUVo0v1cbvkapw/Y9dvw80vwISluQYU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=GNKFMSUW; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-42172ab4b60so8489415e9.0 for ; Thu, 13 Jun 2024 02:28:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1718270920; x=1718875720; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=xTL7AN68DXuCJK85qnCP9b24mcfMbuTgeoppKNKx4+E=; b=GNKFMSUWkWy9RL8bJX1e55EBLWJlwKz5eK28rqMTmbqIHWBldOxrDsAoKr1g82bOxm 59j3NULqHmCmQBrBWcl/hpGwE820D2JbCK10zP+9U5Sdx7UmjdRbGK/AzyYtHs2QZB+L qgBMFOkX4Th+MK3Tsky9obDv8umao1dsDel6hzmbfqBBn3iCsDmxH+eSnOuR16oAoplS kygN/W1NjIoF8MJBOhFeQB9SCxMINt8vKeoZ2WYfHz8Q02DMdpjIAA4enKv/swlqLEmE bjTPVkOCu6++iiLhY7JNok4KV636NfrppOACCyOjRDz0CICQSPyVg1ujdF+nxkDfD9K+ pNTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718270920; x=1718875720; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xTL7AN68DXuCJK85qnCP9b24mcfMbuTgeoppKNKx4+E=; b=pCxmZBGoDePuW0zDcsXejFkjhcN8jC2ORF3P4UhyC2xQl4WGj+PzfziwjFeUig06B7 L7MIao3FzL0/NFHXEsKJG1IkGMZLQKcRyAqwFIPMfqFP0N3uW19rWRhg4KAeAfxTSNPr DWMqsZELl7Gi/CuKFBhYWhGIrtuPwZFIXxEUJ8CI94US0sHLLQmG8yC9YFMwF2esUB3E 3T3ZDXc9qVfTC75kBpJhkpvvD8vhvqKvLiDpBMYHa8FPWXpPsXx5G4fuS+uojC7Tn4zs G+9HtP3RYu08bTuw17TXVK1eroGfdr3zSmWc5HJMzGNdtFT7RXCG2SOuuKVRah78a4Po o+5A== X-Forwarded-Encrypted: i=1; AJvYcCWYsbLQ2oRWvudLpTpNYkWg+OfvCo5LNBTLvuiiIQiuFboHXbagDL9hPZZU5fUqA8UZQQ6IOdqEduM7pbvb2zatdQwDXS9SM/nrj6Tm X-Gm-Message-State: AOJu0YwX3aRcjtAaFicqUNFyDPdD92SfRg3HZioFYhVjI33kFjYS7YY+ cVr57jlspoht6k0Y565XPOs2CSa3tsxWvVCBXEbkhQo4nlbO7VDBuvEP6SxPIeU= X-Received: by 2002:a05:600c:470b:b0:422:52c3:7fe0 with SMTP id 5b1f17b1804b1-422864aef80mr42455395e9.22.1718270920108; Thu, 13 Jun 2024 02:28:40 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:8d3:3800:875c:e292:3280:ccac]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422874e73e8sm54990205e9.43.2024.06.13.02.28.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 02:28:39 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Corbet , Greg Kroah-Hartman , "Rafael J . Wysocki" , Arnd Bergmann , Andy Shevchenko Cc: linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v8 0/2] misc: add a virtual driver for testing the GPIO API Date: Thu, 13 Jun 2024 11:28:28 +0200 Message-ID: <20240613092830.15761-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Bartosz Golaszewski The GPIO subsystem used to have a serious problem with undefined behavior and use-after-free bugs on hot-unplug of GPIO chips. This can be considered a corner-case by some as most GPIO controllers are enabled early in the boot process and live until the system goes down but most GPIO drivers do allow unbind over sysfs, many are loadable modules that can be (force) unloaded and there are also GPIO devices that can be dynamically detached, for instance CP2112 which is a USB GPIO expender. Bugs can be triggered both from user-space as well as by in-kernel users. We have the means of testing it from user-space via the character device but the issues manifest themselves differently in the kernel. This is a proposition of adding a new virtual driver - a configurable GPIO consumer that can be configured over configfs (similarly to gpio-sim) or described on the device-tree. This driver is aimed as a helper in spotting any regressions in hot-unplug handling in GPIOLIB. v7 -> v8: - move the driver to drivers/misc/ as it's not a GPIO provider and so its place is not in drivers/gpio/ - rework the data structures to make them more compact using unions - use correct string helpers for given use-cases - drop dependency on the gpio/driver.h, string.h and kernel.h headers - add a patch exporting to_ext_attribute() to be used by this driver - various minor improvements suggested by Andy Link to v7: https://lore.kernel.org/linux-gpio/20240527144054.155503-1-brgl@bgdev.pl/ v6 -> v7: - this is a complete rewrite of the original idea, the entire interface has changed so it warrants a new round of reviews Link to v6: https://lore.kernel.org/linux-gpio/20230817184356.25020-1-brgl@bgdev.pl/ v5 -> v6: - initialize the flags temp variables at declaration and hopefully make Andy happy finally :) v4 -> v5: - add the gpio-consumer docs to the admin-guide/gpio/ index (reported by kernel test robot ) v3 -> v4: - fix the toggle value assignment - use guard(mutex)() wherever we can return directly from the subsequent function call - use skip_spaces() + strim() to avoid having to do a memmove() when stripping strings off whitespaces - DON'T try to save a couple LOC in ifdefs if that makes them less readable (Andy :) ) v2 -> v3: - use cleanup.h interfaces - add some clarifying commets - more minor code tweaks RFC -> v2: - add documentation - fix various issues pointed out by Andy: use struct_size() where applicable, improve the logic when storing the 'live' property, improve log messages, remove commas in terminators, etc. Bartosz Golaszewski (2): drivers: export to_ext_attr() misc: gpio-virtuser: new virtual testing driver for the GPIO API .../admin-guide/gpio/gpio-virtuser.rst | 176 ++ Documentation/admin-guide/gpio/index.rst | 1 + MAINTAINERS | 8 + drivers/base/core.c | 2 - drivers/misc/Kconfig | 8 + drivers/misc/Makefile | 1 + drivers/misc/gpio-virtuser.c | 1790 +++++++++++++++++ include/linux/device.h | 6 + 8 files changed, 1990 insertions(+), 2 deletions(-) create mode 100644 Documentation/admin-guide/gpio/gpio-virtuser.rst create mode 100644 drivers/misc/gpio-virtuser.c -- 2.43.0