From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A5B7C7EE22 for ; Fri, 5 May 2023 17:31:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232648AbjEERbU (ORCPT ); Fri, 5 May 2023 13:31:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232583AbjEERbS (ORCPT ); Fri, 5 May 2023 13:31:18 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 204251A1F9 for ; Fri, 5 May 2023 10:31:17 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-5187bd3d365so1434211a12.3 for ; Fri, 05 May 2023 10:31:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683307876; x=1685899876; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=qAOxuvlzoNXvPjKXSolx+GWj91lIdWlZPd2J+lepu+A=; b=YajfbfW6/wtHmrsLEvn1JkH+xI6N003d6IHsKYEdYKyQ4XBOf/ltXYAA8TT//7kx7h 8wJuT8QRTxgAHxrmJYouhI/7YgQTZm4mO10KjPCgeJdJMeuE5+h/bLiahSr81Gm/ecKB zDx4TcPrzUJvkSrnc51y29YU+lehMTLTirJ8zF6Y7AvgQTUcfYtQ37OJnKLDHV7h0smL PJn351waqBTnvLrthFCgyYl4ojqlUIUMdMZ9mvD3/1gMVpPtasu86bb2kRnLpCKWJhO/ k73RbTIykvnJHtRsAnnJa8Km60QZxDXHqCZ+6V04mHM7fIYa6vKKdRMKt3CdepgXl1bi CXtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683307876; x=1685899876; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=qAOxuvlzoNXvPjKXSolx+GWj91lIdWlZPd2J+lepu+A=; b=fj7vw1xqnq7s01ysdAyfjHdczanextI5TP5VGRMUcnvALjcwjIDmaQk3PSt0WFY4gG YEx2mXrDlAranDUeDekTSiJyYDo+ZdAizCUjpC7gXOV2OQDifvk7HeWoV9Opw9fygmmy nqk1sO2NcjLWceC6P4d0jjDvli8/WTDqz8kcSZ6/Sndn4s2wAHlRyVMBNMOl1g3TkiBY XJNfKNEN5zQOZ/RLB0h4l1Pjqd67Zzq1iQj+A+alByQM34DSHtK74RCa56Kx0prgDH9E F5GfrTC8M1A0dVZJSjNObArD1m+xFmxUs2crYP+8RIX/xZxgRuzWSsHGDVEQIDpEVcfX DRMQ== X-Gm-Message-State: AC+VfDxmDm/9euw/Cpy+KisgDtWu/nJ3ck4ERHmLHeT7WU/p8XpACvQR NnC5yrFvLmqtTPudoVDxVwYlBRSjzTs= X-Google-Smtp-Source: ACHHUZ5AKtrEhFxY1tyiq165vY9w3gn7Qqc7+wcBsvMx8OszEeBENNSnTQn/dNy8sL8BRZ1pG6YlJeRQjuk= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:152:0:b0:52c:407a:2279 with SMTP id 79-20020a630152000000b0052c407a2279mr529292pgb.0.1683307876644; Fri, 05 May 2023 10:31:16 -0700 (PDT) Date: Fri, 5 May 2023 10:31:15 -0700 In-Reply-To: <6412bf27-4d05-eab8-3db1-d4efa44af3aa@digikod.net> Mime-Version: 1.0 References: <20230505152046.6575-1-mic@digikod.net> <20230505152046.6575-3-mic@digikod.net> <6412bf27-4d05-eab8-3db1-d4efa44af3aa@digikod.net> Message-ID: Subject: Re: [PATCH v1 2/9] KVM: x86/mmu: Add support for prewrite page tracking From: Sean Christopherson To: "=?iso-8859-1?Q?Micka=EBl_Sala=FCn?=" Cc: Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Ingo Molnar , Kees Cook , Paolo Bonzini , Thomas Gleixner , Vitaly Kuznetsov , Wanpeng Li , Alexander Graf , Forrest Yuan Yu , James Morris , John Andersen , Liran Alon , "Madhavan T . Venkataraman" , Marian Rotariu , "Mihai =?utf-8?B?RG9uyJt1?=" , "=?utf-8?B?TmljdciZb3IgQ8OuyJt1?=" , Rick Edgecombe , Thara Gopinath , Will Deacon , Zahra Tarkhani , "=?utf-8?Q?=C8=98tefan_=C8=98icleru?=" , dev@lists.cloudhypervisor.org, kvm@vger.kernel.org, linux-hardening@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, qemu-devel@nongnu.org, virtualization@lists.linux-foundation.org, x86@kernel.org, xen-devel@lists.xenproject.org Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org On Fri, May 05, 2023, Micka=EF=BF=BDl Sala=EF=BF=BDn wrote: >=20 > On 05/05/2023 18:28, Sean Christopherson wrote: > > I have no doubt that we'll need to solve performance and scaling issues= with the > > memory attributes implementation, e.g. to utilize xarray multi-range su= pport > > instead of storing information on a per-4KiB-page basis, but AFAICT, th= e core > > idea is sound. And a very big positive from a maintenance perspective = is that > > any optimizations, fixes, etc. for one use case (CoCo vs. hardening) sh= ould also > > benefit the other use case. > >=20 > > [1] https://lore.kernel.org/all/20230311002258.852397-22-seanjc@google.= com > > [2] https://lore.kernel.org/all/Y2WB48kD0J4VGynX@google.com > > [3] https://lore.kernel.org/all/Y1a1i9vbJ%2FpVmV9r@google.com >=20 > I agree, I used this mechanism because it was easier at first to rely on = a > previous work, but while I was working on the MBEC support, I realized th= at > it's not the optimal way to do it. >=20 > I was thinking about using a new special EPT bit similar to > EPT_SPTE_HOST_WRITABLE, but it may not be portable though. What do you > think? On x86, SPTEs are even more ephemeral than memslots. E.g. for historical r= easons, KVM zaps all SPTEs if _any_ memslot is deleted, which is problematic if the= guest is moving around BARs, using option ROMs, etc. ARM's pKVM tracks metadata in its stage-2 PTEs, i.e. doesn't need an xarray= to otrack attributes, but that works only because pKVM is more privileged than= the host kernel, and the shared vs. private memory attribute that pKVM cares ab= out is very, very restricted in how it can be used and changed. I tried shoehorning private vs. shared metadata into x86's SPTEs in the pas= t, and it ended up being a constant battle with the kernel, e.g. page migration, a= nd with KVM itself, e.g. the above memslot mess.