From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC8763BB9FA for ; Wed, 8 Apr 2026 12:02:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775649732; cv=none; b=OWHwNAv3obe9SIaTOrbC5yffhkhfgUEvqDRHHarXPrKZ2J3y/ZsdCTz/uSYfH+VI1lc5aYr61/i6qHuY5uvVZJNwQta7FhAIsdpCEoUCmvX/oXWnhQ6Fqz3jTGFB8+TAYMl6xhnA7383FoPGMbB6rY/x8HQ/O/Y5pHeelV0vGn8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775649732; c=relaxed/simple; bh=j+Bctf1u2e7YmJBQKZJcXUbKRyq1OMk/hFfMjUn2rLY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=INzw1NTbcDSVl/9BNcmrDQy9L0VVsWCrrevTNWDALfYHrT5Kys2YwS4fmj4N+ZeUt7rWGeNZ6aRj0SLzp7M/1lyXtB0N2OWTFdweDlpDAPqvNxBFHDaaMXisGIpdFF9utznvevnrH6HfHyc80yWiuIeuSt2MR/lSvZjp3lp8U98= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Q70v6FMK; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Q70v6FMK" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-82cd5c07f93so2694052b3a.1 for ; Wed, 08 Apr 2026 05:02:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775649730; x=1776254530; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mu3P1VfNo0DCayRCdHHojPZFKAzDzWNLwEKMHMNVDaE=; b=Q70v6FMKT+oz0zrf2xE8Xk0yqp6uZF412BQmlwq8Vc0APsnXxBoHR2Z5FfKYTaiJsJ xhANDjNc8rcgimZAP4KhKsjenetwWNt7o6zMFXuoghV6MRPERBJ8OLN+RQHrwT8utwTT m4dvNeN4eO4I8ewoHQYrTwCUQFS+p+rhVpZ8BOGuBwka/ntKHEEAR07k7oQBkUBDOo/G UOyUfoVbS5e5UpocCkaAd67N3z9wFvuhVPMZ62Hw0WuXLAGbu8y5UgEMmQsyewvofizk 3wtBnmWVzwsAPTnu/KLmTxhJVISMa8ohhwRRzAjgu8LWElAMG86xNKGeXtxII33tHEAO //bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775649730; x=1776254530; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=mu3P1VfNo0DCayRCdHHojPZFKAzDzWNLwEKMHMNVDaE=; b=dpL3ZEVw2IMBoSH4ZbJAnTxcZ3BgaRbadUFHSjStHpFLWrdfUCHjJ2KMvbK+wBJJUo iq3NqWsDknS6SKGlFJZezDVg/JrlY2mzJLDIr+lAUBdKiH37vsrSDuWgkCWyXAXiapQa kvSIEB0KR+pDDV4YCpuhUr+IzTjIvn83S3gOps1rdouRN3riGxMLSby3QJcbTB+8GHia C3WME22BFKRR0ZaARlj8sJ6PKGU8sAlhNLTNdiSCBiELO2fJxqn2IIlZcwUD5L7LI/9p iMNUcwEN+icdNVxElAVUXlCEvr9zSMQ3Ns6xvSYI3A+zaVmz6HNWDuOkywmIVOUd329q GIXw== X-Forwarded-Encrypted: i=1; AJvYcCW7ybr4Cg7lLLTkVNtScHIpTaDIQkHWuprFfcGxP9zrOtB6EBEdYt+G4q7f/d+USfQplKv7/bk1r4hhSvM=@vger.kernel.org X-Gm-Message-State: AOJu0YwYzx/WXa2GUIpHVIzbLdHFaJjqBmTZenHW+dedWIh9e2286/6U Z6pvK9ztpXLOdqH8VILmZN5OYhWHnYzg7g5VEZ1DEM16dRiTh26NTZqJ X-Gm-Gg: AeBDievb9fGqP2FAh8dvcBPcc0BGpTO1s61LTJZHo5mXHpinv6RikMLGzHa36hjntQ/ pqj1EDzv79TdubTlGVNfJAGWoaffk8UqcCW2t0ZfhhbwtSFg203HfnvjJZ03tNRvu2WgwFvukjr TZAkhxGo1sJFyz7EQPSaWhpAHeEXNLokyp48R5zQhH5x8odaHuAN6V8LgwcTZTdv+EgBYpgIbqH pioK2SJO2dpg/lYf1iiblTUEAwfxPBOVrBrDScC82CApwk+xX6qNrgRZlOVn2dn94YsDF6WZU6s s4Yik5Z+pOEddNaSCqwFvQyRNFtcmLmN/Nk2S6ng7WRTYSlZzp/rzdoAyIzAPtIvfrUViJKf0kV Q1b+x/P6VEZ6Ad3TbL09/yMkVMw8iDaSzhWqK5/JWZW7arS+YRWFoTPpg0jaP/UudCI33wybxS6 PB6g== X-Received: by 2002:a05:6a00:2e93:b0:827:4343:4c1 with SMTP id d2e1a72fcca58-82d0db32d62mr19867111b3a.29.1775649730179; Wed, 08 Apr 2026 05:02:10 -0700 (PDT) Received: from Mac.localdomain ([49.205.216.49]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82cf9b3e169sm21209322b3a.18.2026.04.08.05.02.06 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 08 Apr 2026 05:02:09 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linuxppc-dev@lists.ozlabs.org, Haren Myneni Cc: Madhavan Srinivasan , Christophe Leroy , Venkat Rao Bagalkote , Nicholas Piggin , linux-kernel@vger.kernel.org, "Ritesh Harjani (IBM)" Subject: [RFC v2 04/10] pseries/papr-hvpipe: Fix the usage of copy_to_user() Date: Wed, 8 Apr 2026 17:31:34 +0530 Message-ID: X-Mailer: git-send-email 2.50.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit copy_to_user() return bytes_not_copied to the user buffer. If there was an error writing bytes into the user buffer, i.e. if copy_to_user returns a non-zero value, then we simply return -EFAULT from the ->read() call. Also let's make sure we clear the hvpipe_status flag, if we have consumed the hvpipe msg by making the rtas call. ret = -EFAULT means copy_to_user has failed but that still means that the msg was read from the hvpipe, hence for both cases, success & -EFAULT, we should clear the HVPIPE_MSG_AVAILABLE flag in hvpipe_status. Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/platforms/pseries/papr-hvpipe.c | 23 ++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/platforms/pseries/papr-hvpipe.c b/arch/powerpc/platforms/pseries/papr-hvpipe.c index 402781299497..5c773a6f0efc 100644 --- a/arch/powerpc/platforms/pseries/papr-hvpipe.c +++ b/arch/powerpc/platforms/pseries/papr-hvpipe.c @@ -206,10 +206,11 @@ static int hvpipe_rtas_recv_msg(char __user *buf, int size) bytes_written, size); bytes_written = size; } - ret = copy_to_user(buf, + if (copy_to_user(buf, rtas_work_area_raw_buf(work_area), - bytes_written); - if (!ret) + bytes_written)) + ret = -EFAULT; + else ret = bytes_written; } } else { @@ -328,7 +329,7 @@ static ssize_t papr_hvpipe_handle_read(struct file *file, struct hvpipe_source_info *src_info = file->private_data; struct papr_hvpipe_hdr hdr = {}; - long ret; + ssize_t ret = 0; /* * Return -ENXIO during migration @@ -376,7 +377,7 @@ static ssize_t papr_hvpipe_handle_read(struct file *file, ret = copy_to_user(buf, &hdr, HVPIPE_HDR_LEN); if (ret) - return ret; + return -EFAULT; /* * Message event has payload, so get the payload with @@ -385,19 +386,23 @@ static ssize_t papr_hvpipe_handle_read(struct file *file, if (hdr.flags & HVPIPE_MSG_AVAILABLE) { ret = hvpipe_rtas_recv_msg(buf + HVPIPE_HDR_LEN, size - HVPIPE_HDR_LEN); - if (ret > 0) { + /* + * Always clear MSG_AVAILABLE once the RTAS call has drained + * the message, regardless of whether copy_to_user succeeded. + */ + if (ret > 0 || ret == -EFAULT) src_info->hvpipe_status &= ~HVPIPE_MSG_AVAILABLE; - ret += HVPIPE_HDR_LEN; - } } else if (hdr.flags & HVPIPE_LOST_CONNECTION) { /* * Hypervisor is closing the pipe for the specific * source. So notify user space. */ src_info->hvpipe_status &= ~HVPIPE_LOST_CONNECTION; - ret = HVPIPE_HDR_LEN; } + if (ret >= 0) + ret += HVPIPE_HDR_LEN; + return ret; } -- 2.39.5