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 35ABEE81DF1 for ; Fri, 6 Oct 2023 12:47:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232123AbjJFMrm (ORCPT ); Fri, 6 Oct 2023 08:47:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231603AbjJFMrm (ORCPT ); Fri, 6 Oct 2023 08:47:42 -0400 Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0DC6CF for ; Fri, 6 Oct 2023 05:47:39 -0700 (PDT) Received: by mail-yb1-xb2c.google.com with SMTP id 3f1490d57ef6-d81f079fe73so2396468276.3 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=Ef8GOyJcnoXhTQR1EnHL31K8qZT4pxpdtcyzmFDB+Bu7Ge47vnir9pwM03GOGCliya DNs1IvY0kPBBgEeLxOptOdY+AZDV0skg0/bftvHzzgJZf1SnZTNYLCur6cqBSfxb/DQr qxGo8FUNtf4SlLympv/GCcg/25r1PfSmTyF4+s0ysmM1gwNUGRlri6CQzeM/88lNiFeQ TXLm69z36Evcm/MZnvI1rM8m+I4YshSNRBv6qygoyTUD9RYbLWY5UD/SCjPPavVmBqrw Oy5b+5NgoQ+gn11dIM3NDor/9GNbHbLtOziJZMtdjQgGajnN6zmDBMQnJBgU3V5Mv0Tn yIQQ== X-Gm-Message-State: AOJu0YwbTmlhZeaOqmldno7vsRppPzVD6v+2LMQIHOh2uKQ8WuCesdU7 dwkP357RyudOVKWd0zTsjShJkdMiTeEL6gBM/zHy/Q== X-Google-Smtp-Source: AGHT+IGILgsJf+f8eayHVHqX0rISrGr9tP06v0nLvKR1oTcr5riaw9zUWCGoAJpDUWeKMDK50UY6pLVZ+E+8O7Aw+dY= 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 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org 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