From nobody Mon Feb 9 19:25:33 2026 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B48F2156236 for ; Tue, 24 Dec 2024 06:15:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735020905; cv=none; b=UArTzWy+gkF1ztmLMA8OWSzFkZT05upO0+hynMX8WGvlGXQIfPms2JJAL03nakiLwED/xlfyZfAgC/NX+2DabY5xz3BY04AAQf4TAHl1SRawFJeXq0kASPP/9tfBKN6xxDFvI9u1o/5q1GMK0vbYNtGysb4WSDH1JUgOl+mBnpg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735020905; c=relaxed/simple; bh=cMvDG0BueSdf+zIzu9X8jCotHQSn0EUGYP+uv29jHzM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JgaWfLn1zWhrIc0zZ7n9P+QVKswfkMAdUZAmHanKFxuurqlHuSfYyCH2jd0dvhpCgBq80cV6Fat263H96EXFtbI+iSHbj7Eox1dqZz25DFptZUN7tPpA4hB66gP3ygsPZnQlLtwaxpKU47Ekfp5fW4YiN+aNU9wOXrVOKtnxWPc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=p/uTPPVv; arc=none smtp.client-ip=185.125.188.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="p/uTPPVv" Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 6B66B3F8E3 for ; Tue, 24 Dec 2024 06:08:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1735020513; bh=bvUHNb8XemzT0n3pS2sxj6xTXk/hDt3GgdHjNnvpT8o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p/uTPPVvYPYo6XRC16m2ZeXxECkusBA0KzGt3s3SwXkC9pHKA724T8lSaaimErdem Epkk3zoJwb71o2hicGuXOwMatorkPsI2RoQN09GL0/L4AoWxwLbqbW9VLRotVdnKOj es8YzHqcNzQjhLRXSjf5jOThYN6aVxWyUpi9ZjE60l8myIVjXRfZgFo+QiR44G6YxI jJ5vmN7JtIaF36PmrWRe+5VyHhcmGbhI/bXN3VUocs5vnTHmihGvmUJWrUx/IjU5pL UnDfHJinJ767G4EnmIvReM4bKsjAy88GzUW2LPEmJaCcMUtUye68iSCtkIXwpXl0sg +ySPO9XsoLQNA== Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2166855029eso46523725ad.0 for ; Mon, 23 Dec 2024 22:08:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735020512; x=1735625312; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bvUHNb8XemzT0n3pS2sxj6xTXk/hDt3GgdHjNnvpT8o=; b=IYISZOXYAE2Qc1yg+SEchdUiH7QH/jTy2IVyUuo9JxjwS/B5gRGphYJuoT14Z5oX7i GJVn+WUPOyg66rUgCwHK7AoD1cr3H7YaDs/5tv/doO6Jh/jN+C0vZt5YBtK3r+/dI4iZ UY8JLXynHFdxfJ84QVWdWj0zzIMBmPWbUGk1x1imjfmvONe4gujgmsAtf64Ig0E2f812 nSfHBY3XCsrltt9InB3R1YXDPt39yyJQs3d4dzYVj4hxXgKpaed2+ZjHKqxypxMUNS/V oVNE9Iq7d2r4ltYt36QNSklaVN9nQNnUqUASEasKqn3qT6CMTBylBJDYwl6iqtWZoqhX 6yzg== X-Forwarded-Encrypted: i=1; AJvYcCVCXjghvp056Zh+SnhLlCsj/KIqB3YGQY6vOVN2fYXQgcx/Kauychd/EiTftspynYxbOi1gcqKMyyISiw4=@vger.kernel.org X-Gm-Message-State: AOJu0YwXYbp9U/UyHEBpe9WUdRKJuncdItL/MjW8kaogEl6uxCdVH8zX FlrekBqlGNqh8rcZWcb8+UHW+x1etneYOwE2XZKT/vtqg4rcZl1pMrcPCWp3x1sAufnszghv+rJ OPv0wmIPrNT9aRqIJwDmLXcezqKwjcrvAOW50Syb/ELW3jXj3RqwnVPf7buXecE9UhNwIoq+gny vLiA== X-Gm-Gg: ASbGnctb1ZqKWHyqn6sBEgpBNFO5F5umZlfWVo2FmVkh0Nj4oq61Z31+yN+NW6A/7ba mt0tQitcLkpiraBQy6L1wL1GpqdET554+C/yAM8vlFCnS5fZ5HNWc3KB4ZeGcNbwNFXXiRXyc3t 5I2v7XhzkQtGXwI5VTPUqb8ZoiuCDQlJl7hvVCaJnVsLyTwUBgVlzDXziqvmeSf3aR3tSUFyBiu R7Ta8kZeubn8R1JArAaLwVmymScwBpB1A3aTFAgyWZktnJROVsK/3rGmw== X-Received: by 2002:a17:902:dac6:b0:216:59d4:40e7 with SMTP id d9443c01a7336-219e6f25e08mr151410385ad.55.1735020512090; Mon, 23 Dec 2024 22:08:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IEOAv7tCbuJma5e2bZ7olmLZeIwdxAhJgDLtIE55BW4oJwBp6hpQcck5nq7sQNTozUTn6LFfw== X-Received: by 2002:a17:902:dac6:b0:216:59d4:40e7 with SMTP id d9443c01a7336-219e6f25e08mr151410225ad.55.1735020511776; Mon, 23 Dec 2024 22:08:31 -0800 (PST) Received: from z790sl.. ([240f:74:7be:1:7315:8eec:aecb:29a4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dca02a8csm82262235ad.269.2024.12.23.22.08.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2024 22:08:31 -0800 (PST) From: Koichiro Den To: linux-gpio@vger.kernel.org Cc: linus.walleij@linaro.org, brgl@bgdev.pl, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] gpio: virtuser: lock up configfs that an instantiated device depends on Date: Tue, 24 Dec 2024 15:08:18 +0900 Message-ID: <20241224060819.1492472-4-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241224060819.1492472-1-koichiro.den@canonical.com> References: <20241224060819.1492472-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Once a virtuser device is instantiated and actively used, allowing rmdir for its configfs serves no purpose and can be confusing. Userspace interacts with the virtual consumer at arbitrary times, meaning it depends on its existance. Make the subsystem itself depend on the configfs entry for a virtuser device while it is in active use. Signed-off-by: Koichiro Den --- drivers/gpio/gpio-virtuser.c | 49 ++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpio-virtuser.c b/drivers/gpio/gpio-virtuser.c index c9700c1e4126..45b8f192f860 100644 --- a/drivers/gpio/gpio-virtuser.c +++ b/drivers/gpio/gpio-virtuser.c @@ -1533,6 +1533,32 @@ gpio_virtuser_device_deactivate(struct gpio_virtuser= _device *dev) kfree(dev->lookup_table); } =20 +static void +gpio_virtuser_device_lockup_configfs(struct gpio_virtuser_device *dev, boo= l lock) +{ + struct gpio_virtuser_lookup_entry *entry; + struct gpio_virtuser_lookup *lookup; + struct configfs_subsystem *subsys; + + subsys =3D dev->group.cg_subsys; + + /* + * The device only needs to depend on leaf lookup entries. This is + * sufficient to lock up all the configfs entries that the + * instantiated, alive device depends on. + */ + list_for_each_entry(lookup, &dev->lookup_list, siblings) { + list_for_each_entry(entry, &lookup->entry_list, siblings) { + if (lock) + WARN_ON(configfs_depend_item_unlocked( + subsys, &entry->group.cg_item)); + else + configfs_undepend_item_unlocked( + &entry->group.cg_item); + } + } +} + static ssize_t gpio_virtuser_device_config_live_store(struct config_item *item, const char *page, size_t count) @@ -1545,15 +1571,24 @@ gpio_virtuser_device_config_live_store(struct confi= g_item *item, if (ret) return ret; =20 - guard(mutex)(&dev->lock); + if (live) + gpio_virtuser_device_lockup_configfs(dev, true); =20 - if (live =3D=3D gpio_virtuser_device_is_live(dev)) - return -EPERM; + scoped_guard(mutex, &dev->lock) { + if (live =3D=3D gpio_virtuser_device_is_live(dev)) + ret =3D -EPERM; + else if (live) + ret =3D gpio_virtuser_device_activate(dev); + else + gpio_virtuser_device_deactivate(dev); + } =20 - if (live) - ret =3D gpio_virtuser_device_activate(dev); - else - gpio_virtuser_device_deactivate(dev); + /* + * Undepend is required only if device disablement (live =3D=3D 0) + * succeeds or if device enablement (live =3D=3D 1) fails. + */ + if (live =3D=3D !!ret) + gpio_virtuser_device_lockup_configfs(dev, false); =20 return ret ?: count; } --=20 2.43.0