{"id":2231663,"url":"http://patchwork.ozlabs.org/api/patches/2231663/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/8fda3212a1ad48879c174e92f67472d9b9f1c3b7.1777606826.git.ritesh.list@gmail.com/","project":{"id":2,"url":"http://patchwork.ozlabs.org/api/projects/2/?format=json","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":"<8fda3212a1ad48879c174e92f67472d9b9f1c3b7.1777606826.git.ritesh.list@gmail.com>","list_archive_url":"https://lore.kernel.org/linuxppc-dev/8fda3212a1ad48879c174e92f67472d9b9f1c3b7.1777606826.git.ritesh.list@gmail.com/","date":"2026-05-01T04:11:44","name":"[v3,5/9] pseries/papr-hvpipe: Fix the usage of copy_to_user()","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"4c72be5772b08c33f82b9bb035c85b8214dc3c6b","submitter":{"id":79126,"url":"http://patchwork.ozlabs.org/api/people/79126/?format=json","name":"Ritesh Harjani (IBM)","email":"ritesh.list@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/8fda3212a1ad48879c174e92f67472d9b9f1c3b7.1777606826.git.ritesh.list@gmail.com/mbox/","series":[{"id":502420,"url":"http://patchwork.ozlabs.org/api/series/502420/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=502420","date":"2026-05-01T04:11:39","name":"pseries/papr-hvpipe: Fix deadlock, races and misc cleanups","version":3,"mbox":"http://patchwork.ozlabs.org/series/502420/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2231663/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2231663/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linuxppc-dev+bounces-20356-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\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=SJpvlPnY;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org\n (client-ip=112.213.38.117; helo=lists.ozlabs.org;\n envelope-from=linuxppc-dev+bounces-20356-incoming=patchwork.ozlabs.org@lists.ozlabs.org;\n receiver=patchwork.ozlabs.org)","lists.ozlabs.org;\n arc=none smtp.remote-ip=\"2607:f8b0:4864:20::1031\"","lists.ozlabs.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","lists.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=SJpvlPnY;\n\tdkim-atps=neutral","lists.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com\n (client-ip=2607:f8b0:4864:20::1031; helo=mail-pj1-x1031.google.com;\n envelope-from=ritesh.list@gmail.com; receiver=lists.ozlabs.org)"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g6HhC4Skqz1y04\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 01 May 2026 14:12:59 +1000 (AEST)","from boromir.ozlabs.org (localhost [127.0.0.1])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 4g6Hgr2jsPz30DR;\n\tFri, 01 May 2026 14:12:40 +1000 (AEST)","from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com\n [IPv6:2607:f8b0:4864:20::1031])\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 4g6Hgq4dgJz2xjd\n\tfor <linuxppc-dev@lists.ozlabs.org>; Fri, 01 May 2026 14:12:39 +1000 (AEST)","by mail-pj1-x1031.google.com with SMTP id\n 98e67ed59e1d1-35da9c0c007so1806172a91.2\n        for <linuxppc-dev@lists.ozlabs.org>;\n Thu, 30 Apr 2026 21:12:39 -0700 (PDT)","from localhost.localdomain ([49.205.216.49])\n        by smtp.gmail.com with ESMTPSA id\n d2e1a72fcca58-83515b485eesm1159428b3a.48.2026.04.30.21.12.33\n        (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);\n        Thu, 30 Apr 2026 21:12:36 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1777608760;\n\tcv=none;\n b=O3p45VoSYCTjUw4k8g8MgXq9OgG8qQw2e+WjAbF+6AkiZiAlJyuPJJFGNVRRl/aWiVXyFReiFsqHzWsx2fkLtSOi/z5iD5hmo/O+BRfImyc39SzNpjgwVSfHiFU3hf9u//+EQRZblEzmCD2zxruVLdTwzjUl0K3rHqF+R+4eJjRRsse8UMqw9jzKSzQZWjlljCoZ9j8ywf+P6BgBA3cnPLLyc3K0/oQP6Ua36muC/xAACZkYNdmoqKwwxN8IA80LSQ7C+neZc/NeF1ol3ycl1dwpEAgK4nljt8iEQU8cM4Nzq95cjI1z724RB3JU0c19nP5QnABIw2WeO2e5ujq0Kw==","ARC-Message-Signature":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707;\n\tt=1777608760; c=relaxed/relaxed;\n\tbh=GzTwWKu4/OMgogLdvJRN18BQXd8VP1+UN2ymsqFSQ28=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=BDbuHMgIkIJ3L1y3t/ELaF4WoVT+ZcdbfUnr3cpTZa2H943V9YuqG+PRrBkMGMfc5BBZ1mgxFE+mOo7isxIEA/g0xG8hXVP12nStUnDmzsolguMXr5kLCWNh1UH1ReQIQxL+/4amMraoAAAh1w2ulSmIV8ZBsZd9Ac2mIxiyrq8jDMbGSnsHlsXXUWHmGT0GYxY3fH6mUpkjDc4iR4kBxPa/Z7FJve249aQbvAabWiyLqXIlLamEJJRSP63d8I28VPuumWP0t6USuSsVa2niRd37in+rHJHFbiyvEVfGGeByIiJ0KmsPh9Po0o5UdKVz8Lb9I8hTMkvTGABYeu9vhw==","ARC-Authentication-Results":"i=1; lists.ozlabs.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com; dkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=SJpvlPnY; dkim-atps=neutral;\n spf=pass (client-ip=2607:f8b0:4864:20::1031; helo=mail-pj1-x1031.google.com;\n envelope-from=ritesh.list@gmail.com;\n receiver=lists.ozlabs.org) smtp.mailfrom=gmail.com","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1777608757; x=1778213557;\n darn=lists.ozlabs.org;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n         :message-id:reply-to;\n        bh=GzTwWKu4/OMgogLdvJRN18BQXd8VP1+UN2ymsqFSQ28=;\n        b=SJpvlPnYkKou1+bNCLHUgKTOldkDbWnBZ3meQPGcaKmrf8v2LeqLcNzr7BX9zJouXF\n         mDKnIL4ntW+ItVf8XBmBf2CIkmZDBlQIBVmKg+mEJdUZcoGUMVXk5LqChJLl+E4KB++W\n         RZut+4JZwOj+/gydJPZ3EdZ5i0gaI/Ps3M3sr+nowKfI+82Pk+uPE/8oZQ7d0ATySwSN\n         2GcYEaloqzhH2huS5b/0o5A2KAbTb15vEEntzgr1TcNUoXy627rt1YRYrhACgmq7wIwU\n         XUXyuMtv/jsm8Dyw1mst/EBioFvEdtoOUDPJCHkVCXt6qAVzhwQY9ZisjvHV+NKzWQt7\n         n+9A==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1777608757; x=1778213557;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n         :to:cc:subject:date:message-id:reply-to;\n        bh=GzTwWKu4/OMgogLdvJRN18BQXd8VP1+UN2ymsqFSQ28=;\n        b=kLeU3Qz90iwoytKJaddhyLKuzC0+//MmNRp/wevqVhRpS8f1nXCTnqquCmenzvwSoX\n         lgAAcfVCFAgmVcbxyF7n6rMsCkJXjddeQ7nRpeRjpixEKvypwneUjaKxKgRtoSGSlByu\n         sBdAc5UhxmBdDpSDQexdC8kZ+zTQajQW+4H+SIMzKXkkE+OBSDVMN3iadLBPC5PF/PX/\n         mQLHlvHtH53WR8S2DSKtODwYzWQnoS9IuEJrnBs8yk/i4hqye66kj95rZs5s7LoEcvsY\n         cBEmOvz69bDbzCCn1Z9npNA53OlTv5IpHDktOPsMhPl0VXnTpdycvcTyH2HEeUkpBKna\n         z02g==","X-Gm-Message-State":"AOJu0Ywo4LyfM59RDYElBgEmPNNHRgmf6Fm4T/xPGfitwoX3HpdStzci\n\t7xziSurDgkEiKSdVFbDRCdIqe3ErDzZsAfqljC3IgE1XDeIZOj6nC44+eTZu01z4","X-Gm-Gg":"AeBDieuoeX+zsUBp5rfhop8tDiAE0oKNUhKMg2Uxb7v6XPqOReda5x616jcH1ODeVEX\n\tMeT2UP0IotWSyXP7pPeAV62TfpN+ngULMYrc2qmowaBmnYaLk51gRLxTyXNi7Ma0+9P2qfFaQ3P\n\t4euPGjv1Hi9tHXNPMvgNH3muIrzJZk9ENRAfdkIWKSrnRNcaUyGpa163xjEKg8nifgL8bzsHkln\n\tvyMoShFY5z8bN+zsW+jfUnaXokyx3wqK5hVHfiXHHF1oKNKc9/peEGNQ/CWSILZLuTVbIaRqZDi\n\tVqrUtVWEalySMA69dOZYqiKJ87vddd5uG73bTOy/gjAN9ISgs9vxbEuzsjqU16iuwErVerKzOcf\n\ti4ZGPTshHKULOlqWOgjApMzrujbVmt9hbHT4WBTX4O+E0sDrJdceh63ytPjyIk9pAXipDwptv8r\n\tbrivnL6gTKrRTP3JMpY00h3U1bgI7L2KoWGpzaDMKAF2re71jCcSkvop4nnv2h57k=","X-Received":"by 2002:a05:6a20:2444:b0:39f:a42:9247 with SMTP id\n adf61e73a8af0-3a45fe026bbmr1846152637.37.1777608757090;\n        Thu, 30 Apr 2026 21:12:37 -0700 (PDT)","From":"\"Ritesh Harjani (IBM)\" <ritesh.list@gmail.com>","To":"linuxppc-dev@lists.ozlabs.org,\n\tHaren Myneni <haren@linux.ibm.com>","Cc":"Madhavan Srinivasan <maddy@linux.ibm.com>,\n\tChristophe Leroy <chleroy@kernel.org>,\n\tVenkat Rao Bagalkote <venkat88@linux.ibm.com>,\n\tNicholas Piggin <npiggin@gmail.com>,\n\tlinux-kernel@vger.kernel.org,\n\t\"Ritesh Harjani (IBM)\" <ritesh.list@gmail.com>,\n\tstable@vger.kernel.org","Subject":"[PATCH v3 5/9] pseries/papr-hvpipe: Fix the usage of copy_to_user()","Date":"Fri,  1 May 2026 09:41:44 +0530","Message-ID":"\n <8fda3212a1ad48879c174e92f67472d9b9f1c3b7.1777606826.git.ritesh.list@gmail.com>","X-Mailer":"git-send-email 2.50.1","In-Reply-To":"<cover.1777606826.git.ritesh.list@gmail.com>","References":"<cover.1777606826.git.ritesh.list@gmail.com>","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","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-Spam-Status":"No, score=-0.2 required=3.0 tests=DKIM_SIGNED,DKIM_VALID,\n\tDKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,\n\tSPF_HELO_NONE,SPF_PASS autolearn=disabled version=4.0.1 OzLabs 8","X-Spam-Checker-Version":"SpamAssassin 4.0.1 (2024-03-25) on lists.ozlabs.org"},"content":"copy_to_user() return bytes_not_copied to the user buffer. If there was\nan error writing bytes into the user buffer, i.e. if copy_to_user\nreturns a non-zero value, then we should simply return -EFAULT from the\n->read() call.\n\nOtherwise, in the non-patched version, we may end up mixing\n\"bytes_not_copied + bytes_copied (HVPIPE_HDR_LEN)\" as the return value\nto the user in ->read() call\n\nAlso let's make sure we clear the hvpipe_status flag, if we have\nconsumed the hvpipe msg by making the rtas call. ret = -EFAULT means\ncopy_to_user has failed but that still means that the msg was read from\nthe hvpipe, hence for both cases, success & -EFAULT, we should clear the\nHVPIPE_MSG_AVAILABLE flag in hvpipe_status.\n\nCc: stable@vger.kernel.org\nFixes: cebdb522fd3edd1 (\"powerpc/pseries: Receive payload with ibm,receive-hvpipe-msg RTAS\")\nSigned-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>\n---\n arch/powerpc/platforms/pseries/papr-hvpipe.c | 23 ++++++++++++--------\n 1 file changed, 14 insertions(+), 9 deletions(-)","diff":"diff --git a/arch/powerpc/platforms/pseries/papr-hvpipe.c b/arch/powerpc/platforms/pseries/papr-hvpipe.c\nindex 800649f309a5..c007560d2d8c 100644\n--- a/arch/powerpc/platforms/pseries/papr-hvpipe.c\n+++ b/arch/powerpc/platforms/pseries/papr-hvpipe.c\n@@ -206,10 +206,11 @@ static int hvpipe_rtas_recv_msg(char __user *buf, int size)\n \t\t\t\t\tbytes_written, size);\n \t\t\t\tbytes_written = size;\n \t\t\t}\n-\t\t\tret = copy_to_user(buf,\n+\t\t\tif (copy_to_user(buf,\n \t\t\t\t\trtas_work_area_raw_buf(work_area),\n-\t\t\t\t\tbytes_written);\n-\t\t\tif (!ret)\n+\t\t\t\t\tbytes_written))\n+\t\t\t\tret = -EFAULT;\n+\t\t\telse\n \t\t\t\tret = bytes_written;\n \t\t}\n \t} else {\n@@ -328,7 +329,7 @@ static ssize_t papr_hvpipe_handle_read(struct file *file,\n \n \tstruct hvpipe_source_info *src_info = file->private_data;\n \tstruct papr_hvpipe_hdr hdr = {};\n-\tlong ret;\n+\tssize_t ret = 0;\n \n \t/*\n \t * Return -ENXIO during migration\n@@ -376,7 +377,7 @@ static ssize_t papr_hvpipe_handle_read(struct file *file,\n \n \tret = copy_to_user(buf, &hdr, HVPIPE_HDR_LEN);\n \tif (ret)\n-\t\treturn ret;\n+\t\treturn -EFAULT;\n \n \t/*\n \t * Message event has payload, so get the payload with\n@@ -385,19 +386,23 @@ static ssize_t papr_hvpipe_handle_read(struct file *file,\n \tif (hdr.flags & HVPIPE_MSG_AVAILABLE) {\n \t\tret = hvpipe_rtas_recv_msg(buf + HVPIPE_HDR_LEN,\n \t\t\t\tsize - HVPIPE_HDR_LEN);\n-\t\tif (ret > 0) {\n+\t\t/*\n+\t\t * Always clear MSG_AVAILABLE once the RTAS call has drained\n+\t\t * the message, regardless of whether copy_to_user succeeded.\n+\t\t */\n+\t\tif (ret >= 0 || ret == -EFAULT)\n \t\t\tsrc_info->hvpipe_status &= ~HVPIPE_MSG_AVAILABLE;\n-\t\t\tret += HVPIPE_HDR_LEN;\n-\t\t}\n \t} else if (hdr.flags & HVPIPE_LOST_CONNECTION) {\n \t\t/*\n \t\t * Hypervisor is closing the pipe for the specific\n \t\t * source. So notify user space.\n \t\t */\n \t\tsrc_info->hvpipe_status &= ~HVPIPE_LOST_CONNECTION;\n-\t\tret = HVPIPE_HDR_LEN;\n \t}\n \n+\tif (ret >= 0)\n+\t\tret += HVPIPE_HDR_LEN;\n+\n \treturn ret;\n }\n \n","prefixes":["v3","5/9"]}