Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2856101rwd; Mon, 29 May 2023 01:46:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7VVQeDCq05xoojFxiiHprsA1TiOSJxrnawCIUToWBNIl4Sj55QlTRrm+23AFnSlIoKhJhM X-Received: by 2002:a05:6a00:2348:b0:64f:4d1d:32ba with SMTP id j8-20020a056a00234800b0064f4d1d32bamr17661444pfj.5.1685350017619; Mon, 29 May 2023 01:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685350017; cv=none; d=google.com; s=arc-20160816; b=Y4WJpVoUwY4Ta+fcdlU+scF0yCgzMtQwJQPuKi6OXT66REbwtDRZyJV5ZKVVFUrWIO DAOvjCCx/D1e/d4pcueT7Z8UCiPohAFzumuK6jEau2mwhnTklzTHjZDxayEw+3L8XMsN 3Z3Uq3syEH0K3d/1nugBDeszgjYOt1+Bn1Vy/8Lk0xzOVTG6kiZcIrmxFjihQ8gYgpAK GxuLimraXM1UWzzZcTkQ8uYk5PWu1EdsTG20BI0KlRz78Z065HABpt05aHsG4dsQy3BG HCI8ceiBOrh8WLSZBHkKoZt9jgwjs5UaxNQ3x+RSdZdqw5SfjCtt8BU8n/DdR37cTKoz flcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=Qkh9llis3ZknQKLi8BInsW/mCqj/vRSn8ZSv80WrB3M=; b=kPeVER0gjy6OxW9UmzNL7E8vKR45Lfv5YS5l3bBC49xUWZ5KpBWDg4nPLbkvxYYhFW 5YuODvX0Qg2Txy9ql3a+Bk+ubgQyAo7OBCOdMkT1dOLZuzOmGxuPnOC3HLGW63YDLD41 X6eBnG5gofHJ+hlDJKomZsf5192oM5RT0uC1AgsthtIUcJZSFp1Qgob6eGB7IIUhQ4Mk RtrHCQ7+KJWl3ZqRoVqF4EFiUZoB1mPfYMTfHVyaergRDx1y0ATN86FZQsJBEBPt/CyD oBk0Kisy4a18i7CJTJYWXLOLydMS8WgVISEdhlZgv0nqJRBltWZ9i+ogvINLWOILuybb NtiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=l4Jedt8q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d5-20020a637345000000b0053488ce246dsi9246522pgn.463.2023.05.29.01.46.43; Mon, 29 May 2023 01:46:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=l4Jedt8q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229692AbjE2IdU (ORCPT + 99 others); Mon, 29 May 2023 04:33:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjE2IdT (ORCPT ); Mon, 29 May 2023 04:33:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42F31A4 for ; Mon, 29 May 2023 01:33:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CB3A8611F8 for ; Mon, 29 May 2023 08:33:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26EC8C433D2; Mon, 29 May 2023 08:33:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685349197; bh=WdkMlXgHUbbdzZIgt+sMi4JSkaJspGqcxm6p/N+X3FY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=l4Jedt8qBrjaq3ynBEod8SRHWFkTi9jv2m1cPkw5CdkwNAYKSTUzqkilic6DNbRXX SiQfH207c/yOZ2rEg3TGKhqRTH2qmDaEDV0GQ1vxchjeLKuH4B7Y01aCDYWeNWiDYA X6B8+VlqwPalwZr5h46oNufL+idNC5U9XLizIsSt9srJqUkvPdSl/5Sl939RdI9MyR vS+nNMVQBdERz/inxDEPuAENGkueS6mxKwh5VuPKJ0nAihCWEZ8xCuUXLkuz5P44+O xVz2Y9jYAHNycamiYIfkG5FqHEZ7lSHFBCv+XFACx6noCEExYi4qi77jqGWNs4vn8U F9VwEQx/eCo2g== 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.95) (envelope-from ) id 1q3YJW-0011nz-OT; Mon, 29 May 2023 09:33:14 +0100 Date: Mon, 29 May 2023 09:33:14 +0100 Message-ID: <86edmzczat.wl-maz@kernel.org> From: Marc Zyngier To: Akihiko Odaki Cc: James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] KVM: arm64: Populate fault info for watchpoint In-Reply-To: <20230529024847.8671-1-akihiko.odaki@daynix.com> References: <20230529024847.8671-1-akihiko.odaki@daynix.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/28.2 (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: akihiko.odaki@daynix.com, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 29 May 2023 03:48:47 +0100, Akihiko Odaki wrote: > > When handling ESR_ELx_EC_WATCHPT_LOW, far_el2 member of struct > kvm_vcpu_fault_info will be copied to far member of struct > kvm_debug_exit_arch and exposed to the userspace. The userspace will > see stale values from older faults if the fault info does not get > populated. Nice catch! Some bike-shedding below... > > Fixes: 8fb2046180a0 ("KVM: arm64: Move early handlers to per-EC handlers") > Signed-off-by: Akihiko Odaki > --- > arch/arm64/kvm/hyp/include/hyp/switch.h | 2 +- > arch/arm64/kvm/hyp/nvhe/switch.c | 6 ++++-- > arch/arm64/kvm/hyp/vhe/switch.c | 3 ++- > 3 files changed, 7 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h > index 07d37ff88a3f..2eb0a1481ead 100644 > --- a/arch/arm64/kvm/hyp/include/hyp/switch.h > +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h > @@ -351,7 +351,7 @@ static bool kvm_hyp_handle_cp15_32(struct kvm_vcpu *vcpu, u64 *exit_code) > return false; > } > > -static bool kvm_hyp_handle_iabt_low(struct kvm_vcpu *vcpu, u64 *exit_code) > +static bool kvm_hyp_handle_generic_fault(struct kvm_vcpu *vcpu, u64 *exit_code) > { > if (!__populate_fault_info(vcpu)) > return true; > diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c > index c2cb46ca4fb6..1b77866079dc 100644 > --- a/arch/arm64/kvm/hyp/nvhe/switch.c > +++ b/arch/arm64/kvm/hyp/nvhe/switch.c > @@ -184,8 +184,9 @@ static const exit_handler_fn hyp_exit_handlers[] = { > [ESR_ELx_EC_SYS64] = kvm_hyp_handle_sysreg, > [ESR_ELx_EC_SVE] = kvm_hyp_handle_fpsimd, > [ESR_ELx_EC_FP_ASIMD] = kvm_hyp_handle_fpsimd, > - [ESR_ELx_EC_IABT_LOW] = kvm_hyp_handle_iabt_low, > + [ESR_ELx_EC_IABT_LOW] = kvm_hyp_handle_generic_fault, > [ESR_ELx_EC_DABT_LOW] = kvm_hyp_handle_dabt_low, > + [ESR_ELx_EC_WATCHPT_LOW] = kvm_hyp_handle_generic_fault, > [ESR_ELx_EC_PAC] = kvm_hyp_handle_ptrauth, > }; It is slightly odd to merge instruction abort with watchpoint faults, as the later is solely concerned with data, and not instructions. I'd rather we don't completely unify the handlers, even if they have the same implementation. There will be various differences in handling with NV which will result in diverging implementations. So either duplicate the code (it wouldn't make a huge difference), or add kvm_hyp_handle_iabt_low() and kvm_hyp_handle_watchpt_low() as aliases of kvm_hyp_handle_generic_fault (which would probably be better renamed as kvm_hyp_handle_memory_fault). And then use that as the prologue to the dabt handler. Something like the patch below. Thanks, M. diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h index 0a344184f26c..928983726a62 100644 --- a/arch/arm64/kvm/hyp/include/hyp/switch.h +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h @@ -414,17 +414,21 @@ static bool kvm_hyp_handle_cp15_32(struct kvm_vcpu *vcpu, u64 *exit_code) return false; } -static bool kvm_hyp_handle_iabt_low(struct kvm_vcpu *vcpu, u64 *exit_code) +static bool kvm_hyp_handle_memory_fault(struct kvm_vcpu *vcpu, u64 *exit_code) { if (!__populate_fault_info(vcpu)) return true; return false; } +static bool kvm_hyp_handle_iabt_low(struct kvm_vcpu *vcpu, u64 *exit_code) + __alias(kvm_hyp_handle_memory_fault); +static bool kvm_hyp_handle_watchpt_low(struct kvm_vcpu *vcpu, u64 *exit_code) + __alias(kvm_hyp_handle_memory_fault); static bool kvm_hyp_handle_dabt_low(struct kvm_vcpu *vcpu, u64 *exit_code) { - if (!__populate_fault_info(vcpu)) + if (kvm_hyp_handle_memory_fault(vcpu, exit_code)) return true; if (static_branch_unlikely(&vgic_v2_cpuif_trap)) { diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c index 7730860552da..b357ba7c453d 100644 --- a/arch/arm64/kvm/hyp/nvhe/switch.c +++ b/arch/arm64/kvm/hyp/nvhe/switch.c @@ -186,6 +186,7 @@ static const exit_handler_fn hyp_exit_handlers[] = { [ESR_ELx_EC_FP_ASIMD] = kvm_hyp_handle_fpsimd, [ESR_ELx_EC_IABT_LOW] = kvm_hyp_handle_iabt_low, [ESR_ELx_EC_DABT_LOW] = kvm_hyp_handle_dabt_low, + [ESR_ELx_EC_WATCHPT_LOW] = kvm_hyp_handle_watchpt_low, [ESR_ELx_EC_PAC] = kvm_hyp_handle_ptrauth, }; @@ -196,6 +197,7 @@ static const exit_handler_fn pvm_exit_handlers[] = { [ESR_ELx_EC_FP_ASIMD] = kvm_hyp_handle_fpsimd, [ESR_ELx_EC_IABT_LOW] = kvm_hyp_handle_iabt_low, [ESR_ELx_EC_DABT_LOW] = kvm_hyp_handle_dabt_low, + [ESR_ELx_EC_WATCHPT_LOW] = kvm_hyp_handle_watchpt_low, [ESR_ELx_EC_PAC] = kvm_hyp_handle_ptrauth, }; diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c index e03c3413cf49..46f0fce9b01f 100644 --- a/arch/arm64/kvm/hyp/vhe/switch.c +++ b/arch/arm64/kvm/hyp/vhe/switch.c @@ -311,6 +311,7 @@ static const exit_handler_fn hyp_exit_handlers[] = { [ESR_ELx_EC_FP_ASIMD] = kvm_hyp_handle_fpsimd, [ESR_ELx_EC_IABT_LOW] = kvm_hyp_handle_iabt_low, [ESR_ELx_EC_DABT_LOW] = kvm_hyp_handle_dabt_low, + [ESR_ELx_EC_WATCHPT_LOW] = kvm_hyp_handle_watchpt_low, [ESR_ELx_EC_PAC] = kvm_hyp_handle_ptrauth, [ESR_ELx_EC_ERET] = kvm_hyp_handle_eret, }; -- Without deviation from the norm, progress is not possible.