From patchwork Mon Aug 7 23:01:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 132466 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1798790vqr; Mon, 7 Aug 2023 17:47:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGr7HVNcYyE5Qx48Unm6BDTyPfSEEuukolKVjLMX+T4TqQkCZz01LdVyaE8mUy5gmfZKzry X-Received: by 2002:a05:6a20:9154:b0:13e:8ce5:bed4 with SMTP id x20-20020a056a20915400b0013e8ce5bed4mr14093246pzc.7.1691455650435; Mon, 07 Aug 2023 17:47:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691455650; cv=none; d=google.com; s=arc-20160816; b=AMlKf55tZVvASLl4T67A8yf4vaup9rQ8Tww6it2r4Zyeh0u1Q+vnnmLGZgusZBCTJX E9FIeXMbv6+zjyMMo/Y7ArpNvhEb/Y4+Z+TTxDsgwGsur17ZDDVWBH0Oc2TX8imQFqPK ePHEk/UNtwYW8r39Zhahisa1c1R8M5yjpNerUUNG1QFncmOPLp8kLj3JYIHbHkS0V0zH X1JHV9RWTeCBEnQ9nlJg3xz+s2BJax5di192u57zM86GzsczyqU6Ei6M02KsMhxEUWHv JMeMrkjHBauxJpeHQeJrfQ3cqy6tJyS2hRdUXpHg9TeSBekDqhe4Xw3O+6txc/I35dzH xWYA== 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=bl1TLMRbvm5qHwbmYRTb4VdYc7Xj9ZoiU46WkqVPij4=; fh=HbRmZS+XZk9IdI9bC1USVLouzBEe1WLRItFSyknhPLs=; b=Cso//LXpdu73NHQI5bb7wJywV7ByIJyJvUL11g5Ei9WULTpPnR8tvUstOmEeDRTqKp H3Wuoy4dJ7Rj1WEOr3e+H0UZ+epJZnOmaT2NZKmS1mh9ZoqFDVrrD7mYDBEn9z23b0F5 ogLuicyZ80VUsoe6UsYr/roluKBIwrYYFIQ1GySpIsEXR3cDg7/uM3I0+lRrcIqm1s0T puee7TMX0z/zD0neDZBKZ/YPANggKRXzfnugbuU+WC69NCU7cJurWwEuR1028+FkhIkU Nm3UinMikTmByxrR/aIB+9Zot5UYIsqop4pIwyL93v1KF6lFnJ2U/k2NHBLpNZmvNls1 d16g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=2BOtUuEU; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j34-20020a632322000000b005644829012fsi6475691pgj.701.2023.08.07.17.47.16; Mon, 07 Aug 2023 17:47:30 -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=2BOtUuEU; 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 S230346AbjHGXBn (ORCPT + 99 others); Mon, 7 Aug 2023 19:01:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229942AbjHGXBc (ORCPT ); Mon, 7 Aug 2023 19:01:32 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23E8910F0 for ; Mon, 7 Aug 2023 16:01:31 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5840614b13cso86730437b3.0 for ; Mon, 07 Aug 2023 16:01:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691449290; x=1692054090; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=bl1TLMRbvm5qHwbmYRTb4VdYc7Xj9ZoiU46WkqVPij4=; b=2BOtUuEUFEIj9skMvKxqhTWLGWm0zT85W9Ihp2s4CpbxeUR5ws+01RJ+HQ+yYQxSKj woBvSb4Gk9IPbajI2xb83HAVL2vNi6DqnESZhzmotF6Ol6W/EJeSILA9FOeYje4rZmlQ jwLqD4etekit8dCQHL06GwEffA8P+bK2BwprQsLD6vr9T5p2VjUY/rSCPLXKN8pg0X2n lqCQCQsl6ilU2YFEKJfBss9T/uJCTM8wKKp4u8S1wqiZfR4YgIj+8oKUyz68tt/c7dCt 50DX3ArGIPxPQ5orgu4PasB4iVOVKIP4vUILDfnEp1whQTtvB9OscnFZjDC5X2wkcQqB 1e7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691449290; x=1692054090; 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=bl1TLMRbvm5qHwbmYRTb4VdYc7Xj9ZoiU46WkqVPij4=; b=Iqn1EJqbDNHcdQzD6U/zNMxMoWx1UjYtisswaDL8VR7SkvUvZCAauf4G/CzxWNVmTV xvt7ZDPtOlssFfenM7L9E7GN+Wy9rigpBP8sJY0/yw4AxcIHvB8FEZzJYKMvWwDyXniB uTJMrDenq/5Mc34zPfHfNBhr6Qc7DIUlT/0ehJRW2487UuO0219PwQMWj6YmMbRT0xKC O/RuhxysnWcEfrBGwiXSJxbyCL/xvkyC2Sdbwsh42L7lc6g4n8k6h6WToBuBYwedkSh/ yKOqN83w9Ysp7Bt+iXZKaOPoZ07oboqlXjRr6xnXpG5YbwrXWtOAwK05CTHFTi59RSMX x4WA== X-Gm-Message-State: AOJu0YyiW6n5WiJbCgwdVPKpjOCjaWBKfD9TXzLXFPdKIAVv4lzuIBcs MeSbom304/t08BQqQGXOfkXidmAaWPfrQG0ZDw== X-Received: from ackerleytng-ctop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:13f8]) (user=ackerleytng job=sendgmr) by 2002:a05:690c:c05:b0:576:e268:903d with SMTP id cl5-20020a05690c0c0500b00576e268903dmr109985ywb.2.1691449290326; Mon, 07 Aug 2023 16:01:30 -0700 (PDT) Date: Mon, 7 Aug 2023 23:01:04 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog Message-ID: <21569429bcd8be29f1719649aae0067a00172b66.1691446946.git.ackerleytng@google.com> Subject: [RFC PATCH 01/11] KVM: guest_mem: Refactor out kvm_gmem_alloc_file() From: Ackerley Tng To: pbonzini@redhat.com, seanjc@google.com, tglx@linutronix.de, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, shuah@kernel.org, andrew.jones@linux.dev, ricarkol@google.com, chao.p.peng@linux.intel.com, tabba@google.com, jarkko@kernel.org, yu.c.zhang@linux.intel.com, vannapurve@google.com, ackerleytng@google.com, erdemaktas@google.com, mail@maciej.szmigiero.name, vbabka@suse.cz, david@redhat.com, qperret@google.com, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com 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_BLOCKED,SPF_HELO_NONE,SPF_PASS,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773619800156480227 X-GMAIL-MSGID: 1773619800156480227 kvm_gmem_alloc_file() will allocate and build a file out of an inode. Will be reused later by __kvm_gmem_link() Signed-off-by: Ackerley Tng --- virt/kvm/guest_mem.c | 53 ++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/virt/kvm/guest_mem.c b/virt/kvm/guest_mem.c index 3a3e38151b45..30d0ab8745ee 100644 --- a/virt/kvm/guest_mem.c +++ b/virt/kvm/guest_mem.c @@ -365,12 +365,42 @@ static const struct inode_operations kvm_gmem_iops = { .setattr = kvm_gmem_setattr, }; +static struct file *kvm_gmem_alloc_file(struct kvm *kvm, struct inode *inode, + struct vfsmount *mnt) +{ + struct file *file; + struct kvm_gmem *gmem; + + gmem = kzalloc(sizeof(*gmem), GFP_KERNEL); + if (!gmem) + return ERR_PTR(-ENOMEM); + + file = alloc_file_pseudo(inode, mnt, "kvm-gmem", O_RDWR, &kvm_gmem_fops); + if (IS_ERR(file)) + goto err; + + file->f_flags |= O_LARGEFILE; + file->f_mapping = inode->i_mapping; + + kvm_get_kvm(kvm); + gmem->kvm = kvm; + xa_init(&gmem->bindings); + + file->private_data = gmem; + + list_add(&gmem->entry, &inode->i_mapping->private_list); + + return file; +err: + kfree(gmem); + return file; +} + static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags, struct vfsmount *mnt) { const char *anon_name = "[kvm-gmem]"; const struct qstr qname = QSTR_INIT(anon_name, strlen(anon_name)); - struct kvm_gmem *gmem; struct inode *inode; struct file *file; int fd, err; @@ -399,34 +429,15 @@ static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags, goto err_inode; } - file = alloc_file_pseudo(inode, mnt, "kvm-gmem", O_RDWR, &kvm_gmem_fops); + file = kvm_gmem_alloc_file(kvm, inode, mnt); if (IS_ERR(file)) { err = PTR_ERR(file); goto err_fd; } - file->f_flags |= O_LARGEFILE; - file->f_mapping = inode->i_mapping; - - gmem = kzalloc(sizeof(*gmem), GFP_KERNEL); - if (!gmem) { - err = -ENOMEM; - goto err_file; - } - - kvm_get_kvm(kvm); - gmem->kvm = kvm; - xa_init(&gmem->bindings); - - file->private_data = gmem; - - list_add(&gmem->entry, &inode->i_mapping->private_list); - fd_install(fd, file); return fd; -err_file: - fput(file); err_fd: put_unused_fd(fd); err_inode: