From nobody Sun Apr 5 13:19:41 2026 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (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 BE2CA3FE374 for ; Tue, 24 Mar 2026 13:57:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774360654; cv=none; b=IkNdrwPlygukP06FDH8hgSK1dive8ELvysPBt4rL/Tcnz42rR0U7cBf6tvAXVT615GBo+amW5hxRnX3sVRUy/czHJqAsQA0lp9lwIWl5Yz+MG/BgZ+3m+EFRN4Fl2WN1syTWrOe80Skt0YBbi7Ag9TOKPkF10wWhICAIKuTZU3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774360654; c=relaxed/simple; bh=zGEeROof9gA0W9ZhmvfGBhkwy5T1SiUSisxKNgVng0M=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=e4w+FnW7KMyqykK9AcKEX6OPwbe0Mp08HP4jUAaHvD1tFkPmyCmdgQmK25Rqc2hvv8SRC/S30CQ/ApCxPtu7IgaZUBul+UOH1MpjDkYaSjlkAM4c1XHGWcEBEF6bkshPBM7pWkARoc236XYFwmnN4BKkz2kLAQzWN5bU+Vt2V/Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QLYyQqKa; arc=none smtp.client-ip=209.85.128.74 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=flex--sebastianene.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QLYyQqKa" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-486fcc05b20so24893015e9.3 for ; Tue, 24 Mar 2026 06:57:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774360651; x=1774965451; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=as56aPNtWm44s9wE7zPwXim0QPC6mmk0ed7R9T8xyHw=; b=QLYyQqKaHomCYklE43Lg0S/+Zg8xqPYNYpxMudFK3LjQ0z/VFR/mH7VGLFjrn3qoSh c+tphXLoT7O3BSP2ZnBo5ZXi8S7DkYxQTcUte7mAiOJOennJTAr0ZgE2wivGeHGf+5UL Sl39dYVel8Jppc8mqHLub18Q95IIspfEYQYACgWeC+TlvSbHbi+u96B57E57IIeuWupp aXTDsmGS8bPkflT7D2Ijjr3ctMc1Kstd/z2Of8bEa1M9gw+d8cYhTo1AB6Pm3GrMwgP5 r8rsoTRLE5yfsHzotJtYnWgjbgwdnAiEICMGCjrcafYgm/1SW+w5rjLTOckbs0BSdHXP ionQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774360651; x=1774965451; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=as56aPNtWm44s9wE7zPwXim0QPC6mmk0ed7R9T8xyHw=; b=HtMIvWGDyE5A7eF7f1+8qdym/WhMJXPYDlpohYkPAQUr2zND9KLiqSyVgUbogHrqVg 6sY4zidOz9IUV8nMSNYskCmmV9mYJTEUIOlfwfJ+jz4IfjrywtjiZQTIMbQCJjFFDfpA 9Ad5Ve1sc+47qez4zDhP7/vkhse1eUgNV5+I9kLwD5YcczgT9xiWayeQUGHK/gcH3tGz 8e91ouDJCHJ9SjgenC9PsHAUohn5nDHZeLY9IK0BI7HLy7TODDl0+28QCP4tFxxe7wp7 7B56Bgv0+rYgf2Jx66Zeo8F7tRtOW+BzEntHtipykp8vLjciyPHdmesMiOlxchuoU44l 25rA== X-Forwarded-Encrypted: i=1; AJvYcCVT0V63JWEOdWjho7zda8Mi1XBOXSWDpHRmokxOhVchzdxPsfcy30YvC/dQcekLPNVyOo12r3wwIqsNIeY=@vger.kernel.org X-Gm-Message-State: AOJu0YyIv/EqYUJY16nh1rdl1EeR3WYin/pX4tXsiJNE7JtEa/It4UOf ehsoVR0xZcutp/DnAwt1fP4YnEPT1UxZSAVCfu0yWB6lUpQJKIelDjmwJwNuUuT35cmAm81lQIA 8c3M3wc9q26VvfDRsPfyJS2DBN4GTaQ== X-Received: from wmbjx8.prod.google.com ([2002:a05:600c:5788:b0:485:3ddc:f26b]) (user=sebastianene job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:33a3:b0:486:ffa3:584 with SMTP id 5b1f17b1804b1-486ffa30b40mr104955515e9.15.1774360651034; Tue, 24 Mar 2026 06:57:31 -0700 (PDT) Date: Tue, 24 Mar 2026 13:57:28 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.53.0.983.g0bb29b3bc5-goog Message-ID: <20260324135728.3532400-1-sebastianene@google.com> Subject: [PATCH] KVM: arm64: Inject UNDEF when host is executing an smc with imm16 != 0 From: Sebastian Ene To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, android-kvm@google.com Cc: catalin.marinas@arm.com, joey.gouly@arm.com, mark.rutland@arm.com, maz@kernel.org, oupton@kernel.org, sebastianene@google.com, suzuki.poulose@arm.com, tabba@google.com, vdonnefort@google.com, will@kernel.org, yuzenghui@huawei.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 inject an undefined instruction exception back to the caller. Signed-off-by: Sebastian Ene --- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/h= yp-main.c index e7790097db93..ff6a90a4a4c7 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -756,13 +756,18 @@ static bool handle_host_mte(u64 esr) void handle_trap(struct kvm_cpu_context *host_ctxt) { u64 esr =3D read_sysreg_el2(SYS_ESR); + u16 imm16; =20 switch (ESR_ELx_EC(esr)) { case ESR_ELx_EC_HVC64: handle_host_hcall(host_ctxt); break; case ESR_ELx_EC_SMC64: - handle_host_smc(host_ctxt); + imm16 =3D esr & U16_MAX; + if (!imm16) + handle_host_smc(host_ctxt); + else + inject_undef64(); break; case ESR_ELx_EC_IABT_LOW: case ESR_ELx_EC_DABT_LOW: --=20 2.53.0.983.g0bb29b3bc5-goog