Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp2932096pxy; Mon, 3 May 2021 11:09:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyf5ifQXXYdKyrybtX21dv0geiQfDzuNEklj0ytFP/lFEB/n4zF1A5VqNZ8HcwxYEk9yMBO X-Received: by 2002:a17:902:e84f:b029:ee:cd36:80e3 with SMTP id t15-20020a170902e84fb02900eecd3680e3mr9059793plg.70.1620065380505; Mon, 03 May 2021 11:09:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620065380; cv=none; d=google.com; s=arc-20160816; b=Qhf02S4DTUvlQd3ztFNK3HUhDbnpMsa+MMgGGKYUJlVzkiAvbYQml17wMTT25jLkz8 cVfgQZrWYuYqMyEt8xh/8e7nxDxDZnvECr8wYxoDAbvGT8fF+JozA7oQWUgI5NylHTHI 5DBA2ZsrgzmtHDR4nAk8ua3rstf7H56neFVYnsI5TGGWjswy0Y/mpDbFZere1UUPqe/m bXV/v0Dn0fZxtXXGfsSIbyXHX5LXupBk3VMLOD4inYFy6h3ITfUeAxSp00HA4N0Rtgde wbiWbI6m9OGuQ0sEFGsUt4CM0lcoWHss1PBgq0q965IFHYgrQbQct8ZyFCXkau8nqLNB P4pQ== 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=PevSHnc5jjCQDQYzFPPCqCavVt5SA0QJb/1sUXMAvpA=; b=h0mnPXnhwE8Yqa3JaZ9XARZ/p0NNFXER+grx6BJst+34MjUIwbtQczHqsj9XwLtBqH uv/GAggCF8oNRV9+L8d+uv50NKmfLt2jOaDNH90OYKDOry2mpnMO2u7r3cwlShtYTf35 p7NqPVP3Fh1LjRc8hSJG3KX+8wN94OPRJuCavLw6bz03ttNJlr1HH8kbhlT9MHfBEOJK j/DmbcGrtdqi3XE7tU+3h09sBQ6asPZvAgVyD01Mt7OJkHxPVF4W2tCKusv+dECPyBJt Euo7rmq7dr72Acuro5V3dyG0KqRmBhYTKr6zcNZIRwZ7uH3Dcm90gUJ0bDyfT4tabL4l e7fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="p/pcCk1O"; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b11si423887pgw.248.2021.05.03.11.09.26; Mon, 03 May 2021 11:09:40 -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=@kernel.org header.s=k20201202 header.b="p/pcCk1O"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230185AbhECPEu (ORCPT + 99 others); Mon, 3 May 2021 11:04:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:42622 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230184AbhECPEt (ORCPT ); Mon, 3 May 2021 11:04:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5068D6127A for ; Mon, 3 May 2021 15:03:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620054235; bh=ln+8BofV7Gh4bD8EraABi30+kOtgmTS6KtlBAWP07u8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=p/pcCk1Owl9SAKIf4zZn16m79oUf5KJA8G6Tm/q0sT7O0rGMXwetz1Q8eQEI/CBfQ DOHo2vsd6EMNYMK/jba+J2xzuHo5DrOIkkoBFp+DY2TUUvFRJcysALBk5b6hw/xvb0 7GXm/9gB737FdWTk7h6mP6l84J3Za7xx8ukbniXhVWGhdMJsGIlAv8Z+Lf4S0DORdQ cGtN9osHnMAK6lHsSzZ+qkRr7YEYtkned3Cj5xIazsMB+dMnvqeaTzrU5Mv7EkJx27 9XgkVxiaxpvzSmwfIzdsBqdMfZKO0w+KZ4UQOMe0rSaWPJbGIwiK2gT2zrdLyrO4gX jGITTz2nTmFZw== Received: by mail-ed1-f45.google.com with SMTP id b17so3628892ede.0 for ; Mon, 03 May 2021 08:03:55 -0700 (PDT) X-Gm-Message-State: AOAM532PaRrlixaEkMA61zAbrL/Sso4SIx2JDa4LJAAYWmgTy5iyEcm7 gvQZ9B6IX6Dy2AOJ4ijcgkWSu2yt0lnonjOudTbkwQ== X-Received: by 2002:a05:6402:17b0:: with SMTP id j16mr20168200edy.97.1620054233726; Mon, 03 May 2021 08:03:53 -0700 (PDT) MIME-Version: 1.0 References: <20210430123822.13825-1-brijesh.singh@amd.com> <20210430123822.13825-11-brijesh.singh@amd.com> In-Reply-To: From: Andy Lutomirski Date: Mon, 3 May 2021 08:03:42 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH Part2 RFC v2 10/37] x86/fault: Add support to handle the RMP fault for kernel address To: Dave Hansen Cc: Brijesh Singh , X86 ML , LKML , kvm list , Thomas Gleixner , Borislav Petkov , Joerg Roedel , Tom Lendacky , Paolo Bonzini , Ingo Molnar , David Rientjes , Sean Christopherson , Peter Zijlstra , "H. Peter Anvin" , Tony Luck Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 3, 2021 at 7:44 AM Dave Hansen wrote: > > On 4/30/21 5:37 AM, Brijesh Singh wrote: > > When SEV-SNP is enabled globally, a write from the host goes through the > > RMP check. When the host writes to pages, hardware checks the following > > conditions at the end of page walk: > > > > 1. Assigned bit in the RMP table is zero (i.e page is shared). > > 2. If the page table entry that gives the sPA indicates that the target > > page size is a large page, then all RMP entries for the 4KB > > constituting pages of the target must have the assigned bit 0. > > 3. Immutable bit in the RMP table is not zero. > > > > The hardware will raise page fault if one of the above conditions is not > > met. A host should not encounter the RMP fault in normal execution, but > > a malicious guest could trick the hypervisor into it. e.g., a guest does > > not make the GHCB page shared, on #VMGEXIT, the hypervisor will attempt > > to write to GHCB page. > > Is that the only case which is left? If so, why don't you simply split > the direct map for GHCB pages before giving them to the guest? Or, map > them with vmap() so that the mapping is always 4k? If I read Brijesh's message right, this isn't about 4k. It's about the guest violating host expectations about the page type. I need to go and do a full read of all the relevant specs, but I think there's an analogous situation in TDX: if the host touches guest private memory, the TDX hardware will get extremely angry (more so than AMD hardware). And, if I have understood this patch correctly, it's fudging around the underlying bug by intentionally screwing up the RMP contents to avoid a page fault. Assuming I've understood everything correctly (a big if!), then I think this is backwards. The host kernel should not ever access guest memory without a plan in place to handle failure. We need real accessors, along the lines of copy_from_guest() and copy_to_guest().