From patchwork Tue Nov 15 11:15:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13043502 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 C4370C433FE for ; Tue, 15 Nov 2022 11:16:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229803AbiKOLQV (ORCPT ); Tue, 15 Nov 2022 06:16:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229661AbiKOLQB (ORCPT ); Tue, 15 Nov 2022 06:16:01 -0500 Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9676B1B9C8 for ; Tue, 15 Nov 2022 03:15:54 -0800 (PST) Received: by mail-wr1-x449.google.com with SMTP id d10-20020adfa34a000000b00236616a168bso2686859wrb.18 for ; Tue, 15 Nov 2022 03:15:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=e/OndFv4+hmhVq9SAVUchluz3WYiOe7MOTmH3Il+F48=; b=oY2omYev3mrlBBTVldpbIhtG22X/nKyTJ1jQBLLaBiCeiy/7D8Y0Ze4Jt6xynz/yX6 dMVKV3QHNU3fuWygsEi5tYYv0cgnAjyg4Qjl75kjPJ9tB6TWXcr74j0R0h4pE1cGifVx fH0StiT4CBP8KNjA6OnkiohMQQLdlkgqhPziEYsXSXjPcRT2v0iKamvpxEfIPJ0jej24 wyeDW3xmA2Zu/b/0iSm2z2sUdcBlI85/ErtDdeCGpv+kOmRBtEjZFoOUkzBzavMVRYFj lHQAR46oZbArdSkamgJF6Cff59aA8RCXGVdVPs7UhbDEpmWMzZ/eJQbBc8ghXJ5gA9Ax vI7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=e/OndFv4+hmhVq9SAVUchluz3WYiOe7MOTmH3Il+F48=; b=SPMKBMtV86AAw4g6qr497FZC29kFpmE35Felp0cIxJAsIkaUGzJQ9G9z8Kdm416DGq 1TnQhsYbk8jYyRv8uUvSNBLNQfnTgpNS8l8OQGpoGHu4vKNdIsr6OR4SJlKf9KxVG19g /dqKqfojpz/eUpx83bNwgna+mCaVMsHvT2liGGGz+9I+JMiTJQzLVi/DzZ/v8mJExLPX +RYt4Y9lny3tNolklonSJr7Ea/yix/FR2FxYQrC+KofQM1vZBt23BBG/imhh+GPCgUJ6 dkJdF/rtsADXkbpB8tXIsD+WOY+H1c+lWj2n+Ywp+kdhMK+NBRX8jhqjC1GhNp90e9KG Tkig== X-Gm-Message-State: ANoB5pk8EcyCyeoyPhmGU4jvNLx+M19eskE8gfLUWM5UF7rVrhxKhd/O ZfRLAWttGGy10QVacg0xWjsf/m0ALjRqT2SerDJ5P7uHQNICFUmjYd5maTTYzvgnhDfOr6rAhe7 Mb+UIrtBZ7irehAg7VUAy7gg4xj4LEPk6gsU78IN+wQVxLeRjdTOLFN8= X-Google-Smtp-Source: AA0mqf6RT95dr1Vf9xPW5BAQMoH5P1aV0LZZy0wCQmxtWHHyEaYShHsd7tPEc7+NoI7KBqMUMn14vEyOAQ== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a7b:cc8a:0:b0:3b4:7e87:895f with SMTP id p10-20020a7bcc8a000000b003b47e87895fmr1099830wma.30.1668510953176; Tue, 15 Nov 2022 03:15:53 -0800 (PST) Date: Tue, 15 Nov 2022 11:15:33 +0000 In-Reply-To: <20221115111549.2784927-1-tabba@google.com> Mime-Version: 1.0 References: <20221115111549.2784927-1-tabba@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115111549.2784927-2-tabba@google.com> Subject: [PATCH kvmtool v1 01/17] Initialize the return value in kvm__for_each_mem_bank() From: Fuad Tabba To: kvm@vger.kernel.org Cc: julien.thierry.kdev@gmail.com, andre.przywara@arm.com, alexandru.elisei@arm.com, will@kernel.org, tabba@google.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org If none of the bank types match, the function would return an uninitialized value. Signed-off-by: Fuad Tabba Reviewed-by: Andre Przywara --- kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kvm.c b/kvm.c index 42b8812..78bc0d8 100644 --- a/kvm.c +++ b/kvm.c @@ -387,7 +387,7 @@ int kvm__for_each_mem_bank(struct kvm *kvm, enum kvm_mem_type type, int (*fun)(struct kvm *kvm, struct kvm_mem_bank *bank, void *data), void *data) { - int ret; + int ret = 0; struct kvm_mem_bank *bank; list_for_each_entry(bank, &kvm->mem_banks, list) { From patchwork Tue Nov 15 11:15:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13043503 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 DEE56C4332F for ; Tue, 15 Nov 2022 11:16:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230254AbiKOLQY (ORCPT ); Tue, 15 Nov 2022 06:16:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229913AbiKOLQD (ORCPT ); Tue, 15 Nov 2022 06:16:03 -0500 Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EB261C92C for ; Tue, 15 Nov 2022 03:15:57 -0800 (PST) Received: by mail-wr1-x44a.google.com with SMTP id d10-20020adfa34a000000b00236616a168bso2686889wrb.18 for ; Tue, 15 Nov 2022 03:15:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=O/NNSbnKNScLxQezfUEJjKeiglH5FHoDcqljUqXxi7g=; b=Mc7Ipzvl2EBGkxU/sF2iYiRh9YfNLbDn67MEPFVJegy3GCKjVsv4CIABfNxxvDHrNv Qxrd7LuxSTz33HdPYUI7cwpbL328VSHmfS7qtN4aKQw5R8PEGlmTtW53b+wjwJ3p/HQk DM90uhNiZ3wTecjmmZNdVYuk9a0RGD1HhJhS6Ggw3H+wdpkralqG76K0gjZ9SWEjR+Qb 0qgKnLNH+KsfBh99Z+itkRANz3uzN4516GPIXukDax77Z5IPFUZBE2B4k9YWGecxtEf+ rc1vKhNMdqk8E40na64eo49rM7NhIwrlm6AX2iAweRaKnw2hx3+nPi4A6rbAEjrvGuUe r1zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=O/NNSbnKNScLxQezfUEJjKeiglH5FHoDcqljUqXxi7g=; b=2qAlLY18AMI2eOoze3gws7cX6ks3udPKqml+rzrFAmhjF3XZ/IMKKk8cYpzXB+J6OS hrbrpfh/fIoPtxwk7TFYEA3RSS8AeJJftCKHuE/l4N3O14JDialcNh6BdRptvAwCFPq1 460tyLYlf92iOSdTZWXG0h9RCvyyc59a5x1BE1HqKv23z41kd+wbKfjWajm50sIL12f/ k0QuCxaRl0mQIU57bnfAGBowXO+8MUSYttX+vY026ebANLAU5IAFWQ2xWQAVg0C5Lbmz ud7jX6dYa+8IBaGoCMVtBNWwTwqywsD1kD4gnwIwemkCIUGwvl/bctptqT73Wcxju9xY jzJA== X-Gm-Message-State: ANoB5pkdyx9mndclNzGEAGHFdql/a1B1So7Pq0UDzPTqBzSRcdvF0hwO g2PRkQkPqd7fyhRlHaMplFH/kTbss3BfXEUSgKg9JrOfPkuCfsh2HoS/GZD1wRM9z58B85tvDU7 DqutlMQyZTqTaqSq/uEKwEam/kxExXoUVVdPBGxqOBIMauLUTExU5Wrc= X-Google-Smtp-Source: AA0mqf5DK9hK8xKAZ8Br3M0Yd3LumBnZIQrrzZgrZsK0e9SbArG8LHPO+Tkph6cVRX/IuREm4iOyg/DqYA== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a7b:c013:0:b0:3cf:90de:7724 with SMTP id c19-20020a7bc013000000b003cf90de7724mr55230wmb.18.1668510955400; Tue, 15 Nov 2022 03:15:55 -0800 (PST) Date: Tue, 15 Nov 2022 11:15:34 +0000 In-Reply-To: <20221115111549.2784927-1-tabba@google.com> Mime-Version: 1.0 References: <20221115111549.2784927-1-tabba@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115111549.2784927-3-tabba@google.com> Subject: [PATCH kvmtool v1 02/17] Make mmap_hugetlbfs() static From: Fuad Tabba To: kvm@vger.kernel.org Cc: julien.thierry.kdev@gmail.com, andre.przywara@arm.com, alexandru.elisei@arm.com, will@kernel.org, tabba@google.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This function isn't used outside of util.c. No functional change intended. Signed-off-by: Fuad Tabba Reviewed-by: Andre Przywara --- include/kvm/util.h | 1 - util/util.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/include/kvm/util.h b/include/kvm/util.h index b494548..b0c3684 100644 --- a/include/kvm/util.h +++ b/include/kvm/util.h @@ -140,7 +140,6 @@ static inline int pow2_size(unsigned long x) } struct kvm; -void *mmap_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size); void *mmap_anon_or_hugetlbfs(struct kvm *kvm, const char *hugetlbfs_path, u64 size); #endif /* KVM__UTIL_H */ diff --git a/util/util.c b/util/util.c index 1877105..093bd3b 100644 --- a/util/util.c +++ b/util/util.c @@ -81,7 +81,7 @@ void die_perror(const char *s) exit(1); } -void *mmap_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size) +static void *mmap_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size) { char mpath[PATH_MAX]; int fd; From patchwork Tue Nov 15 11:15:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13043504 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 4EAD5C4332F for ; Tue, 15 Nov 2022 11:16:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232253AbiKOLQa (ORCPT ); Tue, 15 Nov 2022 06:16:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230215AbiKOLQD (ORCPT ); Tue, 15 Nov 2022 06:16:03 -0500 Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E84DD21245 for ; Tue, 15 Nov 2022 03:15:58 -0800 (PST) Received: by mail-wm1-x34a.google.com with SMTP id e8-20020a05600c218800b003cf634f5280so3661731wme.8 for ; Tue, 15 Nov 2022 03:15:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=g3Dqg5oaANYsw5kvQe0hPdcfy+Ftql0DSTHDS61yT+o=; b=GDCeTkd/EHU5mNYUXMJgBs5syjSYqt69jcUeKReb+x6soAiPky3Ex9xxbtkLHu4Ko5 wXBvlN/QNs8DPzBfEolIk/KtUXwZLNdqpx4h8AZzUCNLP0ojlcOwPv9/xppRA+wXlCoD 99N7LiVU1qQ3ZA4h3rSRz3RrrVJLc3NGf9VJufvCXD/+YzwPhzGzhMhvngesRlLCA/bJ OSyfMZssgXfn+6hDuq2844WnFKQPxpcKkXDIkuDSwKGOgWF6a+7k4bhqFImWXmHbMVpR 8pOYDongkHgvz54x1kcFWRoYWFLnnfJHRjC91+DvggumA5070t9Wi/BHkA6buJTmJ85k bk5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=g3Dqg5oaANYsw5kvQe0hPdcfy+Ftql0DSTHDS61yT+o=; b=ZKOv8itwizRFCX9EACYMHvR5g0Q7ihCUo80iPoeoHgC8t3iXFYOvuaZi+eIq5tbrub sYykinCRJZPHSVheLP1OhWdD9/QPCIoxQb5/DLCQ7YccCe2CDN6j39qGp9xKPEmVLW/m NFyFJG3kuub8GTeG4QP8wRyVUElXbucaxMNQAuTUgG0h6fvl5Tgb4Yn3muNAVs3N3WYz yZ4ig4PEuRSA8F5e7upHFtBA2fPlaxVY2NcyzRjwI1J3SalAs4rpgP88p8UY7iJ3VXhB dKOy4HhLqJGZ+hXDP6SbnsNfUxcjwqWmkSKk++/p5lQKJm+xCPWS/Zywdn97S/597kOu 2bvg== X-Gm-Message-State: ANoB5pk9EbCTJePtjjv0yq1IToLOvW0GX11SkeFnibV+hsEvisXVxy6b nPEwlVbPz/PnnSoXgm95BckIVZWS4Q9TGMFImYAN0z+rhHZH2h3Y6HTq/2N5juLVrYIHVfVbLza MaUMl6NLdNAOn89ag4B9hscSZsYX6ZYsmidNEKTvH5D/7DwaR/K/RsXU= X-Google-Smtp-Source: AA0mqf4VeI1LbGM7ZGkgpAyFad1HNZyx6QxLUQdhQykv6h+1GjjmAvnYdmpwqKAh3B+53VHovpNGbAfCuA== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:adf:f489:0:b0:236:5102:bd4c with SMTP id l9-20020adff489000000b002365102bd4cmr10067270wro.415.1668510957448; Tue, 15 Nov 2022 03:15:57 -0800 (PST) Date: Tue, 15 Nov 2022 11:15:35 +0000 In-Reply-To: <20221115111549.2784927-1-tabba@google.com> Mime-Version: 1.0 References: <20221115111549.2784927-1-tabba@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115111549.2784927-4-tabba@google.com> Subject: [PATCH kvmtool v1 03/17] Rename parameter in mmap_anon_or_hugetlbfs() From: Fuad Tabba To: kvm@vger.kernel.org Cc: julien.thierry.kdev@gmail.com, andre.przywara@arm.com, alexandru.elisei@arm.com, will@kernel.org, tabba@google.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org For consistency with other similar functions in the same file and for brevity. No functional change intended. Signed-off-by: Fuad Tabba --- include/kvm/util.h | 2 +- util/util.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/kvm/util.h b/include/kvm/util.h index b0c3684..61a205b 100644 --- a/include/kvm/util.h +++ b/include/kvm/util.h @@ -140,6 +140,6 @@ static inline int pow2_size(unsigned long x) } struct kvm; -void *mmap_anon_or_hugetlbfs(struct kvm *kvm, const char *hugetlbfs_path, u64 size); +void *mmap_anon_or_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size); #endif /* KVM__UTIL_H */ diff --git a/util/util.c b/util/util.c index 093bd3b..22b64b6 100644 --- a/util/util.c +++ b/util/util.c @@ -118,14 +118,14 @@ static void *mmap_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size) } /* This function wraps the decision between hugetlbfs map (if requested) or normal mmap */ -void *mmap_anon_or_hugetlbfs(struct kvm *kvm, const char *hugetlbfs_path, u64 size) +void *mmap_anon_or_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size) { - if (hugetlbfs_path) + if (htlbfs_path) /* * We don't /need/ to map guest RAM from hugetlbfs, but we do so * if the user specifies a hugetlbfs path. */ - return mmap_hugetlbfs(kvm, hugetlbfs_path, size); + return mmap_hugetlbfs(kvm, htlbfs_path, size); else { kvm->ram_pagesize = getpagesize(); return mmap(NULL, size, PROT_RW, MAP_ANON_NORESERVE, -1, 0); From patchwork Tue Nov 15 11:15:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13043505 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 DF5B8C4332F for ; Tue, 15 Nov 2022 11:16:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229955AbiKOLQf (ORCPT ); Tue, 15 Nov 2022 06:16:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230375AbiKOLQE (ORCPT ); Tue, 15 Nov 2022 06:16:04 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4CDD24BC6 for ; Tue, 15 Nov 2022 03:16:00 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 4-20020a250104000000b006de5a38d75bso10022502ybb.20 for ; Tue, 15 Nov 2022 03:16:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=0iVDbAl/wOH2U+H6EW34muc3XZD9nJedZ9yIRaXatks=; b=KsWYZAk7wbm6OIEFqkj1jQ8VFtQJXPuE8kGSMKTColNLrqgjM+2cZ86FZdBJVYW/k5 Bhdc+6DPA+USOmI/QoxuN45xRS/2EIPdrLDWIBcTGhcPYSUQ6mSmNRuJjuOH1pVkezHx DeJGzgD3+xMPFT9Q+69Xu3+8qUEho3jhtUDtCNtKvfBmTz0BFaedG+kuScc1T2cDyjw3 HwW+IBIEPZjoEzks/nqD92Tq6JSfsUlfJGJBsFzakteDm+8yHLq+HRTtlyDe3D949j5S Cao2pLKGbFFa/KpKfmkME3JbesaksalKFeSgm3vbN2Eh4l3yhrXfn3TgYbFodJogA39H 4LlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=0iVDbAl/wOH2U+H6EW34muc3XZD9nJedZ9yIRaXatks=; b=GHIrbPireHFdwON5S2/Nvcb9VxqZTtgOaSpz7XaHlv9EdOt94R5bGD4EB2rw8dEYG2 8LAJRykqEdEHUF+jRouFTFK3wUVI1zXfAuyRe/pN4JXlh9bNincrAQRikKwRbwV2/Zy/ G0M0+wTRKnASeYrb0KjZ2xmGdkoTWk4DziOl581+OgnjItsKWwagzMAxJ9ePx2U8ao1Z m/WlRr/pR8Wu6z3h8JUOBWkmCKWyrlbzWXLkK9hJoZCSg/yTmOdjth2SACZwn6Da9Raq ks5pA+UH+K84CRPkh7EiitXCh/b0XPSNdhkzoTC5o71hAK3FiWL1bkhw5gkp4mOhofOT IFxg== X-Gm-Message-State: ACrzQf0hVUlXQu92G5sh27Yn8LASrwWdSPP63EsnhcbvodSckZi84Kcj tKYGjBRL2ud2d1ONzNX892m++fc9MAR3WDNTr8XTf7Qypg+27Po04rR3zzHRcCTByXC3UaZKNU4 DVUuz3un9QGvIB6hh1BAHLpALqvkJZo3boNrBcSguARyc46ZXCnUGJzU= X-Google-Smtp-Source: AMsMyM7aK8p1bPly6GJPrwpEJiAQoQ3WMIhAJxzW15S6NlHzkFnuyytXtXShOjXRFBMCeN1cflWumACFPg== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a81:484a:0:b0:36b:7d6c:d85 with SMTP id v71-20020a81484a000000b0036b7d6c0d85mr61409906ywa.8.1668510959497; Tue, 15 Nov 2022 03:15:59 -0800 (PST) Date: Tue, 15 Nov 2022 11:15:36 +0000 In-Reply-To: <20221115111549.2784927-1-tabba@google.com> Mime-Version: 1.0 References: <20221115111549.2784927-1-tabba@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115111549.2784927-5-tabba@google.com> Subject: [PATCH kvmtool v1 04/17] Add hostmem va to debug print From: Fuad Tabba To: kvm@vger.kernel.org Cc: julien.thierry.kdev@gmail.com, andre.przywara@arm.com, alexandru.elisei@arm.com, will@kernel.org, tabba@google.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Useful when debugging. Signed-off-by: Fuad Tabba --- arm/kvm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arm/kvm.c b/arm/kvm.c index d51cc15..c84983e 100644 --- a/arm/kvm.c +++ b/arm/kvm.c @@ -66,8 +66,8 @@ void kvm__init_ram(struct kvm *kvm) kvm->arch.memory_guest_start = phys_start; - pr_debug("RAM created at 0x%llx - 0x%llx", - phys_start, phys_start + phys_size - 1); + pr_debug("RAM created at 0x%llx - 0x%llx (host_mem 0x%llx)", + phys_start, phys_start + phys_size - 1, (u64)host_mem); } void kvm__arch_delete_ram(struct kvm *kvm) From patchwork Tue Nov 15 11:15:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13043506 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 C3435C43217 for ; Tue, 15 Nov 2022 11:16:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230389AbiKOLQh (ORCPT ); Tue, 15 Nov 2022 06:16:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230385AbiKOLQF (ORCPT ); Tue, 15 Nov 2022 06:16:05 -0500 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 7720ECE32 for ; Tue, 15 Nov 2022 03:16:03 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-352e29ff8c2so134187127b3.21 for ; Tue, 15 Nov 2022 03:16:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=l4S0tjXl5OOwn+z7QW2vWgpLSdRiAzoEj1Tb/VWK9Zs=; b=kfzrhi1GHeIjfa32c6SZkj8M3TIE/5eqQVyQZ/Zl0EqYd8LhnQHQmkanHYkchhYuXt PfK3SGMD7vw12VSNUtDxLKEfyS/MfuN2Jw9naBClPy2zt3trVqCx+zjN4rVw3EbGooXd UlQx77yNnjxQXyMXRrNdAodYslWXJTAT0spmvS1MC49N9g1UFX4oCchkd8UP8+MqSd2Z RgCsy2uGFnTJWg2WekKqIUZyobJJy8vdqjOX5KIOqM/ENBIPMhZKvFkOl1f9Y/oijvGH ruCvsZaDOeab375jOh+vIs7ncFVkHuJP0VSVqw+eEz8VtIuHl/pZVStRtDKYD9wDnnbn nUXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=l4S0tjXl5OOwn+z7QW2vWgpLSdRiAzoEj1Tb/VWK9Zs=; b=HPv5XDrhNpUvWHOGSGuDD46XDaugkIWKoAXz3VF3lpqXD60MJBE6MqjXDyA0iM3D2b HZTvALvpjHqRHHl8SiZmXKRj741QkaDAiTMFRTkNMQgvA3nQ9hL5LniGugXlGmQOBjAX fXeQuf5aIokE+IbCVQ9mwBb1vm0bowMeb/19LEUETujC/hcmuDXPnPPINkyy04wmBK4X eWeJad+ZHUR71GDR9077HIL3MAN7iTGCHSZ4EAozvnD7H/hfXydOeHPkF14lwCiP/oIn 9VrlRK4dr00lAVTUcHldLai6ADGz/8fKWTmQ8frE4DS5CqV1BacG5aAqN1eTdbPVTwRx 47sw== X-Gm-Message-State: ANoB5pkKEBlJqwOVXxjVZ936GG3fO5RgkuiJnAMpqt1Wr9uGvog/cSXv Ry7aZBZJFqRkPNTrs0OPvycJG7xq90WZkLy+ZzodaWxlUFXQWdqcK+CjNdPP0DaFAGjpkLzWud1 h7EGAqSie5sIFRNmylC0JnijkUpYBA4iOQeasUH8ltw52/3z9Ig1qrxg= X-Google-Smtp-Source: AA0mqf5DB6EGMC9wDQymh6JZnGH2RPp8LALO6BEm7DczaUUKU9ahmapd+kHAplLwvZTsHedP+slBrRHstQ== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:6902:1244:b0:6d5:6914:2ceb with SMTP id t4-20020a056902124400b006d569142cebmr28005286ybu.599.1668510962006; Tue, 15 Nov 2022 03:16:02 -0800 (PST) Date: Tue, 15 Nov 2022 11:15:37 +0000 In-Reply-To: <20221115111549.2784927-1-tabba@google.com> Mime-Version: 1.0 References: <20221115111549.2784927-1-tabba@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115111549.2784927-6-tabba@google.com> Subject: [PATCH kvmtool v1 05/17] Factor out getting the hugetlb block size From: Fuad Tabba To: kvm@vger.kernel.org Cc: julien.thierry.kdev@gmail.com, andre.przywara@arm.com, alexandru.elisei@arm.com, will@kernel.org, tabba@google.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This functionality will be needed separately in a future patch. No functional change intended. Signed-off-by: Fuad Tabba --- util/util.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/util/util.c b/util/util.c index 22b64b6..e6c0951 100644 --- a/util/util.c +++ b/util/util.c @@ -81,13 +81,9 @@ void die_perror(const char *s) exit(1); } -static void *mmap_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size) +static u64 get_hugepage_blk_size(const char *htlbfs_path) { - char mpath[PATH_MAX]; - int fd; struct statfs sfs; - void *addr; - unsigned long blk_size; if (statfs(htlbfs_path, &sfs) < 0) die("Can't stat %s\n", htlbfs_path); @@ -95,10 +91,20 @@ static void *mmap_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size) if ((unsigned int)sfs.f_type != HUGETLBFS_MAGIC) die("%s is not hugetlbfs!\n", htlbfs_path); - blk_size = (unsigned long)sfs.f_bsize; - if (sfs.f_bsize == 0 || blk_size > size) { - die("Can't use hugetlbfs pagesize %ld for mem size %lld\n", - blk_size, (unsigned long long)size); + return sfs.f_bsize; +} + +static void *mmap_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size) +{ + char mpath[PATH_MAX]; + int fd; + void *addr; + u64 blk_size; + + blk_size = get_hugepage_blk_size(htlbfs_path); + if (blk_size == 0 || blk_size > size) { + die("Can't use hugetlbfs pagesize %lld for mem size %lld\n", + (unsigned long long)blk_size, (unsigned long long)size); } kvm->ram_pagesize = blk_size; From patchwork Tue Nov 15 11:15:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13043507 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 7CE80C4332F for ; Tue, 15 Nov 2022 11:16:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230385AbiKOLQi (ORCPT ); Tue, 15 Nov 2022 06:16:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230090AbiKOLQH (ORCPT ); Tue, 15 Nov 2022 06:16:07 -0500 Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65395D4B for ; Tue, 15 Nov 2022 03:16:06 -0800 (PST) Received: by mail-wr1-x449.google.com with SMTP id e21-20020adfa455000000b002365c221b59so2714631wra.22 for ; Tue, 15 Nov 2022 03:16:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=26VBHozH/ssHVsrP9L0J/EmUTUmUD0yTnS7gQZzHSbA=; b=JaVSiVDblGruLINE/fEkVVoNILKUmiZNdYmy1+Ma4W7gV/2jUmEmtUjUdvf3oqfgX9 uD1kOaXeCwP8jt/mHzvxgudBxhQlFBKak6VZ4QyYirRjEztkVj/Vewp2B2BB2sK+v363 7hJPdsjvtzHXpkMKJvPZKKZBqL8bQCcnfYJJCZ82hH7ygSGhq6xq/DlOsoh6wI2gz7kR JeoZMCZ2HIun1QQxQGf3J4IrEDN99lVx71UQOCxRVjPj9ZpxZUFeo5ZJubKj429nbaba vQedRN13pXh6AidrXv82HaQQTq9XM70SVwtLHxwiyerY1+r/bdN2zPQcbk7fO/X8uxtm TRWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=26VBHozH/ssHVsrP9L0J/EmUTUmUD0yTnS7gQZzHSbA=; b=irG7px0+IIsf0uVvpBSfHwFBPStl4xUWnnDokjS7eDS9QvfQAX/XW4tW6lMUQabUlj 3Ai62Vn8v9qMhdrp7yW8qhEf8ccRNfG6o5NDGxhR5bojhNqU0ivoOGdwapT6NWwao5f5 W+5AreXAWWtJASVweZoxcmsZa0+B4eXvaUEULTjHY3PSe5N1vARyUlS5c/HkkMNIc4Dt zuCJnSzwyjKyHdKimX786ntnNN1IY3H/KdUgaMwlIIpPjBjhf+Dznf++V2Qbxa83rY9g L18UvNH2cRzZ9NnHxQBIvvYu7nLWOmTtfE8fvFdWKaTY5s7Ihe/BTCNFsBPwyu5Vo0Eh DYZA== X-Gm-Message-State: ANoB5pkgF+QQYIxHBGgeFDIHEJqUXahdqxYsUNs2NW2qMhKvgNrlqLFW /Hg6lHl/+oZXy+yV6GHXFLAKFNI1uhJ4nNQL5C/25t+pRUOHgtX/U7DKkSglheRtDDcYK9ZgYhn 33SfTHU1NjKT1t9wAoYKUhOgwX5E9U3NuG+Q0xG86Ncxs3Y96Kjxp+78= X-Google-Smtp-Source: AA0mqf4XO9C7Oo358sPPZ583/1GcxF7fOVepdBvRLiczdWYGhKSWftJgBGy3kuBy7Non1Oq+ImBV246TxA== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a7b:c013:0:b0:3cf:90de:7724 with SMTP id c19-20020a7bc013000000b003cf90de7724mr55710wmb.18.1668510964918; Tue, 15 Nov 2022 03:16:04 -0800 (PST) Date: Tue, 15 Nov 2022 11:15:38 +0000 In-Reply-To: <20221115111549.2784927-1-tabba@google.com> Mime-Version: 1.0 References: <20221115111549.2784927-1-tabba@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115111549.2784927-7-tabba@google.com> Subject: [PATCH kvmtool v1 06/17] Use memfd for hugetlbfs when allocating guest ram From: Fuad Tabba To: kvm@vger.kernel.org Cc: julien.thierry.kdev@gmail.com, andre.przywara@arm.com, alexandru.elisei@arm.com, will@kernel.org, tabba@google.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This removes the need of using a temporary file for the fd. Signed-off-by: Fuad Tabba --- util/util.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/util/util.c b/util/util.c index e6c0951..d6ceb5d 100644 --- a/util/util.c +++ b/util/util.c @@ -10,6 +10,14 @@ #include #include +#ifndef MFD_HUGETLB +#define MFD_HUGETLB 0x0004U +#endif + +#ifndef MFD_HUGE_SHIFT +#define MFD_HUGE_SHIFT 26 +#endif + static void report(const char *prefix, const char *err, va_list params) { char msg[1024]; @@ -96,10 +104,12 @@ static u64 get_hugepage_blk_size(const char *htlbfs_path) static void *mmap_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size) { - char mpath[PATH_MAX]; + const char *name = "kvmtool"; + unsigned int flags = 0; int fd; void *addr; u64 blk_size; + int htsize; blk_size = get_hugepage_blk_size(htlbfs_path); if (blk_size == 0 || blk_size > size) { @@ -107,13 +117,18 @@ static void *mmap_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size) (unsigned long long)blk_size, (unsigned long long)size); } + htsize = __builtin_ctzl(blk_size); + if ((1ULL << htsize) != blk_size) + die("Hugepage size must be a power of 2.\n"); + + flags |= MFD_HUGETLB; + flags |= htsize << MFD_HUGE_SHIFT; + kvm->ram_pagesize = blk_size; - snprintf(mpath, PATH_MAX, "%s/kvmtoolXXXXXX", htlbfs_path); - fd = mkstemp(mpath); + fd = memfd_create(name, flags); if (fd < 0) - die("Can't open %s for hugetlbfs map\n", mpath); - unlink(mpath); + die("Can't memfd_create for hugetlbfs map\n"); if (ftruncate(fd, size) < 0) die("Can't ftruncate for mem mapping size %lld\n", (unsigned long long)size); From patchwork Tue Nov 15 11:15:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13043512 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 F1F72C433FE for ; Tue, 15 Nov 2022 11:16:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232917AbiKOLQt (ORCPT ); Tue, 15 Nov 2022 06:16:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbiKOLQJ (ORCPT ); Tue, 15 Nov 2022 06:16:09 -0500 Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FEA6BFB for ; Tue, 15 Nov 2022 03:16:08 -0800 (PST) Received: by mail-wr1-x44a.google.com with SMTP id d10-20020adfa34a000000b00236616a168bso2687022wrb.18 for ; Tue, 15 Nov 2022 03:16:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=VnpKPHd0WqzilqfZYFGWkNsglW1G66eTYlBNQL3waBI=; b=BJ68z9BMC0rBTARUE4noUnIfUJiSVxacaiiddIFRrBgVJ6QY5X9ME2GHyJzunkFyfi SIGos5w75aHiqc2HUiZXzsXikE/jjAxr7Kqw1z/R8Zb1l34lHY4UJ0hxUFf1/m4PqSmm wpDj07m2gV2xu6Hq5qCzbMILFKSP2xsdoKXcfVV2kWllSjryvTvY7KJni/xS9r1C7ml/ jjNW3joTZzvmod+M7mh4JlNaTWgrcYGmGfRA/0WNmPp96BEg6XCgTLzxsOuvZKk5FqRD 5JVvHF2aCcWKcFUUrv29WtO1i7VuCn2a+NUObZl3yMSyV79Soa6CwV/tv0f8N0cj7dIy J2iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=VnpKPHd0WqzilqfZYFGWkNsglW1G66eTYlBNQL3waBI=; b=HqIFfTOIMgA7hTPGjCQLnWIzCch89vBPhAEx2QWQRxhX6i51aM/Q+7QNkYWWMPJfjS xg4Sy8+tWWt5/dXpkSpRY3LjuPSQCcFCJ1+LfcSUkKPIrEojPYzIZBQcOKbDlDtTD7Ws gMlx1j2OOkHiyNx5BmTDBy9TSLN7JQZbf0BDa+U3chy44kgZaX3MfaDiU6nJz9y8o4mx wRKyt4zEumokqVyTdeyVcVZzux9ZOESwiYYmT3fTn5GUVQ3Z+hU6gES85WXYq5UvFTRj VsdX9kQ+1/K6aQVwKB+UH6f4VeYXYPPGQGMh8/v/GIGpH5My748YWDz8IEpbsJXxAtO7 q0JQ== X-Gm-Message-State: ANoB5pnXwJ6ndDsuPHyPNx0pMRdhO7QgTdmUqaA7xfiC/0zIQTbQ9q5U fXGPA/DRZpadY74cNWOmE4vv992G+JnkeTM6B5PlCmA3sEIw2nxemp88+auCeTlrPk2Yc4SpOC8 rFcbM3BIqUhc+pBQ7OwK7mkohmT80yvY1KaXud5PzaqwLfICwtbP6iIE= X-Google-Smtp-Source: AA0mqf4uXEjPUR5fqWyXjU4A8An6oy4Rc5zjenX84xLderJoclJQH13I95iwsTwYJOCViDFKlSlNCYAREw== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a1c:f70d:0:b0:3c5:a867:e59f with SMTP id v13-20020a1cf70d000000b003c5a867e59fmr48816wmh.146.1668510967216; Tue, 15 Nov 2022 03:16:07 -0800 (PST) Date: Tue, 15 Nov 2022 11:15:39 +0000 In-Reply-To: <20221115111549.2784927-1-tabba@google.com> Mime-Version: 1.0 References: <20221115111549.2784927-1-tabba@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115111549.2784927-8-tabba@google.com> Subject: [PATCH kvmtool v1 07/17] Make blk_size a parameter and pass it to mmap_hugetlbfs() From: Fuad Tabba To: kvm@vger.kernel.org Cc: julien.thierry.kdev@gmail.com, andre.przywara@arm.com, alexandru.elisei@arm.com, will@kernel.org, tabba@google.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is the first step of making this function more generic. The main purpose of this patch is to make it easier to review the next one. No functional change intended. Signed-off-by: Fuad Tabba --- util/util.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/util/util.c b/util/util.c index d6ceb5d..d3483d8 100644 --- a/util/util.c +++ b/util/util.c @@ -102,30 +102,20 @@ static u64 get_hugepage_blk_size(const char *htlbfs_path) return sfs.f_bsize; } -static void *mmap_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size) +static void *mmap_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size, u64 blk_size) { const char *name = "kvmtool"; unsigned int flags = 0; int fd; void *addr; - u64 blk_size; - int htsize; + int htsize = __builtin_ctzl(blk_size); - blk_size = get_hugepage_blk_size(htlbfs_path); - if (blk_size == 0 || blk_size > size) { - die("Can't use hugetlbfs pagesize %lld for mem size %lld\n", - (unsigned long long)blk_size, (unsigned long long)size); - } - - htsize = __builtin_ctzl(blk_size); if ((1ULL << htsize) != blk_size) die("Hugepage size must be a power of 2.\n"); flags |= MFD_HUGETLB; flags |= htsize << MFD_HUGE_SHIFT; - kvm->ram_pagesize = blk_size; - fd = memfd_create(name, flags); if (fd < 0) die("Can't memfd_create for hugetlbfs map\n"); @@ -141,13 +131,23 @@ static void *mmap_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size) /* This function wraps the decision between hugetlbfs map (if requested) or normal mmap */ void *mmap_anon_or_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size) { - if (htlbfs_path) - /* - * We don't /need/ to map guest RAM from hugetlbfs, but we do so - * if the user specifies a hugetlbfs path. - */ - return mmap_hugetlbfs(kvm, htlbfs_path, size); - else { + u64 blk_size = 0; + + /* + * We don't /need/ to map guest RAM from hugetlbfs, but we do so + * if the user specifies a hugetlbfs path. + */ + if (htlbfs_path) { + blk_size = get_hugepage_blk_size(htlbfs_path); + + if (blk_size == 0 || blk_size > size) { + die("Can't use hugetlbfs pagesize %lld for mem size %lld\n", + (unsigned long long)blk_size, (unsigned long long)size); + } + + kvm->ram_pagesize = blk_size; + return mmap_hugetlbfs(kvm, htlbfs_path, size, blk_size); + } else { kvm->ram_pagesize = getpagesize(); return mmap(NULL, size, PROT_RW, MAP_ANON_NORESERVE, -1, 0); } From patchwork Tue Nov 15 11:15:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13043511 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 A459FC43217 for ; Tue, 15 Nov 2022 11:16:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229906AbiKOLQr (ORCPT ); Tue, 15 Nov 2022 06:16:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230179AbiKOLQL (ORCPT ); Tue, 15 Nov 2022 06:16:11 -0500 Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C38006544 for ; Tue, 15 Nov 2022 03:16:10 -0800 (PST) Received: by mail-wm1-x349.google.com with SMTP id o5-20020a05600c510500b003cfca1a327fso7660688wms.8 for ; Tue, 15 Nov 2022 03:16:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=njesv85jjjP239HDinbsD6hTH1OvT+B1Z4Pu9bNEgcM=; b=cXYHdWr7aoXpAlfKObEkBwypfuREwEsdSFAOKOMVEZMfFEkZoiU3Czz8ay9I7M4IFm 4Skw6jZnBXsdh1Z1fY8fUHw2ottmaWTZtbtq3KBq+C/KfjpLyc7ufgVMpjR4x3yuXRKn JERqyA/L4x5bF2xPOc0iGvhdc8Pl3YDYebsUGSkZfjOZcjk17wzlUfrY6TCkiwPNtraT vT4tlvCHflWw1h0s2HSIjSm1/A2Suy9f8IyvJyB0D2/UAdArClCCFw2lL3p17epbtOkt 7mYRxCQpsDOkPiZnNLEpgNye5wQ6AQXKkyth4BiQqps1nRqccQGBkvUBRBC44OTNsVXE U1hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=njesv85jjjP239HDinbsD6hTH1OvT+B1Z4Pu9bNEgcM=; b=zjx6dDcocjj7ol9p1rIg9zZDsn9VdWOqlUhzE4oJZF8aKrwMK6Ha1qUxipy1B+p3ik GsYferepqN2zGHEsycBZw91bGrwlgPG5kLTi0xsQeCUx3EsNBmZlXf8qSAeAsdejb2op rfp+F/4oJ2sM/uXtm9WO/0DL2Xeb7NPmQVp1M47rRY7mja/e29myF/L2sb+arAHccxeT X4+9PW+/S2US7wvmdfrHQSkznMT8vHqm3XMngQYOz2k9qwE3onrUJxd7r4ZlghlH9EZN R9f3c+sSRpA3e73rzpBqWN7IM+puQK6XpDu7evZ4QCALGaRMXMVxiL7lhI44ymGM5lGC B0Hg== X-Gm-Message-State: ANoB5pnG73rPZC3ucTMdxBLwj5JhVDEEnDLLw+b3qp72F60NL6m+oMLy Vw6J9oXDy9wa/VLag4B88eelzPTWIjkFAxjo1arpzFPcazT3sbiDPnQ/AAWDUWbwUdAp2ynyU6G 69Poym7TgNiyP48GA/sO9hBGjZsJ0ZKho8MhKnhvTdQ0cymHq0J1tZL8= X-Google-Smtp-Source: AA0mqf7ME0nM78asXz1TaaB0fkOWJ0iQV7M6gwDQS1d4ZCujhn76mFPDmhiVoqubfqOke8Xn0kCva7piGg== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:600c:1c92:b0:3cf:7b65:76c5 with SMTP id k18-20020a05600c1c9200b003cf7b6576c5mr1065873wms.166.1668510969270; Tue, 15 Nov 2022 03:16:09 -0800 (PST) Date: Tue, 15 Nov 2022 11:15:40 +0000 In-Reply-To: <20221115111549.2784927-1-tabba@google.com> Mime-Version: 1.0 References: <20221115111549.2784927-1-tabba@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115111549.2784927-9-tabba@google.com> Subject: [PATCH kvmtool v1 08/17] Use memfd for all guest ram allocations From: Fuad Tabba To: kvm@vger.kernel.org Cc: julien.thierry.kdev@gmail.com, andre.przywara@arm.com, alexandru.elisei@arm.com, will@kernel.org, tabba@google.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Allocate all guest ram backed by memfd/ftruncate instead of anonymous mmap. This will make it easier to use kvm with fd-based kvm guest memory proposals [*]. It also would make it easier to use ipc memory sharing should that be needed in the future. Signed-off-by: Fuad Tabba [*] https://lore.kernel.org/all/20221025151344.3784230-1-chao.p.peng@linux.intel.com/ --- include/kvm/kvm.h | 1 + include/kvm/util.h | 3 +++ kvm.c | 4 ++++ util/util.c | 33 ++++++++++++++++++++------------- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/include/kvm/kvm.h b/include/kvm/kvm.h index 3872dc6..d0d519b 100644 --- a/include/kvm/kvm.h +++ b/include/kvm/kvm.h @@ -87,6 +87,7 @@ struct kvm { struct kvm_config cfg; int sys_fd; /* For system ioctls(), i.e. /dev/kvm */ int vm_fd; /* For VM ioctls() */ + int ram_fd; /* For guest memory. */ timer_t timerid; /* Posix timer for interrupts */ int nrcpus; /* Number of cpus to run */ diff --git a/include/kvm/util.h b/include/kvm/util.h index 61a205b..369603b 100644 --- a/include/kvm/util.h +++ b/include/kvm/util.h @@ -140,6 +140,9 @@ static inline int pow2_size(unsigned long x) } struct kvm; +int memfd_alloc(u64 size, bool hugetlb, u64 blk_size); +void *mmap_anon_or_hugetlbfs_align(struct kvm *kvm, const char *htlbfs_path, + u64 size, u64 align); void *mmap_anon_or_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size); #endif /* KVM__UTIL_H */ diff --git a/kvm.c b/kvm.c index 78bc0d8..ed29d68 100644 --- a/kvm.c +++ b/kvm.c @@ -160,6 +160,7 @@ struct kvm *kvm__new(void) mutex_init(&kvm->mem_banks_lock); kvm->sys_fd = -1; kvm->vm_fd = -1; + kvm->ram_fd = -1; #ifdef KVM_BRLOCK_DEBUG kvm->brlock_sem = (pthread_rwlock_t) PTHREAD_RWLOCK_INITIALIZER; @@ -174,6 +175,9 @@ int kvm__exit(struct kvm *kvm) kvm__arch_delete_ram(kvm); + if (kvm->ram_fd >= 0) + close(kvm->ram_fd); + list_for_each_entry_safe(bank, tmp, &kvm->mem_banks, list) { list_del(&bank->list); free(bank); diff --git a/util/util.c b/util/util.c index d3483d8..278bcc2 100644 --- a/util/util.c +++ b/util/util.c @@ -102,36 +102,38 @@ static u64 get_hugepage_blk_size(const char *htlbfs_path) return sfs.f_bsize; } -static void *mmap_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size, u64 blk_size) +int memfd_alloc(u64 size, bool hugetlb, u64 blk_size) { const char *name = "kvmtool"; unsigned int flags = 0; int fd; - void *addr; - int htsize = __builtin_ctzl(blk_size); - if ((1ULL << htsize) != blk_size) - die("Hugepage size must be a power of 2.\n"); + if (hugetlb) { + int htsize = __builtin_ctzl(blk_size); - flags |= MFD_HUGETLB; - flags |= htsize << MFD_HUGE_SHIFT; + if ((1ULL << htsize) != blk_size) + die("Hugepage size must be a power of 2.\n"); + + flags |= MFD_HUGETLB; + flags |= htsize << MFD_HUGE_SHIFT; + } fd = memfd_create(name, flags); if (fd < 0) - die("Can't memfd_create for hugetlbfs map\n"); + die("Can't memfd_create for memory map\n"); + if (ftruncate(fd, size) < 0) die("Can't ftruncate for mem mapping size %lld\n", (unsigned long long)size); - addr = mmap(NULL, size, PROT_RW, MAP_PRIVATE, fd, 0); - close(fd); - return addr; + return fd; } /* This function wraps the decision between hugetlbfs map (if requested) or normal mmap */ void *mmap_anon_or_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size) { u64 blk_size = 0; + int fd; /* * We don't /need/ to map guest RAM from hugetlbfs, but we do so @@ -146,9 +148,14 @@ void *mmap_anon_or_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size) } kvm->ram_pagesize = blk_size; - return mmap_hugetlbfs(kvm, htlbfs_path, size, blk_size); } else { kvm->ram_pagesize = getpagesize(); - return mmap(NULL, size, PROT_RW, MAP_ANON_NORESERVE, -1, 0); } + + fd = memfd_alloc(size, htlbfs_path, blk_size); + if (fd < 0) + return MAP_FAILED; + + kvm->ram_fd = fd; + return mmap(NULL, size, PROT_RW, MAP_PRIVATE, kvm->ram_fd, 0); } From patchwork Tue Nov 15 11:15:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13043508 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 D155BC433FE for ; Tue, 15 Nov 2022 11:16:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232305AbiKOLQl (ORCPT ); Tue, 15 Nov 2022 06:16:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229751AbiKOLQO (ORCPT ); Tue, 15 Nov 2022 06:16:14 -0500 Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D7836551 for ; Tue, 15 Nov 2022 03:16:13 -0800 (PST) Received: by mail-wm1-x349.google.com with SMTP id bg21-20020a05600c3c9500b003c2acbff422so779877wmb.0 for ; Tue, 15 Nov 2022 03:16:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=UA7RisSlDwyhxZSwr+fm8P5Gobfl19wI6DqwNPfj+j4=; b=ooKD/ZL78K9qjsu9X7pyTNtyTNkSR59YIhoRTWetM9sTWU4Surd/mYArxFcuYkPrX7 AaiG67gEVRjOiTkUe5PjJazeINyFpdEGfrHJKZ+BAJEzvajFoicIlRMLZhXHR+kNFThy Q1wRKt8QOYXXNm4NnJ7G0XmZS/IwV5uxZQC9xgZaVRQHVShJRSCGGBHUPeG8T/ir5nAo ER2IAU1iUKkyo1X70r4DT0MxhdRo9Vx5P2w+6qZX3NKfzSWzjMm57MZKBhR+n8OtuWOc a8EpttedoZ3Oyk32h8UIj+tSeXiH7pk2YXwNxFukIO9NaPEikxF9evP5lnAG7gUAAG4k ZbZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=UA7RisSlDwyhxZSwr+fm8P5Gobfl19wI6DqwNPfj+j4=; b=JnIssVBlvMfyJGMo5+/yFgq92mG+7FODmudfhwqKefAbmk7F+Yr7Aipu+62IlTvVsJ SbDAme7AzWSah/GB49qRsL1GQeeCiqPrfcyAHmbTetTEKy9Eh32LrHEsm47nRe7UWG1h R5QAMd58btCvVe63bWGdIwqbSPEL0M8GEJN+v8Ehy6bhVAjQ0ku48GUarsFgU3hR6nGX w1sLQGCLBxUYy/2PQDfQ8k0HzoIEnwnwzt+5ENhMJyhPQwoUfhIzgL4rhz175g8D3oKc C58FGQVi2ZWNgVi6bwKZujjZ03EeM40HqAaghTVpq/vEVOJXruCjOkxToy5ycFYjqjvD /R8w== X-Gm-Message-State: ANoB5pm6lsEOVf95yL7NX8koakkpZe5Pcmt0rv0b4cU9TDul+9FRDHOc nXAHwJbYaqEnFgjoLEu9mY93+o3yp+gwEB2ZDv+NOgO8EqYhB6EQ/xduZnVrmJ5RT5qcPuL2RwW 087MY1YMN1yN9Fbf0YTgGlfzPg7p1Fwcmdt7FU+qgzo41n2xOLLoMThA= X-Google-Smtp-Source: AA0mqf7SwmuRT9Rqd9LUhGdtwQMchOlIToVJyMO+nke6xLfKgpqdIxdmZJNq1EIVVlJLj5FOykFJdo5HfA== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:600c:19c8:b0:3cf:8df5:68dc with SMTP id u8-20020a05600c19c800b003cf8df568dcmr1044332wmq.15.1668510971466; Tue, 15 Nov 2022 03:16:11 -0800 (PST) Date: Tue, 15 Nov 2022 11:15:41 +0000 In-Reply-To: <20221115111549.2784927-1-tabba@google.com> Mime-Version: 1.0 References: <20221115111549.2784927-1-tabba@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115111549.2784927-10-tabba@google.com> Subject: [PATCH kvmtool v1 09/17] Allocate pvtime memory with memfd From: Fuad Tabba To: kvm@vger.kernel.org Cc: julien.thierry.kdev@gmail.com, andre.przywara@arm.com, alexandru.elisei@arm.com, will@kernel.org, tabba@google.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Ensure that all guest memory is fd-based. Signed-off-by: Fuad Tabba --- arm/aarch64/pvtime.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/arm/aarch64/pvtime.c b/arm/aarch64/pvtime.c index 2933ac7..a7ba03e 100644 --- a/arm/aarch64/pvtime.c +++ b/arm/aarch64/pvtime.c @@ -8,25 +8,35 @@ #define ARM_PVTIME_STRUCT_SIZE (64) static void *usr_mem; +int user_mem_fd = -1; static int pvtime__alloc_region(struct kvm *kvm) { char *mem; + int mem_fd; int ret = 0; - mem = mmap(NULL, ARM_PVTIME_SIZE, PROT_RW, - MAP_ANON_NORESERVE, -1, 0); - if (mem == MAP_FAILED) + mem_fd = memfd_alloc(ARM_PVTIME_SIZE, false, 0); + if (mem_fd < 0) return -errno; + mem = mmap(NULL, ARM_PVTIME_SIZE, PROT_RW, MAP_PRIVATE, mem_fd, 0); + if (mem == MAP_FAILED) { + ret = -errno; + close(mem_fd); + return ret; + } + ret = kvm__register_ram(kvm, ARM_PVTIME_BASE, ARM_PVTIME_SIZE, mem); if (ret) { munmap(mem, ARM_PVTIME_SIZE); + close(mem_fd); return ret; } usr_mem = mem; + user_mem_fd = mem_fd; return ret; } @@ -38,7 +48,9 @@ static int pvtime__teardown_region(struct kvm *kvm) kvm__destroy_mem(kvm, ARM_PVTIME_BASE, ARM_PVTIME_SIZE, usr_mem); munmap(usr_mem, ARM_PVTIME_SIZE); + close(user_mem_fd); usr_mem = NULL; + user_mem_fd = -1; return 0; } From patchwork Tue Nov 15 11:15:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13043509 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 458B4C433FE for ; Tue, 15 Nov 2022 11:16:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232655AbiKOLQo (ORCPT ); Tue, 15 Nov 2022 06:16:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229455AbiKOLQQ (ORCPT ); Tue, 15 Nov 2022 06:16:16 -0500 Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42C095FAA for ; Tue, 15 Nov 2022 03:16:15 -0800 (PST) Received: by mail-wm1-x349.google.com with SMTP id u9-20020a05600c00c900b003cfb12839d6so3664555wmm.5 for ; Tue, 15 Nov 2022 03:16:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IOlnWRW2tAFQ5q+3RbVn/g3jOsn3BcEoAmGRbW4y3Sc=; b=cRTT7FmrUcUcNEWFAa1X868DOxSsppIh+SyOm+tP+0wPPmhMYg4CXwAzjYZNQrf8Ay f+4qQP2DEfbUxzLgOoW8KF5W9utjfEQSyxBzAm1pdmnWjjWvpqL1Kxhji2+ezVzmde18 dyFMqiZEB4cj71oPlHnxjT7b+YUEnJRH1fO7izSI0RVvGreIdS1HNzQnWRxIaSNYKKsm SCvOBCw33L47YfXdEtr8vHSJ7fkkr6uxVjrxR3MewQwsoo5U+YYGd0rSFzDcs4DE0FVG JeqyhnYkiWcp54jgk7R1jE3thCUvIw6wU/w6LRPBPLcuM+0Zk6lUeHeY/6jHBJ6i0G3c l8hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=IOlnWRW2tAFQ5q+3RbVn/g3jOsn3BcEoAmGRbW4y3Sc=; b=4GTBHCVrayOUBjk6ejkABPp6tQ1Mvpkm52lq2lpBGooG02OLoDPFEdp4GPC2XBVbi1 avsiAiAS6NIAE9obS7Cr7Ve2Ivwaoin910WVvgm2/OH8fdCCUQERNiMMUviyZ6JhCWKj MkVyKlLlrAis0oJf50b2iEiRZJO+ro7o707b7HZFkYsHTsKsyh7cQGoy+IC4QN0g0Q9N ojB9xkuHMZNUzxoEP4Wlb5TI7oiOl+tjZKOWRk7BqrGsOrg5TVmLOln/xadCKPw8n/qp xb+tHR1cw4HU0BPJzbhqynse11Vp4R5cLLpBrtP/v/4DxMhwBEksun4BvRLUzPsa/PjD 178A== X-Gm-Message-State: ANoB5pkK6gt96geAehbUFsADJT23O2BLE+NHeHqX46cwPeltmdZWzVnI 8xHRAzLGqDzXtTqi2D2vaI1udFfZJKO8b6TFMOXHDGtxrnPIakhPPvH1ud0KfNLvEXwhFlhXeUN Agjl0Hdm/zt/gbThTxIQwmYViOHShWrH+CrN23pTVTFmT9S1qC/ZxNes= X-Google-Smtp-Source: AA0mqf6VGAgxpyvtv2yP0V7yDiDmmgBgURvRdQwSSoc5dpPVgUgfygd5TDuKQhKBfMRZsJB08qvqeHN+nQ== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:600c:310c:b0:3cf:d58f:f66e with SMTP id g12-20020a05600c310c00b003cfd58ff66emr98626wmo.165.1668510973867; Tue, 15 Nov 2022 03:16:13 -0800 (PST) Date: Tue, 15 Nov 2022 11:15:42 +0000 In-Reply-To: <20221115111549.2784927-1-tabba@google.com> Mime-Version: 1.0 References: <20221115111549.2784927-1-tabba@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115111549.2784927-11-tabba@google.com> Subject: [PATCH kvmtool v1 10/17] Allocate vesa memory with memfd From: Fuad Tabba To: kvm@vger.kernel.org Cc: julien.thierry.kdev@gmail.com, andre.przywara@arm.com, alexandru.elisei@arm.com, will@kernel.org, tabba@google.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Ensure that all guest memory is fd-based. Signed-off-by: Fuad Tabba --- framebuffer.c | 2 ++ hw/vesa.c | 15 +++++++++++++-- include/kvm/framebuffer.h | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/framebuffer.c b/framebuffer.c index fb8f51d..a025293 100644 --- a/framebuffer.c +++ b/framebuffer.c @@ -73,6 +73,8 @@ int fb__exit(struct kvm *kvm) fb->targets[i]->stop(fb); munmap(fb->mem, fb->mem_size); + if (fb->mem_fd >= 0) + close(fb->mem_fd); } return 0; diff --git a/hw/vesa.c b/hw/vesa.c index 7f82cdb..522ffa3 100644 --- a/hw/vesa.c +++ b/hw/vesa.c @@ -41,6 +41,7 @@ static struct framebuffer vesafb = { .depth = VESA_BPP, .mem_addr = VESA_MEM_ADDR, .mem_size = VESA_MEM_SIZE, + .mem_fd = -1, }; static void vesa_pci_io(struct kvm_cpu *vcpu, u64 addr, u8 *data, u32 len, @@ -66,6 +67,7 @@ struct framebuffer *vesa__init(struct kvm *kvm) { u16 vesa_base_addr; char *mem; + int mem_fd; int r; BUILD_BUG_ON(!is_power_of_two(VESA_MEM_SIZE)); @@ -88,22 +90,31 @@ struct framebuffer *vesa__init(struct kvm *kvm) if (r < 0) goto unregister_ioport; - mem = mmap(NULL, VESA_MEM_SIZE, PROT_RW, MAP_ANON_NORESERVE, -1, 0); - if (mem == MAP_FAILED) { + mem_fd = memfd_alloc(ARM_PVTIME_SIZE, false, 0, 0); + if (mem_fd < 0) { r = -errno; goto unregister_device; } + mem = mmap(NULL, VESA_MEM_SIZE, PROT_RW, MAP_PRIVATE, mem_fd, 0); + if (mem == MAP_FAILED) { + r = -errno; + goto close_memfd; + } + r = kvm__register_dev_mem(kvm, VESA_MEM_ADDR, VESA_MEM_SIZE, mem); if (r < 0) goto unmap_dev; vesafb.mem = mem; + vesafb.mem_fd = mem_fd; vesafb.kvm = kvm; return fb__register(&vesafb); unmap_dev: munmap(mem, VESA_MEM_SIZE); +close_memfd: + close(mem_fd); unregister_device: device__unregister(&vesa_device); unregister_ioport: diff --git a/include/kvm/framebuffer.h b/include/kvm/framebuffer.h index e3200e5..c340273 100644 --- a/include/kvm/framebuffer.h +++ b/include/kvm/framebuffer.h @@ -22,6 +22,7 @@ struct framebuffer { char *mem; u64 mem_addr; u64 mem_size; + int mem_fd; struct kvm *kvm; unsigned long nr_targets; From patchwork Tue Nov 15 11:15:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13043510 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 41028C4332F for ; Tue, 15 Nov 2022 11:16:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230350AbiKOLQq (ORCPT ); Tue, 15 Nov 2022 06:16:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229666AbiKOLQS (ORCPT ); Tue, 15 Nov 2022 06:16:18 -0500 Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F171B6D for ; Tue, 15 Nov 2022 03:16:17 -0800 (PST) Received: by mail-wm1-x34a.google.com with SMTP id bi19-20020a05600c3d9300b003cf9d6c4016so10366541wmb.8 for ; Tue, 15 Nov 2022 03:16:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NIh7hm1vgq4axzRzMsuAHgxMQ1Qyi0g563BuecOU0iE=; b=o/Jm+iBUclqgHWET7gEwK75p2CjV30bgbQzC70E902kLfWQgtP44WMCJ0lCGQqmDsK BkhQCaFXmTT6VQwO03RVgDIaKaPqybik6PgGWyf3IYT4nAMwa5yVjGCSbfCAiXHNHJLT II7lS9qvGkpgd+0D1+oq09Ug7VgotF7yYOm6RV+XzHMYwzdMBHFWy5zB4v5ziRjIm2Ef l95IWqLwDLgnQ73kYtckKrDKTNUD2QXd9SipslLlxZrscMStpAH5JpaQMZzP0TypFgAk ZSbJlvLM1JIX2bmz6WhU2muRiE8uuukk3dMyPjvNfeFTNf++M17He9b/kIlhfz5Fl1na qTbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=NIh7hm1vgq4axzRzMsuAHgxMQ1Qyi0g563BuecOU0iE=; b=waVs5W4PDehJ1fPrRF0z/kmcunNlkxbbpuHxX/Vfz3G4TwoufupCYJlhsrWpcRZ4aT /wE5XcuGucO+yb1HoGSa6kHJw07NcZzAdo7evDSoRBz9pkcrm2iVTTnQvD0iLJRT8p6j ojstkocaCQL9+u6wEaAwzJU3q00sqJt1cukgvgd/XrKNs2TKIN6wSFxuNdh8DMVa+zsE He5Fx9GDTu/7tqxDsf5xlyKh8ZoJZT97h94jXqpcKonzOAycTOG29P/hkhIHHMMMujl6 0oud1ATAaFXncfSc6wNJMkIZPe5fEzyW9FdD//daD9jC5XuE7Dh/6YniSU7XCFCc6wAD UiTA== X-Gm-Message-State: ANoB5plykhUIh6nz79zdHrSqRdwUWB9vri4lbZKOIhrGAOhpYgWqNSKs RjDsI9/04cKKpYpdksQ9hl/gAwPX7/hagQEO1g9n7AiuvJVKiZvAdUVwwXd/X5KmmYHI9QEvmrZ eoYlbrErSkAYOy9uT/KxZxHHt7zS87WSnOh90Cs/mPL/lcrmyaWiDpZA= X-Google-Smtp-Source: AA0mqf5wOnNfPMSuwQH//NTcL25qBdsbJ1MQADv5FF1HKdx1IxtXGrKCoiQ9oiCnCxXlBzmsAxpp76icwQ== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a1c:a302:0:b0:3c4:5806:104e with SMTP id m2-20020a1ca302000000b003c45806104emr1108716wme.42.1668510975995; Tue, 15 Nov 2022 03:16:15 -0800 (PST) Date: Tue, 15 Nov 2022 11:15:43 +0000 In-Reply-To: <20221115111549.2784927-1-tabba@google.com> Mime-Version: 1.0 References: <20221115111549.2784927-1-tabba@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115111549.2784927-12-tabba@google.com> Subject: [PATCH kvmtool v1 11/17] Add a function that allocates aligned memory if specified From: Fuad Tabba To: kvm@vger.kernel.org Cc: julien.thierry.kdev@gmail.com, andre.przywara@arm.com, alexandru.elisei@arm.com, will@kernel.org, tabba@google.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add a variant of mmap_anon_or_hugetlbfs() that allocates memory aligned as specified. This function doesn't map or allocate more memory than the requested amount. Signed-off-by: Fuad Tabba --- util/util.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/util/util.c b/util/util.c index 278bcc2..953e2d8 100644 --- a/util/util.c +++ b/util/util.c @@ -129,10 +129,17 @@ int memfd_alloc(u64 size, bool hugetlb, u64 blk_size) return fd; } -/* This function wraps the decision between hugetlbfs map (if requested) or normal mmap */ -void *mmap_anon_or_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size) +/* + * This function allocates memory aligned to align_sz. + * It also wraps the decision between hugetlbfs (if requested) or normal mmap. + */ +void *mmap_anon_or_hugetlbfs_align(struct kvm *kvm, const char *htlbfs_path, + u64 size, u64 align_sz) { u64 blk_size = 0; + u64 total_map = size + align_sz; + u64 start_off, end_off; + void *addr_map, *addr_align; int fd; /* @@ -152,10 +159,38 @@ void *mmap_anon_or_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size) kvm->ram_pagesize = getpagesize(); } + /* Create a mapping with room for alignment without allocating. */ + addr_map = mmap(NULL, total_map, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, + -1, 0); + if (addr_map == MAP_FAILED) + return MAP_FAILED; + fd = memfd_alloc(size, htlbfs_path, blk_size); if (fd < 0) return MAP_FAILED; + /* Map the allocated memory in the fd to the specified alignment. */ + addr_align = (void *)ALIGN((u64)addr_map, align_sz); + if (mmap(addr_align, size, PROT_RW, MAP_PRIVATE | MAP_FIXED, fd, 0) == + MAP_FAILED) { + close(fd); + return MAP_FAILED; + } + + /* Remove the mapping for unused address ranges. */ + start_off = addr_align - addr_map; + if (start_off) + munmap(addr_map, start_off); + + end_off = align_sz - start_off; + if (end_off) + munmap((void *)((u64)addr_align + size), end_off); + kvm->ram_fd = fd; - return mmap(NULL, size, PROT_RW, MAP_PRIVATE, kvm->ram_fd, 0); + return addr_align; +} + +void *mmap_anon_or_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size) +{ + return mmap_anon_or_hugetlbfs_align(kvm, htlbfs_path, size, 0); } From patchwork Tue Nov 15 11:15:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13043513 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 E1149C433FE for ; Tue, 15 Nov 2022 11:16:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237872AbiKOLQy (ORCPT ); Tue, 15 Nov 2022 06:16:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbiKOLQV (ORCPT ); Tue, 15 Nov 2022 06:16:21 -0500 Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEABA5F8C for ; Tue, 15 Nov 2022 03:16:19 -0800 (PST) Received: by mail-wm1-x349.google.com with SMTP id c5-20020a1c3505000000b003c56da8e894so10388503wma.0 for ; Tue, 15 Nov 2022 03:16:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=lM2yp/osnDi1TeBXG+cCa07bf+K2sNDUuqRai/Rm3iA=; b=QqGHZuFt9BpKZpnu1D4I30sZEaQLAMgs4U88rGIHONK9CZbID9l7eFDMzmr4R9tFH2 5jP0ICK+/ug9aIsQAGfv+5ERmuNsytJ7OR6XO7Fw3NFTN8Gsx7hM7xoYd5FYpH/btxw4 wcfMS8FSX3RJjFRrMIYIBCu8Zgs09OvxUjZaOMmCbFFs5D2ZI9YxHRZOfHgZtefek1QZ r4BV/vDh+RUc31ebxuH2+KLVqp8gW3deY9arRnC/bPvwLvJWb1XkP3VpI0JrOaIf779F wqSNtYub+fyFvIFk92aUdvRNgrWI1WWL7qwyGg64ha6Gljr6XZxhoqvnvFql743VGDxG upqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=lM2yp/osnDi1TeBXG+cCa07bf+K2sNDUuqRai/Rm3iA=; b=t5ei9hLoQ463RczoAGmfRJWHtzPIb5/AxdT0zgzw1F2DqkJAq6XTA0zXlfpNs8iCnc 1Vf7HUzLNI2/SvAqA1DVZWUV3qPJMjBM9akxoZ30bVUFTXN1H0dqTPCFx0dbZqaqH+R1 9FYkuW3naMvuGh6iwht41dn9K4GDVqwPZeCKWoR3iqcVE/8PLWHcX5ijJ3c9XEcRy1Bl 4gcKAhs9JrPag5cn/z99ZSMv6gAaQ/seVbSYwgY8YMpUGv05tU2NvVvdww8EqtwTtJxj 9JytmZZj2iSgCb0iVy9leJ9zWBJzr0MA22+RpEVUG/OaQhijCQBqpktTan9NADoKSSKu g2TA== X-Gm-Message-State: ANoB5pm2MpwUjwwUxr/xrVqKRsxVkrSVtmAhrGnzYScgr9pFLNWDy1b6 +r5b9guzRdgnUKmY9AgsMAYfV9aen0LH1UsDZSFztufW+6Gaq4cnkjcPRfTOF2iaZlcihIGMp9X fHzkb4IUEMrxJw8UF2VZozigwRzgZMT3qPgb2OovHI2EYlM76VsoATBg= X-Google-Smtp-Source: AA0mqf5yc2TO3aBf8mgzQGCaT6xkTcG4eeSytOnceUTf+c8ZtwUaAPxkK/Ck1/soa22THgPSTMi/oRksFg== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:600c:3b19:b0:3cf:7514:a80d with SMTP id m25-20020a05600c3b1900b003cf7514a80dmr204260wms.0.1668510978137; Tue, 15 Nov 2022 03:16:18 -0800 (PST) Date: Tue, 15 Nov 2022 11:15:44 +0000 In-Reply-To: <20221115111549.2784927-1-tabba@google.com> Mime-Version: 1.0 References: <20221115111549.2784927-1-tabba@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115111549.2784927-13-tabba@google.com> Subject: [PATCH kvmtool v1 12/17] Use new function to align memory From: Fuad Tabba To: kvm@vger.kernel.org Cc: julien.thierry.kdev@gmail.com, andre.przywara@arm.com, alexandru.elisei@arm.com, will@kernel.org, tabba@google.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Use the new mmap_anon_or_hugetlbfs_align() to allocate memory aligned as needed instead of doing it at the caller while allocating and mapping more than needed. Signed-off-by: Fuad Tabba --- arm/kvm.c | 10 +++++----- riscv/kvm.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/arm/kvm.c b/arm/kvm.c index c84983e..0e5bfad 100644 --- a/arm/kvm.c +++ b/arm/kvm.c @@ -37,17 +37,17 @@ void kvm__init_ram(struct kvm *kvm) * 2M trumps 64K, so let's go with that. */ kvm->ram_size = kvm->cfg.ram_size; - kvm->arch.ram_alloc_size = kvm->ram_size + SZ_2M; - kvm->arch.ram_alloc_start = mmap_anon_or_hugetlbfs(kvm, + kvm->arch.ram_alloc_size = kvm->ram_size; + kvm->arch.ram_alloc_start = mmap_anon_or_hugetlbfs_align(kvm, kvm->cfg.hugetlbfs_path, - kvm->arch.ram_alloc_size); + kvm->arch.ram_alloc_size, + SZ_2M); if (kvm->arch.ram_alloc_start == MAP_FAILED) die("Failed to map %lld bytes for guest memory (%d)", kvm->arch.ram_alloc_size, errno); - kvm->ram_start = (void *)ALIGN((unsigned long)kvm->arch.ram_alloc_start, - SZ_2M); + kvm->ram_start = kvm->arch.ram_alloc_start; madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size, MADV_MERGEABLE); diff --git a/riscv/kvm.c b/riscv/kvm.c index 4d6f5cb..e26b4f0 100644 --- a/riscv/kvm.c +++ b/riscv/kvm.c @@ -70,17 +70,17 @@ void kvm__arch_init(struct kvm *kvm) * 2M trumps 64K, so let's go with that. */ kvm->ram_size = min(kvm->cfg.ram_size, (u64)RISCV_MAX_MEMORY(kvm)); - kvm->arch.ram_alloc_size = kvm->ram_size + SZ_2M; - kvm->arch.ram_alloc_start = mmap_anon_or_hugetlbfs(kvm, + kvm->arch.ram_alloc_size = kvm->ram_size; + kvm->arch.ram_alloc_start = mmap_anon_or_hugetlbfs_align(kvm, kvm->cfg.hugetlbfs_path, - kvm->arch.ram_alloc_size); + kvm->arch.ram_alloc_size, + SZ_2M); if (kvm->arch.ram_alloc_start == MAP_FAILED) die("Failed to map %lld bytes for guest memory (%d)", kvm->arch.ram_alloc_size, errno); - kvm->ram_start = (void *)ALIGN((unsigned long)kvm->arch.ram_alloc_start, - SZ_2M); + kvm->ram_start = kvm->arch.ram_alloc_start; madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size, MADV_MERGEABLE); From patchwork Tue Nov 15 11:15:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13043514 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 545EFC433FE for ; Tue, 15 Nov 2022 11:17:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232468AbiKOLQ4 (ORCPT ); Tue, 15 Nov 2022 06:16:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229828AbiKOLQW (ORCPT ); Tue, 15 Nov 2022 06:16:22 -0500 Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8A6A1FA for ; Tue, 15 Nov 2022 03:16:21 -0800 (PST) Received: by mail-wm1-x34a.google.com with SMTP id az40-20020a05600c602800b003cfa26c40easo632337wmb.1 for ; Tue, 15 Nov 2022 03:16:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ZNbzIEZR7wJQWpPy5wb7w4cFM9l/Az4OUx7XpiY0a/o=; b=LZE0OOUOxX2awpOp9ovpgPE7+BEXi2XQ3RiEpfNWqDi1/2dILneWoT+VmCqN4hvMlT RAZH+H84/KNhWzDy3KYJCmkqmIt25lH0kV90aEyK6I3BkAf0RT4q0cqqg5qT2+8sliiL xt/zaKteHtYtUnFk9+6HeD3Jo8D+uw9A1UafnZr8TNBoPvLhVf7y0CzDOqGhuLYPyiNN tl7hi7Z/zaNmk6dV6N4CyFQ1xMU656P5StVe2KelNLLUgAMIuKFmtXxogjQPgn9wzDuC D2RwHjtunnifTiubY/ASfH+pkApPEIsHMV4ms5zCk5ybtLO8ODaVDvnisL8eMk+idmZB PbZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=ZNbzIEZR7wJQWpPy5wb7w4cFM9l/Az4OUx7XpiY0a/o=; b=ILuwxDvxwYtJGbRSxVktHb1SJEECUtZAR4TzTyFaMXpbGhDTEXEbIdcU1JZkLzgD7s 1xjSFlhZ6SkPMHqiLfXdBtAg0yktn80i6fLTN9/AOwKCmG7hIuYeOplEBBkidxd75CjT 36LWGKA8Ldqsbdft+SurMcKSsRD3BwWzQDY+dSD4NalS1m/zfMfWJmXn7OCqx/NKNiZX rXtlVdBvN6R6welQ0gWuo2jqCwPYnDPb/X61djbDUsCEgdWt4H9MQdmlUblcEjiHoLTP FpfHngHY6MS+fIGAdHuymejHhpmAEtsvGcBLWZrGFDVrva66I1BL7mNz2qR23a18iSs+ xKaw== X-Gm-Message-State: ANoB5pk02SzycKAKNbR3k48TQ2ZB3ByEFBkQ9rzNBd5Xj6unYte9BI40 IZODR3YTPK4pyihFTQ3zo2KvJjfYWq918i+b9RgVpOo67OXO06zwdfA+5x8GTKGIGR8ZIE2aDq5 gW9Xb+m8AaESlTZWkQoBy3Jd+DNKrAj3cKkrOOTYcOFk52OTgzVq726I= X-Google-Smtp-Source: AA0mqf63HJyuuNJh7tu8T03eM+GLeZVO/WaAg0LuJIISepyJGYgwGubPHYiK1ZPMYhQpLHv9noLyDvNzqQ== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a5d:524f:0:b0:236:77f4:6e19 with SMTP id k15-20020a5d524f000000b0023677f46e19mr10659949wrc.638.1668510980290; Tue, 15 Nov 2022 03:16:20 -0800 (PST) Date: Tue, 15 Nov 2022 11:15:45 +0000 In-Reply-To: <20221115111549.2784927-1-tabba@google.com> Mime-Version: 1.0 References: <20221115111549.2784927-1-tabba@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115111549.2784927-14-tabba@google.com> Subject: [PATCH kvmtool v1 13/17] Remove struct fields and code used for alignment From: Fuad Tabba To: kvm@vger.kernel.org Cc: julien.thierry.kdev@gmail.com, andre.przywara@arm.com, alexandru.elisei@arm.com, will@kernel.org, tabba@google.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Now that the allocator allocates aligned memory, remove arch-specific code and struct fields used for alignment. No functional change intended. Signed-off-by: Fuad Tabba --- arm/include/arm-common/kvm-arch.h | 7 ------- arm/kvm.c | 31 +++++++++++-------------------- riscv/include/kvm/kvm-arch.h | 7 ------- riscv/kvm.c | 21 +++++++-------------- 4 files changed, 18 insertions(+), 48 deletions(-) diff --git a/arm/include/arm-common/kvm-arch.h b/arm/include/arm-common/kvm-arch.h index b2ae373..654abc9 100644 --- a/arm/include/arm-common/kvm-arch.h +++ b/arm/include/arm-common/kvm-arch.h @@ -96,13 +96,6 @@ static inline bool arm_addr_in_ioport_region(u64 phys_addr) } struct kvm_arch { - /* - * We may have to align the guest memory for virtio, so keep the - * original pointers here for munmap. - */ - void *ram_alloc_start; - u64 ram_alloc_size; - /* * Guest addresses for memory layout. */ diff --git a/arm/kvm.c b/arm/kvm.c index 0e5bfad..770075e 100644 --- a/arm/kvm.c +++ b/arm/kvm.c @@ -27,7 +27,6 @@ bool kvm__arch_cpu_supports_vm(void) void kvm__init_ram(struct kvm *kvm) { u64 phys_start, phys_size; - void *host_mem; int err; /* @@ -37,42 +36,34 @@ void kvm__init_ram(struct kvm *kvm) * 2M trumps 64K, so let's go with that. */ kvm->ram_size = kvm->cfg.ram_size; - kvm->arch.ram_alloc_size = kvm->ram_size; - kvm->arch.ram_alloc_start = mmap_anon_or_hugetlbfs_align(kvm, - kvm->cfg.hugetlbfs_path, - kvm->arch.ram_alloc_size, - SZ_2M); + kvm->ram_start = mmap_anon_or_hugetlbfs_align(kvm, + kvm->cfg.hugetlbfs_path, + kvm->ram_size, SZ_2M); - if (kvm->arch.ram_alloc_start == MAP_FAILED) + if (kvm->ram_start == MAP_FAILED) die("Failed to map %lld bytes for guest memory (%d)", - kvm->arch.ram_alloc_size, errno); + kvm->ram_size, errno); - kvm->ram_start = kvm->arch.ram_alloc_start; - - madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size, - MADV_MERGEABLE); - - madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size, - MADV_HUGEPAGE); + madvise(kvm->ram_start, kvm->ram_size, MADV_MERGEABLE); + madvise(kvm->ram_start, kvm->ram_size, MADV_HUGEPAGE); phys_start = kvm->cfg.ram_addr; phys_size = kvm->ram_size; - host_mem = kvm->ram_start; - err = kvm__register_ram(kvm, phys_start, phys_size, host_mem); + err = kvm__register_ram(kvm, phys_start, phys_size, kvm->ram_start); if (err) die("Failed to register %lld bytes of memory at physical " "address 0x%llx [err %d]", phys_size, phys_start, err); kvm->arch.memory_guest_start = phys_start; - pr_debug("RAM created at 0x%llx - 0x%llx (host_mem 0x%llx)", - phys_start, phys_start + phys_size - 1, (u64)host_mem); + pr_debug("RAM created at 0x%llx - 0x%llx (host ram_start 0x%llx)", + phys_start, phys_start + phys_size - 1, (u64)kvm->ram_start); } void kvm__arch_delete_ram(struct kvm *kvm) { - munmap(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size); + munmap(kvm->ram_start, kvm->ram_size); } void kvm__arch_read_term(struct kvm *kvm) diff --git a/riscv/include/kvm/kvm-arch.h b/riscv/include/kvm/kvm-arch.h index 1e130f5..5bb7eee 100644 --- a/riscv/include/kvm/kvm-arch.h +++ b/riscv/include/kvm/kvm-arch.h @@ -56,13 +56,6 @@ struct kvm; struct kvm_arch { - /* - * We may have to align the guest memory for virtio, so keep the - * original pointers here for munmap. - */ - void *ram_alloc_start; - u64 ram_alloc_size; - /* * Guest addresses for memory layout. */ diff --git a/riscv/kvm.c b/riscv/kvm.c index e26b4f0..d05b8e4 100644 --- a/riscv/kvm.c +++ b/riscv/kvm.c @@ -48,7 +48,7 @@ void kvm__init_ram(struct kvm *kvm) void kvm__arch_delete_ram(struct kvm *kvm) { - munmap(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size); + munmap(kvm->ram_start, kvm->ram_size); } void kvm__arch_read_term(struct kvm *kvm) @@ -70,23 +70,16 @@ void kvm__arch_init(struct kvm *kvm) * 2M trumps 64K, so let's go with that. */ kvm->ram_size = min(kvm->cfg.ram_size, (u64)RISCV_MAX_MEMORY(kvm)); - kvm->arch.ram_alloc_size = kvm->ram_size; - kvm->arch.ram_alloc_start = mmap_anon_or_hugetlbfs_align(kvm, - kvm->cfg.hugetlbfs_path, - kvm->arch.ram_alloc_size, - SZ_2M); + kvm->ram_start = mmap_anon_or_hugetlbfs_align(kvm, + kvm->cfg.hugetlbfs_path, + kvm->ram_size, SZ_2M); - if (kvm->arch.ram_alloc_start == MAP_FAILED) + if (kvm->ram_start == MAP_FAILED) die("Failed to map %lld bytes for guest memory (%d)", kvm->arch.ram_alloc_size, errno); - kvm->ram_start = kvm->arch.ram_alloc_start; - - madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size, - MADV_MERGEABLE); - - madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size, - MADV_HUGEPAGE); + madvise(kvm->ram_start, kvm->ram_size, MADV_MERGEABLE); + madvise(kvm->ram_start, kvm->ram_size, MADV_HUGEPAGE); } #define FDT_ALIGN SZ_4M From patchwork Tue Nov 15 11:15:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13043515 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 7AEE9C4332F for ; Tue, 15 Nov 2022 11:17:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237915AbiKOLQ6 (ORCPT ); Tue, 15 Nov 2022 06:16:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230340AbiKOLQZ (ORCPT ); Tue, 15 Nov 2022 06:16:25 -0500 Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC9756551 for ; Tue, 15 Nov 2022 03:16:23 -0800 (PST) Received: by mail-wr1-x44a.google.com with SMTP id w23-20020adf8bd7000000b002358f733307so2691565wra.17 for ; Tue, 15 Nov 2022 03:16:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=yCP+R1g4kcGfSH64+R9MdUQUTy2IYW1+H52mLQqOgI0=; b=GkgRruqA0ppSlajCi5sm7hIvaWziRxBEokjpV00yqTBlg11/iJ5bQ4fv88DDvvVyrn PFRSyu6npvXn1oWFj07Xd7+8grAiaZgMt75w7BROa4SPEyYuebDSXU25m1SzPRokS/85 jf/TK5QpHH4RdPGBgrr8kqkTuB9lDfkJXIFhKAJVNOVIYiWHbb8MpqU/OzEZipUyHufO FFJpIybTzPzY2zglp86kVhUnGPR6DMIsQ/hUnYaiCsbZPlntd/HPqHnUNzVL969VWSl4 IQms1zf/51S0Ar1BGI4YAbeknS66cjS6c67VPFE/SYfbdDkftidqSGDW4vW66bqZIiuq NGKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=yCP+R1g4kcGfSH64+R9MdUQUTy2IYW1+H52mLQqOgI0=; b=KHhaszFeIQosqyBvJSAVngv12Iec1/edPdoNEbtI+bx9BzCWLPd2+fqVP4vxJ3bz7t msi9MMLL1pwdMoDbDaYyYTYHxDj/4NI/Z0KxrDfpo9s0B67/pQtMqpQHkukorDszF+Wu hUO1vP69kqjPQyk4irz939MtOsoldz21X/RUhndZH1dfwAdxFGQDLnxFlES3FXvO3SRU RarUKCJKda+hsz+Sba8J3A1+hhW68JahQpe6ZYxTFcHxehhLkZB1qW5Cf2g8UhMp5bNq 5spuhd/e5T8Q5ztvp/BOlwtaBS6BEHhXTwGm0/Oro1BvgEywZXcxhcmKVYC9Vg8ESWtN xqcg== X-Gm-Message-State: ANoB5pkm9ZgNpqjirjaBlk7vFY756aZ2YlCiL6bswjWVAO4HPw+A34OZ MGhu4vO8SETV8AbhlIhz5H/IKcxvw2/lVSrffFE7Aav6Oy2aOK1kl+ZRXW9+iqkR3i3lPLBMoZa yaMAuVOYepg0zTUAvoX7GGWIx2mdedjtAG+3hzkcpqVqat07tANNxg9w= X-Google-Smtp-Source: AA0mqf592W1RIt1x7Z41ndYoXso/HvA7o2CB/Xgvo7p+oQzoIrG6P3bXvLp6fVweCFHAHgk8gXtmn344LQ== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:600c:354c:b0:3cf:d70d:d5b3 with SMTP id i12-20020a05600c354c00b003cfd70dd5b3mr1057541wmq.202.1668510982429; Tue, 15 Nov 2022 03:16:22 -0800 (PST) Date: Tue, 15 Nov 2022 11:15:46 +0000 In-Reply-To: <20221115111549.2784927-1-tabba@google.com> Mime-Version: 1.0 References: <20221115111549.2784927-1-tabba@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115111549.2784927-15-tabba@google.com> Subject: [PATCH kvmtool v1 14/17] Replace kvm_arch_delete_ram with kvm_delete_ram From: Fuad Tabba To: kvm@vger.kernel.org Cc: julien.thierry.kdev@gmail.com, andre.przywara@arm.com, alexandru.elisei@arm.com, will@kernel.org, tabba@google.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Now that deleting ram is the same across all architectures, no need for arch-specific deletion of ram. No functional change intended. Signed-off-by: Fuad Tabba --- arm/kvm.c | 5 ----- include/kvm/kvm.h | 1 - kvm.c | 13 +++++++++---- mips/kvm.c | 5 ----- powerpc/kvm.c | 5 ----- riscv/kvm.c | 5 ----- x86/kvm.c | 5 ----- 7 files changed, 9 insertions(+), 30 deletions(-) diff --git a/arm/kvm.c b/arm/kvm.c index 770075e..5cceef8 100644 --- a/arm/kvm.c +++ b/arm/kvm.c @@ -61,11 +61,6 @@ void kvm__init_ram(struct kvm *kvm) phys_start, phys_start + phys_size - 1, (u64)kvm->ram_start); } -void kvm__arch_delete_ram(struct kvm *kvm) -{ - munmap(kvm->ram_start, kvm->ram_size); -} - void kvm__arch_read_term(struct kvm *kvm) { serial8250__update_consoles(kvm); diff --git a/include/kvm/kvm.h b/include/kvm/kvm.h index d0d519b..f0be524 100644 --- a/include/kvm/kvm.h +++ b/include/kvm/kvm.h @@ -198,7 +198,6 @@ void kvm__arch_validate_cfg(struct kvm *kvm); void kvm__arch_set_cmdline(char *cmdline, bool video); void kvm__arch_init(struct kvm *kvm); u64 kvm__arch_default_ram_address(void); -void kvm__arch_delete_ram(struct kvm *kvm); int kvm__arch_setup_firmware(struct kvm *kvm); int kvm__arch_free_firmware(struct kvm *kvm); bool kvm__arch_cpu_supports_vm(void); diff --git a/kvm.c b/kvm.c index ed29d68..695c038 100644 --- a/kvm.c +++ b/kvm.c @@ -169,14 +169,19 @@ struct kvm *kvm__new(void) return kvm; } -int kvm__exit(struct kvm *kvm) +static void kvm__delete_ram(struct kvm *kvm) { - struct kvm_mem_bank *bank, *tmp; - - kvm__arch_delete_ram(kvm); + munmap(kvm->ram_start, kvm->ram_size); if (kvm->ram_fd >= 0) close(kvm->ram_fd); +} + +int kvm__exit(struct kvm *kvm) +{ + struct kvm_mem_bank *bank, *tmp; + + kvm__delete_ram(kvm); list_for_each_entry_safe(bank, tmp, &kvm->mem_banks, list) { list_del(&bank->list); diff --git a/mips/kvm.c b/mips/kvm.c index 0faa03a..0a0d025 100644 --- a/mips/kvm.c +++ b/mips/kvm.c @@ -56,11 +56,6 @@ void kvm__init_ram(struct kvm *kvm) } } -void kvm__arch_delete_ram(struct kvm *kvm) -{ - munmap(kvm->ram_start, kvm->ram_size); -} - void kvm__arch_set_cmdline(char *cmdline, bool video) { diff --git a/powerpc/kvm.c b/powerpc/kvm.c index 7b0d066..8d467e9 100644 --- a/powerpc/kvm.c +++ b/powerpc/kvm.c @@ -148,11 +148,6 @@ void kvm__arch_init(struct kvm *kvm) SPAPR_PCI_IO_WIN_SIZE); } -void kvm__arch_delete_ram(struct kvm *kvm) -{ - munmap(kvm->ram_start, kvm->ram_size); -} - void kvm__irq_trigger(struct kvm *kvm, int irq) { kvm__irq_line(kvm, irq, 1); diff --git a/riscv/kvm.c b/riscv/kvm.c index d05b8e4..4a2a3df 100644 --- a/riscv/kvm.c +++ b/riscv/kvm.c @@ -46,11 +46,6 @@ void kvm__init_ram(struct kvm *kvm) kvm->arch.memory_guest_start = phys_start; } -void kvm__arch_delete_ram(struct kvm *kvm) -{ - munmap(kvm->ram_start, kvm->ram_size); -} - void kvm__arch_read_term(struct kvm *kvm) { serial8250__update_consoles(kvm); diff --git a/x86/kvm.c b/x86/kvm.c index 328fa75..8d29904 100644 --- a/x86/kvm.c +++ b/x86/kvm.c @@ -177,11 +177,6 @@ void kvm__arch_init(struct kvm *kvm) die_perror("KVM_CREATE_IRQCHIP ioctl"); } -void kvm__arch_delete_ram(struct kvm *kvm) -{ - munmap(kvm->ram_start, kvm->ram_size); -} - void kvm__irq_line(struct kvm *kvm, int irq, int level) { struct kvm_irq_level irq_level; From patchwork Tue Nov 15 11:15:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13043516 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 8B00BC43217 for ; Tue, 15 Nov 2022 11:17:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238090AbiKOLRC (ORCPT ); Tue, 15 Nov 2022 06:17:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229913AbiKOLQ1 (ORCPT ); Tue, 15 Nov 2022 06:16:27 -0500 Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C22E614B for ; Tue, 15 Nov 2022 03:16:26 -0800 (PST) Received: by mail-wr1-x449.google.com with SMTP id u13-20020adfa18d000000b00236566b5b40so2657942wru.9 for ; Tue, 15 Nov 2022 03:16:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=C9R+z2LfKFQNn3W3okfxPlt0ApO8wFNDoYzLdWHqipE=; b=TEb62ETv4s/fBxh8STMq8bC+bnsCcOj4LS7CIyyc0mr356/Rwu6h6Sx9SSHU3Kx5SZ y6Qm+g596y9sON2XOJS28ERfBmIWcnlaIbVdcZ3/41zzbe6XwIfiXPBIQFQTEe7+7Xun v9MkhqvSqVkFJV7Z5udpPF1KOoZSUIQxw9IUu/imSn5v3LRImQws0/efQ7swdr6VwLw9 ctVoc4qb/ASFJnlVYvDhNVbbq/YixCeWAy1ZUPH89VZUrGQm0oaUy4XUJbMZKAmmQjBQ PIYhqUtgqxkJNYlob4O+T1cxXRu/BOpzdXxsjZwRkjLkyv8UuY0mAioRAgHiXtN0gqnu 9+yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=C9R+z2LfKFQNn3W3okfxPlt0ApO8wFNDoYzLdWHqipE=; b=6+C4MiafL/tDrNjJlfVbwxJyZC7Z5sQp1gOsc+xQuEWK3ACKgm2YEcSGpdiJP3Qrny mkK3wuMJmh8W2DvLOEjywK36Kg9bfm3q+cySC6Bzlu687yw+7wyTMLVCuKCyAdk8cBmX 7uDOkaUw0dr2ldM+MOcMm6+prCgx1XRo6VpGSetTtdG3qbZRbJx29OmvlFsd+NSXqtAw 0aX/GhcuXqoUhPqJw4DqBL0oTmZlvzrH5v06CXDM3ZaoEmJNbPrqev3W9Mr+9MCmXX43 f6xco/hRfQK5A4BX6LVTHrBX6qFC0kbtf9lqGUW8lr9PCHjawjX+1h/7OJDC8vKZzy8w JhVw== X-Gm-Message-State: ANoB5pk1n32379bmxwV6XeHPe7DjMQNAuDYqXkl6KnaKvZsKyokp55d9 NbfS7f+QYZfy0v3FknMGXKn3P6YN1r/JE/M3zttN7vcR/i0Tmcr/a1hA44PqBBZeHJMuonR54A1 D/z6qFuFSCSb5Gsi5w+25HdHZZHKbIDRpbo/kjtKYDaQMfm4VqsXEeW4= X-Google-Smtp-Source: AA0mqf7BCbGj3TedjfZGh/xq4ME17hGxGp4AlXDiQ8fzErVnCv8X/Qi4OqbvXB8dgg0VpGlnDyA3jhlRjA== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:600c:3c93:b0:3b4:cd96:1748 with SMTP id bg19-20020a05600c3c9300b003b4cd961748mr120128wmb.2.1668510984581; Tue, 15 Nov 2022 03:16:24 -0800 (PST) Date: Tue, 15 Nov 2022 11:15:47 +0000 In-Reply-To: <20221115111549.2784927-1-tabba@google.com> Mime-Version: 1.0 References: <20221115111549.2784927-1-tabba@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115111549.2784927-16-tabba@google.com> Subject: [PATCH kvmtool v1 15/17] Remove no-longer unused macro From: Fuad Tabba To: kvm@vger.kernel.org Cc: julien.thierry.kdev@gmail.com, andre.przywara@arm.com, alexandru.elisei@arm.com, will@kernel.org, tabba@google.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Not needed anymore since we're not doing anonymous allocation. No functional change intended. Signed-off-by: Fuad Tabba --- include/kvm/util.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/kvm/util.h b/include/kvm/util.h index 369603b..f807fcc 100644 --- a/include/kvm/util.h +++ b/include/kvm/util.h @@ -35,7 +35,6 @@ extern bool do_debug_print; #define PROT_RW (PROT_READ|PROT_WRITE) -#define MAP_ANON_NORESERVE (MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE) extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); extern void die_perror(const char *s) NORETURN; From patchwork Tue Nov 15 11:15:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13043517 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 6D66AC4332F for ; Tue, 15 Nov 2022 11:17:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229779AbiKOLRT (ORCPT ); Tue, 15 Nov 2022 06:17:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232197AbiKOLQa (ORCPT ); Tue, 15 Nov 2022 06:16:30 -0500 Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5ACA13CD8 for ; Tue, 15 Nov 2022 03:16:28 -0800 (PST) Received: by mail-wm1-x34a.google.com with SMTP id m34-20020a05600c3b2200b003cf549cb32bso10386694wms.1 for ; Tue, 15 Nov 2022 03:16:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=sE/AjWGs85/jSnKi8kMix3x7KNT1E0UXCsHHKkvydVw=; b=Fhf8kzCbiOIw1urSU9e47/uZlsJ3VJeGJu/AiGsRB+hJ7XrqDOy+HRkYzEnXgwwRJJ ZRq0/9U9t9HylcL89/DJhxMSsEjr20fn+qkeaSaxW8VgzqAtzv0DVgxVgOBF7IcYhken JwUZTD+gY6TV/HADNOYE+aVemozVHFOurUPJpNAb5lUDFpzLsSI1AgOgRCmvAI+PGf0w vQ3OjFPyvyfgpEysXKMaVIBZ/Sv/XyQl4qp3KqOumjQRpslt5KN0se6WhbT73WKwH8N4 XHh8qPAkMWd40bxd6AJxyWXtrxy2pyIT/XuzD/k1c1HXXuzIZvegmtjf3CtCg6Z7s/Mm KBMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=sE/AjWGs85/jSnKi8kMix3x7KNT1E0UXCsHHKkvydVw=; b=fEiBSS60HvhDze3yzjDN7D13SGwg5eiCt0u+FdQHic4SmVdlittKLZy78VOrE43ghz 1A1MwAYmSgX4tbtgl4YNHYkM/NwMtnUwHTKt9xwjihb9WpCj/CIHyOrFAeILOZaiLzhI X4zCL0Hi0yds8GfEBi/Y5H7sWE598/vRLNWfGxqQb2upNcatP+LK9BFxXZAU+AtLWUn4 fPFsFb68BXf3G81UCnRQhjGmtCvQrz1Wf4dFRPx8Ck/kyD+Rr2Ydpm4yDAKykiA4yus6 ZXesZZmTS0jh1tKobDh2+aVLF5il+9V+n3pTEHMWPRT9scHVHTXDMkdBxQTo8R6c//Iv 7iSQ== X-Gm-Message-State: ANoB5pmz6tI+uexFvU8PDpXw4b0J4e51U0AsUUHKh2hv0KyNPo2M2x74 ZHNdQnY4zmBg0iHHsCZNQlMTWpaBtOLV8ZLA17dZQYgp9L0YsG6wjYEp4ZTtrXP+L10IFoaWFkm Ol/HY/e30FeePDJ1cu8vY0IFt9YH7XvFLvBpHxyHYON0vfvYltp0pddY= X-Google-Smtp-Source: AA0mqf4DUpAVLKt4u3X4kUyNKM+2ktYZQ0+aAP8X+Rz8jazkzEAeqUm3O0+LLgWkUMpgxQAD6ssxWXbIBw== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:600c:54ed:b0:3cf:486f:2700 with SMTP id jb13-20020a05600c54ed00b003cf486f2700mr1114421wmb.83.1668510987166; Tue, 15 Nov 2022 03:16:27 -0800 (PST) Date: Tue, 15 Nov 2022 11:15:48 +0000 In-Reply-To: <20221115111549.2784927-1-tabba@google.com> Mime-Version: 1.0 References: <20221115111549.2784927-1-tabba@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115111549.2784927-17-tabba@google.com> Subject: [PATCH kvmtool v1 16/17] Factor out set_user_memory_region code From: Fuad Tabba To: kvm@vger.kernel.org Cc: julien.thierry.kdev@gmail.com, andre.przywara@arm.com, alexandru.elisei@arm.com, will@kernel.org, tabba@google.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is common code, and will be reused in the future when setting memory regions using file descriptors. No functional change intended. Signed-off-by: Fuad Tabba --- kvm.c | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/kvm.c b/kvm.c index 695c038..a1eb365 100644 --- a/kvm.c +++ b/kvm.c @@ -193,10 +193,30 @@ int kvm__exit(struct kvm *kvm) } core_exit(kvm__exit); + +static int set_user_memory_region(int vm_fd, u32 slot, u32 flags, + u64 guest_phys, u64 size, + u64 userspace_addr) +{ + int ret = 0; + struct kvm_userspace_memory_region mem = { + .slot = slot, + .flags = flags, + .guest_phys_addr = guest_phys, + .memory_size = size, + .userspace_addr = (unsigned long)userspace_addr, + }; + + ret = ioctl(vm_fd, KVM_SET_USER_MEMORY_REGION, &mem); + if (ret < 0) + ret = -errno; + + return ret; +} + int kvm__destroy_mem(struct kvm *kvm, u64 guest_phys, u64 size, void *userspace_addr) { - struct kvm_userspace_memory_region mem; struct kvm_mem_bank *bank; int ret; @@ -220,18 +240,10 @@ int kvm__destroy_mem(struct kvm *kvm, u64 guest_phys, u64 size, goto out; } - mem = (struct kvm_userspace_memory_region) { - .slot = bank->slot, - .guest_phys_addr = guest_phys, - .memory_size = 0, - .userspace_addr = (unsigned long)userspace_addr, - }; - - ret = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &mem); - if (ret < 0) { - ret = -errno; + ret = set_user_memory_region(kvm->vm_fd, bank->slot, 0, guest_phys, 0, + (u64) userspace_addr); + if (ret < 0) goto out; - } list_del(&bank->list); free(bank); @@ -246,7 +258,6 @@ out: int kvm__register_mem(struct kvm *kvm, u64 guest_phys, u64 size, void *userspace_addr, enum kvm_mem_type type) { - struct kvm_userspace_memory_region mem; struct kvm_mem_bank *merged = NULL; struct kvm_mem_bank *bank; struct list_head *prev_entry; @@ -327,19 +338,11 @@ int kvm__register_mem(struct kvm *kvm, u64 guest_phys, u64 size, flags |= KVM_MEM_READONLY; if (type != KVM_MEM_TYPE_RESERVED) { - mem = (struct kvm_userspace_memory_region) { - .slot = slot, - .flags = flags, - .guest_phys_addr = guest_phys, - .memory_size = size, - .userspace_addr = (unsigned long)userspace_addr, - }; - - ret = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &mem); - if (ret < 0) { - ret = -errno; + ret = set_user_memory_region(kvm->vm_fd, slot, flags, + guest_phys, size, + (u64) userspace_addr); + if (ret < 0) goto out; - } } list_add(&bank->list, prev_entry); From patchwork Tue Nov 15 11:15:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13043519 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 B9E25C4332F for ; Tue, 15 Nov 2022 11:17:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230375AbiKOLRV (ORCPT ); Tue, 15 Nov 2022 06:17:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232544AbiKOLQc (ORCPT ); Tue, 15 Nov 2022 06:16:32 -0500 Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B05D21BEB3 for ; Tue, 15 Nov 2022 03:16:30 -0800 (PST) Received: by mail-wm1-x349.google.com with SMTP id c1-20020a7bc001000000b003cfe40fca79so1148077wmb.6 for ; Tue, 15 Nov 2022 03:16:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=RrwzRsB22pRwqfA6j+FOYGMh9VZ422ekWmaxzemiqxQ=; b=Slp7czprnwmYuZ415Tpi7Ar8cf0xmT3saibucqgkljWMwisDYhB8IylzI3jvbakIkK 197ZHBFwH8avTYXwIS+gIpUU5yhvU4TEn0jVsAAigBPiIXsQDPQW6iE+BDmsFhjXDowu SLd66Ucil0UFwbsURF6Ae5J+Sl18SVhduaNtockidnm6FNm23QWxMLScwIAbV9GdJ0Na 0h8ozf56B+AhoDuV13QWJc4sjz4chg3KdGLFFijzGFp9GaCvBiiFeAT1wX0EeeW0iRRk hRpCnqmiTxFt652sdI4uG/jKT8ai/gCup+OJ83sTgp6xrS9fKDNSQZj4d3jesm0JNePp Bc4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=RrwzRsB22pRwqfA6j+FOYGMh9VZ422ekWmaxzemiqxQ=; b=gNSx22iko5COVIaMjemfp4SngJ9sEaj0RYiMeLeP2e2m3o2KSG9NYxdQm52gJcfV6o tOjsicFbLaxF2PQSfO0tU6upUpCnr3t45xm5pmzp/rU5Vd/zodsXN1dGoOCHAvQ1bIkt 5nsJKxZ8faEb6cj9MEKlHn6AdX5FnzhLNdUbbYPqphbIXNOIpFz8tWNz2Ze2gwKYeE8T eG/eyKBDJ+wVCcmfyNmkXR2ShXpk2rkbrbq7GKeUkU+cHvsdpzoGeF4dcwmovWgbvFHC 0SLYNgnsiztRavp+FL93CwHy4HCH/9qPcVyQ/ERu0Ru54XiCKoDwRjtwCtyv21hLN1tT nbcg== X-Gm-Message-State: ANoB5pkSrvpA/mLD+cy2D7K5ukF2QfwU+PZqikmbjaGnbHbDHGbgo7k0 UXZJNAuHvP9cSSsf3O32qx/ZndNfiSo/JcyrYB9wdPAKvQFbdOGbBI0yEr+JGn6radYf1ufmG1/ D2ak8RDIaf5BBVmmTfxpUZUThZRdRPcihOSqCcrA0qF/AJRlApL/eyP0= X-Google-Smtp-Source: AA0mqf4DPzMK2Ddtk7GAom5Xpda1Ji5kjnD6ltgEtOTk2ID6j31UQC3Y3382smQQNTmAlKxlME5yNKfQag== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:adf:f508:0:b0:22e:5149:441d with SMTP id q8-20020adff508000000b0022e5149441dmr10245660wro.661.1668510989265; Tue, 15 Nov 2022 03:16:29 -0800 (PST) Date: Tue, 15 Nov 2022 11:15:49 +0000 In-Reply-To: <20221115111549.2784927-1-tabba@google.com> Mime-Version: 1.0 References: <20221115111549.2784927-1-tabba@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115111549.2784927-18-tabba@google.com> Subject: [PATCH kvmtool v1 17/17] Pass the memory file descriptor and offset when registering ram From: Fuad Tabba To: kvm@vger.kernel.org Cc: julien.thierry.kdev@gmail.com, andre.przywara@arm.com, alexandru.elisei@arm.com, will@kernel.org, tabba@google.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Since the memory file descriptor is the canonical reference to guest memory, pass that and the offset when registering guest memory. Future fd-based kvm proposals might even not require a userspace address [*]. No functional change intended. Signed-off-by: Fuad Tabba [*] https://lore.kernel.org/all/20221025151344.3784230-1-chao.p.peng@linux.intel.com/ --- arm/aarch64/pvtime.c | 2 +- arm/kvm.c | 3 ++- hw/cfi_flash.c | 4 +++- hw/vesa.c | 2 +- include/kvm/kvm.h | 17 +++++++++-------- kvm.c | 3 ++- mips/kvm.c | 6 +++--- powerpc/kvm.c | 2 +- riscv/kvm.c | 2 +- vfio/core.c | 3 ++- x86/kvm.c | 6 +++--- 11 files changed, 28 insertions(+), 22 deletions(-) diff --git a/arm/aarch64/pvtime.c b/arm/aarch64/pvtime.c index a7ba03e..9b06ee4 100644 --- a/arm/aarch64/pvtime.c +++ b/arm/aarch64/pvtime.c @@ -28,7 +28,7 @@ static int pvtime__alloc_region(struct kvm *kvm) } ret = kvm__register_ram(kvm, ARM_PVTIME_BASE, - ARM_PVTIME_SIZE, mem); + ARM_PVTIME_SIZE, mem, mem_fd, 0); if (ret) { munmap(mem, ARM_PVTIME_SIZE); close(mem_fd); diff --git a/arm/kvm.c b/arm/kvm.c index 5cceef8..8772a55 100644 --- a/arm/kvm.c +++ b/arm/kvm.c @@ -50,7 +50,8 @@ void kvm__init_ram(struct kvm *kvm) phys_start = kvm->cfg.ram_addr; phys_size = kvm->ram_size; - err = kvm__register_ram(kvm, phys_start, phys_size, kvm->ram_start); + err = kvm__register_ram(kvm, phys_start, phys_size, kvm->ram_start, + kvm->ram_fd, 0); if (err) die("Failed to register %lld bytes of memory at physical " "address 0x%llx [err %d]", phys_size, phys_start, err); diff --git a/hw/cfi_flash.c b/hw/cfi_flash.c index 7faecdf..92a6567 100644 --- a/hw/cfi_flash.c +++ b/hw/cfi_flash.c @@ -131,6 +131,7 @@ struct cfi_flash_device { u32 size; void *flash_memory; + int flash_fd; u8 program_buffer[PROGRAM_BUFF_SIZE]; unsigned long *lock_bm; u64 block_address; @@ -451,7 +452,7 @@ static int map_flash_memory(struct kvm *kvm, struct cfi_flash_device *sfdev) int ret; ret = kvm__register_mem(kvm, sfdev->base_addr, sfdev->size, - sfdev->flash_memory, + sfdev->flash_memory, sfdev->flash_fd, 0, KVM_MEM_TYPE_RAM | KVM_MEM_TYPE_READONLY); if (!ret) sfdev->is_mapped = true; @@ -583,6 +584,7 @@ static struct cfi_flash_device *create_flash_device_file(struct kvm *kvm, ret = -errno; goto out_free; } + sfdev->flash_fd = fd; sfdev->base_addr = KVM_FLASH_MMIO_BASE; sfdev->state = READY; sfdev->read_mode = READ_ARRAY; diff --git a/hw/vesa.c b/hw/vesa.c index 522ffa3..277d638 100644 --- a/hw/vesa.c +++ b/hw/vesa.c @@ -102,7 +102,7 @@ struct framebuffer *vesa__init(struct kvm *kvm) goto close_memfd; } - r = kvm__register_dev_mem(kvm, VESA_MEM_ADDR, VESA_MEM_SIZE, mem); + r = kvm__register_dev_mem(kvm, VESA_MEM_ADDR, VESA_MEM_SIZE, mem, mem_fd, 0); if (r < 0) goto unmap_dev; diff --git a/include/kvm/kvm.h b/include/kvm/kvm.h index f0be524..33cae9d 100644 --- a/include/kvm/kvm.h +++ b/include/kvm/kvm.h @@ -135,24 +135,25 @@ bool kvm__emulate_io(struct kvm_cpu *vcpu, u16 port, void *data, int direction, bool kvm__emulate_mmio(struct kvm_cpu *vcpu, u64 phys_addr, u8 *data, u32 len, u8 is_write); int kvm__destroy_mem(struct kvm *kvm, u64 guest_phys, u64 size, void *userspace_addr); int kvm__register_mem(struct kvm *kvm, u64 guest_phys, u64 size, void *userspace_addr, - enum kvm_mem_type type); + int memfd, u64 offset, enum kvm_mem_type type); static inline int kvm__register_ram(struct kvm *kvm, u64 guest_phys, u64 size, - void *userspace_addr) + void *userspace_addr, int memfd, u64 offset) { - return kvm__register_mem(kvm, guest_phys, size, userspace_addr, - KVM_MEM_TYPE_RAM); + return kvm__register_mem(kvm, guest_phys, size, userspace_addr, memfd, + offset, KVM_MEM_TYPE_RAM); } static inline int kvm__register_dev_mem(struct kvm *kvm, u64 guest_phys, - u64 size, void *userspace_addr) + u64 size, void *userspace_addr, + int memfd, u64 offset) { - return kvm__register_mem(kvm, guest_phys, size, userspace_addr, - KVM_MEM_TYPE_DEVICE); + return kvm__register_mem(kvm, guest_phys, size, userspace_addr, memfd, + offset, KVM_MEM_TYPE_DEVICE); } static inline int kvm__reserve_mem(struct kvm *kvm, u64 guest_phys, u64 size) { - return kvm__register_mem(kvm, guest_phys, size, NULL, + return kvm__register_mem(kvm, guest_phys, size, NULL, -1, 0, KVM_MEM_TYPE_RESERVED); } diff --git a/kvm.c b/kvm.c index a1eb365..0c6ed3d 100644 --- a/kvm.c +++ b/kvm.c @@ -256,7 +256,8 @@ out: } int kvm__register_mem(struct kvm *kvm, u64 guest_phys, u64 size, - void *userspace_addr, enum kvm_mem_type type) + void *userspace_addr, int memfd, u64 offset, + enum kvm_mem_type type) { struct kvm_mem_bank *merged = NULL; struct kvm_mem_bank *bank; diff --git a/mips/kvm.c b/mips/kvm.c index 0a0d025..ebb2b19 100644 --- a/mips/kvm.c +++ b/mips/kvm.c @@ -38,21 +38,21 @@ void kvm__init_ram(struct kvm *kvm) phys_size = kvm->ram_size; host_mem = kvm->ram_start; - kvm__register_ram(kvm, phys_start, phys_size, host_mem); + kvm__register_ram(kvm, phys_start, phys_size, host_mem, kvm->ram_fd, 0); } else { /* one region for memory that fits below MMIO range */ phys_start = 0; phys_size = KVM_MMIO_START; host_mem = kvm->ram_start; - kvm__register_ram(kvm, phys_start, phys_size, host_mem); + kvm__register_ram(kvm, phys_start, phys_size, host_mem, kvm->ram_fd, 0); /* one region for rest of memory */ phys_start = KVM_MMIO_START + KVM_MMIO_SIZE; phys_size = kvm->ram_size - KVM_MMIO_START; host_mem = kvm->ram_start + KVM_MMIO_START; - kvm__register_ram(kvm, phys_start, phys_size, host_mem); + kvm__register_ram(kvm, phys_start, phys_size, host_mem, kvm->ram_fd, 0); } } diff --git a/powerpc/kvm.c b/powerpc/kvm.c index 8d467e9..c36c497 100644 --- a/powerpc/kvm.c +++ b/powerpc/kvm.c @@ -88,7 +88,7 @@ void kvm__init_ram(struct kvm *kvm) "overlaps MMIO!\n", phys_size); - kvm__register_ram(kvm, phys_start, phys_size, host_mem); + kvm__register_ram(kvm, phys_start, phys_size, host_mem, kvm->ram_fd, 0); } void kvm__arch_set_cmdline(char *cmdline, bool video) diff --git a/riscv/kvm.c b/riscv/kvm.c index 4a2a3df..bb79c5d 100644 --- a/riscv/kvm.c +++ b/riscv/kvm.c @@ -38,7 +38,7 @@ void kvm__init_ram(struct kvm *kvm) phys_size = kvm->ram_size; host_mem = kvm->ram_start; - err = kvm__register_ram(kvm, phys_start, phys_size, host_mem); + err = kvm__register_ram(kvm, phys_start, phys_size, host_mem, kvm->ram_fd, 0); if (err) die("Failed to register %lld bytes of memory at physical " "address 0x%llx [err %d]", phys_size, phys_start, err); diff --git a/vfio/core.c b/vfio/core.c index 3ff2c0b..ea189a0 100644 --- a/vfio/core.c +++ b/vfio/core.c @@ -255,7 +255,8 @@ int vfio_map_region(struct kvm *kvm, struct vfio_device *vdev, region->host_addr = base; ret = kvm__register_dev_mem(kvm, region->guest_phys_addr, map_size, - region->host_addr); + region->host_addr, vdev->fd, + region->info.offset); if (ret) { vfio_dev_err(vdev, "failed to register region with KVM"); return ret; diff --git a/x86/kvm.c b/x86/kvm.c index 8d29904..cee82d3 100644 --- a/x86/kvm.c +++ b/x86/kvm.c @@ -107,7 +107,7 @@ void kvm__init_ram(struct kvm *kvm) phys_size = kvm->ram_size; host_mem = kvm->ram_start; - kvm__register_ram(kvm, phys_start, phys_size, host_mem); + kvm__register_ram(kvm, phys_start, phys_size, host_mem, kvm->ram_fd, 0); } else { /* First RAM range from zero to the PCI gap: */ @@ -115,7 +115,7 @@ void kvm__init_ram(struct kvm *kvm) phys_size = KVM_32BIT_GAP_START; host_mem = kvm->ram_start; - kvm__register_ram(kvm, phys_start, phys_size, host_mem); + kvm__register_ram(kvm, phys_start, phys_size, host_mem, kvm->ram_fd, 0); /* Second RAM range from 4GB to the end of RAM: */ @@ -123,7 +123,7 @@ void kvm__init_ram(struct kvm *kvm) phys_size = kvm->ram_size - phys_start; host_mem = kvm->ram_start + phys_start; - kvm__register_ram(kvm, phys_start, phys_size, host_mem); + kvm__register_ram(kvm, phys_start, phys_size, host_mem, kvm->ram_fd, 0); } }