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 X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=BAYES_00,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2E84C4338F for ; Sat, 21 Aug 2021 10:56:57 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 59AE461211 for ; Sat, 21 Aug 2021 10:56:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 59AE461211 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id E20884B18D; Sat, 21 Aug 2021 06:56:56 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id x9eBcEu17pJg; Sat, 21 Aug 2021 06:56:52 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 556244B193; Sat, 21 Aug 2021 06:56:52 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id D2D1F4B18D for ; Sat, 21 Aug 2021 06:56:50 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hzZZy7Szp8fp for ; Sat, 21 Aug 2021 06:56:49 -0400 (EDT) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 9F62C4B183 for ; Sat, 21 Aug 2021 06:56:49 -0400 (EDT) Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 92BB16113E; Sat, 21 Aug 2021 10:56:48 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mHOgA-006MEI-Gc; Sat, 21 Aug 2021 11:56:46 +0100 Date: Sat, 21 Aug 2021 11:56:46 +0100 Message-ID: <875yvzqd5d.wl-maz@kernel.org> From: Marc Zyngier To: Raghavendra Rao Ananta Subject: Re: [PATCH] KVM: arm64: Ratelimit error log during guest debug exception In-Reply-To: References: <20210819223406.1132426-1-rananta@google.com> <87sfz4qx9r.wl-maz@kernel.org> 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/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: rananta@google.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, pshier@google.com, ricarkol@google.com, oupton@google.com, reijiw@google.com, jingzhangos@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, 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 Cc: Will Deacon , Catalin Marinas , Peter Shier , linux-kernel@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Sat, 21 Aug 2021 00:01:24 +0100, Raghavendra Rao Ananta wrote: > > [1 ] > On Fri, Aug 20, 2021 at 2:29 AM Marc Zyngier wrote: > > > > On Thu, 19 Aug 2021 23:34:06 +0100, > > Raghavendra Rao Ananta wrote: > > > > > > Potentially, the guests could trigger a debug exception that's > > > outside the exception class range. > > > > How? All the exception classes that lead to this functions are already > > handled in the switch/case statement. > > > I guess I didn't think this through. Landing into kvm_handle_guest_debug() > itself is not possible :) Exactly. > > My take on this is that this code isn't reachable, and that it could > > be better rewritten as: > > > > diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c > > index 6f48336b1d86..ae7ec086827b 100644 > > --- a/arch/arm64/kvm/handle_exit.c > > +++ b/arch/arm64/kvm/handle_exit.c > > @@ -119,28 +119,14 @@ static int kvm_handle_guest_debug(struct kvm_vcpu > *vcpu) > > { > > struct kvm_run *run = vcpu->run; > > u32 esr = kvm_vcpu_get_esr(vcpu); > > - int ret = 0; > > > > run->exit_reason = KVM_EXIT_DEBUG; > > run->debug.arch.hsr = esr; > > > > - switch (ESR_ELx_EC(esr)) { > > - case ESR_ELx_EC_WATCHPT_LOW: > > + if (ESR_ELx_EC(esr) == ESR_ELx_EC_WATCHPT_LOW) > > run->debug.arch.far = vcpu->arch.fault.far_el2; > > - fallthrough; > > - case ESR_ELx_EC_SOFTSTP_LOW: > > - case ESR_ELx_EC_BREAKPT_LOW: > > - case ESR_ELx_EC_BKPT32: > > - case ESR_ELx_EC_BRK64: > > - break; > > - default: > > - kvm_err("%s: un-handled case esr: %#08x\n", > > - __func__, (unsigned int) esr); > > - ret = -1; > > - break; > > - } > > > > - return ret; > > + return 0; > > } > > > This looks better, but do you think we would be compromising on readability? I don't think so. The exit handler table is, on its own, pretty explicit about what we route to this handler, and the comment above the function clearly states that we exit to userspace for all the debug ECs. M. -- Without deviation from the norm, progress is not possible. _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm 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 X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4DF0C4338F for ; Sat, 21 Aug 2021 10:58:34 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 817A36120F for ; Sat, 21 Aug 2021 10:58:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 817A36120F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Kpia5Od0C18gqQ2HoLV3BIOGI9rQ5kpoSIr79SJYt8E=; b=bX+24a0RysOBV0 yRcaY3X9rFHPIXhkZqjddypsyuki64/UTQfvcP190i/Ii1pPyMScbIhVByOf5aieBkSLwNKN1y5GN hD4NJnDaqXXXg1u/Am+GW2ENTTkEa0zhHQKMX0cR2WPc9EoUzbW/+x9Sn1XALFQZ6QWJNPdpUR5rX 6kyjUM94Q70b/a8eEjaz5W9v9t0tagDOGKhiOOXLJ4fYIsX+YO0DVcCnL2fLfHQSbuyS/Pa4a/a9W B94GTRZwDF4rVkNxf1fUxReAWhpyfH/APRFBykI/SW934gtHlRDZs6veMGlKTT+CGKwU8IAmMenMW sowFkxIlODD2vLEafEhQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mHOgG-00Cj6T-N3; Sat, 21 Aug 2021 10:56:52 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mHOgD-00Cj60-3G for linux-arm-kernel@lists.infradead.org; Sat, 21 Aug 2021 10:56:50 +0000 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 92BB16113E; Sat, 21 Aug 2021 10:56:48 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mHOgA-006MEI-Gc; Sat, 21 Aug 2021 11:56:46 +0100 Date: Sat, 21 Aug 2021 11:56:46 +0100 Message-ID: <875yvzqd5d.wl-maz@kernel.org> From: Marc Zyngier To: Raghavendra Rao Ananta Cc: Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org Subject: Re: [PATCH] KVM: arm64: Ratelimit error log during guest debug exception In-Reply-To: References: <20210819223406.1132426-1-rananta@google.com> <87sfz4qx9r.wl-maz@kernel.org> 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/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: rananta@google.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, pshier@google.com, ricarkol@google.com, oupton@google.com, reijiw@google.com, jingzhangos@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210821_035649_214172_BAFA574F X-CRM114-Status: GOOD ( 26.78 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sat, 21 Aug 2021 00:01:24 +0100, Raghavendra Rao Ananta wrote: > > [1 ] > On Fri, Aug 20, 2021 at 2:29 AM Marc Zyngier wrote: > > > > On Thu, 19 Aug 2021 23:34:06 +0100, > > Raghavendra Rao Ananta wrote: > > > > > > Potentially, the guests could trigger a debug exception that's > > > outside the exception class range. > > > > How? All the exception classes that lead to this functions are already > > handled in the switch/case statement. > > > I guess I didn't think this through. Landing into kvm_handle_guest_debug() > itself is not possible :) Exactly. > > My take on this is that this code isn't reachable, and that it could > > be better rewritten as: > > > > diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c > > index 6f48336b1d86..ae7ec086827b 100644 > > --- a/arch/arm64/kvm/handle_exit.c > > +++ b/arch/arm64/kvm/handle_exit.c > > @@ -119,28 +119,14 @@ static int kvm_handle_guest_debug(struct kvm_vcpu > *vcpu) > > { > > struct kvm_run *run = vcpu->run; > > u32 esr = kvm_vcpu_get_esr(vcpu); > > - int ret = 0; > > > > run->exit_reason = KVM_EXIT_DEBUG; > > run->debug.arch.hsr = esr; > > > > - switch (ESR_ELx_EC(esr)) { > > - case ESR_ELx_EC_WATCHPT_LOW: > > + if (ESR_ELx_EC(esr) == ESR_ELx_EC_WATCHPT_LOW) > > run->debug.arch.far = vcpu->arch.fault.far_el2; > > - fallthrough; > > - case ESR_ELx_EC_SOFTSTP_LOW: > > - case ESR_ELx_EC_BREAKPT_LOW: > > - case ESR_ELx_EC_BKPT32: > > - case ESR_ELx_EC_BRK64: > > - break; > > - default: > > - kvm_err("%s: un-handled case esr: %#08x\n", > > - __func__, (unsigned int) esr); > > - ret = -1; > > - break; > > - } > > > > - return ret; > > + return 0; > > } > > > This looks better, but do you think we would be compromising on readability? I don't think so. The exit handler table is, on its own, pretty explicit about what we route to this handler, and the comment above the function clearly states that we exit to userspace for all the debug ECs. M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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 X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=BAYES_00,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F11F4C4338F for ; Sat, 21 Aug 2021 10:56:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D39246120E for ; Sat, 21 Aug 2021 10:56:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234228AbhHUK52 (ORCPT ); Sat, 21 Aug 2021 06:57:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:38150 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229968AbhHUK51 (ORCPT ); Sat, 21 Aug 2021 06:57:27 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 92BB16113E; Sat, 21 Aug 2021 10:56:48 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mHOgA-006MEI-Gc; Sat, 21 Aug 2021 11:56:46 +0100 Date: Sat, 21 Aug 2021 11:56:46 +0100 Message-ID: <875yvzqd5d.wl-maz@kernel.org> From: Marc Zyngier To: Raghavendra Rao Ananta Cc: Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org Subject: Re: [PATCH] KVM: arm64: Ratelimit error log during guest debug exception In-Reply-To: References: <20210819223406.1132426-1-rananta@google.com> <87sfz4qx9r.wl-maz@kernel.org> 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/27.1 (x86_64-pc-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: rananta@google.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, pshier@google.com, ricarkol@google.com, oupton@google.com, reijiw@google.com, jingzhangos@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 21 Aug 2021 00:01:24 +0100, Raghavendra Rao Ananta wrote: > > [1 ] > On Fri, Aug 20, 2021 at 2:29 AM Marc Zyngier wrote: > > > > On Thu, 19 Aug 2021 23:34:06 +0100, > > Raghavendra Rao Ananta wrote: > > > > > > Potentially, the guests could trigger a debug exception that's > > > outside the exception class range. > > > > How? All the exception classes that lead to this functions are already > > handled in the switch/case statement. > > > I guess I didn't think this through. Landing into kvm_handle_guest_debug() > itself is not possible :) Exactly. > > My take on this is that this code isn't reachable, and that it could > > be better rewritten as: > > > > diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c > > index 6f48336b1d86..ae7ec086827b 100644 > > --- a/arch/arm64/kvm/handle_exit.c > > +++ b/arch/arm64/kvm/handle_exit.c > > @@ -119,28 +119,14 @@ static int kvm_handle_guest_debug(struct kvm_vcpu > *vcpu) > > { > > struct kvm_run *run = vcpu->run; > > u32 esr = kvm_vcpu_get_esr(vcpu); > > - int ret = 0; > > > > run->exit_reason = KVM_EXIT_DEBUG; > > run->debug.arch.hsr = esr; > > > > - switch (ESR_ELx_EC(esr)) { > > - case ESR_ELx_EC_WATCHPT_LOW: > > + if (ESR_ELx_EC(esr) == ESR_ELx_EC_WATCHPT_LOW) > > run->debug.arch.far = vcpu->arch.fault.far_el2; > > - fallthrough; > > - case ESR_ELx_EC_SOFTSTP_LOW: > > - case ESR_ELx_EC_BREAKPT_LOW: > > - case ESR_ELx_EC_BKPT32: > > - case ESR_ELx_EC_BRK64: > > - break; > > - default: > > - kvm_err("%s: un-handled case esr: %#08x\n", > > - __func__, (unsigned int) esr); > > - ret = -1; > > - break; > > - } > > > > - return ret; > > + return 0; > > } > > > This looks better, but do you think we would be compromising on readability? I don't think so. The exit handler table is, on its own, pretty explicit about what we route to this handler, and the comment above the function clearly states that we exit to userspace for all the debug ECs. M. -- Without deviation from the norm, progress is not possible.