From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 91712106B50B for ; Wed, 25 Mar 2026 11:59:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=yzeKl+AouOYYbQjJFcOMyd2oEWZtlPJam7WU/4siiDI=; b=dNGspwAK8ATnH/VGGCPelIarFJ bmaUtgvpji/QzYFiyOI8aoEyMBVTaOPCc/ME91T4tYpp7e3H5rB7593RkHkmYgTJN0okNeEeZFzTA 9pMJwZw3WL2y/zajOF6aEGd53R2Hg6q49NEyLifebeI/nFPuPLYT73ZBGZwpZ7FrPnMYBrAkplGvO WdkpwEyJXTt7h3PjBvmNK8smC4PHL/oLqubC9SZjyfwgqWP4USkPh2Y9rj/Lc5fkwxsTLVourq1Ja Z/g3SJP/vPFfnhNGqALlwD7u/AlLVJo/b90QfjHXl8liiwEkjzYRKgSYlOCsj/HEqEX+0TxdlKpS3 /4AjIsIA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1w5Mt4-00000003Kwc-3nrF; Wed, 25 Mar 2026 11:59:03 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1w5Msy-00000003Kvf-0eul for linux-arm-kernel@lists.infradead.org; Wed, 25 Mar 2026 11:59:01 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 61E0644093; Wed, 25 Mar 2026 11:58:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AA1FC4CEF7; Wed, 25 Mar 2026 11:58:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774439935; bh=6luj6doPeND31Eisbvd/5/okrRnTF7y5LhkTtTOiI2k=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=K0cWtlIdmFEgXNXSOUbMRLBPCs8rvJ3FeGENlI80z08J96fqXXaAbtvM5jOXItpFs rbLzuF9eLxQ+3R4YNiUsveh/rS/etU/GIoq6b83PoB68ckYRg0HTwHePWWTCD+8dCP qND4OgT6xsJsYzg8khnMBC2aLCQ85ONZgkhMS08tvQrgSwzlzkc/msN2+BbETiWfA0 z+UmGLlBG87n5Dz1sAs6Niow+KyWqhTYBA1GLdOBAwMGNCMhcLLmzB2mcoXXJS2NF2 e2pp5riU/raokH5LwprtO78mjfjQlrtwDZ2OfejIlfJk5U0g+rEEKIEJ/Olr5xVWKG 6UISpo4V7rhTw== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w5Msu-00000005XSb-3bKb; Wed, 25 Mar 2026 11:58:52 +0000 Date: Wed, 25 Mar 2026 11:58:52 +0000 Message-ID: <86jyv03ytf.wl-maz@kernel.org> From: Marc Zyngier To: Sebastian Ene Cc: Vincent Donnefort , 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, 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 In-Reply-To: References: <20260325113138.4171430-1-sebastianene@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: sebastianene@google.com, vdonnefort@google.com, 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, oupton@kernel.org, suzuki.poulose@arm.com, tabba@google.com, will@kernel.org, yuzenghui@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260325_045858_410739_0694868A X-CRM114-Status: GOOD ( 33.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, 25 Mar 2026 11:41:17 +0000, Sebastian Ene wrote: > > 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. I don't see that obtaining ESR_EL2 is that hard or expensive. Given that everything is in the same compilation unit, the compiler will probably optimise it. But if I have to state the obvious: you are *handling* an SMC instruction. Surely handle_host_smc() is the correct spot for that job? M. -- Without deviation from the norm, progress is not possible.