From nobody Thu Apr 2 02:54:12 2026 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 36F503BFE40 for ; Mon, 30 Mar 2026 10:54:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774868088; cv=none; b=tO0ayB03791Nx3O6IEU0pXx81LW0v+jTK1l9SSjei7elN1njpzWBjvnO8ZawyzeUUymTcGPrF+uaI7f0LCalINxpXNZrC+1K0t3oHqQx0M7Gos243R8fcwsWaXkt1Za3HamV4uH2Xg6ZlCUzgt78Oy/AZ1P60eelSY9L5iqNodY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774868088; c=relaxed/simple; bh=n8/FjOxzEWawetfjf8dTLKWl6TONEIaNu/yMlW5S67w=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=N7k4PCsi9npqZO56lf8mysTOh8z5nsk3e2W/wY2Co044pyex4qm150v7yg+5aRYRu7l2qPRCRx6pk1s7FBMKT7a0XC4p0IJlH9QLFqb2L0oxmA/DLLuEPIuN5OBT6Q+cBCL5i4t6skI3mDQB7ViSSY0JyF0BwK9PhWNzLWT4krY= 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=AL/Xg/MU; arc=none smtp.client-ip=209.85.128.73 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="AL/Xg/MU" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-48542d5aa9eso39288585e9.0 for ; Mon, 30 Mar 2026 03:54:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774868084; x=1775472884; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=OCpQaHn340hA9gXHDWXNQio0q+3ps0T5nKIr2QuIXig=; b=AL/Xg/MUgPWClHTk17TYtct1PTepuEceEOzFwG10AIJ0JLYMrAuldUWXrxibxGs1dW 6y6VIMI8VLmjjHwhhIaHkP4EkQn3Wfv4BY922CJSnfZu8wLCVPX59YgI+tbiXO1F5obx nuNRs3Y5D7m6MD5xHbNwm0DsgpIj0jJMbw9m3qENf+m0xbcbmzcoUaF1raqqBgkAWr1S c03DNc83ymYozrP4zrm8qOraVHvXJm2KanaJrWjyYODPyUmxm5/ngoGrMpc061fNPO3H iofMY/yRoZPS/eVoHVrqAD/jScTEwH/B0Ok2DhvHSNLMhflC/VayJi4j5RzTFABzjeaW 64Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774868084; x=1775472884; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=OCpQaHn340hA9gXHDWXNQio0q+3ps0T5nKIr2QuIXig=; b=YpNsGxUq/ooK1rafQlUOWl3MDhOyD5I+eALR/yo4pwq2BD5Ayy0eWzyLKQpK4tgclc Ss/d/OV4ZeckVlF51vWj26CLas0Yqj2HT6uAn9OIm7H4/78ukojvkOserSdvo20v6NYD y1Bjz2r/IuvRq0beqHvutEL1zhw3b7fX8bCB6Zb2PhgqRS+eIuWa0U+oEfr9iquSKfnJ ZXYAdQaZkFmMIpbyiOdCdBBt10HrXXkZRAJ15PNE/CwQMh4i3E6Q6OjevNn5p/YHWcn/ 8rdm1HprwKzDbq4LvUTVRGNXOdhRtYE+p9GerLS1chDHYs77ScSPL3fCD4NRNW5mPuMr f2sQ== X-Forwarded-Encrypted: i=1; AJvYcCVaxlcJVlgtqcHMTIFtl6D4YnI5YiLcAPvuVGUS6Gt7shcOHv/cQv673q6GSpbQp0ta+GWv1KTWCcENlOY=@vger.kernel.org X-Gm-Message-State: AOJu0YyxA8e3ZMRtekMSZPl8f+yxEf7Ob+M9QSwt1wN3YhLqw7G4+oqB LC7dkGF5SlL4jYeNE9S81MYQgjAldFwokQHg+lh3LI7ueaHmt2HO9Dos7a1IkPX/iiIyxxQBGsv V+BkAjQNnr79pZdjG487BL1YkrHwDMQ== X-Received: from wmro3.prod.google.com ([2002:a05:600c:3783:b0:483:41b6:adeb]) (user=sebastianene job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:5290:b0:486:fcdf:c065 with SMTP id 5b1f17b1804b1-4872808d317mr201624445e9.27.1774868084528; Mon, 30 Mar 2026 03:54:44 -0700 (PDT) Date: Mon, 30 Mar 2026 10:54:41 +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.1018.g2bb0e51243-goog Message-ID: <20260330105441.3226904-1-sebastianene@google.com> Subject: [PATCH v3] KVM: arm64: Prevent the host from using 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 un-handled in pKVM when an SMC instruction is trapped. Since the HVC is a private interface between EL2 and the host, enforce the host kernel running under pKVM to use an immediate value of 0 only when using SMCs to make it clear for non-compliant software talking to Trustzone that we only use SMCCC. Signed-off-by: Sebastian Ene Reviewed-by: Vincent Donnefort --- v2 -> current: - move the ESR decoding of the imm16 in the handle_host_smc where it was supposed to be - updated the commit message to include the reason behind while we are not doing for HVCs as well - updated the commit message to clarify that pKVM is not handling the imm16 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 !=3D 0" Link to v2: https://lore.kernel.org/all/20260325113138.4171430-1-sebastianene@google.co= m/ Link to v1: https://lore.kernel.org/all/20260324135728.3532400-1-sebastianene@google.co= m/ --- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/h= yp-main.c index e7790097db93..461cf5cb5ac7 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -676,8 +676,14 @@ static void default_host_smc_handler(struct kvm_cpu_co= ntext *host_ctxt) static void handle_host_smc(struct kvm_cpu_context *host_ctxt) { DECLARE_REG(u64, func_id, host_ctxt, 0); + u64 esr =3D read_sysreg_el2(SYS_ESR); bool handled; =20 + if (esr & ESR_ELx_xVC_IMM_MASK) { + cpu_reg(host_ctxt, 0) =3D SMCCC_RET_NOT_SUPPORTED; + goto exit_skip_instr; + } + func_id &=3D ~ARM_SMCCC_CALL_HINTS; =20 handled =3D kvm_host_psci_handler(host_ctxt, func_id); @@ -686,6 +692,7 @@ static void handle_host_smc(struct kvm_cpu_context *hos= t_ctxt) if (!handled) default_host_smc_handler(host_ctxt); =20 +exit_skip_instr: /* SMC was trapped, move ELR past the current PC. */ kvm_skip_host_instr(); } --=20 2.53.0.1018.g2bb0e51243-goog