From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 EF86436896D for ; Tue, 31 Mar 2026 02:41:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774924874; cv=none; b=FJMtDcbmtbpKanvDz+4OfRp1BtnpGOh4lBXwtg3+ZLaIGk5ew4Y7E+lLR0ZJWQW4wHBo5IhGRN0HhZEh9KyDuGG8GETzSUhtfJtRVbYpNsJwqPA6gg3pRHDWe9vLllGCF84lZ9236TgYRx63UjHapOqMXSplgeyzlproPgP8qxE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774924874; c=relaxed/simple; bh=ObRxpbE/eUS3h8F3m+U6Yj6wv+FCD3d3U1SDjVIZ6jw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=E7yv4RmT1JZakLFaWTW6U5gbxbphLyVC/l1z3maYmE1dUWaUJ28yUa5/G1NjXMy2tu/F3bjrR967JaMw+90CEROuB36qM963ZjihszUF/ZGdi0mFmD92YAgy5izNaJ/BmmZhfEEOC0UxQ/SVloB7xrI6Toh1ubE4Tyiuug2/Wu0= 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=YftIQWB3; arc=none smtp.client-ip=209.85.128.52 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="YftIQWB3" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-486fd5360d4so68225825e9.1 for ; Mon, 30 Mar 2026 19:41:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774924871; x=1775529671; 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=LXnJaJoemcaiDGH1WZmG/hzLsuogYk0N7x2l4+nhrvM=; b=YftIQWB3vkwu/Kpw2H0nj8OdmaGGatoLLqGU+L/sEfME0JAVAEaxDWxTFXe9YVD5az 4J+NHjVRCKunGHu83qVSOdoePsE/lWXtcNVfD1FN/t5wWJ/9FtOOknc3J7kkauzL01JW P9kcfZGK+RcIHbbvz3tuzz7Kq3a+/++9xCcJ0q1mTttTc1soKuGfZ4D1aVjP5Ec9N2vN uLDXJh2BIKHWXgx8/ToKOg0+j+x4RiHh/YZF5M2ygOFeTCTO0ZYUDSJ3AV7s+17Qrf/C H8a5X7pT6V0OXp18Cm3VnQbw29AgQ1z8kgLXZdmeaUNOYgZ2WtC4l0nxoIqqEMpjD3qC 9aZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774924871; x=1775529671; 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=LXnJaJoemcaiDGH1WZmG/hzLsuogYk0N7x2l4+nhrvM=; b=YfKNuPERhdB5hgBwblZ7D+wGaJjq/L9gzT/8PHCzdNarqDH14Cmk+hec8MuFCH6xnC wUtJcDqPOiY2CHeHdS8dqSpbt1jYJLExfXqaA4Uj5OFaOm93wnQE9M6FqkJt+1KRW0h5 dibd0S2FUVMRbD36xI5B4Cdh2p1y8VxkbXx6n9XGkWdv0lPHh2xZ/yyTLoVdKptbYXER vuO5eCju6AchzLxvKo07lfF7UpwMsFwRfEQDK2TAMBKsgJdOUZToYBfMypPXdgdadk7+ 4FLUfkIUuSJf1fgpg6+gqzbK/lDpVY2wPKlkefBrnCKZezOY7aSjpiNTaD7qgo0H3KVG 4brQ== X-Forwarded-Encrypted: i=1; AJvYcCVZROiTmN0XHOF2UfpoqaozYXjecuZtIsC/uZX1UbLsVBdOwKSH/1NRB3Tq9bs8f81Slt25IUmFk326tx0=@vger.kernel.org X-Gm-Message-State: AOJu0YypL9l6Y+lMdPj+Vl7PG7R4WVp0ZeB5zVhMxBa8jv/wVGBOg815 /RruOcX3K5khPe3Qn9vTtK9W/ijK8NhopRpSMYs5lLmmrUx89yR3zir56+T5yRwnBemn7GnNOlm FQUbobzJ2 X-Gm-Gg: ATEYQzxKbBUTENhY0eatTVcLDc7GUdCop5VkS1edj7TqbxGnR8zW8mbcM3zq0YgmJwP 8ZvNHF7G8COglWJn4OQo0NMMkEoAivrfhIYQ5wAxs2JtnGPSAev7TbqBD7N8YXS6hGcjhHARB9o IKfCrxhqfkbHHEs4GCuSKkSiZk3zVxHZ/QdIYv+kCRFnksK7bm9NywymAOyG2EkFdX0aNnTYeGN 8ufBcgD+8+H/xgeKciu1RXGcHsc7+j4016T6xg2YbbueSdopQXkDehofTSUpNakbs3bSkOKuDw+ k0ZV0GFGZHvAyw9z6juC4ZY19BxK3CV8P+5FI53H/rmmx7TRHikcYIWaUZ6dV0wmk8zkCQH6BQn YsnbceeIZOYetEik/f5ZRHTBUZ48oJNtSzXziELpN6rnABG36pBl7SzXCQHq/Gu1dYRPS09JsjI yYX3m9hc9Tv6dnwxJSyxYRSMpZZ96yv1e+jCh2Q804jYAX2cwK43lk+yrB4wiRXDWGtp0= X-Received: by 2002:a05:600c:c090:b0:487:338:b4df with SMTP id 5b1f17b1804b1-4873de6ca3dmr61799345e9.15.1774924871032; Mon, 30 Mar 2026 19:41:11 -0700 (PDT) Received: from google.com (198.115.140.34.bc.googleusercontent.com. [34.140.115.198]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4873062ec9bsm219312745e9.7.2026.03.30.19.41.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Mar 2026 19:41:09 -0700 (PDT) Date: Tue, 31 Mar 2026 03:41:05 +0100 From: Vincent Donnefort To: Sebastian Ene 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 v3] KVM: arm64: Prevent the host from using an smc with imm16 != 0 Message-ID: References: <20260330105441.3226904-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: <20260330105441.3226904-1-sebastianene@google.com> On Mon, Mar 30, 2026 at 10:54:41AM +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 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 != 0" > > Link to v2: > https://lore.kernel.org/all/20260325113138.4171430-1-sebastianene@google.com/ > Link to v1: > https://lore.kernel.org/all/20260324135728.3532400-1-sebastianene@google.com/ > > --- > 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/hyp-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_context *host_ctxt) > static void handle_host_smc(struct kvm_cpu_context *host_ctxt) > { > DECLARE_REG(u64, func_id, host_ctxt, 0); > + u64 esr = read_sysreg_el2(SYS_ESR); > bool handled; > > + if (esr & ESR_ELx_xVC_IMM_MASK) { > + cpu_reg(host_ctxt, 0) = SMCCC_RET_NOT_SUPPORTED; > + goto exit_skip_instr; > + } > + > func_id &= ~ARM_SMCCC_CALL_HINTS; > > handled = kvm_host_psci_handler(host_ctxt, func_id); > @@ -686,6 +692,7 @@ static void handle_host_smc(struct kvm_cpu_context *host_ctxt) > if (!handled) > default_host_smc_handler(host_ctxt); > > +exit_skip_instr: > /* SMC was trapped, move ELR past the current PC. */ > kvm_skip_host_instr(); > } > -- > 2.53.0.1018.g2bb0e51243-goog >