From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 D1C593CFF79 for ; Wed, 25 Mar 2026 11:41:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774438885; cv=none; b=hBGy5kc7Q6OT2Q+hiMZpO6yq0vLtqD03tfVjB6KGwiNqFs8iGstQYWmC0TB6vFhxB9uI1UIZXDT8/8bpoSYTy5y+Ev84bSZH8ILnxYXuuTCBtmzdJqRVVp/c++0er6/I77i/zULfIMHYkV2jWUvJSEq7Z3pJRjArW/lkrxHEBFs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774438885; c=relaxed/simple; bh=MpcjsemM3LmMcoHooTMoaxadZdP5gIT5DsFtteobzUU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TJ+Dne7OeK8xYHEqKuFF3MlG8hlgjVUNH8AI9d4y9pUpdJotiUN/W6LPuev/6cJhIMGDoN0ZJQmwRTKJ0U97KK3y7G+HFuv540xkxaIBYxGocmXGflHDUksGp/J9XcCu6BGGKvge2HpmmwL2g7rNNRS31PFdeynlEnw8LrMtKvM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=X7CmJVFk; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="X7CmJVFk" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-485317b6bd0so56375e9.1 for ; Wed, 25 Mar 2026 04:41:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774438882; x=1775043682; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=cs9jWxbOU9zeEIpB1f4ZXLcUS7XMeoF1APCchnD0TKU=; b=X7CmJVFk7jix59Q2tI/sYaQdOAx6d6l5q3J32dgQJUbtRIC020+rVzvhlAHnF9x71M btFtOmyF/H3uSYeg8PkXNcdBWpDcHctbs4epuRAAWPHgavvMli4cBlcbctIwnvumgsXC SQwijycVnwxfu3kEXz6iVM1rkXCgo3b5N4I/rp3R+bwxrwOhfm2uWcllS92gLFL57lQF H/HNR/LpeYWHX0kuD0p8kY0E1l01JX/OOm7LU/Ljkst2RgLVv4Gq1dbDWrsue9vJfPEe Fpx2qmsTiS/yN49DEMPBP2iyYqMncu4RofmNod6kd+zDFJ5r7UpPUeC0euV6zHWrYUqO sXiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774438882; x=1775043682; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cs9jWxbOU9zeEIpB1f4ZXLcUS7XMeoF1APCchnD0TKU=; b=cPClbvhpq8Clq+wwVNF5efQea/B0Io31Zz+HqjbLiA18y8u5bnZwCW71gGUKYLT0Y5 emSxjSGupoziAq1s9BaYGaBFaZwcEexWC5M7mq5FznaoaUgrbbys0BywM1LYXFdjgw+a Ug1vipeSvz9uAooYnFpjtCOgMIKFwisIzEPx/8Hi6lg47bJcY2+Q16tMbPg+MGRcOh/4 nbs3uEqIeDTFK1oHLmuiOg7FKTt5W8kqTdswduiT5SvCvl2Ni53j62LiEjytiuemQ5/z w1uC/DYEOBaqM5E2eFaPjn36Zm2w2AsCz6zco7Pw+jYFyNCtVn2tg1e5/O0u8brgSzSZ Eh2g== X-Forwarded-Encrypted: i=1; AJvYcCVRovEi6Uo8bbwEHwlswFO4k50jq9k6sz09TMV/DP0YzEBYXuyakabI30JErRD42vXqk3se9Stst3OqdHM=@vger.kernel.org X-Gm-Message-State: AOJu0Yw/EIeBM1hbYC+COLW62+LqodfDja3LpNiqvULSpq+Oom3ULJXX MQEfLrybK0652GxcR2xOWu5FtN9Urd4pG1/51UCdXE5Xp3RXi+nQMXp329Q8PCzSQg== X-Gm-Gg: ATEYQzwJnB4lVpfIYbpihHVCQfDZ4/07hDGX95MKXLhB11Cnzi/bOqX7IRcDJhyt9fA R2HSi1j/aOFz5fN90QhtsQ/RpLnDV+tUwjUYdazfBkfcg7pN3TDVqZE+XOKUiYnhrd8e7w9BUsk w3qLVj7tdEHafNo7m7slXkcGsn7TmfbOgZvrC0qN+X3Lh82lIRsB46QLtG5B2AqymRVYyMyJu84 tbRnrY6uvBUeIRCWmqAQ+aQqcDdUPYA1cO5rWfM8L1pTKUR3cDI+aGvuEg41usb4D/xFAhItYzT WVj9i/Odvam0V+NpuBvBiWXjXBF5tRD63B3ursj6piwEX2t22UfQvbMkkYMrHzIOyqk2hHrYniQ jUAloeKFCVUzE8+O3FJcxLGSw2TK5t/SedjHJ93+iMRSLjiM5ArN3bIjWDhWL+uYHNo3+Z8ssW+ pygGjdYx3zjj+Oh+Xkfn6sSSFcL/zncLZNBbzWu9gxckuMzHmdJOg/RIrG2rrHmpNeOY0= X-Received: by 2002:a05:600c:17d6:b0:480:683f:743d with SMTP id 5b1f17b1804b1-48716828baamr534525e9.14.1774438881656; Wed, 25 Mar 2026 04:41:21 -0700 (PDT) Received: from google.com (209.13.205.35.bc.googleusercontent.com. [35.205.13.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43b644ae37dsm48451320f8f.2.2026.03.25.04.41.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2026 04:41:21 -0700 (PDT) Date: Wed, 25 Mar 2026 11:41:17 +0000 From: Sebastian Ene To: Vincent Donnefort Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, android-kvm@google.com, catalin.marinas@arm.com, joey.gouly@arm.com, mark.rutland@arm.com, maz@kernel.org, oupton@kernel.org, suzuki.poulose@arm.com, tabba@google.com, will@kernel.org, yuzenghui@huawei.com Subject: Re: [PATCH v2] KVM: arm64: Prevent the host from using an smc with imm16 != 0 Message-ID: References: <20260325113138.4171430-1-sebastianene@google.com> 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=us-ascii Content-Disposition: inline In-Reply-To: On Wed, Mar 25, 2026 at 11:35:18AM +0000, Vincent Donnefort wrote: > On Wed, Mar 25, 2026 at 11:31:38AM +0000, Sebastian Ene wrote: > > The ARM Service Calling Convention (SMCCC) specifies that the function > > identifier and parameters should be passed in registers, leaving the > > 16-bit immediate field of the SMC instruction un-handled. > > Currently, our pKVM handler ignores the immediate value, which could lead > > to non-compliant software relying on implementation-defined behavior. > > Enforce the host kernel running under pKVM to use an immediate value > > of 0 by decoding the ISS from the ESR_EL2 and return a not supported > > error code back to the caller. > > > > Signed-off-by: Sebastian Ene > > --- > > v1 -> v2: > > > > - Dropped injecting an UNDEF and return an error instead > > (SMCCC_RET_NOT_SUPPORTED) > > - Used the mask ESR_ELx_xVC_IMM_MASK instead of masking with U16_MAX > > - Updated the title of the commit message from: > > "[PATCH] KVM: arm64: Inject UNDEF when host is executing an > > smc with imm16 != 0 > > > --- > > arch/arm64/kvm/hyp/nvhe/hyp-main.c | 6 ++++++ > > 1 file changed, 6 insertions(+) > > > > diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c > > index e7790097db93..4ffe30fd8707 100644 > > --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c > > +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c > > @@ -762,6 +762,12 @@ void handle_trap(struct kvm_cpu_context *host_ctxt) > > handle_host_hcall(host_ctxt); > > break; > > case ESR_ELx_EC_SMC64: > > + if (ESR_ELx_xVC_IMM_MASK & esr) { > > + cpu_reg(host_ctxt, 0) = SMCCC_RET_NOT_SUPPORTED; > > + kvm_skip_host_instr(); > > + break; > > + } > > + > > I wonder if it isn't better to move that into handle_host_smc() as this is part > of how we handle the SMC after all? (and it calls that kvm_skip_host_instr() > already) > I was thinking of doing that as well but I prefer this since we don't have to look again at the esr in the callee. > > handle_host_smc(host_ctxt); > > break; > > case ESR_ELx_EC_IABT_LOW: > > -- > > 2.53.0.1018.g2bb0e51243-goog > >