Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2227568/?format=api
{ "id": 2227568, "url": "http://patchwork.ozlabs.org/api/patches/2227568/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20260424070103.1-hv-gpci-v2-pengpeng@iscas.ac.cn/", "project": { "id": 2, "url": "http://patchwork.ozlabs.org/api/projects/2/?format=api", "name": "Linux PPC development", "link_name": "linuxppc-dev", "list_id": "linuxppc-dev.lists.ozlabs.org", "list_email": "linuxppc-dev@lists.ozlabs.org", "web_url": "https://github.com/linuxppc/wiki/wiki", "scm_url": "https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git", "webscm_url": "https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/", "list_archive_url": "https://lore.kernel.org/linuxppc-dev/", "list_archive_url_format": "https://lore.kernel.org/linuxppc-dev/{}/", "commit_url_format": "https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?id={}" }, "msgid": "<20260424070103.1-hv-gpci-v2-pengpeng@iscas.ac.cn>", "list_archive_url": "https://lore.kernel.org/linuxppc-dev/20260424070103.1-hv-gpci-v2-pengpeng@iscas.ac.cn/", "date": "2026-04-23T15:32:00", "name": "[v2] powerpc/perf/hv-gpci: bound sysfs output with helpers", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "d97e895605ba4f062c39eacd798b4fe39b433b01", "submitter": { "id": 93000, "url": "http://patchwork.ozlabs.org/api/people/93000/?format=api", "name": "Pengpeng Hou", "email": "pengpeng@iscas.ac.cn" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20260424070103.1-hv-gpci-v2-pengpeng@iscas.ac.cn/mbox/", "series": [ { "id": 501260, "url": "http://patchwork.ozlabs.org/api/series/501260/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=501260", "date": "2026-04-23T15:32:00", "name": "[v2] powerpc/perf/hv-gpci: bound sysfs output with helpers", "version": 2, "mbox": "http://patchwork.ozlabs.org/series/501260/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2227568/comments/", "check": "success", "checks": "http://patchwork.ozlabs.org/api/patches/2227568/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "\n <linuxppc-dev+bounces-20024-incoming=patchwork.ozlabs.org@lists.ozlabs.org>", "X-Original-To": [ "incoming@patchwork.ozlabs.org", "linuxppc-dev@lists.ozlabs.org" ], "Delivered-To": "patchwork-incoming@legolas.ozlabs.org", "Authentication-Results": [ "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org\n (client-ip=2404:9400:21b9:f100::1; helo=lists.ozlabs.org;\n envelope-from=linuxppc-dev+bounces-20024-incoming=patchwork.ozlabs.org@lists.ozlabs.org;\n receiver=patchwork.ozlabs.org)", "lists.ozlabs.org;\n arc=none smtp.remote-ip=159.226.251.25", "lists.ozlabs.org;\n dmarc=none (p=none dis=none) header.from=iscas.ac.cn", "lists.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=iscas.ac.cn\n (client-ip=159.226.251.25; helo=cstnet.cn;\n envelope-from=pengpeng@iscas.ac.cn; receiver=lists.ozlabs.org)" ], "Received": [ "from lists.ozlabs.org (lists.ozlabs.org\n [IPv6:2404:9400:21b9:f100::1])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1 raw public key)\n server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g1rkc3xplz1xvV\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 24 Apr 2026 08:44:40 +1000 (AEST)", "from boromir.ozlabs.org (localhost [127.0.0.1])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 4g1rkV48b3z2xnZ;\n\tFri, 24 Apr 2026 08:44:34 +1000 (AEST)", "from cstnet.cn (smtp25.cstnet.cn [159.226.251.25])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n\t(No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 4g1rkT0jPhz2xfR\n\tfor <linuxppc-dev@lists.ozlabs.org>; Fri, 24 Apr 2026 08:44:30 +1000 (AEST)", "from 03-hv-gpci-v2.eml (unknown [111.196.245.116])\n\tby APP-05 (Coremail) with SMTP id zQCowADXZQnEoOppH3RsDg--.36943S2;\n\tFri, 24 Apr 2026 06:44:20 +0800 (CST)" ], "ARC-Seal": "i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1776984274;\n\tcv=none;\n b=b4U9xI/Hm0sBZlGN0IsE7wqSEln6RT/p4m5J5Cp0+R+rTg+M6arO9L2UEjVkZMMnKL5X8n9gdAmfjSn2BozPiP05yMo6GG+EliUbmRt1fWWOSy6BRP7A+lixla6ln3fNtZoxMJiNVfwPyYgtImZOKpmy8kYpXfJm4rvtrTrRxdu29j8I5aM+NKUVgBkuk+j87FBKqb3sy11ES4eO4mi0tFZRgcefxdXOHCd1cX0JqoKLLIBWSFOamzHB+LAWSKUyhapFjLp9cFvkNNvWy6rTSVxqr6quUuB4DOlGai1CudeKRJFMW8/x6kkxtwb6KDUZX3l/Gy4K6BLFS/Mc1uHnRg==", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707;\n\tt=1776984274; c=relaxed/relaxed;\n\tbh=wRhGLU8l2WDuwEYGPvevLodPqc2GVxa/gMx/U4sI6X4=;\n\th=From:Date:Message-ID:To:Cc:Subject:In-Reply-To:References;\n b=X9a6c+x7mZm+LAUfN9PeTSSaqseaNpwvO4jOMEtY/mIBH73jEZoQH0J4jqDZBWW5FC5UH4jGO4lG7LFGJPnjhyuyGQblKYE2xf6FyWogviaYEorhC2kAZlmDe/cpuZEAgsE6MP0XUN5u7QQUeX3IV3LYsOn5bukfZFd5KXVo8Gkd5FS/4hvEzozA8EI6NvPEgjRKQ8atQUEa5DCBQy2woLWz2LcdHAzbOTAj/oPTKu8O3nZH/P+5cVMy6c/sMuY5pbWPcwBcU5+NfKFFo7mNP31wmw6O1W4IDir9tNXesd5GPsTsG5UgPilxDKdGAQtVQVuFxZPVBxBum2xNwmm6og==", "ARC-Authentication-Results": "i=1; lists.ozlabs.org;\n dmarc=none (p=none dis=none) header.from=iscas.ac.cn;\n spf=pass (client-ip=159.226.251.25; helo=cstnet.cn;\n envelope-from=pengpeng@iscas.ac.cn;\n receiver=lists.ozlabs.org) smtp.mailfrom=iscas.ac.cn", "From": "Pengpeng Hou <pengpeng@iscas.ac.cn>", "Date": "Thu, 23 Apr 2026 23:32:00 +0800", "Message-ID": "<20260424070103.1-hv-gpci-v2-pengpeng@iscas.ac.cn>", "To": "Madhavan Srinivasan <maddy@linux.ibm.com>,\n Michael Ellerman <mpe@ellerman.id.au>, Christophe Leroy <chleroy@kernel.org>", "Cc": "Nicholas Piggin <npiggin@gmail.com>, Kees Cook <kees@kernel.org>,\n linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,\n stable@vger.kernel.org, pengpeng@iscas.ac.cn", "Subject": "[PATCH v2] powerpc/perf/hv-gpci: bound sysfs output with helpers", "In-Reply-To": "<20260417074825.22967-1-pengpeng@iscas.ac.cn>", "References": "<20260417074825.22967-1-pengpeng@iscas.ac.cn>", "X-CM-TRANSID": "zQCowADXZQnEoOppH3RsDg--.36943S2", "X-Coremail-Antispam": "1UD129KBjvJXoW3GF1UKrWxKF4DCrykZw45GFg_yoWxXF48pF\n\t4rCr47Kw45Gw1UurW0k3Z7Zr13u39Fy347Jay8Kr9ayrs7A39FkFyIyFyYkryxCrWxCFy8\n\tCrZxtws8CanrXa7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2\n\t9KBjDU0xBIdaVrnRJUUUvK14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0\n\trVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2jI8I6cxK6x804I0_JFv_Gryl8cAvFVAK0II2c7\n\txJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE\n\t2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv67AKxVWxJr0_GcWl84ACjc\n\txK6I8E87Iv6xkF7I0E14v26F4UJVW0owAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40E\n\tFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr\n\t0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcVAKI48JM4x0x7Aq67IIx4CEVc8vx2IE\n\trcIFxwCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbV\n\tWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF\n\t67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42\n\tIY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF\n\t0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxh\n\tVjvjDU0xZFpf9x0JUpwZcUUUUU=", "X-Originating-IP": "[111.196.245.116]", "X-CM-SenderInfo": "pshqw1xhqjqxpvfd2hldfou0/", "X-Spam-Status": "No, score=1.1 required=3.0 tests=DATE_IN_PAST_06_12,\n\tRCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=disabled\n\tversion=4.0.1 OzLabs 8", "X-Spam-Level": "*", "X-Spam-Checker-Version": "SpamAssassin 4.0.1 (2024-03-25) on lists.ozlabs.org", "X-Mailing-List": "linuxppc-dev@lists.ozlabs.org", "List-Id": "<linuxppc-dev.lists.ozlabs.org>", "List-Help": "<mailto:linuxppc-dev+help@lists.ozlabs.org>", "List-Owner": "<mailto:linuxppc-dev+owner@lists.ozlabs.org>", "List-Post": "<mailto:linuxppc-dev@lists.ozlabs.org>", "List-Archive": "<https://lore.kernel.org/linuxppc-dev/>,\n <https://lists.ozlabs.org/pipermail/linuxppc-dev/>", "List-Subscribe": "<mailto:linuxppc-dev+subscribe@lists.ozlabs.org>,\n <mailto:linuxppc-dev+subscribe-digest@lists.ozlabs.org>,\n <mailto:linuxppc-dev+subscribe-nomail@lists.ozlabs.org>", "List-Unsubscribe": "<mailto:linuxppc-dev+unsubscribe@lists.ozlabs.org>", "Precedence": "list" }, "content": "systeminfo_gpci_request() and\naffinity_domain_via_partition_result_parse() hex-encode hypervisor data\ninto the single-page sysfs read buffer with sprintf(buf + *n, ...).\nBoth helpers only check PAGE_SIZE after the formatting loops have\nalready advanced past the end of the buffer.\n\nAdd small helpers around sysfs_emit_at() for hex-byte and newline\nappends, and stop once the sysfs buffer is full. This keeps the repeated\nbounds handling local instead of open-coding it at each append site.\n\nFixes: 71f1c39647d8 (\"powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show processor bus topology information\")\nFixes: a15e0d6a6929 (\"powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show affinity domain via partition information\")\nSigned-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>\n---\nChanges since v1:\n- refactor the repeated sysfs_emit_at() handling into helpers as suggested\n by Christophe Leroy", "diff": "diff --git a/arch/powerpc/perf/hv-gpci.c b/arch/powerpc/perf/hv-gpci.c\nindex 5cac2cf3bd1e..2f543f0671ba 100644\n--- a/arch/powerpc/perf/hv-gpci.c\n+++ b/arch/powerpc/perf/hv-gpci.c\n@@ -11,6 +11,7 @@\n \n #include <linux/init.h>\n #include <linux/perf_event.h>\n+#include <linux/sysfs.h>\n #include <asm/firmware.h>\n #include <asm/hvcall.h>\n #include <asm/io.h>\n@@ -129,11 +130,36 @@ static int sysinfo_counter_request[] = {\n \n static DEFINE_PER_CPU(char, hv_gpci_reqb[HGPCI_REQ_BUFFER_SIZE]) __aligned(sizeof(uint64_t));\n \n+static int hv_gpci_emit_hex_byte(char *buf, size_t *n, u8 byte)\n+{\n+\tint len;\n+\n+\tlen = sysfs_emit_at(buf, *n, \"%02x\", byte);\n+\tif (len <= 0)\n+\t\treturn -EFBIG;\n+\n+\t*n += len;\n+\treturn 0;\n+}\n+\n+static int hv_gpci_emit_newline(char *buf, size_t *n)\n+{\n+\tint len;\n+\n+\tlen = sysfs_emit_at(buf, *n, \"\\n\");\n+\tif (len <= 0)\n+\t\treturn -EFBIG;\n+\n+\t*n += len;\n+\treturn 0;\n+}\n+\n static unsigned long systeminfo_gpci_request(u32 req, u32 starting_index,\n \t\t\tu16 secondary_index, char *buf,\n \t\t\tsize_t *n, struct hv_gpci_request_buffer *arg)\n {\n \tunsigned long ret;\n+\tint rc;\n \tsize_t i, j;\n \n \targ->params.counter_request = cpu_to_be32(req);\n@@ -176,9 +202,14 @@ static unsigned long systeminfo_gpci_request(u32 req, u32 starting_index,\n \tfor (i = 0; i < be16_to_cpu(arg->params.returned_values); i++) {\n \t\tj = i * be16_to_cpu(arg->params.cv_element_size);\n \n-\t\tfor (; j < (i + 1) * be16_to_cpu(arg->params.cv_element_size); j++)\n-\t\t\t*n += sprintf(buf + *n, \"%02x\", (u8)arg->bytes[j]);\n-\t\t*n += sprintf(buf + *n, \"\\n\");\n+\t\tfor (; j < (i + 1) * be16_to_cpu(arg->params.cv_element_size); j++) {\n+\t\t\trc = hv_gpci_emit_hex_byte(buf, n, (u8)arg->bytes[j]);\n+\t\t\tif (rc)\n+\t\t\t\treturn rc;\n+\t\t}\n+\t\trc = hv_gpci_emit_newline(buf, n);\n+\t\tif (rc)\n+\t\t\treturn rc;\n \t}\n \n \tif (*n >= PAGE_SIZE) {\n@@ -461,10 +492,14 @@ static ssize_t affinity_domain_via_domain_show(struct device *dev, struct device\n \treturn ret;\n }\n \n-static void affinity_domain_via_partition_result_parse(int returned_values,\n-\t\t\tint element_size, char *buf, size_t *last_element,\n-\t\t\tsize_t *n, struct hv_gpci_request_buffer *arg)\n+static int affinity_domain_via_partition_result_parse(int returned_values,\n+\t\t\t\t\t\t int element_size,\n+\t\t\t\t\t\t char *buf,\n+\t\t\t\t\t\t size_t *last_element,\n+\t\t\t\t\t\t size_t *n,\n+\t\t\t\t\t\t struct hv_gpci_request_buffer *arg)\n {\n+\tint rc;\n \tsize_t i = 0, j = 0;\n \tsize_t k, l, m;\n \tuint16_t total_affinity_domain_ele, size_of_each_affinity_domain_ele;\n@@ -483,27 +518,40 @@ static void affinity_domain_via_partition_result_parse(int returned_values,\n \t */\n \twhile (i < returned_values) {\n \t\tk = j;\n-\t\tfor (; k < j + element_size; k++)\n-\t\t\t*n += sprintf(buf + *n, \"%02x\", (u8)arg->bytes[k]);\n-\t\t*n += sprintf(buf + *n, \"\\n\");\n+\t\tfor (; k < j + element_size; k++) {\n+\t\t\trc = hv_gpci_emit_hex_byte(buf, n, (u8)arg->bytes[k]);\n+\t\t\tif (rc)\n+\t\t\t\treturn rc;\n+\t\t}\n+\t\trc = hv_gpci_emit_newline(buf, n);\n+\t\tif (rc)\n+\t\t\treturn rc;\n \n \t\ttotal_affinity_domain_ele = (u8)arg->bytes[k - 2] << 8 | (u8)arg->bytes[k - 3];\n \t\tsize_of_each_affinity_domain_ele = (u8)arg->bytes[k] << 8 | (u8)arg->bytes[k - 1];\n \n \t\tfor (l = 0; l < total_affinity_domain_ele; l++) {\n \t\t\tfor (m = 0; m < size_of_each_affinity_domain_ele; m++) {\n-\t\t\t\t*n += sprintf(buf + *n, \"%02x\", (u8)arg->bytes[k]);\n+\t\t\t\trc = hv_gpci_emit_hex_byte(buf, n, (u8)arg->bytes[k]);\n+\t\t\t\tif (rc)\n+\t\t\t\t\treturn rc;\n \t\t\t\tk++;\n \t\t\t}\n-\t\t\t*n += sprintf(buf + *n, \"\\n\");\n+\t\t\trc = hv_gpci_emit_newline(buf, n);\n+\t\t\tif (rc)\n+\t\t\t\treturn rc;\n \t\t}\n \n-\t\t*n += sprintf(buf + *n, \"\\n\");\n+\t\trc = hv_gpci_emit_newline(buf, n);\n+\t\tif (rc)\n+\t\t\treturn rc;\n \t\ti++;\n \t\tj = k;\n \t}\n \n \t*last_element = k;\n+\n+\treturn 0;\n }\n \n static ssize_t affinity_domain_via_partition_show(struct device *dev, struct device_attribute *attr,\n@@ -514,6 +562,7 @@ static ssize_t affinity_domain_via_partition_show(struct device *dev, struct dev\n \tsize_t n = 0;\n \tsize_t last_element = 0;\n \tu32 starting_index;\n+\tint element_size, rc, returned_values;\n \n \targ = (void *)get_cpu_var(hv_gpci_reqb);\n \tmemset(arg, 0, HGPCI_REQ_BUFFER_SIZE);\n@@ -546,10 +595,16 @@ static ssize_t affinity_domain_via_partition_show(struct device *dev, struct dev\n \t * to buffer util we get all the information.\n \t */\n \twhile (ret == H_PARAMETER) {\n-\t\taffinity_domain_via_partition_result_parse(\n-\t\t\tbe16_to_cpu(arg->params.returned_values) - 1,\n-\t\t\tbe16_to_cpu(arg->params.cv_element_size), buf,\n-\t\t\t&last_element, &n, arg);\n+\t\treturned_values = be16_to_cpu(arg->params.returned_values);\n+\t\telement_size = be16_to_cpu(arg->params.cv_element_size);\n+\t\trc = affinity_domain_via_partition_result_parse(returned_values - 1,\n+\t\t\t\t\t\t\t\telement_size, buf,\n+\t\t\t\t\t\t\t\t&last_element, &n,\n+\t\t\t\t\t\t\t\targ);\n+\t\tif (rc) {\n+\t\t\tput_cpu_var(hv_gpci_reqb);\n+\t\t\treturn rc;\n+\t\t}\n \n \t\tif (n >= PAGE_SIZE) {\n \t\t\tput_cpu_var(hv_gpci_reqb);\n@@ -578,10 +633,15 @@ static ssize_t affinity_domain_via_partition_show(struct device *dev, struct dev\n \t}\n \n parse_result:\n-\taffinity_domain_via_partition_result_parse(\n-\t\tbe16_to_cpu(arg->params.returned_values),\n-\t\tbe16_to_cpu(arg->params.cv_element_size),\n-\t\tbuf, &last_element, &n, arg);\n+\treturned_values = be16_to_cpu(arg->params.returned_values);\n+\telement_size = be16_to_cpu(arg->params.cv_element_size);\n+\trc = affinity_domain_via_partition_result_parse(returned_values,\n+\t\t\t\t\t\t\telement_size, buf,\n+\t\t\t\t\t\t\t&last_element, &n, arg);\n+\tif (rc) {\n+\t\tput_cpu_var(hv_gpci_reqb);\n+\t\treturn rc;\n+\t}\n \n \tput_cpu_var(hv_gpci_reqb);\n \treturn n;\n", "prefixes": [ "v2" ] }