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 1AEAFC77B72 for ; Sat, 15 Apr 2023 03:12:39 +0000 (UTC) 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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3g+cpXOFAFomdGdpilj7UmDJRzZPxsU1LUlaqXKJPqU=; b=YwxXuEyZ3jGwkw RklwMsPv43NKpsIlAZSBL2n+JO7is6UX85w6KhC0RSWu5IYNBwcKSpuM+arwpumBwsSN2SnE9jld8 ngw3h19bcXlVeMMXBmOKBxqKCakC9uliz+izHjxmNsrBwBxwGsfwoBnKCuwDPDJyTDBkQF0TxknrP WAfr+uSe9GivXFFZNvmJKujk8733RGIuYK6T7Eqvivj9mVuf2KpQdzdf3dvR00fHsod310YnAP6R1 b9HAlZyluTJL3YwMDrl6IP+OrCdoazNx6nq7nYSjb2wVbm72wc1UbVKd8CRIy5K4frj1qlxeYXo3B mErYY5QKlJuVVZATKpWw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pnWK2-00B9vk-0c; Sat, 15 Apr 2023 03:11:30 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pnWJy-00B9uO-1i for linux-arm-kernel@lists.infradead.org; Sat, 15 Apr 2023 03:11:27 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1a273b3b466so353925ad.1 for ; Fri, 14 Apr 2023 20:11:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681528278; x=1684120278; 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=SvRefNBdCntu+pZy/U4eeOw/+P3jSNTuSKl+Y+gg558=; b=OaOvmpDzv3+8A9qM0qt9IBR6/9mwsQAdQ1m6VNkf9JoXLA1xW95KIz9IV7p9qDwB/R erNPV+9DAqp+ny5DIU6YGDnc4QuaoBlrLXVS2UnfB/xrrNCTt5mXxPLgoqmj0sGQid7Z bFcyOanzbtEWTa65RmFlRPcWtTJM7yT/0GmKd9aSB8uKwlEKyS1cKPleQgMP3aKF+QmO 8clATWzgmpwh8UlfmPMhTp42jUyrmvkuxTtu05CEfEJnK+WQUW+HHESiwPOOcmnt7QZ/ OWizNb8hrGOWjopFvr5fje68NSgxCJAR9kX5Q8VLkO4W3HJWfxEjVksgzskzp3Jb/lbP aUEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681528278; x=1684120278; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=SvRefNBdCntu+pZy/U4eeOw/+P3jSNTuSKl+Y+gg558=; b=O5hFUV50pi1l6zLeinH0fBBp0Z82GF1abbnFPLCNzEXxswaoNeonQzhj9bk3n/U4WL GhPTgi+tjKRgnRl1TgCAioksQ5Gjcvo5L6G4PWNjiIy43Lruewh1JynUDPOeRUxZnT1l 3tIHIyKMgiq7XatKgZAMmdrV/HurtDNFRbjjFx1jzjf60L+uPzftuH/9cl5MnOuk1HRN P+PqCmTWDfs4XehZog6b9hV9HE7rYCPiAKtO8Mz07OIDsw8dUdeam93grXnYfyYvnReg Hl/LSTu8K70pO6g0a3R02kW+nqycL/65nKQUCvLgXuNX9RDRFxDydTTfRt1g7GVJ5+zH VkkA== X-Gm-Message-State: AAQBX9d0HXepO3z0RUjHWuZI5ChN5W2mHroy3ofiFEPo+R0ZfAyRu1NG VuHwqXJ6+12MIjueqyRVayg6gw== X-Google-Smtp-Source: AKy350aoUX99YiXsrWHE9U96HGSkzRYFTGlU9fSvZAsPt4wh+G9nV4c/x4EB7232wRvYCSx1HZcJ0w== X-Received: by 2002:a17:902:f0d4:b0:19a:5a9d:3c with SMTP id v20-20020a170902f0d400b0019a5a9d003cmr73915pla.16.1681528277707; Fri, 14 Apr 2023 20:11:17 -0700 (PDT) Received: from google.com (223.103.125.34.bc.googleusercontent.com. [34.125.103.223]) by smtp.gmail.com with ESMTPSA id i12-20020a63cd0c000000b00517be28bcf9sm3412025pgg.86.2023.04.14.20.11.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 20:11:16 -0700 (PDT) Date: Fri, 14 Apr 2023 20:11:12 -0700 From: Reiji Watanabe To: Marc Zyngier Cc: Mark Rutland , Oliver Upton , Will Deacon , Catalin Marinas , kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Alexandru Elisei , Zenghui Yu , Suzuki K Poulose , Paolo Bonzini , Ricardo Koller , Jing Zhang , Raghavendra Rao Anata , Shaoqin Huang , Rob Herring Subject: Re: [PATCH v2 2/2] KVM: arm64: PMU: Don't overwrite PMUSERENR with vcpu loaded Message-ID: <20230415031112.gdb4vghgs3q42koa@google.com> References: <20230408034759.2369068-1-reijiw@google.com> <20230408034759.2369068-3-reijiw@google.com> <20230412051410.emaip77vyak624pu@google.com> <86v8i1l7ru.wl-maz@kernel.org> <86jzygkvmw.wl-maz@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <86jzygkvmw.wl-maz@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230414_201126_590769_157843DE X-CRM114-Status: GOOD ( 28.83 ) 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 > > > > > Uh, right, interrupts are not masked during those windows... > > > > > > > > > > What I am currently considering on this would be disabling > > > > > IRQs while manipulating the register, and introducing a new flag > > > > > to indicate whether the PMUSERENR for the guest EL0 is loaded, > > > > > and having kvm_set_pmuserenr() check the new flag. > > > > > > > > > > The code would be something like below (local_irq_save/local_irq_restore > > > > > needs to be excluded for NVHE though). > > > > > > It shouldn't need to be excluded. It should be fairly harmless, unless > > > I'm missing something really obvious? > > > > The reason why I think local_irq_{save,restore} should be excluded > > are because they use trace_hardirqs_{on,off} (Since IRQs are > > masked here for NVHE, practically, they shouldn't be called with > > the current KVM implementation though). > > Gah. Indeed, we end-up with a lot of unwanted crap, and absolutely no > way to locally override it. > > > I'm looking at using "ifndef __KVM_NVHE_HYPERVISOR__" or other > > ways to organize the code for this. > > I'd vote for something like the code below: Thank you for the suggestion. Considering that we may have similar cases in the future, I will implement as you suggested in v3. Thank you, Reiji > > diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile > index 530347cdebe3..1796fadb26cc 100644 > --- a/arch/arm64/kvm/hyp/nvhe/Makefile > +++ b/arch/arm64/kvm/hyp/nvhe/Makefile > @@ -10,7 +10,7 @@ asflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS > # will explode instantly (Words of Marc Zyngier). So introduce a generic flag > # __DISABLE_TRACE_MMIO__ to disable MMIO tracing for nVHE KVM. > ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS -D__DISABLE_TRACE_MMIO__ > -ccflags-y += -fno-stack-protector \ > +ccflags-y += -fno-stack-protector -DNO_TRACE_IRQFLAGS \ > -DDISABLE_BRANCH_PROFILING \ > $(DISABLE_STACKLEAK_PLUGIN) > > diff --git a/include/linux/irqflags.h b/include/linux/irqflags.h > index 5ec0fa71399e..ab0ae58dd797 100644 > --- a/include/linux/irqflags.h > +++ b/include/linux/irqflags.h > @@ -198,9 +198,10 @@ extern void warn_bogus_irq_restore(void); > > /* > * The local_irq_*() APIs are equal to the raw_local_irq*() > - * if !TRACE_IRQFLAGS. > + * if !TRACE_IRQFLAGS or if NO_TRACE_IRQFLAGS is localy > + * set. > */ > -#ifdef CONFIG_TRACE_IRQFLAGS > +#if defined(CONFIG_TRACE_IRQFLAGS) && !defined(NO_TRACE_IRQFLAGS) > > #define local_irq_enable() \ > do { \ > > > > Since {__activate,__deactivate}_traps_common() are pretty lightweight > > functions, I'm also considering disabling IRQs in their call sites > > (i.e. activate_traps_vhe_load/deactivate_traps_vhe_put), instead of in > > __{de}activate_traps_common() (Thanks for this suggestion, Oliver). > > That would work too. > > Thanks, > > 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