From patchwork Thu Oct 7 00:09:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1537491 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=CzSq95tb; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HPsFk43wcz9sXS for ; Thu, 7 Oct 2021 11:12:10 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4HPsFk2wh2z3029 for ; Thu, 7 Oct 2021 11:12:10 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=CzSq95tb; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=2605:2700:0:5::4713:9cab; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=CzSq95tb; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [IPv6:2605:2700:0:5::4713:9cab]) (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 lists.ozlabs.org (Postfix) with ESMTPS id 4HPsCQ6Ss4z306R for ; Thu, 7 Oct 2021 11:10:10 +1100 (AEDT) Received: from hatter.bewilderbeest.net (71-212-29-146.tukw.qwest.net [71.212.29.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 71073631; Wed, 6 Oct 2021 17:10:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1633565406; bh=4NkVLqGg/KjNptjTQZ/atTM1MYPT1i0umkxcy4BLe98=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CzSq95tbOSKIzT6diFAHOJsgLiMCNcj5ajO00p1C5HcInWN9ksZR/bd0WjLe6dBGX RNX+QqLt7veMKgWlTCog4xgySxQadL7iZVufNPu5ud8/4AvocYLbQN4JOaS3PFXKKk EY0IrOBtNn5Rng7h8pEcUZnxxX46TLGLyPNWAP6Y= From: Zev Weiss To: openbmc@lists.ozlabs.org Subject: [PATCH 1/9] sysfs: add sysfs_remove_bin_file_self() function Date: Wed, 6 Oct 2021 17:09:46 -0700 Message-Id: <20211007000954.30621-2-zev@bewilderbeest.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211007000954.30621-1-zev@bewilderbeest.net> References: <20211007000954.30621-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Zev Weiss , "Rafael J. Wysocki" , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Bjorn Helgaas , Rob Herring , Daniel Vetter , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Jeremy Kerr , Heiner Kallweit Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" This is simply the bin_attribute analog to sysfs_remove_file_self(). Signed-off-by: Zev Weiss --- fs/sysfs/file.c | 13 +++++++++++++ include/linux/sysfs.h | 1 + 2 files changed, 14 insertions(+) diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index d019d6ac6ad0..b2b85be95adf 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -572,6 +572,19 @@ void sysfs_remove_bin_file(struct kobject *kobj, } EXPORT_SYMBOL_GPL(sysfs_remove_bin_file); +/** + * sysfs_remove_file_self - remove binary object attribute from its own method + * @kobj: object to operate on + * @attr: binary attribute descriptor + * + * See kernfs_remove_self() for details. + */ +bool sysfs_remove_bin_file_self(struct kobject *kobj, const struct bin_attribute *attr) +{ + return sysfs_remove_file_self(kobj, &attr->attr); +} +EXPORT_SYMBOL_GPL(sysfs_remove_bin_file_self); + static int internal_change_owner(struct kernfs_node *kn, kuid_t kuid, kgid_t kgid) { diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index e3f1e8ac1f85..49de5189cf88 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -273,6 +273,7 @@ int __must_check sysfs_create_bin_file(struct kobject *kobj, const struct bin_attribute *attr); void sysfs_remove_bin_file(struct kobject *kobj, const struct bin_attribute *attr); +bool sysfs_remove_bin_file_self(struct kobject *kobj, const struct bin_attribute *attr); int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target, const char *name); From patchwork Thu Oct 7 00:09:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1537490 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=keZbSDNA; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HPsDq12D3z9sXS for ; Thu, 7 Oct 2021 11:11:23 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4HPsDp6vrWz3bXR for ; Thu, 7 Oct 2021 11:11:22 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=keZbSDNA; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=71.19.156.171; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=keZbSDNA; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [71.19.156.171]) (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 lists.ozlabs.org (Postfix) with ESMTPS id 4HPsCQ0jJ8z2ynB for ; Thu, 7 Oct 2021 11:10:09 +1100 (AEDT) Received: from hatter.bewilderbeest.net (71-212-29-146.tukw.qwest.net [71.212.29.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id F2E326E4; Wed, 6 Oct 2021 17:10:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1633565408; bh=ER5WeqZHv4e5QUzYa734QUR0PoxbR0U3SjMD2lEHAUA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=keZbSDNA1mMasatHDQtMaMkueuv/Wl/NrVxagKzSv9B2w8npcfZGhAiaoF/dNtDER 98B2ey8BNFF1lhoTJc0FXByC7wJz63gmpbx1r9/VHzznuwcPdM8OV/l3krJd2TqiSp u1ld/Adc8PuzQ9G8CgUPBkNOwKQCzWRQxjBbcbGQ= From: Zev Weiss To: openbmc@lists.ozlabs.org Subject: [PATCH 2/9] sysfs: add growable flag to struct bin_attribute Date: Wed, 6 Oct 2021 17:09:47 -0700 Message-Id: <20211007000954.30621-3-zev@bewilderbeest.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211007000954.30621-1-zev@bewilderbeest.net> References: <20211007000954.30621-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Zev Weiss , "Rafael J. Wysocki" , Greg Kroah-Hartman , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , linux-kernel@vger.kernel.org, Rob Herring , Daniel Vetter , Bjorn Helgaas , Jeremy Kerr , Dan Williams , Heiner Kallweit Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" Previously, sysfs_kf_bin_write() unconditionally disallowed writing past the existing size of the file. In order to support mutable device-tree status properties (which are bin_attributes), we need to be able to write a longer value over a shorter existing one (e.g. writing "reserved\n" over "okay\0"). bin_attributes that require this can now set the growable flag to disable that checking and allow arbitrary amounts of data to be written at arbitrary offsets. Signed-off-by: Zev Weiss --- fs/sysfs/file.c | 2 +- include/linux/sysfs.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index b2b85be95adf..156df003ea8f 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -147,7 +147,7 @@ static ssize_t sysfs_kf_bin_write(struct kernfs_open_file *of, char *buf, struct kobject *kobj = of->kn->parent->priv; loff_t size = file_inode(of->file)->i_size; - if (size) { + if (!battr->growable && size) { if (size <= pos) return -EFBIG; count = min_t(ssize_t, count, size - pos); diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 49de5189cf88..f8a56094c6c9 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -175,6 +175,7 @@ struct address_space; struct bin_attribute { struct attribute attr; size_t size; + bool growable:1; void *private; struct address_space *(*f_mapping)(void); ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *, From patchwork Thu Oct 7 00:09:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1537492 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=Z2Snd7k8; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HPsGB4WqTz9sXS for ; Thu, 7 Oct 2021 11:12:34 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4HPsGB3Cpvz2yb6 for ; Thu, 7 Oct 2021 11:12:34 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=Z2Snd7k8; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=2605:2700:0:5::4713:9cab; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=Z2Snd7k8; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [IPv6:2605:2700:0:5::4713:9cab]) (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 lists.ozlabs.org (Postfix) with ESMTPS id 4HPsCS1DRHz2yxm for ; Thu, 7 Oct 2021 11:10:12 +1100 (AEDT) Received: from hatter.bewilderbeest.net (71-212-29-146.tukw.qwest.net [71.212.29.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 0A7C772E; Wed, 6 Oct 2021 17:10:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1633565410; bh=UaP+I3aEfwYCqu+AhNqB3qb/bc06VjyurZYTcvpHLj0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z2Snd7k88x1gsHrzmMujLVxsaywkIr7HTLXrlaC7srgZaYPg+pJzqHfMo8wsy70ol QTU/iO/cgyzOYdcdlwjGmERFA8qiXXqzWLEeSr8mSCyCf4SKYh6Q7Mx0WWfHjxQdTh K+3X9qVLMl59O+YXwafMJQJ4Wq3nArSYPK+JNRJw= From: Zev Weiss To: openbmc@lists.ozlabs.org Subject: [PATCH 3/9] lib/string: add sysfs_buf_streq() Date: Wed, 6 Oct 2021 17:09:48 -0700 Message-Id: <20211007000954.30621-4-zev@bewilderbeest.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211007000954.30621-1-zev@bewilderbeest.net> References: <20211007000954.30621-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andy Shevchenko , devicetree@vger.kernel.org, Kees Cook , Zev Weiss , Greg Kroah-Hartman , Nick Desaulniers , linux-kernel@vger.kernel.org, Rob Herring , Jonathan Cameron , Jeremy Kerr , Andrew Morton , Andrey Konovalov , Francis Laniel , Alexey Dobriyan , Daniel Axtens Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" This is intended for use with mutable device-tree string properties. As with sysfs_streq(), it accepts a trailing linefeed for convenient shell access (e.g. 'echo foo > /sys/firmware/devicetree/...'), but also accepts a trailing NUL terminator to match how DT string properties are presented when read (so that we don't reject userspace writing back exactly what it had previously read from the file). Signed-off-by: Zev Weiss --- include/linux/string.h | 1 + lib/string.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/linux/string.h b/include/linux/string.h index 5e96d656be7a..d066ff82d1ec 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -183,6 +183,7 @@ extern char **argv_split(gfp_t gfp, const char *str, int *argcp); extern void argv_free(char **argv); extern bool sysfs_streq(const char *s1, const char *s2); +extern bool sysfs_buf_streq(const void *buf, size_t blen, const char *str); int match_string(const char * const *array, size_t n, const char *string); int __sysfs_match_string(const char * const *array, size_t n, const char *s); diff --git a/lib/string.c b/lib/string.c index b2de45a581f4..aab5cadb6b98 100644 --- a/lib/string.c +++ b/lib/string.c @@ -715,6 +715,40 @@ bool sysfs_streq(const char *s1, const char *s2) } EXPORT_SYMBOL(sysfs_streq); +/** + * sysfs_buf_streq - check if a buffer matches a string, modulo trailing \n or \0 + * @buf: pointer to the buffer to check + * @blen: length of the buffer to check + * @str: string to compare against + * + * This routine returns true iff the buffer equals the string, treating a + * trailing \n or \0 on the buffer as an accepted terminator, the length of + * which (aside from the optional terminator) must match the length of the + * string. It's geared for use with sysfs bin_attribute inputs, which may + * terminate with newlines or NULs (the latter to match how device-tree string + * properties in particular are presented on read). + */ +bool sysfs_buf_streq(const void *buf, size_t blen, const char *str) +{ + const char *p = buf; + size_t slen = strlen(str); + if (blen < slen) + return false; + + if (memcmp(p, str, slen)) + return false; + + switch (blen - slen) { + case 0: + return true; + case 1: + return p[slen] == '\n' || p[slen] == '\0'; + default: + return false; + } +} +EXPORT_SYMBOL(sysfs_buf_streq); + /** * match_string - matches given string in an array * @array: array of strings From patchwork Thu Oct 7 00:09:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1537493 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=gbOT1++M; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HPsH65Gtlz9sXS for ; Thu, 7 Oct 2021 11:13:22 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4HPsH62Ygvz2ynN for ; Thu, 7 Oct 2021 11:13:22 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=gbOT1++M; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=71.19.156.171; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=gbOT1++M; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [71.19.156.171]) (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 lists.ozlabs.org (Postfix) with ESMTPS id 4HPsCS3dpGz308J for ; Thu, 7 Oct 2021 11:10:12 +1100 (AEDT) Received: from hatter.bewilderbeest.net (71-212-29-146.tukw.qwest.net [71.212.29.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id B13EEB11; Wed, 6 Oct 2021 17:10:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1633565410; bh=m1RXT0HKfhkF80qBBFrD7o1Digzwr88Vjm6uogtzkXw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gbOT1++MJbeyR+JEdu/exweu5sXz1+O20WUNQ5n+F4mEMLiTZAQDj7TPnLRB7PCnJ c/fIYdJ5gmDoeuX8WLApoapKBdA0UQ/VQteF29l3L5oUkr26LdRU5jA0lVE+gL2N0y ImJ+ORbdxfmZEa5GTX9UgHpYWwmbktXLq8xlGTl8= From: Zev Weiss To: openbmc@lists.ozlabs.org Subject: [PATCH 4/9] of: add self parameter to __of_sysfs_remove_bin_file() Date: Wed, 6 Oct 2021 17:09:49 -0700 Message-Id: <20211007000954.30621-5-zev@bewilderbeest.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211007000954.30621-1-zev@bewilderbeest.net> References: <20211007000954.30621-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Zev Weiss , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Rob Herring , Jeremy Kerr , Frank Rowand Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" This allows using the function to remove a bin_attribute from that attribute's own methods (by calling sysfs_remove_bin_file_self() instead of sysfs_remove_bin_file()). Signed-off-by: Zev Weiss --- drivers/of/kobj.c | 13 ++++++++----- drivers/of/of_private.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/of/kobj.c b/drivers/of/kobj.c index 6675b5e56960..06d6c90f7aa1 100644 --- a/drivers/of/kobj.c +++ b/drivers/of/kobj.c @@ -84,12 +84,15 @@ int __of_add_property_sysfs(struct device_node *np, struct property *pp) return rc; } -void __of_sysfs_remove_bin_file(struct device_node *np, struct property *prop) +void __of_sysfs_remove_bin_file(struct device_node *np, struct property *prop, bool self) { if (!IS_ENABLED(CONFIG_SYSFS)) return; - sysfs_remove_bin_file(&np->kobj, &prop->attr); + if (self) + sysfs_remove_bin_file_self(&np->kobj, &prop->attr); + else + sysfs_remove_bin_file(&np->kobj, &prop->attr); kfree(prop->attr.attr.name); } @@ -97,7 +100,7 @@ void __of_remove_property_sysfs(struct device_node *np, struct property *prop) { /* at early boot, bail here and defer setup to of_init() */ if (of_kset && of_node_is_attached(np)) - __of_sysfs_remove_bin_file(np, prop); + __of_sysfs_remove_bin_file(np, prop, false); } void __of_update_property_sysfs(struct device_node *np, struct property *newprop, @@ -108,7 +111,7 @@ void __of_update_property_sysfs(struct device_node *np, struct property *newprop return; if (oldprop) - __of_sysfs_remove_bin_file(np, oldprop); + __of_sysfs_remove_bin_file(np, oldprop, false); __of_add_property_sysfs(np, newprop); } @@ -157,7 +160,7 @@ void __of_detach_node_sysfs(struct device_node *np) /* only remove properties if on sysfs */ if (of_node_is_attached(np)) { for_each_property_of_node(np, pp) - __of_sysfs_remove_bin_file(np, pp); + __of_sysfs_remove_bin_file(np, pp, false); kobject_del(&np->kobj); } diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 75e67b8bb826..fff157c63907 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -134,7 +134,7 @@ extern int __of_update_property(struct device_node *np, extern void __of_detach_node(struct device_node *np); extern void __of_sysfs_remove_bin_file(struct device_node *np, - struct property *prop); + struct property *prop, bool selfremove); /* illegal phandle value (set when unresolved) */ #define OF_PHANDLE_ILLEGAL 0xdeadbeef From patchwork Thu Oct 7 00:09:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1537494 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=cz+GMC44; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HPsHZ6vBBz9sXS for ; Thu, 7 Oct 2021 11:13:46 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4HPsHZ5Kvfz2yg4 for ; Thu, 7 Oct 2021 11:13:46 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=cz+GMC44; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=2605:2700:0:5::4713:9cab; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=cz+GMC44; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [IPv6:2605:2700:0:5::4713:9cab]) (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 lists.ozlabs.org (Postfix) with ESMTPS id 4HPsCT1HVZz309K for ; Thu, 7 Oct 2021 11:10:13 +1100 (AEDT) Received: from hatter.bewilderbeest.net (71-212-29-146.tukw.qwest.net [71.212.29.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 597DAC4F; Wed, 6 Oct 2021 17:10:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1633565411; bh=cSziyfy743JedtW4xRUNVrSzMdvpgBMMh/fwJwFcHxU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cz+GMC44xNjrax4KSWP/45q0mdz1QwTmEvoQGPUcQCseAE9LUQC/RE/X8f1mlkMAM Db3hnwmr5IvBUUDwHGN8kGnQE+4blLSqov7KASCyW3vr6Tcq2fS4YfVq/GWlvjNVp7 fLDBmr8MPQBql/mYuuCMznAg6RfPMvpPaIYMisOo= From: Zev Weiss To: openbmc@lists.ozlabs.org Subject: [PATCH 5/9] of: add self parameter to of_update_property() Date: Wed, 6 Oct 2021 17:09:50 -0700 Message-Id: <20211007000954.30621-6-zev@bewilderbeest.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211007000954.30621-1-zev@bewilderbeest.net> References: <20211007000954.30621-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Zev Weiss , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Rob Herring , Jeremy Kerr , Frank Rowand Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" This is to indicate that the property is being updated via its own sysfs method so that we ultimately call into kernfs_remove_self() and avoid the deadlock that would occur otherwise. Signed-off-by: Zev Weiss --- drivers/of/base.c | 7 ++++--- drivers/of/dynamic.c | 2 +- drivers/of/kobj.c | 4 ++-- drivers/of/of_private.h | 4 ++-- include/linux/of.h | 7 ++++++- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index f720c0d246f2..ce4d3bc2f8a6 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1902,8 +1902,9 @@ int __of_update_property(struct device_node *np, struct property *newprop, return 0; } + /* - * of_update_property - Update a property in a node, if the property does + * of_update_property_self - Update a property in a node, if the property does * not exist, add it. * * Note that we don't actually remove it, since we have given out @@ -1911,7 +1912,7 @@ int __of_update_property(struct device_node *np, struct property *newprop, * Instead we just move the property to the "dead properties" list, * and add the new property to the property list */ -int of_update_property(struct device_node *np, struct property *newprop) +int of_update_property_self(struct device_node *np, struct property *newprop, bool self) { struct property *oldprop; unsigned long flags; @@ -1927,7 +1928,7 @@ int of_update_property(struct device_node *np, struct property *newprop) raw_spin_unlock_irqrestore(&devtree_lock, flags); if (!rc) - __of_update_property_sysfs(np, newprop, oldprop); + __of_update_property_sysfs(np, newprop, oldprop, self); mutex_unlock(&of_mutex); diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index cd3821a6444f..8a67f3e1b223 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -652,7 +652,7 @@ static int __of_changeset_entry_apply(struct of_changeset_entry *ce) __of_remove_property_sysfs(ce->np, ce->prop); break; case OF_RECONFIG_UPDATE_PROPERTY: - __of_update_property_sysfs(ce->np, ce->prop, ce->old_prop); + __of_update_property_sysfs(ce->np, ce->prop, ce->old_prop, false); break; } diff --git a/drivers/of/kobj.c b/drivers/of/kobj.c index 06d6c90f7aa1..378cb421aae1 100644 --- a/drivers/of/kobj.c +++ b/drivers/of/kobj.c @@ -104,14 +104,14 @@ void __of_remove_property_sysfs(struct device_node *np, struct property *prop) } void __of_update_property_sysfs(struct device_node *np, struct property *newprop, - struct property *oldprop) + struct property *oldprop, bool self) { /* At early boot, bail out and defer setup to of_init() */ if (!of_kset) return; if (oldprop) - __of_sysfs_remove_bin_file(np, oldprop, false); + __of_sysfs_remove_bin_file(np, oldprop, self); __of_add_property_sysfs(np, newprop); } diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index fff157c63907..3c6816237278 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -64,7 +64,7 @@ int of_node_is_attached(struct device_node *node); int __of_add_property_sysfs(struct device_node *np, struct property *pp); void __of_remove_property_sysfs(struct device_node *np, struct property *prop); void __of_update_property_sysfs(struct device_node *np, struct property *newprop, - struct property *oldprop); + struct property *oldprop, bool self); int __of_attach_node_sysfs(struct device_node *np); void __of_detach_node_sysfs(struct device_node *np); #else @@ -74,7 +74,7 @@ static inline int __of_add_property_sysfs(struct device_node *np, struct propert } static inline void __of_remove_property_sysfs(struct device_node *np, struct property *prop) {} static inline void __of_update_property_sysfs(struct device_node *np, - struct property *newprop, struct property *oldprop) {} + struct property *newprop, struct property *oldprop, bool self) {} static inline int __of_attach_node_sysfs(struct device_node *np) { return 0; diff --git a/include/linux/of.h b/include/linux/of.h index 6f1c41f109bb..0e6479a884eb 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -401,7 +401,12 @@ extern int of_machine_is_compatible(const char *compat); extern int of_add_property(struct device_node *np, struct property *prop); extern int of_remove_property(struct device_node *np, struct property *prop); -extern int of_update_property(struct device_node *np, struct property *newprop); +extern int of_update_property_self(struct device_node *np, struct property *newprop, bool self); + +static inline int of_update_property(struct device_node *np, struct property *newprop) +{ + return of_update_property_self(np, newprop, false); +} /* For updating the device tree at runtime */ #define OF_RECONFIG_ATTACH_NODE 0x0001 From patchwork Thu Oct 7 00:09:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1537495 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=LJnbGq7T; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HPsJw0qx4z9sXS for ; Thu, 7 Oct 2021 11:14:56 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4HPsJv6Pc9z3bgl for ; Thu, 7 Oct 2021 11:14:55 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=LJnbGq7T; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=2605:2700:0:5::4713:9cab; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=LJnbGq7T; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [IPv6:2605:2700:0:5::4713:9cab]) (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 lists.ozlabs.org (Postfix) with ESMTPS id 4HPsCT4M9tz2ynx for ; Thu, 7 Oct 2021 11:10:13 +1100 (AEDT) Received: from hatter.bewilderbeest.net (71-212-29-146.tukw.qwest.net [71.212.29.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id C94CFC65; Wed, 6 Oct 2021 17:10:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1633565412; bh=X7NcKoZNi7nh2DbYzKpYnZIhtNF3Gmm/jHD3A05+bD4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LJnbGq7T4ITbr8iPodDndpzFsO83HayGNRUaqWxHfxLjDGm94vkTZoCtoI7sIULoj buTVz6hkQIaZJUMCSbGdDevAAoFHUZ3PPZ6M6AhLFBbhTLGlfwp79l0vouM8SYY29D 7E9N6KqIf0NLcQ7yLNK1JPJJD6uz4n0WtJ9PAzQ0= From: Zev Weiss To: openbmc@lists.ozlabs.org Subject: [PATCH 6/9] of: add support for 'dynamic' DT property Date: Wed, 6 Oct 2021 17:09:51 -0700 Message-Id: <20211007000954.30621-7-zev@bewilderbeest.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211007000954.30621-1-zev@bewilderbeest.net> References: <20211007000954.30621-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Zev Weiss , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Rob Herring , Jeremy Kerr , Frank Rowand Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" Nodes marked with this (boolean) property will have a writable status sysfs file, which can be used to toggle them between "okay" and "reserved", effectively hot-plugging them. Note that this will only be effective for devices on busses that register for OF reconfig notifications (currently spi, i2c, and platform), and only if CONFIG_OF_DYNAMIC is enabled. Signed-off-by: Zev Weiss --- drivers/of/kobj.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/drivers/of/kobj.c b/drivers/of/kobj.c index 378cb421aae1..141ae23f3130 100644 --- a/drivers/of/kobj.c +++ b/drivers/of/kobj.c @@ -36,6 +36,69 @@ static ssize_t of_node_property_read(struct file *filp, struct kobject *kobj, return memory_read_from_buffer(buf, count, &offset, pp->value, pp->length); } +static ssize_t of_node_status_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t offset, size_t count) +{ + int rc; + char *newstatus; + struct property **deadprev; + struct property *newprop = NULL; + struct property *oldprop = container_of(bin_attr, struct property, attr); + struct device_node *np = container_of(kobj, struct device_node, kobj); + + if (WARN_ON_ONCE(strcmp(oldprop->name, "status"))) + return -EIO; + + if (offset) + return -EINVAL; + + if (sysfs_buf_streq(buf, count, "okay") || sysfs_buf_streq(buf, count, "ok")) + newstatus = "okay"; + else if (sysfs_buf_streq(buf, count, "reserved")) + newstatus = "reserved"; + else if (sysfs_buf_streq(buf, count, "disabled")) + newstatus = "disabled"; + else + return -EINVAL; + + if (!strcmp(newstatus, oldprop->value)) + return count; + + /* + * of_update_property_self() doesn't free replaced properties, so + * rifle through deadprops first to see if there's an equivalent old + * status property we can reuse instead of allocating a new one. + */ + mutex_lock(&of_mutex); + for (deadprev = &np->deadprops; *deadprev; deadprev = &(*deadprev)->next) { + struct property *deadprop = *deadprev; + if (!strcmp(deadprop->name, "status") && + deadprop->length == strlen(newstatus) + 1 && + !strcmp(deadprop->value, newstatus)) { + *deadprev = deadprop->next; + deadprop->next = NULL; + newprop = deadprop; + break; + } + } + mutex_unlock(&of_mutex); + + if (!newprop) { + newprop = kzalloc(sizeof(*newprop), GFP_KERNEL); + if (!newprop) + return -ENOMEM; + + newprop->name = oldprop->name; + newprop->value = newstatus; + newprop->length = strlen(newstatus) + 1; + } + + rc = of_update_property_self(np, newprop, true); + + return rc ? rc : count; +} + /* always return newly allocated name, caller must free after use */ static const char *safe_name(struct kobject *kobj, const char *orig_name) { @@ -79,6 +142,12 @@ int __of_add_property_sysfs(struct device_node *np, struct property *pp) pp->attr.size = secure ? 0 : pp->length; pp->attr.read = of_node_property_read; + if (!strcmp(pp->name, "status") && of_property_read_bool(np, "dynamic")) { + pp->attr.attr.mode |= 0200; + pp->attr.write = of_node_status_write; + pp->attr.growable = true; + } + rc = sysfs_create_bin_file(&np->kobj, &pp->attr); WARN(rc, "error adding attribute %s to node %pOF\n", pp->name, np); return rc; From patchwork Thu Oct 7 00:09:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1537496 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=kY2SIwim; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HPsKM2qNxz9sXS for ; Thu, 7 Oct 2021 11:15:19 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4HPsKM1F5Zz2ygF for ; Thu, 7 Oct 2021 11:15:19 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=kY2SIwim; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=71.19.156.171; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=kY2SIwim; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [71.19.156.171]) (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 lists.ozlabs.org (Postfix) with ESMTPS id 4HPsCV0QN6z30GD for ; Thu, 7 Oct 2021 11:10:14 +1100 (AEDT) Received: from hatter.bewilderbeest.net (71-212-29-146.tukw.qwest.net [71.212.29.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 41682C9C; Wed, 6 Oct 2021 17:10:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1633565412; bh=8PxEBgL6W+cioy40DEeituztueb3LeZkbsP0wIoL/Sw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kY2SIwimC82+8OVRRx8RawwF6vON2/1tDFBmvkufF7BIAcyB+uL6Ai+6ZuY+GFjod zbBfRwJ8PooTFUPhODE8SDsA9JxMdfv4Rpj9GonN5n+q66yGceoBcXEaBE60Vr1B7k X3BebMxwRHlKJqdGuEgPuvumw2A4rQM285HvdyyU= From: Zev Weiss To: openbmc@lists.ozlabs.org Subject: [PATCH 7/9] of: make OF_DYNAMIC selectable independently of OF_UNITTEST Date: Wed, 6 Oct 2021 17:09:52 -0700 Message-Id: <20211007000954.30621-8-zev@bewilderbeest.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211007000954.30621-1-zev@bewilderbeest.net> References: <20211007000954.30621-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Zev Weiss , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Rob Herring , Jeremy Kerr , Frank Rowand Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" The writable status sysfs file enabled by the 'dynamic' DT property requires CONFIG_OF_DYNAMIC to be useful, but that shouldn't require dragging in CONFIG_OF_UNITTEST as well. Signed-off-by: Zev Weiss --- drivers/of/Kconfig | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 3dfeae8912df..8e0ba87db030 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -55,12 +55,14 @@ config OF_KOBJ # Hardly any platforms need this. It is safe to select, but only do so if you # need it. config OF_DYNAMIC - bool "Support for dynamic device trees" if OF_UNITTEST + bool "Support for dynamic device trees" select OF_KOBJ help On some platforms, the device tree can be manipulated at runtime. - While this option is selected automatically on such platforms, you - can enable it manually to improve device tree unit test coverage. + With this option enabled, device tree nodes that are marked with + the "dynamic" property can have their status toggled between + "okay" and "reserved" via sysfs. This can also be enabled to + increase test coverage with CONFIG_OF_UNITTEST if desired. config OF_ADDRESS def_bool y From patchwork Thu Oct 7 00:09:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1537497 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=iKvC3Kdw; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HPsLG73Wdz9sXS for ; Thu, 7 Oct 2021 11:16:06 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4HPsLG3Mn8z2ynK for ; Thu, 7 Oct 2021 11:16:06 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=iKvC3Kdw; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=71.19.156.171; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=iKvC3Kdw; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [71.19.156.171]) (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 lists.ozlabs.org (Postfix) with ESMTPS id 4HPsCV6fpwz30JK for ; Thu, 7 Oct 2021 11:10:14 +1100 (AEDT) Received: from hatter.bewilderbeest.net (71-212-29-146.tukw.qwest.net [71.212.29.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 232BAB11; Wed, 6 Oct 2021 17:10:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1633565413; bh=KPHYi63s/G5XAlxpI8QkOVb49ijpIDoF7YfnJ8N7apw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iKvC3KdwWMtPY936nAP1AEkiUaITTjyc55y6lQs6QNxcbjUOgwzmzE5ifms9CPcaM 6EGAYE/k7e05sRe2IPqp8DOBwMsYS7W+au5bOj8EsO+RJUsqLNcnGMSzWuOKO3uemp H524UwzBbq393MbRfpDckxxgBx4hBZDzRX60od6I= From: Zev Weiss To: openbmc@lists.ozlabs.org Subject: [PATCH 8/9] dt-bindings: document new 'dynamic' common property Date: Wed, 6 Oct 2021 17:09:53 -0700 Message-Id: <20211007000954.30621-9-zev@bewilderbeest.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211007000954.30621-1-zev@bewilderbeest.net> References: <20211007000954.30621-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Zev Weiss , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Rob Herring , Jeremy Kerr Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" Signed-off-by: Zev Weiss --- .../devicetree/bindings/common-properties.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Documentation/devicetree/bindings/common-properties.txt b/Documentation/devicetree/bindings/common-properties.txt index 98a28130e100..db6c54e1071d 100644 --- a/Documentation/devicetree/bindings/common-properties.txt +++ b/Documentation/devicetree/bindings/common-properties.txt @@ -83,3 +83,21 @@ gpio@0 { #gpio-cells = <2>; #daisy-chained-devices = <3>; }; + +Dynamic devices +--------------- + +Certain devices may require support for runtime attachment and +detachment (hot-plugging, essentially). + +Optional properties: + - dynamic: Boolean; indicates that the device's status may change at + runtime. + +Example: +&spi1 { + compatible = "name"; + status = "reserved"; + ... + dynamic; +}; From patchwork Thu Oct 7 00:09:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1537499 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=EitWl8Ql; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HPsLn1RcGz9sXS for ; Thu, 7 Oct 2021 11:16:33 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4HPsLm71b7z3bW7 for ; Thu, 7 Oct 2021 11:16:32 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=EitWl8Ql; dkim-atps=neutral X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=2605:2700:0:5::4713:9cab; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=EitWl8Ql; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [IPv6:2605:2700:0:5::4713:9cab]) (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 lists.ozlabs.org (Postfix) with ESMTPS id 4HPsCW2nWkz2yxj; Thu, 7 Oct 2021 11:10:15 +1100 (AEDT) Received: from hatter.bewilderbeest.net (71-212-29-146.tukw.qwest.net [71.212.29.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 8A47BC9D; Wed, 6 Oct 2021 17:10:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1633565413; bh=XbnBokbU4ntbWci1KrAbGbAkUYozeIlG0GRIL9z3qXo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EitWl8QleIUt2OPZiPMJHveL8FiAN7YvAna53lj/V5pHG85jwRgWKeB0Wul/1oG+R UK2CqTSLh+QHrGhAwU8tWk6lV+2b9ykqCNlrtjz/Q2VlW7CkoV2BXGK1Yns/FebXek MK4ZnWkn9bRJ0AIs3j9nJ8x5SEtyaU6WmkO0dO+U= From: Zev Weiss To: openbmc@lists.ozlabs.org Subject: [PATCH 9/9] ARM: dts: aspeed: Add e3c246d4i BIOS flash device Date: Wed, 6 Oct 2021 17:09:54 -0700 Message-Id: <20211007000954.30621-10-zev@bewilderbeest.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211007000954.30621-1-zev@bewilderbeest.net> References: <20211007000954.30621-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-aspeed@lists.ozlabs.org, Zev Weiss , Andrew Jeffery , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Rob Herring , Jeremy Kerr , linux-arm-kernel@lists.infradead.org Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" This uses a dynamic DT node because the BIOS SPI flash requires significant coordination with the host system (power state tracking, GPIOs, IPMI messages) before the BMC can touch it, and needs to be relinquished back to the host when the BMC is done accessing it. Signed-off-by: Zev Weiss --- .../boot/dts/aspeed-bmc-asrock-e3c246d4i.dts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/arm/boot/dts/aspeed-bmc-asrock-e3c246d4i.dts b/arch/arm/boot/dts/aspeed-bmc-asrock-e3c246d4i.dts index 9b4cf5ebe6d5..428198703824 100644 --- a/arch/arm/boot/dts/aspeed-bmc-asrock-e3c246d4i.dts +++ b/arch/arm/boot/dts/aspeed-bmc-asrock-e3c246d4i.dts @@ -68,6 +68,29 @@ flash@0 { }; }; +&spi1 { + /* + * The BIOS SPI flash is shared with the host via an external mux, and + * is not accessible by the BMC by default (hence reserved/dynamic + * here rather than okay). This would ideally be done on the flash@0 + * node instead of the spi1 controller, but the driver infrastructure + * to support dynamic devices at that level of the device tree isn't + * currently in place, and it's the only flash chip on this + * controller, so we can get away with the coarser granularity here + * until support for making individual flash chips dynamic is + * available. + */ + status = "reserved"; + dynamic; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_spi1_default>; + flash@0 { + status = "okay"; + label = "bios"; + m25p,fast-read; + }; +}; + &uart5 { status = "okay"; };