From patchwork Mon Feb 13 16:33:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13138683 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 D4398C636CC for ; Mon, 13 Feb 2023 16:31:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230465AbjBMQbs (ORCPT ); Mon, 13 Feb 2023 11:31:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230202AbjBMQbr (ORCPT ); Mon, 13 Feb 2023 11:31:47 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFEEEDBEE for ; Mon, 13 Feb 2023 08:31:39 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id m10so3950668wrn.4 for ; Mon, 13 Feb 2023 08:31:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=h3qVJ0bF2LOwR9FYE4JKJYonbraLFt3EzjvQr+HEt5I=; b=liepqDU8BjQRRlqGydEYdx93GNpUuRUB4f8PDXBkqBGH0W6S0XWpBVYCZsc9iErDlS fF+K4LR1GHvjQnpF97bj/CVsvnrKoJ523VRQayK+4FQ7p1fY2/qYxbtJBsMNefPNWGKN XA13eaXGPssEhfaDk12KteXLktoHVOBNblEcY/nfGVKsN2sGa9yaPvAtmd/psdS1iQAT E2sx58UlnbcY1v+x8cApav0t2D/1s4vjuSakMZuzpx9Mys26KSYeBriJ9kqLXl5Xgw67 oNYZqiPvoHBjCx4Xivs0PRtVRLTvZt6YolFwluFRmg/D3UgEr1RSKjW/o2UsOVlxLsIc /z6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=h3qVJ0bF2LOwR9FYE4JKJYonbraLFt3EzjvQr+HEt5I=; b=SVjqgNR7qtq85PyZaVXbp1XeoHhxCi5lz8mBZNaE1KPoa6F+F0Dqb/iJvlG9mB7dzl IT1DSAPGSVLZ8AMWhP3dEtwEq9KZ86kkm9iwR0xgr2TPXLY3C0GG8x4n7qVoOtNM1uKd livp0gtxRHrOf4fiUT9LIQN5/hMgFdornnXLArKLQU90j/0MwO9wz7wydcEizBiyYMGI LQvdwkgpvcn70KNl3RX0dgz26ltxVAfGaEq/7DHiLZWoanFddGydgagHDddu/ioqEBcD 9QqKH09ZqBbK3hwm2l2sPzGdrfYLeWvWYBK+M4u+dsSJMZ0BORrDnItzDWIMkdMHvN6V 7v6w== X-Gm-Message-State: AO0yUKVYMCO/qUA7BB+JrvkHKZDAxTDFXYYcl774wgO7rd4Fj0UEPnms U3tHO/JT/CaeJsGoY2jaoVoqDSB7exbscdyW X-Google-Smtp-Source: AK7set+FMQGnQbionigXPOFcaopns6mx0RcJpp4eRSZlla6ji1UnvYJa5YnaE4tdUCm9h95vyrTvRw== X-Received: by 2002:a5d:42c9:0:b0:2c5:4f29:c103 with SMTP id t9-20020a5d42c9000000b002c54f29c103mr7902079wrr.52.1676305898353; Mon, 13 Feb 2023 08:31:38 -0800 (PST) Received: from nuc.fritz.box (p200300f6af2efd00225e3e97da45b943.dip0.t-ipconnect.de. [2003:f6:af2e:fd00:225e:3e97:da45:b943]) by smtp.gmail.com with ESMTPSA id s7-20020a5d5107000000b002c556a4f1casm3877993wrt.42.2023.02.13.08.31.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 08:31:38 -0800 (PST) From: Mathias Krause To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Sean Christopherson , Paolo Bonzini , Mathias Krause Subject: [PATCH 1/5] KVM: x86: Shrink struct kvm_pmu Date: Mon, 13 Feb 2023 17:33:47 +0100 Message-Id: <20230213163351.30704-2-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213163351.30704-1-minipli@grsecurity.net> References: <20230213163351.30704-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Move the 'version' member to the beginning of the structure to reuse an existing hole instead of introducing another one. This allows us to save 8 bytes for 64 bit builds. Signed-off-by: Mathias Krause --- arch/x86/include/asm/kvm_host.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 6aaae18f1854..43329c60a6b5 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -516,6 +516,7 @@ struct kvm_pmc { #define KVM_PMC_MAX_FIXED 3 #define KVM_AMD_PMC_MAX_GENERIC 6 struct kvm_pmu { + u8 version; unsigned nr_arch_gp_counters; unsigned nr_arch_fixed_counters; unsigned available_event_types; @@ -528,7 +529,6 @@ struct kvm_pmu { u64 global_ovf_ctrl_mask; u64 reserved_bits; u64 raw_event_mask; - u8 version; struct kvm_pmc gp_counters[KVM_INTEL_PMC_MAX_GENERIC]; struct kvm_pmc fixed_counters[KVM_PMC_MAX_FIXED]; struct irq_work irq_work; From patchwork Mon Feb 13 16:33:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13138684 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 56D08C64ED9 for ; Mon, 13 Feb 2023 16:31:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231145AbjBMQbv (ORCPT ); Mon, 13 Feb 2023 11:31:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230446AbjBMQbs (ORCPT ); Mon, 13 Feb 2023 11:31:48 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 315141C5AC for ; Mon, 13 Feb 2023 08:31:41 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id az4-20020a05600c600400b003dff767a1f1so9492354wmb.2 for ; Mon, 13 Feb 2023 08:31:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gL3WY5uINlzkgyRq7H7dB8gj8YytqwpDUD1ql7z7pK4=; b=hPTxoCu4/JNwETqutr1XeI0h2A+vQZHDu54xpEqdCBR+IiDlUtuV/j4MxbmdYjgfT0 BqUUIcAHdOCLwtamrYQuCY66ss1l5mfGSbv9idlxRI8p/BgqUCO2HCXDbduL0kwnpcxu Ko6jubB915WKqxj/jqW1yi5Vw1LyFiUqh/dM7fIlGEC4O1dUZoPSOag6xbrHj4AoiimM ELFRh1jdJsQq5xnsYHnF955YXk9HZ+zs/bZqnwbsYEyjVVWBQXnuNxHYQZvPLmEtO7hr ozn5jcy0D74BwZc5gNHRMgBvW7880niRu+QHMQjDSoqg5HcH/ehq6VWrObnqQLkt8KXD OiQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gL3WY5uINlzkgyRq7H7dB8gj8YytqwpDUD1ql7z7pK4=; b=Okg8v+HQtpCsxhrHYY3olepOX+6hV4E8C4ENsEwG1+QPQekvD8RBdxjqL6kxtUWIxI kb1xN+xLsvnEOrciWXxeoTdlUcGMlhpe7iRZhTo0LJWR6ZjRe5JOCvqntv3j5mCcRqHF IESM3LqlIUHHaalDv0438MXTSPhrCHYusPMSd9moEAuPK0IfW/VgFoFP26i6SipMutoI j9VtIlcTB9qKMMA6PCE6ajjXrTV1sR5Kafe25sy/oE2RhbTU9t2LHcnAoDlpnTV3D8pu CDjYmY20YEyxez0cy7Hp0blRRxc+ooCtwpsK12aF0L6KJKNCHpBCCUvxjP5qDer31Eu7 nVGw== X-Gm-Message-State: AO0yUKV5N2cX3nW0i18lBDoxgUsZW46JpWU4z6gaX34XOnz0xdZL1U8W WzGUmfMwiH3WpzBk13JGAO286lCcz6AKjGMo X-Google-Smtp-Source: AK7set8S/1VeRbbWTaHFhH8+N2psjylMhzSWMWCIAMpS9QURMcnaJA+HnYVwNcQ4MeV4TlKDJm8cYw== X-Received: by 2002:a05:600c:16d4:b0:3e0:fad:675a with SMTP id l20-20020a05600c16d400b003e00fad675amr18623402wmn.38.1676305899157; Mon, 13 Feb 2023 08:31:39 -0800 (PST) Received: from nuc.fritz.box (p200300f6af2efd00225e3e97da45b943.dip0.t-ipconnect.de. [2003:f6:af2e:fd00:225e:3e97:da45:b943]) by smtp.gmail.com with ESMTPSA id s7-20020a5d5107000000b002c556a4f1casm3877993wrt.42.2023.02.13.08.31.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 08:31:38 -0800 (PST) From: Mathias Krause To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Sean Christopherson , Paolo Bonzini , Mathias Krause Subject: [PATCH 2/5] KVM: x86: Shrink struct kvm_queued_exception Date: Mon, 13 Feb 2023 17:33:48 +0100 Message-Id: <20230213163351.30704-3-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213163351.30704-1-minipli@grsecurity.net> References: <20230213163351.30704-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Reshuffle the boolean members of struct kvm_queued_exception and make them individual bits, allowing denser packing. This allows us to shrink the object size from 24 to 16 bytes for 64 bit builds. Signed-off-by: Mathias Krause --- arch/x86/include/asm/kvm_host.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 43329c60a6b5..040eee3e9583 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -701,13 +701,13 @@ struct kvm_vcpu_xen { }; struct kvm_queued_exception { - bool pending; - bool injected; - bool has_error_code; + u8 pending : 1; + u8 injected : 1; + u8 has_error_code : 1; + u8 has_payload : 1; u8 vector; u32 error_code; unsigned long payload; - bool has_payload; }; struct kvm_vcpu_arch { From patchwork Mon Feb 13 16:33:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13138686 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 7C649C64ED8 for ; Mon, 13 Feb 2023 16:31:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231148AbjBMQbw (ORCPT ); Mon, 13 Feb 2023 11:31:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230469AbjBMQbs (ORCPT ); Mon, 13 Feb 2023 11:31:48 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 849251DB9B for ; Mon, 13 Feb 2023 08:31:41 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id by3so11547538wrb.10 for ; Mon, 13 Feb 2023 08:31:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=M1IcDb7o/gYGclSpaFMTR0Z6rRoV6K10f7w16ZZ0sHg=; b=EAEv2qg0oPGOf8z7OLWgmMYZJNXgIakX8VzrnhYE0qmI1XNlgtTc3jEmA/zL/eEPvH 7uzW8RC5fI5YNdFUjtulJwA6m35Izs+lVhJxM/E8UMzi3lyI6YMUOFRNvq2PbHDWM0pj xXOjGoHkZVrFDnR9XkCG60Za8tTWfWHE74nnFCoMMmUoauismMhg5jDSCdbB5/cg2VP5 MnyEV8WBnfel0PY3ANXLB8kBPhRREzFAekvWpOJBxyuVg6LuDGsJP3PTun0H+P59/vuT GanQZqrhhBygyaIs/m/PiJyxCUa68RmyjaVB/daFvEcM2qIdrXvadBqvFIWCtjqb13TJ pSNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M1IcDb7o/gYGclSpaFMTR0Z6rRoV6K10f7w16ZZ0sHg=; b=LSbl+E5QtRlyjW7iZ6OopiVz+1LWWU8DKWJ+X9vN2is077Zp9JpUC8Iccv5loWNzX4 lOPVN/M2i5Dd110lolemUlaRzIPEcFVoBQYMS+zA1Uok+o2cgTYvtMKEeOm7THMtB2hV D9O4a7g6W+5NuDYaruRX/bbjzJi/FIT3H22u1WJG6e/8CuTv34a3CD0WpdzCBRTMF/Wv gNwhg2ZzA7OUF8VyxOVQruW3eLU/VFxUWomJpIYva1CzjhEBtDzkpuy4VCUgykysysus u2CvKf1CeX/fRmvcVgF1sYueGOJn5+6cDw+QbWa88KqeYgb+0gfv2siEvRaxH0UfaKAj 0Vjg== X-Gm-Message-State: AO0yUKX8abo6O1pUQXHvIcaxS4fgCdgSple2tbdcFkG/URQDt3LIfJ0p NxAaI5P4DNTsl8irYk/Q3/kiPzRPGEn4pi4z X-Google-Smtp-Source: AK7set8Be25w1kAQrFs/TZMjM7YKuMUvrTyRkn7GIaX1YpI8Knwb5rHxJB2D8ZxX12VEmSt4OEc2NA== X-Received: by 2002:adf:fa04:0:b0:2c5:59e8:30cd with SMTP id m4-20020adffa04000000b002c559e830cdmr2574422wrr.9.1676305899993; Mon, 13 Feb 2023 08:31:39 -0800 (PST) Received: from nuc.fritz.box (p200300f6af2efd00225e3e97da45b943.dip0.t-ipconnect.de. [2003:f6:af2e:fd00:225e:3e97:da45:b943]) by smtp.gmail.com with ESMTPSA id s7-20020a5d5107000000b002c556a4f1casm3877993wrt.42.2023.02.13.08.31.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 08:31:39 -0800 (PST) From: Mathias Krause To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Sean Christopherson , Paolo Bonzini , Mathias Krause Subject: [PATCH 3/5] KVM: Shrink struct kvm_mmu_memory_cache Date: Mon, 13 Feb 2023 17:33:49 +0100 Message-Id: <20230213163351.30704-4-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213163351.30704-1-minipli@grsecurity.net> References: <20230213163351.30704-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Move the 'capacity' member around to make use of the padding hole on 64 bit systems instead of introducing yet another one. This allows us to save 8 bytes per instance for 64 bit builds of which, e.g., x86's struct kvm_vcpu_arch has a few. Signed-off-by: Mathias Krause --- include/linux/kvm_types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h index 76de36e56cdf..8e4f8fa31457 100644 --- a/include/linux/kvm_types.h +++ b/include/linux/kvm_types.h @@ -92,10 +92,10 @@ struct gfn_to_pfn_cache { */ struct kvm_mmu_memory_cache { int nobjs; + int capacity; gfp_t gfp_zero; gfp_t gfp_custom; struct kmem_cache *kmem_cache; - int capacity; void **objects; }; #endif From patchwork Mon Feb 13 16:33:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13138687 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 6729FC636CC for ; Mon, 13 Feb 2023 16:31:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230502AbjBMQbz (ORCPT ); Mon, 13 Feb 2023 11:31:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230486AbjBMQbt (ORCPT ); Mon, 13 Feb 2023 11:31:49 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5379D1DBAB for ; Mon, 13 Feb 2023 08:31:42 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id az4-20020a05600c600400b003dff767a1f1so9492407wmb.2 for ; Mon, 13 Feb 2023 08:31:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5R9IHW3Vc8hHuytFcQqc/EbsgNLSr+qUBtW2LZuwhKo=; b=mOvd2eMD6QLHz2v4lsp37mHHKKF2WTr+lT6m5AFMibytX39ZrCQbcVZetFrpk3Sbte n2nZyb0KnigW310tkHtMVoZFiKAs21VD9w0dDzFqZ9mVJkmYFMqbaV+g5HqlTEZ9NxBs B0iOyOY0hcMJXZx9zk6sYcq2ioZMpRdHc2bQ6v4meVPLWQyAhoGoJzeChBqUvxBt7M3/ uSfVEdSBzXvkyd/Mvi1Qn4oLnZ6DLhzZHWOrSGz1T5lkZLvYWOnm6q4Hw98GLsmRXttH tVi2OwnbYHUMlJH+S30PuIpcBbKoJaHTSdYi+uf+EDWuGHuUXQe8OQsY3l70kE6eKjO7 oXPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5R9IHW3Vc8hHuytFcQqc/EbsgNLSr+qUBtW2LZuwhKo=; b=QhQn9itOA6zcAU9xPk8w32eQaRgzeeD+og4iwZ77Arx+aGVmPRLaGTgO2jyImgTWua YZYVntUkgEsM+l93vwxOh/qUn919f6GO4Bob4Pf5tSgm6WRsMg+Eabo8K1o0pMBo1YxF D71mQX496EchtLqIPZq8fA20vEn5yoHGYZIGpxtGUXOK1MqLqq+Xt/YyWZhZpsFtN57k enl7Qw1jgCsgxMbv7VSa7qlU/tZga1uOq9ILGLJGWC4xbe/j+SmbSGvfvoZJLbqQhYYS 4uczoPrlUkDuVGZA0icUULxRl5+YGOVjFecQ3BhfyJ4DL31zv8IDuHEsX6FkCxy/EIz0 oTYg== X-Gm-Message-State: AO0yUKWbiyfURC4ixGkpBbEynWw/7/C3ChMrr8iMTH7uLgnEYI6gGqR2 +/E1L28yLpTU4F6v1txMnw/NfkDW6nHUW6Aa X-Google-Smtp-Source: AK7set//U03qp8rXuTdVuLS/9D+F7/9YZA8Byw1LnudM3CTwbMgDqUxnUsCjvN/ChQuTe21MPf+LsA== X-Received: by 2002:a05:600c:330a:b0:3df:de27:4191 with SMTP id q10-20020a05600c330a00b003dfde274191mr19226786wmp.16.1676305900763; Mon, 13 Feb 2023 08:31:40 -0800 (PST) Received: from nuc.fritz.box (p200300f6af2efd00225e3e97da45b943.dip0.t-ipconnect.de. [2003:f6:af2e:fd00:225e:3e97:da45:b943]) by smtp.gmail.com with ESMTPSA id s7-20020a5d5107000000b002c556a4f1casm3877993wrt.42.2023.02.13.08.31.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 08:31:40 -0800 (PST) From: Mathias Krause To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Sean Christopherson , Paolo Bonzini , Mathias Krause Subject: [PATCH 4/5] KVM: x86: Shrink struct kvm_vcpu_arch Date: Mon, 13 Feb 2023 17:33:50 +0100 Message-Id: <20230213163351.30704-5-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213163351.30704-1-minipli@grsecurity.net> References: <20230213163351.30704-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Reshuffle the members of struct kvm_vcpu_arch to make use of otherwise unused padding holes, allowing denser packing without disrupting their grouping. This allows us to shrink the object size by 48 bytes for 64 bit builds. Signed-off-by: Mathias Krause --- Instead of attempting to create an optimal shuffle by sorting members by their alignment constraints, I intended to keep the members grouped by their meaning to keep the maintainability of the code. arch/x86/include/asm/kvm_host.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 040eee3e9583..5036456b05b0 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -824,18 +824,18 @@ struct kvm_vcpu_arch { int halt_request; /* real mode on Intel only */ + u32 kvm_cpuid_base; int cpuid_nent; struct kvm_cpuid_entry2 *cpuid_entries; - u32 kvm_cpuid_base; u64 reserved_gpa_bits; int maxphyaddr; /* emulate context */ - struct x86_emulate_ctxt *emulate_ctxt; bool emulate_regs_need_sync_to_vcpu; bool emulate_regs_need_sync_from_vcpu; + struct x86_emulate_ctxt *emulate_ctxt; int (*complete_userspace_io)(struct kvm_vcpu *vcpu); gpa_t time; @@ -916,17 +916,17 @@ struct kvm_vcpu_arch { unsigned long last_retry_addr; struct { - bool halted; gfn_t gfns[ASYNC_PF_PER_VCPU]; struct gfn_to_hva_cache data; u64 msr_en_val; /* MSR_KVM_ASYNC_PF_EN */ u64 msr_int_val; /* MSR_KVM_ASYNC_PF_INT */ - u16 vec; u32 id; + u16 vec; bool send_user_only; u32 host_apf_flags; bool delivery_as_pf_vmexit; bool pageready_pending; + bool halted; } apf; /* OSVW MSRs (AMD only) */ @@ -942,6 +942,9 @@ struct kvm_vcpu_arch { u64 msr_kvm_poll_control; + /* set at EPT violation at this point */ + unsigned long exit_qualification; + /* * Indicates the guest is trying to write a gfn that contains one or * more of the PTEs used to translate the write itself, i.e. the access @@ -959,9 +962,6 @@ struct kvm_vcpu_arch { */ bool write_fault_to_shadow_pgtable; - /* set at EPT violation at this point */ - unsigned long exit_qualification; - /* pv related host specific info */ struct { bool pv_unhalted; @@ -979,9 +979,6 @@ struct kvm_vcpu_arch { /* Host CPU on which VM-entry was most recently attempted */ int last_vmentry_cpu; - /* AMD MSRC001_0015 Hardware Configuration */ - u64 msr_hwcr; - /* pv related cpuid info */ struct { /* @@ -1006,6 +1003,9 @@ struct kvm_vcpu_arch { */ bool pdptrs_from_userspace; + /* AMD MSRC001_0015 Hardware Configuration */ + u64 msr_hwcr; + #if IS_ENABLED(CONFIG_HYPERV) hpa_t hv_root_tdp; #endif From patchwork Mon Feb 13 16:33:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13138688 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 7DC76C6379F for ; Mon, 13 Feb 2023 16:31:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230347AbjBMQb4 (ORCPT ); Mon, 13 Feb 2023 11:31:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230498AbjBMQbt (ORCPT ); Mon, 13 Feb 2023 11:31:49 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1885D1E298 for ; Mon, 13 Feb 2023 08:31:43 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id m14so12839680wrg.13 for ; Mon, 13 Feb 2023 08:31:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qNEDXzKGcLxGE5vSCOn4Gl1824w8NdzbMa0+BJPShNE=; b=b2NaKfo18h8EQ0ckZNBtyxLzCyw5M9p4fhmVsYeoz0XiLrx8boQvjYY21CLoNE1E3l H2uKeunpMpjc+4/RcIpCjUOFvo5V5nIvIHtgLSh2lVO0FW8OgZi1NfbTMWhbOHibIBxs 5jJ1DPqKsLjmJeU6t5Ic1ZjRykllSad8RqWA+6ZU/GJDJpmmrDDnBr+JpjL/ET+8ogU+ 1XGH9acCYd2vKMnrzWIs7LrbpER/2dfdUV24Ux6YMuwQ5jDUN6s6bF663wPubApxlPhv iecR8CIbWzOtqjCLXu9oCTSgZxTZm1srzQXDdvH4enhvnQgNSAOW5E2PyoF1rWUytJkY tZAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qNEDXzKGcLxGE5vSCOn4Gl1824w8NdzbMa0+BJPShNE=; b=0KJoI6JzNiGrCTqmWjCwDbiNPqnQYp6YKVIiLC9noQJaA9hiyKYwth+1mCdxfcbzaU +YElwycLTmAFswZaLEh6ekpVDNEDzOwmKv9iX3YdDwTLvbQWX8P2JD0iffpTKCJ/7APf pORlPalW4l4xxQQ+8XKpLPnCo4rfe+Ir8aj4qUL1oW9yLLF0SBtiMOuq9exTbuWASzqw rmzzrvB8tCDI/I/zmxYmUIwq/N0RvEJ87DOUSEGyb8BroMi/hC28qO6zbPc3yrcRSttz GX32OjBhGReIicpwb4gHdekmfqxuX58mB1jsQDtJwu/16SF/jElR49yjLKrWTK+yptd+ oMUg== X-Gm-Message-State: AO0yUKWnXdDOqvlxGTnGgRJh2WAhaxFWQrwQ72YI0rTF1j6BgdMPFCau 3LEQqZTdlyVFxUnxrfRlAy0djx3+VbwPRGrwcy0= X-Google-Smtp-Source: AK7set/LWizz6X1on8RNDb5ylCVP38yg270tfMyvtYLfp4tz2hO9d2gTLmo4FUtabOqeuqe1yUlNrw== X-Received: by 2002:a05:6000:1c7:b0:2c5:585d:74c6 with SMTP id t7-20020a05600001c700b002c5585d74c6mr4064199wrx.12.1676305901519; Mon, 13 Feb 2023 08:31:41 -0800 (PST) Received: from nuc.fritz.box (p200300f6af2efd00225e3e97da45b943.dip0.t-ipconnect.de. [2003:f6:af2e:fd00:225e:3e97:da45:b943]) by smtp.gmail.com with ESMTPSA id s7-20020a5d5107000000b002c556a4f1casm3877993wrt.42.2023.02.13.08.31.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 08:31:41 -0800 (PST) From: Mathias Krause To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Sean Christopherson , Paolo Bonzini , Mathias Krause Subject: [PATCH 5/5] KVM: Shrink struct kvm_vcpu Date: Mon, 13 Feb 2023 17:33:51 +0100 Message-Id: <20230213163351.30704-6-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213163351.30704-1-minipli@grsecurity.net> References: <20230213163351.30704-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Reshuffle the members of struct kvm_vcpu to make use of otherwise unused padding holes, allowing denser packing without disrupting the grouping nor introducing wrong cacheline sharing. The embedded mutex and spinlocks continue to not share cachelines, so no regressions because of lock contention leading to cacheline trashing is expected. This allows us to save 40 bytes for 64 bit builds. Signed-off-by: Mathias Krause --- include/linux/kvm_host.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 4f26b244f6d0..6e3e5a540037 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -330,8 +330,8 @@ struct kvm_vcpu { int srcu_depth; #endif int mode; + unsigned int guest_debug; u64 requests; - unsigned long guest_debug; struct mutex mutex; struct kvm_run *run; @@ -340,8 +340,8 @@ struct kvm_vcpu { struct rcuwait wait; #endif struct pid __rcu *pid; - int sigset_active; sigset_t sigset; + int sigset_active; unsigned int halt_poll_ns; bool valid_wakeup; @@ -356,10 +356,10 @@ struct kvm_vcpu { #ifdef CONFIG_KVM_ASYNC_PF struct { - u32 queued; struct list_head queue; struct list_head done; spinlock_t lock; + u32 queued; } async_pf; #endif