Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1355500pxj; Wed, 19 May 2021 04:18:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIufKagXPKVbtDC7ENz8FHNXZE6v/ZNfVn+RF1YCkVK9Tv2+xYFJ6+jzNBzGiW0MSH5ndG X-Received: by 2002:a02:5289:: with SMTP id d131mr12413106jab.121.1621423139221; Wed, 19 May 2021 04:18:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621423139; cv=none; d=google.com; s=arc-20160816; b=fxAA6ZCnP0Dt3i4zcW8zCTKE57nI3VQJCi+LH2vhFk6f2cKmC650Voe+HVTW0Ri775 ecqJGLUBJ/T2e2+RSrK2eRkOfw1CFpy38iOwlRtO0D0XXaf1D4CibhG2tYB2jT5n+cpg pAstSWxf/Lwl8QH5KKgLgADSRv6qw5Omjpt6k7cZcD57MvnYHaYm/LwyiheTw46dL3TL rF5SrDjQaUMZ2rQSOwDPUmZLfORYifLVms9xveHbUVCtaWyNZeKntCnTBheSx4V64mG5 yBUAPY0HDwE9B3YXp+czxgzmL2Aj/dA7UtjVjnr3UDGrUwhZYufXCPdXN/i6XutxyZl/ hhrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=eiOP4WhukkqWvHIe+lpGPImxAkNhpIv8Q/xSjCssMYE=; b=hOn5uev63wvv8aDZ2a8yPtIoJRtiPegUpyS/6QQF9U6Eu2A56Xm8YiG88W+hhxWgU6 F9TSCpr7gU2nOOZDpGcp6MMyBP+QlAPlNu4w3AWlya2NbLBKeMkUSvfDbpLBI/CyCPSb 8rA5JFCaFMAnERrTwsQt9mMobEOEappne6rM6wdEFGqHTZzJBRKwbPSCpCK+5pXlr4qV qqWOi83L54MyUcCzhZjTt0BifULZqXisFLlXEGwfBFr8Fxk27AAxbgSjNiK6WUV5JHus 0GhKyDS+Rqgvg9LC/mGeWS9bX3FGYrn46oBdpCt14ORV22lN44GcSigiOYLicknpxV5L N5qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tfxl3LXo; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n3si30422024ioh.98.2021.05.19.04.18.46; Wed, 19 May 2021 04:18:59 -0700 (PDT) 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=@google.com header.s=20161025 header.b=tfxl3LXo; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346152AbhERCDE (ORCPT + 99 others); Mon, 17 May 2021 22:03:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235741AbhERCDE (ORCPT ); Mon, 17 May 2021 22:03:04 -0400 Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 683A5C061573 for ; Mon, 17 May 2021 19:01:46 -0700 (PDT) Received: by mail-io1-xd2a.google.com with SMTP id d11so7835065iod.5 for ; Mon, 17 May 2021 19:01:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=eiOP4WhukkqWvHIe+lpGPImxAkNhpIv8Q/xSjCssMYE=; b=tfxl3LXoKZOqzT25D2GmW0+3xhRoFtBHcapsoEUgP/Y+G+IIEd26DVi4XfSTMt/FFE CZdH1dKND7CZCr6KMu83xPt5UNz5++3PAuzjUBR1xSSRia6faT3U/sR7mnmJQUIpmO9a fm7tfJ2vVKDCgCeA5fQ2lOj79nZGfv9jv4Rihxkc8Jenn/IaTDtftEJSyDHTh+LkMbtM 04kZjdWbalMCbROilNT+Mv2OwxWvis3o0IQL32EbYQ9Fx/JMxSY93CWQ1E8H1L3Q8uVm IMIOseFJEsXXwiDeA0I1NVrmDH99Vjp7K5zMD+D3HeP2DhDoc/wQz+gQVN4blXZI8ZF9 qTvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=eiOP4WhukkqWvHIe+lpGPImxAkNhpIv8Q/xSjCssMYE=; b=MF5f6Oap1YgtzKgTCz8ANfsVpB0v+sfX+rRQphfnpgzyQn4+qY6Oy8d28Yp5g226NU ibzh86mO81m9abks6tyhYDxa3qhdBbI369r4c4jeL2vfuRIbWkgjGUR/EB3ITeVETE5v ffktyZdaoWl+R2EQ23QurEfZvV3SKX5/Me5wp1i4hHR+ZUdO+VS8hxhXdBOaN5ZikGdM s5Thf5+UcKSktn/UpYzb+FMXjq4Bt55iCQGtdFL/ISrYPRXY0AcSEJnnco4dq34UUYue ya0PQBh4uk2nnrjOaMr9G/8wVQ0524oWrataNMOdVdIS9tymQqP10eJIzskDIr+iyqWS ZPdg== X-Gm-Message-State: AOAM533G48GBo/79/s9s3Ol9E64g3Eb0I7AJnUa35E3EeoIqCKRPEzhN zlDE9Quo6i38quUxCmfoEXgGDwJFVLnOP7LC+bmauQ== X-Received: by 2002:a05:6638:b14:: with SMTP id a20mr2975623jab.132.1621303305671; Mon, 17 May 2021 19:01:45 -0700 (PDT) MIME-Version: 1.0 References: <20210513043441.GA28019@ashkalra_ubuntu_server> <7ac12a36-5886-cb07-cc77-a96daa76b854@redhat.com> <20210514090523.GA21627@ashkalra_ubuntu_server> <20210514100519.GA21705@ashkalra_ubuntu_server> In-Reply-To: <20210514100519.GA21705@ashkalra_ubuntu_server> From: Steve Rutherford Date: Mon, 17 May 2021 19:01:09 -0700 Message-ID: Subject: Re: [PATCH v2 2/4] mm: x86: Invoke hypercall when page encryption status is changed To: Ashish Kalra Cc: Borislav Petkov , Paolo Bonzini , Sean Christopherson , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Joerg Roedel , Tom Lendacky , X86 ML , KVM list , LKML , Venu Busireddy , Brijesh Singh Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 14, 2021 at 3:05 AM Ashish Kalra wrote: > > On Fri, May 14, 2021 at 11:34:32AM +0200, Borislav Petkov wrote: > > On Fri, May 14, 2021 at 09:05:23AM +0000, Ashish Kalra wrote: > > > Ideally we should fail/stop migration even if a single guest page > > > encryption status cannot be notified and that should be the way to > > > proceed in this case, the guest kernel should notify the source > > > userspace VMM to block/stop migration in this case. > > > > Yap, and what I'm trying to point out here is that if the low level > > machinery fails for whatever reason and it cannot recover, we should > > propagate that error up the chain so that the user is aware as to why it > > failed. > > > > I totally agree. > > > WARN is a good first start but in some configurations those splats don't > > even get shown as people don't look at dmesg, etc. > > > > And I think it is very important to propagate those errors properly > > because there's a *lot* of moving parts involved in a guest migration > > and you have encrypted memory which makes debugging this probably even > > harder, etc, etc. > > > > I hope this makes more sense. > > > > > From a practical side, i do see Qemu's migrate_add_blocker() interface > > > but that looks to be a static interface and also i don't think it will > > > force stop an ongoing migration, is there an existing mechanism > > > to inform userspace VMM from kernel about blocking/stopping migration ? > > > > Hmm, so __set_memory_enc_dec() which calls > > notify_addr_enc_status_changed() is called by the guest, right, when it > > starts migrating. > > > > No, actually notify_addr_enc_status_changed() is called whenever a range > of memory is marked as encrypted or decrypted, so it has nothing to do > with migration as such. > > This is basically modifying the encryption attributes on the page tables > and correspondingly also making the hypercall to inform the hypervisor about > page status encryption changes. The hypervisor will use this information > during an ongoing or future migration, so this information is maintained > even though migration might never be initiated here. > > > Can an error value from it be propagated up the callchain so it can be > > turned into an error messsage for the guest owner to see? > > > > The error value cannot be propogated up the callchain directly > here, but one possibility is to leverage the hypercall and use Sean's > proposed hypercall interface to notify the host/hypervisor to block/stop > any future/ongoing migration. > > Or as from Paolo's response, writing 0 to MIGRATION_CONTROL MSR seems > more ideal. > > Thanks, > Ashish How realistic is this type of failure? If you've gotten this deep, it seems like something has gone very wrong if the memory you are about to mark as shared (or encrypted) doesn't exist and isn't mapped. In particular, is the kernel going to page fault when it tries to reinitialize the page it's currently changing the c-bit of? From what I recall, most paths that do either set_memory_encrypted or set_memory_decrypted memset the region being toggled. Note: dma_pool doesn't immediately memset, but the VA it's providing to set_decrypted is freshly fetched from a recently allocated region (something has to have gone pretty wrong if this is invalid if I'm not mistaken. No one would think twice if you wrote to that freshly allocated page). The reason I mention this is that SEV migration is going to be the least of your concerns if you are already on a one-way train towards a Kernel oops. I'm not certain I would go so far as to say this should BUG() instead (I think the page fault on access might be easier to debug a BUG here), but I'm pretty skeptical that the kernel is going to do too well if it doesn't know if its kernel VAs are valid. If, despite the above, we expect to infrequently-but-not-never disable migration with no intention of reenabling it, we should signal it differently than we currently signal migration enablement. Currently, if you toggle migration from on to off there is an implication that you are about to reboot, and you are only ephemerally unable to migrate. Having permanent disablement be indistinguishable from a really long reboot is a recipe for a really sad long timeout in userspace.