From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 258923CEB8B for ; Wed, 25 Mar 2026 11:35:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774438525; cv=none; b=grM6vvBDf1J3jeSfHaoUbK3Xi3vgb2sL03GpRxMILW3H+8l9gAJn40xOZUqIyot5VYPkHyBcWvhkHluu1vXr0aF5ncHALhY5Uwrc9wi28usGADK8OQZHUgEd6ebowrR3lB73+SHozJuUkgh5B3H4XtZ9dlndjgojtJP/NfrSGp8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774438525; c=relaxed/simple; bh=qMzt9FUj03HMUvDVnnr74rtwo0PMBSzEfu90mfD0QzQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=o250fumUh3z7FkjcIYkLS2kaxqC4PHCwlFS9s5jFLfBAhLPeAmCIe/ii+siZnAWzSajeFU3JyH5yXXzpKlsibGQmetDfEllJszU1bDWZI+QrEHOaIfGaoU8s1yU+d9uaEwh6rkXAYaCdYo34HfcdLxGKSR/he506PZWn+gc2fKo= 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=TlxacvF6; arc=none smtp.client-ip=209.85.221.46 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="TlxacvF6" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-43b40fb7f95so2242859f8f.3 for ; Wed, 25 Mar 2026 04:35:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774438522; x=1775043322; 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=zkE1roP0rQTN4agoxojZxa0tqCSQLd/1PEJ1rtsPXGA=; b=TlxacvF6+QJORY2L9XDvV2EIMqvNplXkQDQKbVdbGtTVmoh/bAwAYllmUoOvSmoqXt yLw+PXAESYlZAECogCU+D7s/X4RrZxfu8CzReezQ77rvX1rzJC17dWUvijSZ0gyDUHjy TZwZ8OjlO0t49oz6NJW1y67YNpEmu/D+RrahvGC2ip70Gg394nXHnT11rWMYy5D0KJbm jvRtp6XNv3b4cUrSkWvAW+hBKgbzFEkWc7waFwBYQED7sD/qPW0e7eez/V3NyZ+ZIQUx 77lfrl9Mui8vVHpXYaEan4QFhBFkKTm9bz3l2lmLNQenymemJwoQI7iX7rBJo+Y7Wxlf cKdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774438522; x=1775043322; 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=zkE1roP0rQTN4agoxojZxa0tqCSQLd/1PEJ1rtsPXGA=; b=RwIzggLYvf/mnXWjDZxFUQU6qTeJfLeLLyPLfSB3EZYB9Kp5zV89Z4D9Q3F1+N+esN PvLBetyMmnvvXqXhV3NvJQdP0r4kq5YfoCUD6Wmck2LM/Pm9AyP8jVhowpQrCawZPVlD OOTjVsPbYqR5ai55Mr5Spt+r3CsG6opMzZA2lY72dyJDj1iooFM+K2H91IL/1ZujqmrN hCCAzfQweyzQAKZzBujmjLofJMTwjF5ceqxYJZ7FmLPPJIj26CfItt2rh8vSLkaOT7AZ Ulf3rM3GxOgdqY/iJcLyVm/ptzahN0/SAhckKD48Hr1W/dSBX1yt1NByruEL8d4qDDfm es1A== X-Forwarded-Encrypted: i=1; AJvYcCXI67bM8nHOnbDzDIFd38k6uEersX+RFOIQ0c/E2gh0J48tm9XFYMpi8qnCesOHuvRJQiA+OW0cbu8vXGI=@vger.kernel.org X-Gm-Message-State: AOJu0YwkSAlUExUKd85/nfZc9FqELKmb4i5hC06eA1h9i4uwF9VChrQ5 zUanJRbOuxAdyF1hXF9WCoALjjzAx82wny3LlntYUwb0UjglN6BbEo6+ml1lYxH4iROIhCwt/0M kbtp1qQ== X-Gm-Gg: ATEYQzxvazugj1Sb6cxYfRVzpWkX3PAl6P9mNJYxUu8iU9ZhTDwYXaTULnzB73f8ALp wd8DA/ci0/1dlTSIWvQUzaR2NqZ82pzhypwE4EUa9Uygj5J3NeAvX6Sm+f9LZZmnMMr4j+WD3Pt N+gNpfpA4+DHSOZXr5KNyDvmDRUwJ3+uT1MR83YB7haXhqRW1gryzgJGxWAvlO+dCAUpa71Kmh4 fY8do0S2o/K+hQh1T9VRqZgDraTpIb8wHgC1WGImu/bRh+AJV0TPpuRNtFwsW1QZoMXJ620X1n7 CfTsvU5MCksYkYumpgGGYezDVj96AaxcWP7ptyz+mf6l+sGgOSAn1aGRXtHVVJlORaUl4sVTX/z n30Rk+YfAOeC6SWSjJ8HF8+vTikpMXTJMhtGmDPok/QPACNAVLjWxZ6NWoa5Ef5ES7p+vRfngx+ HlhchRM8pl0yrENxpd1rbDmIEfk8TXACvnWeVo/ZW7ODU7SU+XIaoWBmGxXGf8f+nFfi8= X-Received: by 2002:a5d:6806:0:b0:439:c157:2577 with SMTP id ffacd0b85a97d-43b88a055a4mr3167113f8f.34.1774438522008; Wed, 25 Mar 2026 04:35:22 -0700 (PDT) Received: from google.com (198.115.140.34.bc.googleusercontent.com. [34.140.115.198]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43b86fbb195sm10280737f8f.14.2026.03.25.04.35.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2026 04:35:21 -0700 (PDT) Date: Wed, 25 Mar 2026 11:35:18 +0000 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 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: <20260325113138.4171430-1-sebastianene@google.com> 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) > handle_host_smc(host_ctxt); > break; > case ESR_ELx_EC_IABT_LOW: > -- > 2.53.0.1018.g2bb0e51243-goog >