Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1892413rwb; Fri, 28 Jul 2023 17:30:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlEIewNL7UwHd1MnnNbYf/OFiYXB7KF67wiQkKzeN+Qg+cZPBxvgR1XumgqXtxeCsQzVBfXQ X-Received: by 2002:a17:906:cc0b:b0:994:56d3:8a42 with SMTP id ml11-20020a170906cc0b00b0099456d38a42mr652733ejb.27.1690590612675; Fri, 28 Jul 2023 17:30:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690590612; cv=none; d=google.com; s=arc-20160816; b=qCSpMLDvbRz2OlA4zTlOw5mHNJGAxVKsWFJ6VgXHSfXxPcH3jxvbZ9YB3iv03OcYqk 1eaq+1rUFTexhHo6aw6+/LLWHyFKlPGYxaAoa0bTeRWBQCk3pPzCAz4q/0azrrY9iRbm lv8StsH5LTgq6Af49fcVwawwNnKy+ilbZ3Fsl50w5dCcXOTM7zZ6lZKfmGtlHK4L+Dzq 7xqETffi3u8wfT6ero6jUPpwEJdjYKOC6aKg0td0othw6K6pHzcpsZuGIG6+oph9FBBm K72pbEzEn4P1K8WB07PzhHKB1FthuLKH2BZTXmPEy93ojFBCeEfCnnmuRAlbftvf/mBb /qcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=rJg9MbukUkeAf25VcBnSvGPEfaUIyqqF94QJU8orhSY=; fh=JzLma3+Q/oWSYGfTBgu97+ae/1ATr+FW7o9ctdhoDw0=; b=KYmkmiBlP+85nr2SL1Jibgc4W0M3MPcBuxteohKJ24I9v3064OQMmwQu9StXzzsn4u 9XvKVzGHH76UzBOt7wA2FKUd7n9udMwA4unNWBfN0VsWIIx2RCi9B8/ROVfhS+yYeiKI e+BqLPZUSCXlr0O31a2fblgRjQmAfva5z7J08JwWX3WvgEUq7rR3Zw3FgymQxpMCJv7q bMZUW+u69Px9r49myNLfbKs9hj/YLD8PoU1z05pLxcdrx+LQKy0X7fzTdSaMdjSffPN1 Dn1ctnY9yhFDoU8hcbXRfYIaqdOOxH+6vpoQMdRQuELBpGsfEtfBpPVqUDfhVpbzDzr6 pjCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=Zp0GOXqU; 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 q22-20020a17090622d600b00992d262ff61si3502742eja.989.2023.07.28.17.29.48; Fri, 28 Jul 2023 17:30:12 -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=Zp0GOXqU; 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 S235833AbjG2ADh (ORCPT + 99 others); Fri, 28 Jul 2023 20:03:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbjG2ADg (ORCPT ); Fri, 28 Jul 2023 20:03:36 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D9D619BA for ; Fri, 28 Jul 2023 17:03:35 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1bba5563cd6so17061855ad.3 for ; Fri, 28 Jul 2023 17:03:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690589015; x=1691193815; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=rJg9MbukUkeAf25VcBnSvGPEfaUIyqqF94QJU8orhSY=; b=Zp0GOXqU9vAtanM7byzLEY1ZTAuQCQrnfrak1thKcFFHMBCZO/N4KqKDBd5I3kJffW Vh8ovzLtMVpv7R9tgjnJuitRPz0iowTqbSccpqb9sCrit8s8jZkHgE3EKWmaz9/YJybN uhR+1LBQ/EGKFm12kofvmo1N8Or8Mhd5I9QIxgAZxJjUnAncn/OfNQ+xg9V9rSfFrTW5 6+gyXWvxsDfod0XUAEoSS/aCS0HqakbjGuI1/I8BU2Uy6FDW2YJ6LrCVt60GU5GehRX5 3Ug/sPFW2Iawha4cKCkpfEtG9Mwjo7aL2M8Rz65tztUDm7ObzFqkZ6ozvUAWJtziwaLO +gKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690589015; x=1691193815; h=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=rJg9MbukUkeAf25VcBnSvGPEfaUIyqqF94QJU8orhSY=; b=X2EVzPDTNsPA5oAdZaFZvlMSzpvMiQJkkjWGRlKNahSM02CcljYm8xE3X/VyTA6TuS /zkylAaJVyWYtqsatxWBfUHy71hlAO1rtXnsOMJSkKsWSAbuecga/qPcBUmplS3mCW/W dAgRa+JkmH3SJwDUhlIvx2CJ//pVHGMT8f0kLDtvhoqOFQRvZ7PA1+pp+WhuB0XAr/Cm X54mv01hoBYLdJlvD3yduVfQ3a3TkSi6h9Euv1iwN+kYApfn1hNHdrwlLgG8niy1To0i ybB+OQrjCmR32DtxvFwO5iM8KVEYzL1ZguRLuVv+oOYNQvIWX9l+IwmGRoWA5hcx9hYp veMA== X-Gm-Message-State: ABy/qLa3zJvnxMLBTKg4WLt6lGLxHZ1efkxsUTeU7m00yIElo4c6vTjA eH4yYqvuoH4iuFp4m0G4xnNuwocak+8= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:c951:b0:1ae:6895:cb96 with SMTP id i17-20020a170902c95100b001ae6895cb96mr12864pla.5.1690589014804; Fri, 28 Jul 2023 17:03:34 -0700 (PDT) Date: Fri, 28 Jul 2023 17:03:33 -0700 In-Reply-To: Mime-Version: 1.0 References: <20230718234512.1690985-1-seanjc@google.com> <20230718234512.1690985-7-seanjc@google.com> Message-ID: Subject: Re: [RFC PATCH v11 06/29] KVM: Introduce KVM_SET_USER_MEMORY_REGION2 From: Sean Christopherson To: Quentin Perret 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@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, 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, linux-kernel@vger.kernel.org, Chao Peng , Fuad Tabba , Jarkko Sakkinen , Yu Zhang , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , Vlastimil Babka , David Hildenbrand , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" Content-Type: text/plain; charset="us-ascii" 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=ham 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, Jul 28, 2023, Quentin Perret wrote: > On Tuesday 18 Jul 2023 at 16:44:49 (-0700), Sean Christopherson wrote: > > --- a/include/uapi/linux/kvm.h > > +++ b/include/uapi/linux/kvm.h > > @@ -95,6 +95,16 @@ struct kvm_userspace_memory_region { > > __u64 userspace_addr; /* start of the userspace allocated memory */ > > }; > > > > +/* for KVM_SET_USER_MEMORY_REGION2 */ > > +struct kvm_userspace_memory_region2 { > > + __u32 slot; > > + __u32 flags; > > + __u64 guest_phys_addr; > > + __u64 memory_size; > > + __u64 userspace_addr; > > + __u64 pad[16]; > > Should we replace that pad[16] with: > > __u64 size; > > where 'size' is the size of the structure as seen by userspace? This is > used in other UAPIs (see struct sched_attr for example) and is a bit > more robust for future extensions (e.g. an 'old' kernel can correctly > reject a newer version of the struct with additional fields it doesn't > know about if that makes sense, etc). "flags" serves that purpose, i.e. allows userspace to opt-in to having KVM actually consume what is currently just padding. The padding is there mainly to simplify kernel/KVM code, e.g. the number of bytes that KVM needs to copy in is static. But now that I think more on this, I don't know why we didn't just unconditionally bump the size of kvm_userspace_memory_region. We tried to play games with unions and overlays, but that was a mess[*]. KVM would need to do multiple uaccess reads, but that's not a big deal. Am I missing something, or did past us just get too clever and miss the obvious solution? [*] https://lkml.kernel.org/r/Y7xrtf9FCuYRYm1q%40google.com