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=-2.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 BD3DDC433DF for ; Thu, 9 Jul 2020 18:52:05 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 85DF420767 for ; Thu, 9 Jul 2020 18:52:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="qr7nn8y1"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IwbEGXgT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 85DF420767 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+yr8v+9k2nHvC1aSVQDvNNF3jV/SuqmiFFUIUId8cvU=; b=qr7nn8y1AKkUM1QaT9n5kgJGp yfLyEIwdUYc7CXbmiz9h7ySBFN/uR78x31lMvgezvNUMziIV1xUWkGpWgYh9E2gQs8ADhj0dtH7l6 oTB3f3nkOQmXAa5P09snb82C0eem27DMhUmujflP3U/KPdgNL5XwRbdTc55qGoX9dcj0NrGn3vKl/ zgqq1dXUVzn4C16b7W2uBKhMATkMBrc2OzzfzDfl5D1wUMwbn7TjtoV9NWEqghg94oVKjVk4vQGnk Bd9OdZXvZejxQk3oK5gQgiBPpXo3soYMsc5nKnw9pi8h/ehAWf+gN226f9UYfkKOAfrqbKiKUSzn1 Ncl0hGIsw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jtbcv-0003fn-1G; Thu, 09 Jul 2020 18:50:33 +0000 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120] helo=us-smtp-1.mimecast.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jtbcr-0003f8-JK for linux-arm-kernel@lists.infradead.org; Thu, 09 Jul 2020 18:50:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594320627; 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=eDjUkBxgk+0m9DY3FG9SguEpAAZLHaqqS9UNWO/w7mI=; b=IwbEGXgTHXZ+nv+FBrc2wXf/xEdB3apDvN+YOyRR7O+Z2FW6bJB3R8Rog4VQtRIF9ySDdp y72BahaU508gX9Uzy2cR04mtzKGhyw0Zinqm4XpGB4KabsQTxAzgRMg/wsSGfnziY0CF5X ujQzcJcSjt+vAeL19hAnAR3J4dw8tyY= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-163-_chLOWFbOtCCvKXhDUIxEQ-1; Thu, 09 Jul 2020 14:50:24 -0400 X-MC-Unique: _chLOWFbOtCCvKXhDUIxEQ-1 Received: by mail-wr1-f69.google.com with SMTP id j3so2787705wrq.9 for ; Thu, 09 Jul 2020 11:50:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=eDjUkBxgk+0m9DY3FG9SguEpAAZLHaqqS9UNWO/w7mI=; b=lpIIZ/WLbFm3DaG6F7R2ee9K9ncP7tTabUvUuhbkJZEA0rS7eWsHhvBe/m8rUPgLNw Hp8FAsP1mrgfX3NZ/RW036C4HsMkwaIhGTf3wbHvx9dPtWvv6/6aij9iMi/bp1fWUoZ7 d5HNGmTsP6ICFqohJskObiV5EBvR3tFHcz/nW2Ji0Z1ukQiEQJL6suceMrmxSM/CMJOh H0Zy/JDXWQPi8NjgCRVzsgW/WK3h/s4VjHu/TipAF+XcAVp2gNOuyH0ZPWUQgCQr9khM gAFBw3kvOhL9VhhPY9M4XBiADCpw+emP0xV9d6hMWF70I1AMy5VXYQbQUq4/5GjFtxvU d36A== X-Gm-Message-State: AOAM530u7hoYXq8PXQEVrk5DCb9JRNFuLSvwWGEA+fRYzr6CGMMSZ51D QezZi8cRAEZbSdtpRh33PNDtzNM5aHmMq/DF3LyeifdeXE2HSsb0pRhAnbSCyPVOcYh9He8gfP1 30bDigTO1taPrjmZ97n7hqndQ9gkFGkPxiHA= X-Received: by 2002:adf:f0c5:: with SMTP id x5mr64686914wro.396.1594320623495; Thu, 09 Jul 2020 11:50:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyv7VxN6KkZvCJY5A7wMGZeoVW0kkYIL64e4SfUAdw3gCZVUK9OucuaTHOeSHMf+Gfd57g2ew== X-Received: by 2002:adf:f0c5:: with SMTP id x5mr64686894wro.396.1594320623160; Thu, 09 Jul 2020 11:50:23 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:9541:9439:cb0f:89c? ([2001:b07:6468:f312:9541:9439:cb0f:89c]) by smtp.gmail.com with ESMTPSA id f197sm6391056wme.33.2020.07.09.11.50.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Jul 2020 11:50:22 -0700 (PDT) Subject: Re: [Question] How to testing SDEI client driver To: James Morse , Gavin Shan References: <8cdef8ea-e550-ccff-2041-526d6f6fcda0@redhat.com> <3cc7e69c-9315-5138-85f7-7b36e17b67a1@redhat.com> <2b5ef5b2-cf6b-3f4e-4250-c1d0a34e9873@arm.com> <69ecf58f-bf9d-6c2d-37ab-4397b30fff4b@redhat.com> <78280b26-925f-27a1-6c4b-c079a2fe3878@arm.com> From: Paolo Bonzini Message-ID: <0e9a724f-97b7-ffd3-2050-e3b8c5236609@redhat.com> Date: Thu, 9 Jul 2020 20:50:21 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <78280b26-925f-27a1-6c4b-c079a2fe3878@arm.com> Content-Language: en-US X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200709_145029_692789_A2EC5A9B X-CRM114-Status: GOOD ( 39.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, maz@kernel.org, linux-arm-kernel@lists.infradead.org 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 09/07/20 20:30, James Morse wrote: > I can see why this would be useful. Is it widely used, or a bit of a niche sport? > I don't recall seeing anything about it last time I played with migration... It's widely used (at least Google uses it a lot). >> The main showstopper is that you cannot rely on guest cooperation (also >> because it works surprisingly well without). > > Aren't we changing the guest kernel to support this? Certainly I agree the guest may not > know about anything. Yes, but the fallback is synchronous page faults and if the guest doesn't collaborate it's business as usual. Now I see better what you meant: the "fake swap" device would not prevent *other* memory from being swapped even without the guest's consent. However, in the case of e.g. postcopy live migration you're in a bit of a bind, because the working set is both: 1) exactly the set of pages that are unlikely to be ready on the destination 2) the set of pages that the guest would choose not to place in the "fake swap". >> Are there usecases for injecting SDEIs from QEMU? > > Yes. RAS. > > When the VMM takes a SIGBUS:MCEERR_AO it can decide if and how to report this to the > guest. If it advertised firmware-first support at boot, there are about five options, of > which SDEI is one. It could emulate something platform specific, or do nothing at all. Ok, for x86 there's an ioctl to inject MCEs and I was not really sure how ARM does it. But it could still be a kernel-managed event, just one that QEMU can trigger at will. >> If not, it can be done much more easily with KVM > > The SDEI state would need to be exposed to Qemu to be migrated. If Qemu wants to use it > for a shared event which is masked on the local vCPU, we'd need to force the other vCPU to > exit to see if they can take it. Its not impossible, just very fiddly. > > The mental-model I try to stick to is the VMM is the firmware for the guest, and KVM > 'just' does the stuff it has to to maintain the illusion of real hardware, e.g. plumbing > stage2 page faults into mm as if they were taken from the VMM, and making the > timers+counters work. Actually I try to make the firmware for the guest... the firmware of the guest (with paravirtualized help from the hypervisor or VMM when needed). I think we've argued about that with Marc a lot though, so it may not be the most common view in the ARM world! My model is that KVM does processor stuff, while the VMM does everything else. It doesn't always match, for example KVM does more GIC emulation than would fit this model (IIRC it handles the distributor?). But this is why I would prefer to put the system register manipulation in KVM rather than the VMM, possibly with ioctls on the vCPU file descriptor for use from the VMM. > >> (and it would also >> would be really, really slow if each page fault had to be redirected >> through QEMU), > > Isn't this already true for any post-copy live migration? > There must be some way of telling Qemu that this page is urgently needed ahead of whatever > it is copying at the moment. It's done with userfaultfd, so it's entirely asynchronous. It's important to get the fault delivered quickly to the guest however, because that affects the latency. > There are always going to be pages we must have, and can't make progress until we do. (The > vectors, the irq handlers .. in modules ..) Yup but fortunately they don't change often. For postcopy the problematic pages are ironically those in the working set, not those that never change (because those can be migrated just fine)! >>>> Yes, The SDEI specification already mentioned >>>> this: the client handler should have all required resources in place before >>>> the handler is going to run. However, I don't see it's a problem so far. >>> >>> What if they are swapped out? This thing becomes re-entrant ... which the spec forbids. >>> The host has no clue what is in guest memory. > >> On x86 we don't do the notification if interrupts are disabled. > > ... because you can't schedule()? What about CONFIG_PREEMPT? arm64 has that enabled in its > defconfig. I anticipate its the most common option. No not because we can't schedule() but because it would be a reentrancy nightmare. Actually it's even stricter: we don't do the notification at all if we're in supervisor mode. As I said above, we don't expect that to be a big deal because the pages with the most churn for live migration will be userspace data. >> On ARM >> I guess you'd do the same until SDEI_EVENT_COMPLETE (so yeah that would >> be some state that has to be migrated). > > My problem with SDEI is the extra complexity it brings for features you don't want. > Its an NMI, that's the last thing you want as you can't schedule() Scheduling can be done outside the NMI handler as long as it's done before returning to EL3. But yeah, on x86 it's nice that the page fault exception handler can schedule() just fine (see kvm_async_pf_task_wait_schedule in arch/x86/kernel/kvm.c). > PPI are a scarce resource, so this would need some VMM involvement at boot to say which > PPI can be used. We do this for the PMU too. Yep, this is part of why we didn't consider PPIs. > ... I'd like to look into how x86 uses this, and what other hypervisors may do in this > area. (another nightmare is supporting similar but different things for KVM, Xen, HyperV > and VMWare. I'm sure other hypervisors are available...) I'm not sure if any other hypervisor than KVM does it. Well, IBM's proprietary hypervisors do it, but only on POWER or s390. >> In fact it would be nice if >> SDEI_EVENT_COMPLETE meant "wait for synchronous page-in" while >> SDEI_EVENT_COMPLETE_AND_RESUME meant "handle it asynchronously". > > Sneaky. How does x86 do this? I assume there is a hypercall for 'got it' or 'not now'. > If we go the PPI route we could use the same. (Ideally as much as possible is done in > common code) It doesn't do it yet, but it is planned to have a hypercall to inform KVM of the choice. I explained to Gavin what the v2.0 of the x86 interface will look like, so that ARM can already do it like that and perhaps even share some code or data structures. Paolo _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel