Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1405903pxb; Fri, 21 Jan 2022 17:54:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJzPaUJ4GnKuIEVLQ01S/Ty77nV9Zm0vxehkF4td/oF7C18T/zDAK8bQd4mwFxoExDWUZ15h X-Received: by 2002:a17:902:ced2:b0:14a:699e:3ab3 with SMTP id d18-20020a170902ced200b0014a699e3ab3mr6393829plg.0.1642816479696; Fri, 21 Jan 2022 17:54:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642816479; cv=none; d=google.com; s=arc-20160816; b=J298xMrJxa/4aXbI75zjhGAwpKCZLKEcm6CCFZKEtjgRN35OLoX48dIxpmjHTiPXCl Udg5EtLdlwuhLwZLhZvFdcJPA8PJePEZ2V1H86b3LAqx/O+g8pZOFWNvZpNJXU4jgn71 xQB6F/irziN7bsCYoWLYuz2KUJ28n3ayd6tFc3tdWe5bz/D3lRAaW+PiXa+aDKOe7Sfd VA3ilU5wg9/TrXIJPVktGU2D6dWk7nmV/enna6KKhZaf7dC87Zr902EicofNVCHBKa/o y7Dzlz20GjEBhUiA/2Z5iaISJ3/yHR4IF0EOKWb23SBh5Q7W6+a2nKbI5I03rGO6r3l4 aY2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=fgXDJ3PF1MZa2hRHaWiI+Ji2fHQH7cq02OZtg+RHXGE=; b=jYS0zhhuuY+Mmf9fdlQdJACHhBaMGPSCCZ3IxMMyy3KqZ7hrZkNMEnBpDVLMmZsrrD BKo2b87RRcvbHXYIK8OIAd8yU90mjDzskp5DPk1DhoHjpZdFTvSeNTugQvSeYUCzuFv2 hQAMRf9PG/f57NY62NirMb/wGKlEjnAWyKmudvlOcv3hCZkwRV0qu+2dr0HNVs2HoXiy UED+cpblfNgOt5U5Umt+7sixhGzAp3oke1f0fWdTQwExD/jx1IucUxRVrvNJ7skZ5j8F TUBZKvRRaVZsYGfcxV4nYJWyY7r0DBxIomqgF1+zIk3zKV43pvdl8IJKGtcZz02wyI+X WV+Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x71si2136258pgd.523.2022.01.21.17.54.27; Fri, 21 Jan 2022 17:54:39 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381562AbiAUPaA (ORCPT + 99 others); Fri, 21 Jan 2022 10:30:00 -0500 Received: from foss.arm.com ([217.140.110.172]:55212 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351009AbiAUP37 (ORCPT ); Fri, 21 Jan 2022 10:29:59 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 33601101E; Fri, 21 Jan 2022 07:29:59 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.1.33]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 818573F774; Fri, 21 Jan 2022 07:29:53 -0800 (PST) Date: Fri, 21 Jan 2022 15:29:50 +0000 From: Mark Rutland To: Christian Borntraeger Cc: Paolo Bonzini , linux-kernel@vger.kernel.org, Michael Ellerman , aleksandar.qemu.devel@gmail.com, alexandru.elisei@arm.com, anup.patel@wdc.com, aou@eecs.berkeley.edu, atish.patra@wdc.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, 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, Anup Patel , Atish Patra Subject: Re: [PATCH v2 0/7] kvm: fix latent guest entry/exit bugs Message-ID: References: <20220119105854.3160683-1-mark.rutland@arm.com> <20220119192217.GD43919@C02TD0UTHF1T.local> <2688b779-9cb8-b6ea-f8cc-93bc8ddf72f3@redhat.com> <85d3899e-7da5-abad-743b-e5d6dde21800@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 21, 2022 at 03:42:48PM +0100, Christian Borntraeger wrote: > Am 21.01.22 um 15:30 schrieb Mark Rutland: > > On Fri, Jan 21, 2022 at 03:17:01PM +0100, Christian Borntraeger wrote: > > > Am 21.01.22 um 10:53 schrieb Christian Borntraeger: > > > > Am 20.01.22 um 16:14 schrieb Christian Borntraeger: > > > > > Am 20.01.22 um 13:03 schrieb Mark Rutland: > > > > > > On Thu, Jan 20, 2022 at 12:28:09PM +0100, Paolo Bonzini wrote: > > > > > > > On 1/19/22 20:22, Mark Rutland wrote: > > > > > > > > I wonder, is the s390 guest entry/exit*preemptible*  ? > > > > > > > > > > > > > > > > If a timer IRQ can preempt in the middle of the EQS, we wouldn't balance > > > > > > > > things before a ctx-switch to the idle thread, which would then be able > > > > > > > > to hit this. > > > > > > > > > > > > > > > > I'll need to go audit the other architectures for similar. > > > > > > > > > > > > > > They don't enable interrupts in the entry/exit path so they should be okay. > > > > > > > > > > > > True. > > > > > > > > > > > > So it sounds like for s390 adding an explicit preempt_{disable,enable}() is the > > > > > > right thing to do. I'll add that and explanatory commentary. > > > > > > > > > > That would not be trivial I guess. We do allow (and need) page faults on sie for guest > > > > > demand paging and > > > > > > > > > > this piece of arch/s390/mm/fault.c > > > > > > > > > >         case GMAP_FAULT: > > > > >                  if (faulthandler_disabled() || !mm) > > > > >                          goto out; > > > > >                  break; > > > > >          } > > > > > > > > > > would no longer work since faulthandler_disabled checks for the preempt count. > > > > > > > > > > > > > > > > > Something like this > > > > > > > > > > > > diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c > > > > index d30f5986fa85..1c7d45346e12 100644 > > > > --- a/arch/s390/mm/fault.c > > > > +++ b/arch/s390/mm/fault.c > > > > @@ -385,10 +385,18 @@ static inline vm_fault_t do_exception(struct pt_regs *regs, int access) > > > >                         return 0; > > > >                 goto out; > > > >         case USER_FAULT: > > > > -       case GMAP_FAULT: > > > >                 if (faulthandler_disabled() || !mm) > > > >                         goto out; > > > >                 break; > > > > +               /* > > > > +                * We know that we interrupted SIE and we are not in a IRQ. > > > > +                * preemption might be disabled thus checking for in_atomic > > > > +                * would result in failures > > > > +                */ > > > > +       case GMAP_FAULT: > > > > +               if (pagefault_disabled() || !mm) > > > > +                       goto out; > > > > +               break; > > > >         } > > > > > > > >         perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address); > > > > > > > > seems to work with preemption disabled around sie. Not sure yet if this is correct. > > > > > > > > > No it does not work. scheduling while preemption is disabled. > > > > Hmm... which exceptions do we expect to take from a guest? > > > > I wonder if we can handle those more like other architectures by getting those > > to immediately return from the sie64a() call with some status code that we can > > handle outside of the guest_state_{enter,exit}_irqoff() critical section. > > We take all kind of page faults (invalid->valid, ro->rw) on the sie instruction and > run that in the context of the pgm_check handler just like for userspace. Do we only expect to tak faults from a guest (which IIUC at the GMAP_FAULT cases in the bit above), or are there other esceptions we expect to take from the middle of a SIE? > the pgm_check handler does a sie_exit (similar to the interrupt handlers) by > setting the return IA. Sure, but that sie_exit happens *after* the handler runs, where as I'm asking whether we can structure this like all the other architectures and turn all exceptions into returns from sie64a() that we can handle after having called guest_state_exit_irqoff(). > > On arm64 in VHE mode, we swap our exception vectors when entering/exiting the > > guest to allow us to do that; I wonder if we could do similar here? Does this idea sound at all plausible? Thanks, Mark.