From nobody Tue Nov 26 04:38:56 2024 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (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 A01606EB7C for ; Tue, 22 Oct 2024 04:17:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729570645; cv=none; b=k+YESgCPfQtVx/UaoZu44w0AvwSHCRH5rCMtY5dcHU/Syr3D/2wjByXh6j92pLAyQXcetwaLO2AyGKTPjHGlsZZ9LyydfeBm7pVphrUQFSV6t0qcN2bWpZF/13FYk+Z9a6ZGg5sZCAGfuxuqnMXgscvvqjitLBnCax+TnRpyMtk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729570645; c=relaxed/simple; bh=nCR6eSYZoIUnv62h9XkzPEQUfmyePMrQlbxXjeqjc1U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=j8lo3+UgV5Fe6DRBT2a/gt6ErIrIouOXPHLqlC3XEU+bHdrf4xxnAx6JXVrVl+r/xeh38OUKUR1t7aaPkak4/A8LiOAs+DZ4mEIgQswzzomOlMKtt9xBufdQrrY69Pc4ajSNuBfpLXpBXio1UYilYNnOQIbFS1Gx3fnFSqaWFFg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=fail smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=YpvWk+O7; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="YpvWk+O7" Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49LKJmiM004661 for ; Tue, 22 Oct 2024 04:17:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= Tdkej9tfa36Vd2vuixq/tj81ncNxKtylXtt57HOCl3M=; b=YpvWk+O7c8Gmnzvb OuFu9gMIkke0iNVuQobeTjirpgo9VrUh8HSFnSdwARKB2phpyrwwMsOxL+MthfpD ixXh7b3FVm+LqdsOh0HCHh7ATpYphELYyIwQgeW2tSey89lEQluJUoTopYoV2AfN 9Il9xBzO1cYhuaaPOW+80zvpJyrEpB8ukenf5DSntKYAjeGUEUltE3jFIw8ny5ij OFe4vcETLSfqIOgGrASloqhJXxb8qH5CcKPaALktzdKBpdMajweWnDZ9As3RjzFf JukZu2XZZcDWOSBunZXiMO3lpl+p0gjMCCySVOIkNw4nSoY2G06gIC3w8lZ73JU5 yL2VPA== Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42c6vxxuph-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 22 Oct 2024 04:17:16 +0000 (GMT) Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-71e6e4a51feso4226695b3a.0 for ; Mon, 21 Oct 2024 21:17:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729570636; x=1730175436; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Tdkej9tfa36Vd2vuixq/tj81ncNxKtylXtt57HOCl3M=; b=OV/TRco0d/lb2T/2FaDLMMhDWNboJkrnJJ1Ron7Ztsv99ki44ZQ1PcrzAz5H6wprtg lfY3NpPDX1WMEUVU1C9XHrmLojoyJfNL4eLzvizTwESjuLG5zesMqqcvLLjKLr74OoVF w4oJvjeE8Zhu1r1nFsVx9b4R2N/sgTj1DdUn43AUYo+bNVhwedLhOaK8CTikLGfQ2nKA nxutI9PqunPAstC8cx/f2Afv0BvkX/edHsEcFfkezdEOBCWuht8yYZW9BWYV0ZTYUtwa KcJKpA5ehmMwlVzCRTH9brz0TXl9BTb1T/lMasQnSPEu0inJWIGhgyH4NiyD+ygy3y6w T7hg== X-Forwarded-Encrypted: i=1; AJvYcCUhrM0+8DM3n4/2WZZBOFDhdQj3XWQyw9PXdDgYR2/chnigk51egHKAs0tUBDatRKs68hNdaLNswO0EOKo=@vger.kernel.org X-Gm-Message-State: AOJu0YzCzawvrP6TePY4KXA9W560PkcilU3uNXDyPukYFq21aXCorBP3 rcS06yVmhr0Y43WevK1Hnhdvq2J5nTdZO96cHWCaehpnfYnOwdM0bfJqHJNBOey4mKQkJYG5+5H vgHxIj+hPfWafWnRzx+6CuogT1SYDWr8bo848C4Y7NmDKxPWRossQBgSHoym93yU= X-Received: by 2002:a05:6a21:1349:b0:1d0:603b:bf76 with SMTP id adf61e73a8af0-1d92c5729abmr18339063637.34.1729570635902; Mon, 21 Oct 2024 21:17:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEEUEFea4BiFa1YOh3N6h1+Jyb4uSBn6P00YWWH1fIJkQubb38xnsMRypqA3DS4/7pfBsxRWQ== X-Received: by 2002:a05:6a21:1349:b0:1d0:603b:bf76 with SMTP id adf61e73a8af0-1d92c5729abmr18339049637.34.1729570635588; Mon, 21 Oct 2024 21:17:15 -0700 (PDT) Received: from ip-172-31-25-79.us-west-2.compute.internal (ec2-35-81-238-112.us-west-2.compute.amazonaws.com. [35.81.238.112]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e5ad25cb6dsm4836169a91.1.2024.10.21.21.17.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 21:17:15 -0700 (PDT) From: Bjorn Andersson Date: Tue, 22 Oct 2024 04:17:11 +0000 Subject: [PATCH 1/2] rpmsg: glink: Handle rejected intent request better Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241022-pmic-glink-ecancelled-v1-1-9e26fc74e0a3@oss.qualcomm.com> References: <20241022-pmic-glink-ecancelled-v1-0-9e26fc74e0a3@oss.qualcomm.com> In-Reply-To: <20241022-pmic-glink-ecancelled-v1-0-9e26fc74e0a3@oss.qualcomm.com> To: Bjorn Andersson , Mathieu Poirier , Chris Lew , Konrad Dybcio , Johan Hovold Cc: linux-arm-msm@vger.kernel.org, Bjorn Andersson , linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Bjorn Andersson , stable@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1729570634; l=3793; i=bjorn.andersson@oss.qualcomm.com; s=20241022; h=from:subject:message-id; bh=nCR6eSYZoIUnv62h9XkzPEQUfmyePMrQlbxXjeqjc1U=; b=EPYZ4TiHJdE/TrDEG2vMI1DOhNjQ5BNVJOpuX69S5TUCN4Dvb4fmplayc7hJYKKfMTdA+cvj/ oMGKfmJs4EvCV7ZVI41y7/PuLFBFyxGAVPSqUlGJDwcihW/Unldci5/ X-Developer-Key: i=bjorn.andersson@oss.qualcomm.com; a=ed25519; pk=SAhIzN2NcG7kdNPq3QMED+Agjgc2IyfGAldevLwbJnU= X-Proofpoint-ORIG-GUID: 4PbpNCympU-yGBtU5-rlF4BcI2jvxmvY X-Proofpoint-GUID: 4PbpNCympU-yGBtU5-rlF4BcI2jvxmvY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 clxscore=1015 malwarescore=0 mlxlogscore=999 bulkscore=0 impostorscore=0 lowpriorityscore=0 adultscore=0 phishscore=0 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410220026 The initial implementation of request intent response handling dealt with two outcomes; granted allocations, and all other cases being considered -ECANCELLED (likely from "cancelling the operation as the remote is going down"). But on some channels intent allocation is not supported, instead the remote will pre-allocate and announce a fixed number of intents for the sender to use. If for such channels an rpmsg_send() is being invoked before any channels have been announced, an intent request will be issued and as this comes back rejected the call is failed with -ECANCELLED. Given that this is reported in the same way as the remote being shut down, there's no way for the client to differentiate the two cases. In line with the original GLINK design, change the return value to -EAGAIN for the case where the remote rejects an intent allocation request. It's tempting to handle this case in the GLINK core, as we expect intents to show up in this case. But there's no way to distinguish between this case and a rejection for a too big allocation, nor is it possible to predict if a currently used (and seeminly suitable) intent will be returned for reuse or not. As such, returning the error to the client and allow it to react seems to be the only sensible solution. In addition to this, commit 'c05dfce0b89e ("rpmsg: glink: Wait for intent, not just request ack")' changed the logic such that the code always wait for an intent request response and an intent. This works out in most cases, but in the event that a intent request is rejected and no further intent arrives (e.g. client asks for a too big intent), the code will stall for 10 seconds and then return -ETIMEDOUT; instead of a more suitable error. This change also resulted in intent requests racing with the shutdown of the remote would be exposed to this same problem, unless some intent happens to arrive. A patch for this was developed and posted by Sarannya S [1], and has been incorporated here. To summarize, the intent request can end in 4 ways: - Timeout, no response arrived =3D> return -ETIMEDOUT - Abort TX, the edge is going away =3D> return -ECANCELLED - Intent request was rejected =3D> return -EAGAIN - Intent request was accepted, and an intent arrived =3D> return 0 This patch was developed with input from Sarannya S, Deepak Kumar Singh, and Chris Lew. [1] https://lore.kernel.org/all/20240925072328.1163183-1-quic_deesin@quicin= c.com/ Fixes: c05dfce0b89e ("rpmsg: glink: Wait for intent, not just request ack") Cc: stable@vger.kernel.org Signed-off-by: Bjorn Andersson Tested-by: Johan Hovold --- drivers/rpmsg/qcom_glink_native.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_n= ative.c index 0b2f290069080638581a13b3a580054d31e176c2..d3af1dfa3c7d71b95dda911dfc7= ad844679359d6 100644 --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -1440,14 +1440,18 @@ static int qcom_glink_request_intent(struct qcom_gl= ink *glink, goto unlock; =20 ret =3D wait_event_timeout(channel->intent_req_wq, - READ_ONCE(channel->intent_req_result) >=3D 0 && - READ_ONCE(channel->intent_received), + READ_ONCE(channel->intent_req_result) =3D=3D 0 || + (READ_ONCE(channel->intent_req_result) > 0 && + READ_ONCE(channel->intent_received)) || + glink->abort_tx, 10 * HZ); if (!ret) { dev_err(glink->dev, "intent request timed out\n"); ret =3D -ETIMEDOUT; + } else if (glink->abort_tx) { + ret =3D -ECANCELED; } else { - ret =3D READ_ONCE(channel->intent_req_result) ? 0 : -ECANCELED; + ret =3D READ_ONCE(channel->intent_req_result) ? 0 : -EAGAIN; } =20 unlock: --=20 2.43.0