From patchwork Mon Jul 17 10:22:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13315391 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 E2BC6EB64DC for ; Mon, 17 Jul 2023 10:23:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231207AbjGQKXL (ORCPT ); Mon, 17 Jul 2023 06:23:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231156AbjGQKXK (ORCPT ); Mon, 17 Jul 2023 06:23:10 -0400 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 0A23D1BE for ; Mon, 17 Jul 2023 03:23:06 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-bfae0f532e4so4185523276.2 for ; Mon, 17 Jul 2023 03:23:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689589385; x=1692181385; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6m73ah1DVsdVA++i2FD7fWY/5U/zHmxaCEfOABOAT1I=; b=E+d6u7bagGYn313L7xU9vf+hfckEtby6XpI4RNJjQotn0tyYMltVlmxNYf4aP5o+xr 1AAVK0rRfu4pr9QCs8eVVIQYt4TgBYrxBiY6A9eXMaOvfBEkn5/oYxLgEu1teRgxlhVK jP/ieTcTuQFowfjn2MidaQkFAjdqLBmS2b3fTr2Ek8Wz/SWeGzklIysmnNHgkJq9J+Bd wEdZ8KL1cxxDMN5pN1RTskEoqLgQWDYvOOPFK1Tu3PMs4v6C7mT00X2w1XGz4GRtVh9s K0zzg4uDPsi7fnIOhdApT23Vc5z9XnHKgeMTrzTUFC6H8kjUpqSWE0LIkZniD3EETvHl rquA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689589385; x=1692181385; 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=6m73ah1DVsdVA++i2FD7fWY/5U/zHmxaCEfOABOAT1I=; b=cj4R3WUIO7/k66ceLNHwu0y7vz/FKYvRTuhyKiaANzFE7TKPixaR1Xu5TYdA0D6cD5 sxO5EuWBWKngCB+cuNd3qMSx0K3IpKj7iz3/pOgEvcFS5fKE6S5zUEezGaTDfAbwUucA bABaPXU+XowvfS+tG2yyrbjeA3hhSVwXOjdDW3kTm+kH6MwoWZ0zZJAOq40DouvXq8vF WG/ra4v67JE/rL3jZDEpMe93dmw/vHakPK/qldfrvxF9rHnY9G8wGzEeJbjoVy70MAgo E7lTjxEJmcJbp0wwrAQ14HYjMTt9mnrDdI5Tth/FsyXr73W8j8vL3J+4MDZPeg3uUiiE L9/w== X-Gm-Message-State: ABy/qLZb1gu2bLF6JNdS/YAEkKFSD3wmxgtzaZpIm3KRjcINx9IdAjll rzh2QMMbqyTEHuiGWUnEE9KtxShKzC/FrRBLyaU5lzwYCgkP/Gl51R/tzn81tEas3Rr7H74zv7J N2kkIrMXEw21Iqva2oOZnCjIqkESfaS7fWCW7EWpf2qajk1KpQEmLyvc= X-Google-Smtp-Source: APBJJlFX3h2KG9PglQ6lM7KzM8ctojxlqh8xlyE9tsoCoe9MzKquqyColBF8Zl2BSdDsFN6LChe20jsCSA== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a25:e755:0:b0:cca:e68d:29aa with SMTP id e82-20020a25e755000000b00ccae68d29aamr64913ybh.12.1689589384703; Mon, 17 Jul 2023 03:23:04 -0700 (PDT) Date: Mon, 17 Jul 2023 11:22:59 +0100 In-Reply-To: <20230717102300.3092062-1-tabba@google.com> Mime-Version: 1.0 References: <20230717102300.3092062-1-tabba@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230717102300.3092062-2-tabba@google.com> Subject: [PATCH kvmtool v1 1/2] Factor out getting the host page size From: Fuad Tabba To: kvm@vger.kernel.org Cc: julien.thierry.kdev@gmail.com, will@kernel.org, penberg@kernel.org, alexandru.elisei@arm.com, tabba@google.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Factor out getting the page size of the host into a separate function. This will be used in the subsequent patch. No functional change intended. Signed-off-by: Fuad Tabba --- builtin-run.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/builtin-run.c b/builtin-run.c index b1a27fd..2801735 100644 --- a/builtin-run.c +++ b/builtin-run.c @@ -360,9 +360,21 @@ static void kernel_usage_with_options(void) KVM_BINARY_NAME); } +static long host_page_size(void) +{ + long page_size = sysconf(_SC_PAGE_SIZE); + + if (page_size < 0) { + pr_warning("sysconf(_SC_PAGE_SIZE) failed"); + return 0; + } + + return page_size; +} + static u64 host_ram_size(void) { - long page_size; + long page_size = host_page_size(); long nr_pages; nr_pages = sysconf(_SC_PHYS_PAGES); @@ -371,12 +383,6 @@ static u64 host_ram_size(void) return 0; } - page_size = sysconf(_SC_PAGE_SIZE); - if (page_size < 0) { - pr_warning("sysconf(_SC_PAGE_SIZE) failed"); - return 0; - } - return (u64)nr_pages * page_size; } From patchwork Mon Jul 17 10:23:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13315390 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 7726EC001B0 for ; Mon, 17 Jul 2023 10:23:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231182AbjGQKXK (ORCPT ); Mon, 17 Jul 2023 06:23:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230336AbjGQKXJ (ORCPT ); Mon, 17 Jul 2023 06:23:09 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 544E8133 for ; Mon, 17 Jul 2023 03:23:08 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-576d63dfc1dso40011287b3.3 for ; Mon, 17 Jul 2023 03:23:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689589387; x=1692181387; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=O2goHzsn0D7HLr3tWD6DJt7oilv+gAdPmwXSb9fS+yQ=; b=gminds/ETQitdaI6YLgMMuWkwB0vHrFbaCDOofroPnvgn1GRmf3SiCRVn1pQeKiH42 L5PK8D6TKoqpsd83MeLNGTJlKzpKzu2qmE2iV09lbahrySvT5rX3zsp6vnlacayu2sYG KJXnqXXcsCOz1FCj3sKP5IzwCSoLI2VoZwMdjw0s17P6ZOxsDnwHVLniozAx3Bc5q2AM q5NWEMrXp4zwErGUaKceRrOkjXFMzn3etZm7AxswQMO66I6bPeslqej+IZPZZ32lRKgW HkkrQWH49sYj3H41nlU2YlFX9ILLYZA5G3WC9V4JP+1RmIxCFYQzQ0vmm2DLjl3LZAp5 I5kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689589387; x=1692181387; 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=O2goHzsn0D7HLr3tWD6DJt7oilv+gAdPmwXSb9fS+yQ=; b=gtYIVP8Qz8LCgiH9olOxTuHEfNIFK/onPsnsYTCKHFb8P13a7z9SwcO7zyqwUA2xe+ iRuU5pWRw6aAY1XgVbVGWkafqGcMninpIENZYYJVmrgRZe/l8k+yhvQCA0XeocVg5b25 mYYtATycNw0QyrgJYj5ww1ugjOMJGsUPCT8j9ZW+GtSKQh0f83nreOthW9tmyAB7k7uK uaVo7uSdcZCmeWjJfEpV4JHYbZQqs9vb0vV7EQJRawTxKXZvmL9JA8VhmxGpFT6ER7jF CEnoOxmu0TAu2GHN1MRRE0Skd+qWGWxfg9rHxF98YRxAmwCpzwEzGe5/yh1VEYfJTnnq DA2w== X-Gm-Message-State: ABy/qLYQ4Ke5Rglkzc4NUeY3qu+RpgepR/OMkgRZkdAr0bbAdEajwvC8 8emkA5ra1vMAEhWHUXGywQQjLYB8yN+bdjYQEKwcUaq+96ajwfwz3cY37KnKO7aA1Wsw9ivz1g4 GzG1hx87qCHkypFdnTp/0HuZQ1QGz/zoueeSNwspT7q8xiLX06UnrbNA= X-Google-Smtp-Source: APBJJlE6E020XdNxFiVnmjKsvkyxf/YWTfMmVWwpeoQcis4ViM6lLgwtoLC3BUWpTsG5CObCkTb2+/IqAw== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a81:bd4a:0:b0:576:af04:3495 with SMTP id n10-20020a81bd4a000000b00576af043495mr140441ywk.9.1689589387459; Mon, 17 Jul 2023 03:23:07 -0700 (PDT) Date: Mon, 17 Jul 2023 11:23:00 +0100 In-Reply-To: <20230717102300.3092062-1-tabba@google.com> Mime-Version: 1.0 References: <20230717102300.3092062-1-tabba@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230717102300.3092062-3-tabba@google.com> Subject: [PATCH kvmtool v1 2/2] Align the calculated guest ram size to the host's page size From: Fuad Tabba To: kvm@vger.kernel.org Cc: julien.thierry.kdev@gmail.com, will@kernel.org, penberg@kernel.org, alexandru.elisei@arm.com, tabba@google.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org If host_ram_size() * RAM_SIZE_RATIO does not result in a value aligned to the host page size, it triggers an error in __kvm_set_memory_region(), called via the KVM_SET_USER_MEMORY_REGION ioctl, which requires the size to be page-aligned. Fixes: 18bd8c3bd2a7 ("kvm tools: Don't use all of host RAM for guests by default") Signed-off-by: Fuad Tabba --- builtin-run.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin-run.c b/builtin-run.c index 2801735..ff8ba0b 100644 --- a/builtin-run.c +++ b/builtin-run.c @@ -406,7 +406,7 @@ static u64 get_ram_size(int nr_cpus) if (ram_size > available) ram_size = available; - return ram_size; + return ALIGN(ram_size, host_page_size()); } static const char *find_kernel(void)