Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp355612rdb; Fri, 6 Oct 2023 05:48:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMYHkCDMoQxo6ify4B3gaUzvhRNbZvgwCzpJNEbEe5M7kDiks/RljDN6qPeVRiRthnDx+k X-Received: by 2002:a05:6e02:1c4d:b0:34b:ac73:eb97 with SMTP id d13-20020a056e021c4d00b0034bac73eb97mr10178075ilg.14.1696596487278; Fri, 06 Oct 2023 05:48:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696596487; cv=none; d=google.com; s=arc-20160816; b=benIpqNtHE2vU1rTZpLfpuE/wePLugurM8Vdmvlq44bXZq7HYohTxQhXYQeN/BclXB Iw9UDoHqgOVXQjsr6VHhyCjwYTfsfaFX+3Tn9Gcv9ygMOmrEH4GfbNOQBg68zr5fDXxY Yqr1ww5MYTdN2v+16T/9Cvrk+IZxvraEYLfUuSzldTSdOFbhEm/jVtavopHGeUtVkHH3 SIhC30PZACF1QuZyxHBVvPAj1wcJ4WU3s7a3MKfEAA+nnJWaEIrF4wP7GrPN2Asas+ce c1U3PECqZ0JQe027rY/Yx4WJl1qYfIfS0qYiRMf6raCDSIcPWqEuDCEUM/RQO1TeT9yf Jdqw== 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:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=kE5lcMpcuRWxeOB9S6L9Si7YaWv5hLYl1VeNlBZzT/8=; fh=vqefJevMRAXqpurEcObFcP/cMRxXOwAblaJBkrAOc4M=; b=mrJmD8lo2p/PZPFUouwt4lAUzH8PxDzJQm7f/SqKgAJue82bWyEfyq85OSKIi10hjK riMnEtH4qgxPFUXA0QWEpSgXMbuD/Eo1eoFpIrhjFxVIlxf7yZo28TNQqVaAwUHYRhKi ilIOzmXRloix9QPo6lNDU7p6K7Ijj1YvTap05bMil5QNz7aBHwr1Y5zVzDUDhee5kvkS h9x15d3k935+MgYpS9DAXk0SV0wvmQdeNcb/j+J2i2CxEamGrl3N/T1c0oD7471+vcvz //oOwZmC1Ax++hrpB4ZPTq6rB5HHtohsoJzQqCvwBLJCh/Si1X+jDPe3750G8otpbEfS xVDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=wXitWH63; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id w190-20020a6382c7000000b00577bf1de778si3605784pgd.585.2023.10.06.05.48.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 05:48:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=wXitWH63; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 1A8C680A1363; Fri, 6 Oct 2023 05:48:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232159AbjJFMrn (ORCPT + 99 others); Fri, 6 Oct 2023 08:47:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232046AbjJFMrl (ORCPT ); Fri, 6 Oct 2023 08:47:41 -0400 Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0C92CE for ; Fri, 6 Oct 2023 05:47:39 -0700 (PDT) Received: by mail-yb1-xb33.google.com with SMTP id 3f1490d57ef6-d868d8363e6so2389667276.2 for ; Fri, 06 Oct 2023 05:47:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696596459; x=1697201259; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=kE5lcMpcuRWxeOB9S6L9Si7YaWv5hLYl1VeNlBZzT/8=; b=wXitWH63YyQNrPPne4or1YDsmFgI2V8pRMPSMT6yXVEdd/leOukdoJiEdLKrL+7aag zoga0bm8D+JRbO8cZmC9DSGJSgd/fFZSGCQJApcWPuHk2kA9MES1gm2V8pdNW7h6g651 vmxjn7YuHleZhMefL4xVonsLKfAlMhXpOuUmzj4OvRdDoqiglD6jSVEtAPZ7rSn9fM41 T0/Iq2DJZ1x8sI/PwN7cFQQfSyDzOXGCs/lFBcDIURojuB+25CxbAyYS2oZfhdxXnOrL XZUhW1H4GpAboykPvZxM6DGZytw7ITTziMMurbnnOX7V2/FMNAvDXc1zioGobpuap4qK v47A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696596459; x=1697201259; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kE5lcMpcuRWxeOB9S6L9Si7YaWv5hLYl1VeNlBZzT/8=; b=MePnXzO4iw8RS5/BO3aVv14CWlOmjyT8A2w6/oLRTDhGwO+MS1js2QPwSy94hrv0RF 0OW0Y6zWY7NC1qOPJh018H1dl39xMXklFVjjoy20zJLcvMl74F5GSy2trVrrH7oXv+Y/ Tth9WeIp69tZMhgKvyk4ugxNPNkF5pXIIdlskcDEEBLI37cosKzvvHJW8vvaWvPNAkDO 27uv2gsw4bt5U2EymEl/EteikXlMeXGyLcr3me04kFalX3fJGUprZa2MH3Gg6uqOw5QK Fn1XBxGxG8LBkse3H+9GxOyGlh8zDgbPicITitXvZ7Tu3RMRgoRNAHyBP3INzjei2M2+ Azew== X-Gm-Message-State: AOJu0Yy8Z8xX8XsQcC9Ak3L7EMcaSv85Fm3ufwEzJKginPai3bAt4K1d aULqvyCby5BYj54FuQQMfjPBAwCdBX9Q9F+mQen3jQ== X-Received: by 2002:a5b:807:0:b0:d47:8db3:8bcf with SMTP id x7-20020a5b0807000000b00d478db38bcfmr7283393ybp.49.1696596458614; Fri, 06 Oct 2023 05:47:38 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Fuad Tabba Date: Fri, 6 Oct 2023 13:47:01 +0100 Message-ID: Subject: Re: [RFC PATCH v12 11/33] KVM: Introduce per-page memory attributes To: Sean Christopherson Cc: Paolo Bonzini , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , "Matthew Wilcox (Oracle)" , Andrew Morton , Paul Moore , James Morris , "Serge E. Hallyn" , KVM , "moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)" , KVMARM , LinuxMIPS , linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, open list , Chao Peng , Jarkko Sakkinen , Anish Moorthy , Yu Zhang , Isaku Yamahata , Xu Yilun , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 06 Oct 2023 05:48:04 -0700 (PDT) Hi Sean, On Fri, Oct 6, 2023 at 4:21=E2=80=AFAM Sean Christopherson wrote: > > On Thu, Oct 05, 2023, Fuad Tabba wrote: > > Hi Sean, > > > > On Tue, Oct 3, 2023 at 9:51=E2=80=AFPM Sean Christopherson wrote: > > > > Like I said, pKVM doesn't need a userspace ABI for managing PRIVATE= /SHARED, > > > > just a way of tracking in the host kernel of what is shared (as opp= osed to > > > > the hypervisor, which already has the knowledge). The solution coul= d simply > > > > be that pKVM does not enable KVM_GENERIC_MEMORY_ATTRIBUTES, has its= own > > > > tracking of the status of the guest pages, and only selects KVM_PRI= VATE_MEM. > > > > > > At the risk of overstepping my bounds, I think that effectively givin= g the guest > > > full control over what is shared vs. private is a mistake. It more o= r less locks > > > pKVM into a single model, and even within that model, dealing with er= rors and/or > > > misbehaving guests becomes unnecessarily problematic. > > > > > > Using KVM_SET_MEMORY_ATTRIBUTES may not provide value *today*, e.g. t= he userspace > > > side of pKVM could simply "reflect" all conversion hypercalls, and te= rminate the > > > VM on errors. But the cost is very minimal, e.g. a single extra ioct= l() per > > > converion, and the upside is that pKVM won't be stuck if a use case c= omes along > > > that wants to go beyond "all conversion requests either immediately s= ucceed or > > > terminate the guest". > > > > Now that I understand the purpose of KVM_SET_MEMORY_ATTRIBUTES, I > > agree. However, pKVM needs to track at the host kernel (i.e., EL1) > > whether guest memory is shared or private. > > Why does EL1 need it's own view/opinion? E.g. is it to avoid a accessing= data > that is still private according to EL2 (on behalf of the guest)? > > Assuming that's the case, why can't EL1 wait until it gets confirmation f= rom EL2 > that the data is fully shared before doing whatever it is that needs to b= e done? > > Ah, is the problem that whether or not .mmap() is allowed keys off of the= state > of the memory attributes? If that's so, then yeah, an internal flag in a= ttributes > is probably the way to go. It doesn't need to be a "host kernel private"= flag > though, e.g. an IN_FLUX flag to capture that the attributes aren't fully = realized > might be more intuitive for readers, and might have utility for other att= ributes > in the future too. Yes, it's because of mmap. I think that an IN_FLUX flag might work here. I'll have a go at it and see how it turns out. Thanks, /fuad > > > One approach would be to add another flag to the attributes that > > tracks the host kernel view. The way KVM_SET_MEMORY_ATTRIBUTES is > > implemented now, userspace can zero it, so in that case, that > > operation would need to be masked to avoid that. > > > > Another approach would be to have a pKVM-specific xarray (or similar) > > to do the tracking, but since there is a structure that's already > > doing something similar (i.e.,the attributes array), it seems like it > > would be unnecessary overhead. > > > > Do you have any ideas or preferences? > > > > Cheers, > > /fuad