Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1287764pxb; Fri, 21 Jan 2022 14:25:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJxX2NncN7FRa4KbOy9dir00e2MmtKy/cS9RRanR+G4BEDqqGTbqBFiekePAu8POSOG8DB6i X-Received: by 2002:a63:6707:: with SMTP id b7mr4365986pgc.588.1642803954480; Fri, 21 Jan 2022 14:25:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642803954; cv=none; d=google.com; s=arc-20160816; b=nbHn2Rk9JjmD709dPypN1DisgS9gE/g6gCS4vNbfXj0OaHVrrzQTPficF6iB0+H7PV Htm9lF1Yt5zmHenpzGBECx7352kFSBYKtumWOgEBbxsn3hRiN34bbgU0ywhNVI9TXCm0 or1Ap2mrv+7SrpxNH2gmR+A8R9Q4oTG5WnLjSHtaJpzJLJRu8eAazId+72wmM1jgUg+G NhsYpPeY75C2MkPv261DHMjc76xzleQVh62oqS5uu/sAPOykrqedSuloLcndayYVBErG WC+T9HA6/2VKYtcy5quD8yxsAovDtUDvTC+B+AA87ySOJjnXKZ1s8XdTT04uP9rcZtny i1rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=rmS8L8fuOGkYvKFNmD68YPx7y9KPPBqF8b31jD22Rys=; b=R7JoehdbmqRV2aw2Nq1XahjG3HLDhUb+jJFxFWLn6eUg4NgJjdwXxNRGoXRbN60309 c1oTYA+mlrDPvd39W139Yei1JTlZOXz7aJ9dJHj6Nkd35V4WhV1HaYPBojuQolwxGDmw tUNf3PbmHashuS7IxSjXEy8Ay2x353l6btJgVzlfc9xi0q4XWauEQ69uQwM94MPj5Qif MHbgT+5kKpFAjJ+v9y6NuOmH4HNygDuAoJWarj0Kre4kHcchi+homRzMPhZgCxhz31Ww Ipr7L33zZ4ZsNcb5LtgL/SWyIVgUZMB1772K2BtOBiobnpz3LGb3ITiY6TTZDvNHKW3q vqZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fJZkzZ3q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b19si7201345plz.574.2022.01.21.14.25.42; Fri, 21 Jan 2022 14:25:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fJZkzZ3q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377177AbiATQ5P (ORCPT + 99 others); Thu, 20 Jan 2022 11:57:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:25002 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377067AbiATQ5O (ORCPT ); Thu, 20 Jan 2022 11:57:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642697833; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rmS8L8fuOGkYvKFNmD68YPx7y9KPPBqF8b31jD22Rys=; b=fJZkzZ3qIUiRsdY8AAbks6aqAzzUN4K8oa+5oLuc+FRX5kLugceWfTjzEMKd/1iPC4MLIB dMN8mPDhuP4FYUAVr+DRVwPWplvXi4quMVSzdhmKS5L4haEAv8HPvdD2WSm+xVdY9Sdv9r ErcZrZ5d5yxvYLqaDFsNCEpnr5LkfRA= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-211-OU_QU9z4N2en4SccgRePUQ-1; Thu, 20 Jan 2022 11:57:12 -0500 X-MC-Unique: OU_QU9z4N2en4SccgRePUQ-1 Received: by mail-wm1-f69.google.com with SMTP id bg32-20020a05600c3ca000b00349f2aca1beso4448757wmb.9 for ; Thu, 20 Jan 2022 08:57:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=rmS8L8fuOGkYvKFNmD68YPx7y9KPPBqF8b31jD22Rys=; b=Z1JtiBm96Oaed0wliTMp6U9x+5iG8ZiazhGMQt/HPsxCXUuI8X7GBZuF7Q8Pcm/pGH elgtcoG/dUVqERDX2SpNZuPrXUZib05qB6wkO4ZPL1But9Je0pWnMfwc8YNGuBTJkdGB 11T1qdUCHYMIFoLh1PFm4/N5SMz4SwqwzcYDc1ogXJAPSX8B6jwehyYWRd/e2b5v3rk7 bUKOEiTnKSVLD8M9C5Ayzpx2ZS+D9tj+tXvS6Xfy1L9psHdjJEV2bOZduzmqLzzwO8Gv 65XG3R0b8xuuw3zOhOQct3yiIZNgvfZTCxrUJ2d1fgmLmrQyBGog59FE3NFGkhlr8iEd TA9Q== X-Gm-Message-State: AOAM531GxYy1z9ZCwXlVZ3O8R38JO8+kAb8FBLDilAztgvHp4pSqBK26 k1Nf9C28BYDVbdsZ/gRiiulggrJIPPXDIFlo2a09wnspwKuwR0NO+LJwXoXbbgpmo+klyHmdANC n45LXeNBUnB6/Lffb2OQ84Ev1 X-Received: by 2002:a5d:4451:: with SMTP id x17mr29521516wrr.505.1642697831275; Thu, 20 Jan 2022 08:57:11 -0800 (PST) X-Received: by 2002:a5d:4451:: with SMTP id x17mr29521478wrr.505.1642697831040; Thu, 20 Jan 2022 08:57:11 -0800 (PST) Received: from ?IPV6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.googlemail.com with ESMTPSA id d6sm3209558wrs.85.2022.01.20.08.57.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Jan 2022 08:57:10 -0800 (PST) Message-ID: Date: Thu, 20 Jan 2022 17:57:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH v2 4/7] kvm/mips: rework guest entry logic Content-Language: en-US To: Mark Rutland , linux-kernel@vger.kernel.org Cc: aleksandar.qemu.devel@gmail.com, alexandru.elisei@arm.com, anup.patel@wdc.com, aou@eecs.berkeley.edu, atish.patra@wdc.com, borntraeger@linux.ibm.com, bp@alien8.de, catalin.marinas@arm.com, chenhuacai@kernel.org, dave.hansen@linux.intel.com, frankja@linux.ibm.com, frederic@kernel.org, gor@linux.ibm.com, hca@linux.ibm.com, james.morse@arm.com, jmattson@google.com, joro@8bytes.org, luto@kernel.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, nsaenzju@redhat.com, palmer@dabbelt.com, paulmck@kernel.org, paul.walmsley@sifive.com, peterz@infradead.org, seanjc@google.com, suzuki.poulose@arm.com, svens@linux.ibm.com, tglx@linutronix.de, tsbogend@alpha.franken.de, vkuznets@redhat.com, wanpengli@tencent.com, will@kernel.org References: <20220119105854.3160683-1-mark.rutland@arm.com> <20220119105854.3160683-5-mark.rutland@arm.com> <20220120164455.GA15464@C02TD0UTHF1T.local> From: Paolo Bonzini In-Reply-To: <20220120164455.GA15464@C02TD0UTHF1T.local> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/20/22 17:44, Mark Rutland wrote: > On Wed, Jan 19, 2022 at 10:58:51AM +0000, Mark Rutland wrote: >> In kvm_arch_vcpu_ioctl_run() we use guest_enter_irqoff() and >> guest_exit_irqoff() directly, with interrupts masked between these. As >> we don't handle any timer ticks during this window, we will not account >> time spent within the guest as guest time, which is unfortunate. >> >> Additionally, we do not inform lockdep or tracing that interrupts will >> be enabled during guest execution, which caan lead to misleading traces >> and warnings that interrupts have been enabled for overly-long periods. >> >> This patch fixes these issues by using the new timing and context >> entry/exit helpers to ensure that interrupts are handled during guest >> vtime but with RCU watching, with a sequence: >> >> guest_timing_enter_irqoff(); >> >> guest_state_enter_irqoff(); >> < run the vcpu > >> guest_state_exit_irqoff(); >> >> < take any pending IRQs > >> >> guest_timing_exit_irqoff(); > > Looking again, this patch isn't sufficient. > > On MIPS a guest exit will be handled by kvm_mips_handle_exit() *before* > returning into the "< run the vcpu >" step above, so we won't call > guest_state_exit_irqoff() before using RCU, etc. Indeed. kvm_mips_handle_exit has a weird mutual recursion through runtime-assembled code, but then this is MIPS... This should do it: diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c index e59cb6246f76..6f2291f017f5 100644 --- a/arch/mips/kvm/mips.c +++ b/arch/mips/kvm/mips.c @@ -1192,6 +1192,7 @@ int kvm_mips_handle_exit(struct kvm_vcpu *vcpu) kvm_mips_set_c0_status(); local_irq_enable(); + guest_timing_exit_irqoff(); kvm_debug("kvm_mips_handle_exit: cause: %#x, PC: %p, kvm_run: %p, kvm_vcpu: %p\n", cause, opc, run, vcpu); @@ -1325,6 +1326,7 @@ int kvm_mips_handle_exit(struct kvm_vcpu *vcpu) } if (ret == RESUME_GUEST) { + guest_timing_enter_irqoff(); trace_kvm_reenter(vcpu); /* Paolo