From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A1E1C433E0 for ; Wed, 10 Jun 2020 19:02:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D3E302072E for ; Wed, 10 Jun 2020 19:02:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="j77jjoo7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728528AbgFJTCH (ORCPT ); Wed, 10 Jun 2020 15:02:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726266AbgFJTCG (ORCPT ); Wed, 10 Jun 2020 15:02:06 -0400 Received: from mail-vs1-xe41.google.com (mail-vs1-xe41.google.com [IPv6:2607:f8b0:4864:20::e41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DC91C03E96B for ; Wed, 10 Jun 2020 12:02:06 -0700 (PDT) Received: by mail-vs1-xe41.google.com with SMTP id d21so1900584vsh.12 for ; Wed, 10 Jun 2020 12:02:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XkZ55trzaUYm4ZN8iiWbYVBM5yaqKCA9LC0xYy1/Ppg=; b=j77jjoo7BrC8ciPGZh5G4XNFx0e/IBM+vJQKsFXGHoq2TXyMMOLL5IFSAOeVWYXIHX UUepAz4IhQ0AlzlRyIrLJDLHLN+OtKh3UbUcbB2FA8h2jPk0dBpfyHtdvHuw98gIMd/S XJqRGYa0RiMBLTj/KghRH1rEWrRVKCG5FkNT65MrWebia3qbZLyzgCVQzSovmX+pk/QO YLuGZoIPx1vpd9s1OPQZGxAui+c216eaaqJjwovF8i+u2NRGk6b5wFirQho+mZYNHiCo M4pT5y57eyroD64Cjkknjiy2l/c1llHRr6NKOVDCNXHHADTAr3hlsVP2nooHvKJ0+0Qv boAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XkZ55trzaUYm4ZN8iiWbYVBM5yaqKCA9LC0xYy1/Ppg=; b=kjJgMQAFdAEGdtU5YckQUYXOfJ4fKZJjv4Q8dcMzX0UCh9GK+74Akg6FeTy+JtJPro Vq0KE92DDijraUYoC6LD+AP8T7eYTaghZRBzJwpUZ410gvgDhK/GdBUeAwzcQTx6J7O+ e7Gm5nHQINJrhl/Rx6jhGrRFge2uibZVqV0AIfsMF7dYtYrTQSjdAcUw3DmPhD4Pp6ve 6oQpH+y6HHIsjxa7a4EBXSCmzgXr6B52hyaKgQq7dw7ka4s6su42Gl+XeNrIFh91X2UY /R+Bkh0WTtlmjqoRO8UN3fW8ueFmvU53tuqvngtb7bKRkDtN2R0vHa4cBkzo1WmsKrO8 UJsw== X-Gm-Message-State: AOAM5312DtqXzau11ES7BVk7UpRnMJm6GVAtBPFCtSilL56KBk6BBxdh tCWzswYKKi1miHTeP4AyChQ9djwx2M731jzA5Xl/KQ== X-Google-Smtp-Source: ABdhPJw1h1etsAjqik8ZjlfcXh6LoIcFUCUxEYjPHBc2XH6MGt7HC0fZP7/Ar9KFOlcDw0D5NiX7gZFNtlTQQHnm/A4= X-Received: by 2002:a67:af10:: with SMTP id v16mr4200556vsl.235.1591815725256; Wed, 10 Jun 2020 12:02:05 -0700 (PDT) MIME-Version: 1.0 References: <20200605213853.14959-1-sean.j.christopherson@intel.com> <20200605213853.14959-15-sean.j.christopherson@intel.com> In-Reply-To: <20200605213853.14959-15-sean.j.christopherson@intel.com> From: Ben Gardon Date: Wed, 10 Jun 2020 12:01:54 -0700 Message-ID: Subject: Re: [PATCH 14/21] KVM: Move x86's version of struct kvm_mmu_memory_cache to common code To: Sean Christopherson Cc: Marc Zyngier , Paul Mackerras , Christian Borntraeger , Janosch Frank , Paolo Bonzini , James Morse , Julien Thierry , Suzuki K Poulose , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Feiner , Peter Shier , Junaid Shahid , Christoffer Dall Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 5, 2020 at 2:39 PM Sean Christopherson wrote: > > Move x86's 'struct kvm_mmu_memory_cache' to common code in anticipation > of moving the entire x86 implementation code to common KVM and reusing > it for arm64 and MIPS. Add a new architecture specific asm/kvm_types.h > to control the existence and parameters of the struct. The new header > is needed to avoid a chicken-and-egg problem with asm/kvm_host.h as all > architectures define instances of the struct in their vCPU structs. > > Suggested-by: Christoffer Dall > Signed-off-by: Sean Christopherson Reviewed-by: Ben Gardon > --- > arch/arm64/include/asm/kvm_types.h | 6 ++++++ > arch/mips/include/asm/kvm_types.h | 5 +++++ > arch/powerpc/include/asm/kvm_types.h | 5 +++++ > arch/s390/include/asm/kvm_types.h | 5 +++++ > arch/x86/include/asm/kvm_host.h | 13 ------------- > arch/x86/include/asm/kvm_types.h | 7 +++++++ > include/linux/kvm_types.h | 19 +++++++++++++++++++ > 7 files changed, 47 insertions(+), 13 deletions(-) > create mode 100644 arch/arm64/include/asm/kvm_types.h > create mode 100644 arch/mips/include/asm/kvm_types.h > create mode 100644 arch/powerpc/include/asm/kvm_types.h > create mode 100644 arch/s390/include/asm/kvm_types.h > create mode 100644 arch/x86/include/asm/kvm_types.h > > diff --git a/arch/arm64/include/asm/kvm_types.h b/arch/arm64/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..d0987007d581 > --- /dev/null > +++ b/arch/arm64/include/asm/kvm_types.h > @@ -0,0 +1,6 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_ARM64_KVM_TYPES_H > +#define _ASM_ARM64_KVM_TYPES_H > + > +#endif /* _ASM_ARM64_KVM_TYPES_H */ > + > diff --git a/arch/mips/include/asm/kvm_types.h b/arch/mips/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..5efeb32a5926 > --- /dev/null > +++ b/arch/mips/include/asm/kvm_types.h > @@ -0,0 +1,5 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_MIPS_KVM_TYPES_H > +#define _ASM_MIPS_KVM_TYPES_H > + > +#endif /* _ASM_MIPS_KVM_TYPES_H */ > diff --git a/arch/powerpc/include/asm/kvm_types.h b/arch/powerpc/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..f627eceaa314 > --- /dev/null > +++ b/arch/powerpc/include/asm/kvm_types.h > @@ -0,0 +1,5 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_POWERPC_KVM_TYPES_H > +#define _ASM_POWERPC_KVM_TYPES_H > + > +#endif /* _ASM_POWERPC_KVM_TYPES_H */ > diff --git a/arch/s390/include/asm/kvm_types.h b/arch/s390/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..b66a81f8a354 > --- /dev/null > +++ b/arch/s390/include/asm/kvm_types.h > @@ -0,0 +1,5 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_S390_KVM_TYPES_H > +#define _ASM_S390_KVM_TYPES_H > + > +#endif /* _ASM_S390_KVM_TYPES_H */ > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index fb99e6776e27..8e8fea13b6c7 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -193,8 +193,6 @@ struct x86_exception; > enum x86_intercept; > enum x86_intercept_stage; > > -#define KVM_NR_MEM_OBJS 40 > - > #define KVM_NR_DB_REGS 4 > > #define DR6_BD (1 << 13) > @@ -245,17 +243,6 @@ enum x86_intercept_stage; > > struct kvm_kernel_irq_routing_entry; > > -/* > - * We don't want allocation failures within the mmu code, so we preallocate > - * enough memory for a single page fault in a cache. > - */ > -struct kvm_mmu_memory_cache { > - int nobjs; > - gfp_t gfp_zero; > - struct kmem_cache *kmem_cache; > - void *objects[KVM_NR_MEM_OBJS]; > -}; > - > /* > * the pages used as guest page table on soft mmu are tracked by > * kvm_memory_slot.arch.gfn_track which is 16 bits, so the role bits used > diff --git a/arch/x86/include/asm/kvm_types.h b/arch/x86/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..08f1b57d3b62 > --- /dev/null > +++ b/arch/x86/include/asm/kvm_types.h > @@ -0,0 +1,7 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_X86_KVM_TYPES_H > +#define _ASM_X86_KVM_TYPES_H > + > +#define KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE 40 > + > +#endif /* _ASM_X86_KVM_TYPES_H */ > diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h > index 68e84cf42a3f..a7580f69dda0 100644 > --- a/include/linux/kvm_types.h > +++ b/include/linux/kvm_types.h > @@ -20,6 +20,8 @@ enum kvm_mr_change; > > #include > > +#include > + > /* > * Address types: > * > @@ -58,4 +60,21 @@ struct gfn_to_pfn_cache { > bool dirty; > }; > > +#ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE > +/* > + * Memory caches are used to preallocate memory ahead of various MMU flows, > + * e.g. page fault handlers. Gracefully handling allocation failures deep in > + * MMU flows is problematic, as is triggering reclaim, I/O, etc... while > + * holding MMU locks. Note, these caches act more like prefetch buffers than > + * classical caches, i.e. objects are not returned to the cache on being freed. > + */ > +struct kvm_mmu_memory_cache { > + int nobjs; > + gfp_t gfp_zero; > + struct kmem_cache *kmem_cache; > + void *objects[KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE]; > +}; > +#endif > + > + > #endif /* __KVM_TYPES_H__ */ > -- > 2.26.0 > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35B39C433E0 for ; Wed, 10 Jun 2020 19:40:18 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id E0D782078C for ; Wed, 10 Jun 2020 19:40:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="j77jjoo7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E0D782078C Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvmarm-bounces@lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 8C6614B20A; Wed, 10 Jun 2020 15:40:17 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@google.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id m+Eyhhh0YV7k; Wed, 10 Jun 2020 15:40:16 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id D9B054B1B3; Wed, 10 Jun 2020 15:40:13 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 452334B196 for ; Wed, 10 Jun 2020 15:02:07 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uutk3LEtCRDb for ; Wed, 10 Jun 2020 15:02:06 -0400 (EDT) Received: from mail-vs1-f66.google.com (mail-vs1-f66.google.com [209.85.217.66]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 0FC284B104 for ; Wed, 10 Jun 2020 15:02:06 -0400 (EDT) Received: by mail-vs1-f66.google.com with SMTP id t132so1934914vst.2 for ; Wed, 10 Jun 2020 12:02:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XkZ55trzaUYm4ZN8iiWbYVBM5yaqKCA9LC0xYy1/Ppg=; b=j77jjoo7BrC8ciPGZh5G4XNFx0e/IBM+vJQKsFXGHoq2TXyMMOLL5IFSAOeVWYXIHX UUepAz4IhQ0AlzlRyIrLJDLHLN+OtKh3UbUcbB2FA8h2jPk0dBpfyHtdvHuw98gIMd/S XJqRGYa0RiMBLTj/KghRH1rEWrRVKCG5FkNT65MrWebia3qbZLyzgCVQzSovmX+pk/QO YLuGZoIPx1vpd9s1OPQZGxAui+c216eaaqJjwovF8i+u2NRGk6b5wFirQho+mZYNHiCo M4pT5y57eyroD64Cjkknjiy2l/c1llHRr6NKOVDCNXHHADTAr3hlsVP2nooHvKJ0+0Qv boAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XkZ55trzaUYm4ZN8iiWbYVBM5yaqKCA9LC0xYy1/Ppg=; b=d4vs6nzhwW9/iGeXtr2fkvVYtsqqNY2Zy9yv6SP6K5daRB33z7V39uQkyKwgaLqBee 00OrYOuBaTbLXp8uo2nG+d74vQLcuKc4dJFYj0Me7f6PiuQn+PFjetmoxE6IPm7gPHei KNb9obffvsuy4gflAufvKJPYM56UnfBxuAg6hzGoE4ZIgK8p/QP7b+274LrrSI1CpNb2 Vy8JkKtToQnz85YWR/dQY52Uc48O7g4srEdxg+u1hUJzvkXonl/jnhVVCm4kD1P/SaMD FdmvJg3zcsKIIiJF15kHZqpTYyQWcDaAPkrQYoNT8HtS6slOBFIcugSJk7chyVCcCLqp SgKw== X-Gm-Message-State: AOAM531w/XUeyAw+id40mzyN5jh531H2rEWAwpGUwKLhpGejMT1AZ74N b0bekl7XSNgaFaSeNdm/bFYxl+Actnx2qaQG6mkvCA== X-Google-Smtp-Source: ABdhPJw1h1etsAjqik8ZjlfcXh6LoIcFUCUxEYjPHBc2XH6MGt7HC0fZP7/Ar9KFOlcDw0D5NiX7gZFNtlTQQHnm/A4= X-Received: by 2002:a67:af10:: with SMTP id v16mr4200556vsl.235.1591815725256; Wed, 10 Jun 2020 12:02:05 -0700 (PDT) MIME-Version: 1.0 References: <20200605213853.14959-1-sean.j.christopherson@intel.com> <20200605213853.14959-15-sean.j.christopherson@intel.com> In-Reply-To: <20200605213853.14959-15-sean.j.christopherson@intel.com> From: Ben Gardon Date: Wed, 10 Jun 2020 12:01:54 -0700 Message-ID: Subject: Re: [PATCH 14/21] KVM: Move x86's version of struct kvm_mmu_memory_cache to common code To: Sean Christopherson X-Mailman-Approved-At: Wed, 10 Jun 2020 15:40:12 -0400 Cc: Wanpeng Li , kvm@vger.kernel.org, David Hildenbrand , linux-kernel@vger.kernel.org, Paul Mackerras , Claudio Imbrenda , kvmarm@lists.cs.columbia.edu, Janosch Frank , Marc Zyngier , Joerg Roedel , Christian Borntraeger , Junaid Shahid , kvm-ppc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Jim Mattson , Cornelia Huck , Peter Shier , linux-mips@vger.kernel.org, Paolo Bonzini , Vitaly Kuznetsov , Peter Feiner X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Fri, Jun 5, 2020 at 2:39 PM Sean Christopherson wrote: > > Move x86's 'struct kvm_mmu_memory_cache' to common code in anticipation > of moving the entire x86 implementation code to common KVM and reusing > it for arm64 and MIPS. Add a new architecture specific asm/kvm_types.h > to control the existence and parameters of the struct. The new header > is needed to avoid a chicken-and-egg problem with asm/kvm_host.h as all > architectures define instances of the struct in their vCPU structs. > > Suggested-by: Christoffer Dall > Signed-off-by: Sean Christopherson Reviewed-by: Ben Gardon > --- > arch/arm64/include/asm/kvm_types.h | 6 ++++++ > arch/mips/include/asm/kvm_types.h | 5 +++++ > arch/powerpc/include/asm/kvm_types.h | 5 +++++ > arch/s390/include/asm/kvm_types.h | 5 +++++ > arch/x86/include/asm/kvm_host.h | 13 ------------- > arch/x86/include/asm/kvm_types.h | 7 +++++++ > include/linux/kvm_types.h | 19 +++++++++++++++++++ > 7 files changed, 47 insertions(+), 13 deletions(-) > create mode 100644 arch/arm64/include/asm/kvm_types.h > create mode 100644 arch/mips/include/asm/kvm_types.h > create mode 100644 arch/powerpc/include/asm/kvm_types.h > create mode 100644 arch/s390/include/asm/kvm_types.h > create mode 100644 arch/x86/include/asm/kvm_types.h > > diff --git a/arch/arm64/include/asm/kvm_types.h b/arch/arm64/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..d0987007d581 > --- /dev/null > +++ b/arch/arm64/include/asm/kvm_types.h > @@ -0,0 +1,6 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_ARM64_KVM_TYPES_H > +#define _ASM_ARM64_KVM_TYPES_H > + > +#endif /* _ASM_ARM64_KVM_TYPES_H */ > + > diff --git a/arch/mips/include/asm/kvm_types.h b/arch/mips/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..5efeb32a5926 > --- /dev/null > +++ b/arch/mips/include/asm/kvm_types.h > @@ -0,0 +1,5 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_MIPS_KVM_TYPES_H > +#define _ASM_MIPS_KVM_TYPES_H > + > +#endif /* _ASM_MIPS_KVM_TYPES_H */ > diff --git a/arch/powerpc/include/asm/kvm_types.h b/arch/powerpc/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..f627eceaa314 > --- /dev/null > +++ b/arch/powerpc/include/asm/kvm_types.h > @@ -0,0 +1,5 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_POWERPC_KVM_TYPES_H > +#define _ASM_POWERPC_KVM_TYPES_H > + > +#endif /* _ASM_POWERPC_KVM_TYPES_H */ > diff --git a/arch/s390/include/asm/kvm_types.h b/arch/s390/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..b66a81f8a354 > --- /dev/null > +++ b/arch/s390/include/asm/kvm_types.h > @@ -0,0 +1,5 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_S390_KVM_TYPES_H > +#define _ASM_S390_KVM_TYPES_H > + > +#endif /* _ASM_S390_KVM_TYPES_H */ > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index fb99e6776e27..8e8fea13b6c7 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -193,8 +193,6 @@ struct x86_exception; > enum x86_intercept; > enum x86_intercept_stage; > > -#define KVM_NR_MEM_OBJS 40 > - > #define KVM_NR_DB_REGS 4 > > #define DR6_BD (1 << 13) > @@ -245,17 +243,6 @@ enum x86_intercept_stage; > > struct kvm_kernel_irq_routing_entry; > > -/* > - * We don't want allocation failures within the mmu code, so we preallocate > - * enough memory for a single page fault in a cache. > - */ > -struct kvm_mmu_memory_cache { > - int nobjs; > - gfp_t gfp_zero; > - struct kmem_cache *kmem_cache; > - void *objects[KVM_NR_MEM_OBJS]; > -}; > - > /* > * the pages used as guest page table on soft mmu are tracked by > * kvm_memory_slot.arch.gfn_track which is 16 bits, so the role bits used > diff --git a/arch/x86/include/asm/kvm_types.h b/arch/x86/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..08f1b57d3b62 > --- /dev/null > +++ b/arch/x86/include/asm/kvm_types.h > @@ -0,0 +1,7 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_X86_KVM_TYPES_H > +#define _ASM_X86_KVM_TYPES_H > + > +#define KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE 40 > + > +#endif /* _ASM_X86_KVM_TYPES_H */ > diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h > index 68e84cf42a3f..a7580f69dda0 100644 > --- a/include/linux/kvm_types.h > +++ b/include/linux/kvm_types.h > @@ -20,6 +20,8 @@ enum kvm_mr_change; > > #include > > +#include > + > /* > * Address types: > * > @@ -58,4 +60,21 @@ struct gfn_to_pfn_cache { > bool dirty; > }; > > +#ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE > +/* > + * Memory caches are used to preallocate memory ahead of various MMU flows, > + * e.g. page fault handlers. Gracefully handling allocation failures deep in > + * MMU flows is problematic, as is triggering reclaim, I/O, etc... while > + * holding MMU locks. Note, these caches act more like prefetch buffers than > + * classical caches, i.e. objects are not returned to the cache on being freed. > + */ > +struct kvm_mmu_memory_cache { > + int nobjs; > + gfp_t gfp_zero; > + struct kmem_cache *kmem_cache; > + void *objects[KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE]; > +}; > +#endif > + > + > #endif /* __KVM_TYPES_H__ */ > -- > 2.26.0 > _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.7 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DCD8C433E2 for ; Wed, 10 Jun 2020 19:02:11 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EFABC2072E for ; Wed, 10 Jun 2020 19:02:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="lV4Ck4K+"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="j77jjoo7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EFABC2072E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ymQ0fq2FogNTY/OHmnfCdUtsTKBq8qikdZqY4eNyn+I=; b=lV4Ck4K+qvPXSf AoPIvzzEG9Tn6KTd9LB9s5B7+uTIX7sxQHdUNzEDNBY20bJe/xsAbGk+sppgpL5Y32giN0xop1RVu NavO4dOEIEGpptwrLfvwR2ixcpnMMOr55w3yRUcU2HeTpB9Pzjo0I+jUAhx2bz/3b1UkAODwR2A91 bEIJsljwmgezRhQaTP6d9qCsbZFvHCaqVKJ8oaqlfjAoou/9/8FivP8soc5gmJjYWP83WPS53Gsxz HsC6che5T02hgxoGNdlK9qu59Gy2v71Nlu6PI98TgiyAq/2bfI6PScRC9HK1lQdwirh94/BIBChT0 kHpUxUcDV8p0MpQpaiuw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jj5zG-0003Kf-AG; Wed, 10 Jun 2020 19:02:10 +0000 Received: from mail-vs1-xe43.google.com ([2607:f8b0:4864:20::e43]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jj5zC-0003Jt-Mp for linux-arm-kernel@lists.infradead.org; Wed, 10 Jun 2020 19:02:08 +0000 Received: by mail-vs1-xe43.google.com with SMTP id u17so1919798vsu.7 for ; Wed, 10 Jun 2020 12:02:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XkZ55trzaUYm4ZN8iiWbYVBM5yaqKCA9LC0xYy1/Ppg=; b=j77jjoo7BrC8ciPGZh5G4XNFx0e/IBM+vJQKsFXGHoq2TXyMMOLL5IFSAOeVWYXIHX UUepAz4IhQ0AlzlRyIrLJDLHLN+OtKh3UbUcbB2FA8h2jPk0dBpfyHtdvHuw98gIMd/S XJqRGYa0RiMBLTj/KghRH1rEWrRVKCG5FkNT65MrWebia3qbZLyzgCVQzSovmX+pk/QO YLuGZoIPx1vpd9s1OPQZGxAui+c216eaaqJjwovF8i+u2NRGk6b5wFirQho+mZYNHiCo M4pT5y57eyroD64Cjkknjiy2l/c1llHRr6NKOVDCNXHHADTAr3hlsVP2nooHvKJ0+0Qv boAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XkZ55trzaUYm4ZN8iiWbYVBM5yaqKCA9LC0xYy1/Ppg=; b=HaZU8XJXNBpqZAtvhpubAEpXoJzfUW6aYc8NsyQGnBZDPG43dyELKqxWhNLTagjfHc 8pUgYtF+uwnEX96jMoWi44dULFLjnq5g7RH6XV3lhXMfVVAr9wUodIiKmdgNmqBdTJAe hkE7pKm+36bXFyUjT6N0XB2autItRP+0cE2l6NSUu/3amTQ8F1SGIYKXmTu3alqGoag0 mJhSvUFxqu9GiPwEapG4bX5E/HIDur3NC2PzaFSbdpK95e14RY4M3XrYZBr147TP1rKS cB7zAibGtP+64f4mr9Kccq7iRnm37/HJ/2K+tbmO3ir//iwWwb10IUPZ7ITvEMLBq0fI gCXg== X-Gm-Message-State: AOAM530yjq9oaJXLATJheqD23pPNatEcqtqImJl5LUMNND29Bdp7d6bk n9mR+rWlMQwVP9v7e7zaLLG77IWWmA6eYZGspAB2+A== X-Google-Smtp-Source: ABdhPJw1h1etsAjqik8ZjlfcXh6LoIcFUCUxEYjPHBc2XH6MGt7HC0fZP7/Ar9KFOlcDw0D5NiX7gZFNtlTQQHnm/A4= X-Received: by 2002:a67:af10:: with SMTP id v16mr4200556vsl.235.1591815725256; Wed, 10 Jun 2020 12:02:05 -0700 (PDT) MIME-Version: 1.0 References: <20200605213853.14959-1-sean.j.christopherson@intel.com> <20200605213853.14959-15-sean.j.christopherson@intel.com> In-Reply-To: <20200605213853.14959-15-sean.j.christopherson@intel.com> From: Ben Gardon Date: Wed, 10 Jun 2020 12:01:54 -0700 Message-ID: Subject: Re: [PATCH 14/21] KVM: Move x86's version of struct kvm_mmu_memory_cache to common code To: Sean Christopherson X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200610_120206_762579_86C99331 X-CRM114-Status: GOOD ( 19.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christoffer Dall , Wanpeng Li , kvm@vger.kernel.org, David Hildenbrand , linux-kernel@vger.kernel.org, Paul Mackerras , Claudio Imbrenda , kvmarm@lists.cs.columbia.edu, Janosch Frank , Marc Zyngier , Joerg Roedel , Christian Borntraeger , Julien Thierry , Junaid Shahid , Suzuki K Poulose , kvm-ppc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Jim Mattson , Cornelia Huck , Peter Shier , linux-mips@vger.kernel.org, James Morse , Paolo Bonzini , Vitaly Kuznetsov , Peter Feiner Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Jun 5, 2020 at 2:39 PM Sean Christopherson wrote: > > Move x86's 'struct kvm_mmu_memory_cache' to common code in anticipation > of moving the entire x86 implementation code to common KVM and reusing > it for arm64 and MIPS. Add a new architecture specific asm/kvm_types.h > to control the existence and parameters of the struct. The new header > is needed to avoid a chicken-and-egg problem with asm/kvm_host.h as all > architectures define instances of the struct in their vCPU structs. > > Suggested-by: Christoffer Dall > Signed-off-by: Sean Christopherson Reviewed-by: Ben Gardon > --- > arch/arm64/include/asm/kvm_types.h | 6 ++++++ > arch/mips/include/asm/kvm_types.h | 5 +++++ > arch/powerpc/include/asm/kvm_types.h | 5 +++++ > arch/s390/include/asm/kvm_types.h | 5 +++++ > arch/x86/include/asm/kvm_host.h | 13 ------------- > arch/x86/include/asm/kvm_types.h | 7 +++++++ > include/linux/kvm_types.h | 19 +++++++++++++++++++ > 7 files changed, 47 insertions(+), 13 deletions(-) > create mode 100644 arch/arm64/include/asm/kvm_types.h > create mode 100644 arch/mips/include/asm/kvm_types.h > create mode 100644 arch/powerpc/include/asm/kvm_types.h > create mode 100644 arch/s390/include/asm/kvm_types.h > create mode 100644 arch/x86/include/asm/kvm_types.h > > diff --git a/arch/arm64/include/asm/kvm_types.h b/arch/arm64/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..d0987007d581 > --- /dev/null > +++ b/arch/arm64/include/asm/kvm_types.h > @@ -0,0 +1,6 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_ARM64_KVM_TYPES_H > +#define _ASM_ARM64_KVM_TYPES_H > + > +#endif /* _ASM_ARM64_KVM_TYPES_H */ > + > diff --git a/arch/mips/include/asm/kvm_types.h b/arch/mips/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..5efeb32a5926 > --- /dev/null > +++ b/arch/mips/include/asm/kvm_types.h > @@ -0,0 +1,5 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_MIPS_KVM_TYPES_H > +#define _ASM_MIPS_KVM_TYPES_H > + > +#endif /* _ASM_MIPS_KVM_TYPES_H */ > diff --git a/arch/powerpc/include/asm/kvm_types.h b/arch/powerpc/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..f627eceaa314 > --- /dev/null > +++ b/arch/powerpc/include/asm/kvm_types.h > @@ -0,0 +1,5 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_POWERPC_KVM_TYPES_H > +#define _ASM_POWERPC_KVM_TYPES_H > + > +#endif /* _ASM_POWERPC_KVM_TYPES_H */ > diff --git a/arch/s390/include/asm/kvm_types.h b/arch/s390/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..b66a81f8a354 > --- /dev/null > +++ b/arch/s390/include/asm/kvm_types.h > @@ -0,0 +1,5 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_S390_KVM_TYPES_H > +#define _ASM_S390_KVM_TYPES_H > + > +#endif /* _ASM_S390_KVM_TYPES_H */ > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index fb99e6776e27..8e8fea13b6c7 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -193,8 +193,6 @@ struct x86_exception; > enum x86_intercept; > enum x86_intercept_stage; > > -#define KVM_NR_MEM_OBJS 40 > - > #define KVM_NR_DB_REGS 4 > > #define DR6_BD (1 << 13) > @@ -245,17 +243,6 @@ enum x86_intercept_stage; > > struct kvm_kernel_irq_routing_entry; > > -/* > - * We don't want allocation failures within the mmu code, so we preallocate > - * enough memory for a single page fault in a cache. > - */ > -struct kvm_mmu_memory_cache { > - int nobjs; > - gfp_t gfp_zero; > - struct kmem_cache *kmem_cache; > - void *objects[KVM_NR_MEM_OBJS]; > -}; > - > /* > * the pages used as guest page table on soft mmu are tracked by > * kvm_memory_slot.arch.gfn_track which is 16 bits, so the role bits used > diff --git a/arch/x86/include/asm/kvm_types.h b/arch/x86/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..08f1b57d3b62 > --- /dev/null > +++ b/arch/x86/include/asm/kvm_types.h > @@ -0,0 +1,7 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_X86_KVM_TYPES_H > +#define _ASM_X86_KVM_TYPES_H > + > +#define KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE 40 > + > +#endif /* _ASM_X86_KVM_TYPES_H */ > diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h > index 68e84cf42a3f..a7580f69dda0 100644 > --- a/include/linux/kvm_types.h > +++ b/include/linux/kvm_types.h > @@ -20,6 +20,8 @@ enum kvm_mr_change; > > #include > > +#include > + > /* > * Address types: > * > @@ -58,4 +60,21 @@ struct gfn_to_pfn_cache { > bool dirty; > }; > > +#ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE > +/* > + * Memory caches are used to preallocate memory ahead of various MMU flows, > + * e.g. page fault handlers. Gracefully handling allocation failures deep in > + * MMU flows is problematic, as is triggering reclaim, I/O, etc... while > + * holding MMU locks. Note, these caches act more like prefetch buffers than > + * classical caches, i.e. objects are not returned to the cache on being freed. > + */ > +struct kvm_mmu_memory_cache { > + int nobjs; > + gfp_t gfp_zero; > + struct kmem_cache *kmem_cache; > + void *objects[KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE]; > +}; > +#endif > + > + > #endif /* __KVM_TYPES_H__ */ > -- > 2.26.0 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ben Gardon Date: Wed, 10 Jun 2020 19:01:54 +0000 Subject: Re: [PATCH 14/21] KVM: Move x86's version of struct kvm_mmu_memory_cache to common code Message-Id: List-Id: References: <20200605213853.14959-1-sean.j.christopherson@intel.com> <20200605213853.14959-15-sean.j.christopherson@intel.com> In-Reply-To: <20200605213853.14959-15-sean.j.christopherson@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Sean Christopherson Cc: Marc Zyngier , Paul Mackerras , Christian Borntraeger , Janosch Frank , Paolo Bonzini , James Morse , Julien Thierry , Suzuki K Poulose , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Feiner , Peter Shier , Junaid Shahid , Christoffer Dall On Fri, Jun 5, 2020 at 2:39 PM Sean Christopherson wrote: > > Move x86's 'struct kvm_mmu_memory_cache' to common code in anticipation > of moving the entire x86 implementation code to common KVM and reusing > it for arm64 and MIPS. Add a new architecture specific asm/kvm_types.h > to control the existence and parameters of the struct. The new header > is needed to avoid a chicken-and-egg problem with asm/kvm_host.h as all > architectures define instances of the struct in their vCPU structs. > > Suggested-by: Christoffer Dall > Signed-off-by: Sean Christopherson Reviewed-by: Ben Gardon > --- > arch/arm64/include/asm/kvm_types.h | 6 ++++++ > arch/mips/include/asm/kvm_types.h | 5 +++++ > arch/powerpc/include/asm/kvm_types.h | 5 +++++ > arch/s390/include/asm/kvm_types.h | 5 +++++ > arch/x86/include/asm/kvm_host.h | 13 ------------- > arch/x86/include/asm/kvm_types.h | 7 +++++++ > include/linux/kvm_types.h | 19 +++++++++++++++++++ > 7 files changed, 47 insertions(+), 13 deletions(-) > create mode 100644 arch/arm64/include/asm/kvm_types.h > create mode 100644 arch/mips/include/asm/kvm_types.h > create mode 100644 arch/powerpc/include/asm/kvm_types.h > create mode 100644 arch/s390/include/asm/kvm_types.h > create mode 100644 arch/x86/include/asm/kvm_types.h > > diff --git a/arch/arm64/include/asm/kvm_types.h b/arch/arm64/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..d0987007d581 > --- /dev/null > +++ b/arch/arm64/include/asm/kvm_types.h > @@ -0,0 +1,6 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_ARM64_KVM_TYPES_H > +#define _ASM_ARM64_KVM_TYPES_H > + > +#endif /* _ASM_ARM64_KVM_TYPES_H */ > + > diff --git a/arch/mips/include/asm/kvm_types.h b/arch/mips/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..5efeb32a5926 > --- /dev/null > +++ b/arch/mips/include/asm/kvm_types.h > @@ -0,0 +1,5 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_MIPS_KVM_TYPES_H > +#define _ASM_MIPS_KVM_TYPES_H > + > +#endif /* _ASM_MIPS_KVM_TYPES_H */ > diff --git a/arch/powerpc/include/asm/kvm_types.h b/arch/powerpc/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..f627eceaa314 > --- /dev/null > +++ b/arch/powerpc/include/asm/kvm_types.h > @@ -0,0 +1,5 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_POWERPC_KVM_TYPES_H > +#define _ASM_POWERPC_KVM_TYPES_H > + > +#endif /* _ASM_POWERPC_KVM_TYPES_H */ > diff --git a/arch/s390/include/asm/kvm_types.h b/arch/s390/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..b66a81f8a354 > --- /dev/null > +++ b/arch/s390/include/asm/kvm_types.h > @@ -0,0 +1,5 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_S390_KVM_TYPES_H > +#define _ASM_S390_KVM_TYPES_H > + > +#endif /* _ASM_S390_KVM_TYPES_H */ > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index fb99e6776e27..8e8fea13b6c7 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -193,8 +193,6 @@ struct x86_exception; > enum x86_intercept; > enum x86_intercept_stage; > > -#define KVM_NR_MEM_OBJS 40 > - > #define KVM_NR_DB_REGS 4 > > #define DR6_BD (1 << 13) > @@ -245,17 +243,6 @@ enum x86_intercept_stage; > > struct kvm_kernel_irq_routing_entry; > > -/* > - * We don't want allocation failures within the mmu code, so we preallocate > - * enough memory for a single page fault in a cache. > - */ > -struct kvm_mmu_memory_cache { > - int nobjs; > - gfp_t gfp_zero; > - struct kmem_cache *kmem_cache; > - void *objects[KVM_NR_MEM_OBJS]; > -}; > - > /* > * the pages used as guest page table on soft mmu are tracked by > * kvm_memory_slot.arch.gfn_track which is 16 bits, so the role bits used > diff --git a/arch/x86/include/asm/kvm_types.h b/arch/x86/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..08f1b57d3b62 > --- /dev/null > +++ b/arch/x86/include/asm/kvm_types.h > @@ -0,0 +1,7 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_X86_KVM_TYPES_H > +#define _ASM_X86_KVM_TYPES_H > + > +#define KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE 40 > + > +#endif /* _ASM_X86_KVM_TYPES_H */ > diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h > index 68e84cf42a3f..a7580f69dda0 100644 > --- a/include/linux/kvm_types.h > +++ b/include/linux/kvm_types.h > @@ -20,6 +20,8 @@ enum kvm_mr_change; > > #include > > +#include > + > /* > * Address types: > * > @@ -58,4 +60,21 @@ struct gfn_to_pfn_cache { > bool dirty; > }; > > +#ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE > +/* > + * Memory caches are used to preallocate memory ahead of various MMU flows, > + * e.g. page fault handlers. Gracefully handling allocation failures deep in > + * MMU flows is problematic, as is triggering reclaim, I/O, etc... while > + * holding MMU locks. Note, these caches act more like prefetch buffers than > + * classical caches, i.e. objects are not returned to the cache on being freed. > + */ > +struct kvm_mmu_memory_cache { > + int nobjs; > + gfp_t gfp_zero; > + struct kmem_cache *kmem_cache; > + void *objects[KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE]; > +}; > +#endif > + > + > #endif /* __KVM_TYPES_H__ */ > -- > 2.26.0 >