Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4705622rwo; Tue, 25 Jul 2023 09:44:16 -0700 (PDT) X-Google-Smtp-Source: APBJJlGPSiElcGBCkMQRUWklNiWUaNIDEy62RUlzTpGlZ47soiL0mz/IPPPOQZ8Gcwo10KDl4wga X-Received: by 2002:aa7:d295:0:b0:522:2af1:1ffe with SMTP id w21-20020aa7d295000000b005222af11ffemr5931487edq.9.1690303456550; Tue, 25 Jul 2023 09:44:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690303456; cv=none; d=google.com; s=arc-20160816; b=y9D0RcMRaxocFejNQ4riS5jbpKEBX27AClwFIvcm8PFaLmUKs2HPbV6rMnbwrtfOa3 g54fQUURkmVBOHNiUVJmB9b2Q9sTE7hBZT4fPqpDGf5ZdSYSEB0pK12AH8cv1PuMFzTH Wy+K1u40ynttA3mW9yIHAqxSJ9R0qll7yPHdTgJCRiA92JV89N1p1H8P2EOwuZr2yKPF sI0i0O1FcI1KvRh7FIrMhGx8WW9vvfrwfBBUGCxFQP9n7l4cQfCeyxpj6yiTSrAYq75P DDTKY52NO3ZXsMjDJgRzxgpTIFZuqW+9dBZUBM16TNeRlevbXr0jkf/mJr1eIu5qAb9B BBCQ== 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=JzfMU5Qs8JliFSPK4e1C5em4CWxZCGfzp6e2iymS9Yg=; fh=C56i82F3TMLIsiDGJOQzySniAXUS/vxM5LwrrbE1HpI=; b=bqaHzUTiooErDtymQXSofg1BRPkXUrtUiWD/Tf5WTwCTD4eAd6Kp8t2SBxpiMqxsYZ 4xsDppJabTvWTdbox2uPkxqi8G2O1KaacNZM/1/KFUePouOz4pAHCV7YUjnO9WRQDN4j bK4aYN+5dh2Fj4whx11YrjH+6lDVOnIgHAPSNFsa0MFed1VdbTpxt3MwsVWWPbf9QWW4 5AJut8Py8i7N3yyBoMnx8jlLwVk8Zve7skkzbFNRZwrkvsNnIQMUPW+EkBRRRHw6OvnV vMVN2PN8+U26LruJueHPYdqfyKUSfXzaDPXUksov/K763ZmnHZcOlUkR83rcRSo4d0Ah RZ/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=dW59zwmr; 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 bf24-20020a0564021a5800b005221f404a63si4557384edb.380.2023.07.25.09.43.52; Tue, 25 Jul 2023 09:44:16 -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=dW59zwmr; 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 S231945AbjGYQE1 (ORCPT + 99 others); Tue, 25 Jul 2023 12:04:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230104AbjGYQEO (ORCPT ); Tue, 25 Jul 2023 12:04:14 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00957211E for ; Tue, 25 Jul 2023 09:04:01 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-583c49018c6so43734967b3.0 for ; Tue, 25 Jul 2023 09:04:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690301041; x=1690905841; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=JzfMU5Qs8JliFSPK4e1C5em4CWxZCGfzp6e2iymS9Yg=; b=dW59zwmrsLAamcGnirE6A1LfKT51T61DtWDAOhx4/cSvK3sOAiDmr+BlK4XiPthtzP CN9MlQi3HhBVcH71uuUqq+M14CfwGnGPEE/BpfevOBdEFKHG7J0iaICViLaRAky8BhEp HFcQ65KDccgqhPQn/ChYInnlcEfq7qr0Ma/Jgkr7SmWI+05vO/bEbUCWl8Rn7I2emovI UeVOyMZohBruEuz8fBipp3NgVzf/qbnB/hnqT0XX1CDCZ3KOl7DJQE2yXx50QpLL6+Az IlluRAj7yyIarMAgzXmFlQrKZdiqjqFyPfBBVM/tbJmItA4hkVu10uPsnU/tUYfyPMpN N63Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690301041; x=1690905841; 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=JzfMU5Qs8JliFSPK4e1C5em4CWxZCGfzp6e2iymS9Yg=; b=C3KmMidnrOXpWwyj+i4niM0g/yX5F/89QVq/aa+riykQYcrI5xogwqu4skzWLaYZ3t 11s+2ayfgGi4go5ZFZaJ2SQxDiI2cHvWnSw6nRy8ll4OSclNiCWQCf4gSpghgPne6h1q +McYltmfrWqDTBFzJN9c1QQkrsGuPGoPcn+bgejl4k0Hjk9jFvAwGxfzughuje623NGO 1CyvWEWUm4iZlgSzBNOjpkD+uc7/jRl2WWT562klEfWOtWyckt1LMudRpjtQtQ53y7iN kbg/P/Kr6HBInUkS8JIQ0M6Q4AV4cl0+eNLBd0vZJsBB6Cw2r2NMqDm8ae2MDfOe3lv2 UrZA== X-Gm-Message-State: ABy/qLaWoDUwRhgnvY4rr6o79ggvHaX/wmLRX8sibbTXlZ+ysRC9BCK5 14cV9n56whHNUdicOPpA+q3CXnq8QXw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:46d4:0:b0:cf9:3564:33cc with SMTP id t203-20020a2546d4000000b00cf9356433ccmr81585yba.13.1690301041144; Tue, 25 Jul 2023 09:04:01 -0700 (PDT) Date: Tue, 25 Jul 2023 09:03:59 -0700 In-Reply-To: Mime-Version: 1.0 References: <20230718234512.1690985-1-seanjc@google.com> <20230718234512.1690985-13-seanjc@google.com> Message-ID: Subject: Re: [RFC PATCH v11 12/29] KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory From: Sean Christopherson To: Wei W Wang 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 , Quentin Perret , Michael Roth , 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 Tue, Jul 25, 2023, Wei W Wang wrote: > On Wednesday, July 19, 2023 7:45 AM, Sean Christopherson wrote: > > +int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, > > + gfn_t gfn, kvm_pfn_t *pfn, int *max_order) { > > + pgoff_t index = gfn - slot->base_gfn + slot->gmem.pgoff; > > + struct kvm_gmem *gmem; > > + struct folio *folio; > > + struct page *page; > > + struct file *file; > > + > > + file = kvm_gmem_get_file(slot); > > + if (!file) > > + return -EFAULT; > > + > > + gmem = file->private_data; > > + > > + if (WARN_ON_ONCE(xa_load(&gmem->bindings, index) != slot)) { > > + fput(file); > > + return -EIO; > > + } > > + > > + folio = kvm_gmem_get_folio(file_inode(file), index); > > + if (!folio) { > > + fput(file); > > + return -ENOMEM; > > + } > > + > > + page = folio_file_page(folio, index); > > + > > + *pfn = page_to_pfn(page); > > + *max_order = compound_order(compound_head(page)); > > Maybe better to check if caller provided a buffer to get the max_order: > if (max_order) > *max_order = compound_order(compound_head(page)); > > This is what the previous version did (restrictedmem_get_page), > so that callers who only want to get a pfn don't need to define > an unused "order" param. My preference would be to require @max_order. I can kinda sorta see why a generic implementation (restrictedmem) would make the param optional, but with gmem being KVM-internal I think it makes sense to require the param. Even if pKVM doesn't _currently_ need/want the order of the backing allocation, presumably that's because hugepage support is still on the TODO list, not because pKVM fundamentally doesn't need to know the order of the backing allocation.