Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1221050rwr; Fri, 5 May 2023 10:44:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7h+eQYGEk9DTTOOiw8ZC72vm2lX+QGx1rRM0jJSRZ33Sr09ogNc/qK6UHnq8Rq+CPk/Ak2 X-Received: by 2002:a17:903:294d:b0:19d:1834:92b9 with SMTP id li13-20020a170903294d00b0019d183492b9mr2108261plb.56.1683308664029; Fri, 05 May 2023 10:44:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683308664; cv=none; d=google.com; s=arc-20160816; b=ZffBlCTx8MrRY3L5MBKDBDPaIv7iPHKeuyrvvKTlMfEFDibFshHFFvTh+kI/rRZ008 vkffgrwT2UCFq2OTxYKbCoA0kq8VWg67DW1/NGr572/nehs43P3AMO+2qoCACLcVEW97 AWUZJ53ktP4LjRPzxtINHndxdSNSwCeyQRx8RLj/z29ElniMs7M5tYx0dLMNBrRY0S+I KbEvqM4RajMrcIwNcv+qkfHOWJJ7Xk7+pn47PIePmz94FG+V5/KbNnlwOS4Da04NnFfc NvAQuQAPnDk/y3RrsVD5YaNocD4QhbQ/sdosZYy6SMPlV6y94tl1BXkZ0CUGioCmZmMe zitg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:dkim-signature; bh=qAOxuvlzoNXvPjKXSolx+GWj91lIdWlZPd2J+lepu+A=; b=hTyUq4LuPhehlJP3SUV9UUhqbqLNgEL2zwY/i+U1d6A1+aZkzHKztp8Crx2/v99V6A OOa/K8XPbWePAAqXyZHXFdu+kczKulrX+2PF0vJqCG4mEF29jYi2Q+G9bR/uHOJCzS/R eNhsqqLNkVwuTmIUqMHRLdwhzCclTaiNowXPCTYFoMOYUfN1ESQT++my3BDFaqrzCozJ XY4PAO7wCBMUtj/JWDFlkjX6JFI+hFSqCLjrqosx2JjjMnZmYlt64s/wHnX9oVjhu6CU 9rvdMdL1as1JHc08LLVKDGDnImD1flHrDpD1/okDfdXIPBUh6beH5Cth49fCvqoVG+bu v1lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=YajfbfW6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f16-20020a170902ce9000b001a99ace3e76si2268325plg.554.2023.05.05.10.44.07; Fri, 05 May 2023 10:44:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=YajfbfW6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232769AbjEERbe (ORCPT + 99 others); Fri, 5 May 2023 13:31:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232576AbjEERbS (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 216261A1FE for ; Fri, 5 May 2023 10:31:17 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-52c7ac1abdeso1447320a12.0 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=i1MForm476Y72etTJ0wU8mkyqqFFB4xJ1SXajgRFKHqUirk1RnrEecVeltbDogDZ1f AKm+CX5Gywq7nrfJAcMwo18paPhhGPurjvsglZxkjbMrf83iW/qQ9wxU+oj+zO+V/u9h p509AC+GvkxPdJJAFizxv6mG6HEdU0T+tEK1ifvdt40xZ+xuevUo3o8FzRNVAzksEuMJ u3QqF2A2/2BIH91Jqc+DX2uJlwj32LYcBOUbGO4IYDaeEsOo0dHkVbmrtRm8kERg2l29 ie+IM02jSIpdlLqOmmPnkfSXNy56jns18/+U3MLrKNWmF4vbLKTmyQV5lylADYpZzKNt xq7Q== X-Gm-Message-State: AC+VfDyjrbT82CvNXeLDS8Ftc51K1Xjg/ud4ADPft+7Wvqo0kzbPfN2R ZGpl1qiedO4FrGupsDIwrNsKgtYQU+o= 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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.