Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp825847ybg; Wed, 10 Jun 2020 15:01:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzt2DLp/f53n+KvDq6lz0x4Zg552CAjQ+BLC9QwSKfyAVaLoSAz0xlEjZmb5Isj//4X+Z3G X-Received: by 2002:a17:906:4d14:: with SMTP id r20mr5293342eju.346.1591826503589; Wed, 10 Jun 2020 15:01:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591826503; cv=none; d=google.com; s=arc-20160816; b=TFY0i2X8wZBPyWaqR6p19wU68r/eiUpWBinyWors44v/6wxaUDk0mEXPUF43VhSihI VeYqg4KlOnu1qWMCaat7T7GtYEYP5p5nJnlicZwp4Dy+MpzTwGnzvV+VeIGjJ+jioTyv 0XEzT+kcAh5H5C4SfcNECvmwmcbujfBAg8xyYb09tIJnHwfpM+aIBZEwvwkI2178HzDC XRY6KwiE+ieCIC1rCHUMVzW9Kn6JCJ5Pd6/Ttlwr2SEz39HAZdsDBM4vx2Ez1Iy6sKYw JJnI7kDy08hdTKrGyUly2RY0FioulEskQ4GKY5cpbLfOMIt9sya/gB9S+2WjoNCkaT0B BYnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Q55NYjy9IRmkKRciGyl293b435BFJrXWdUL8I09kIMU=; b=jTZVcLbIOfV1Ab7CLUqx9fC/laIZOkd+3eaeRzNA9vmKYuxRchv9oaNUaBV5vdKi3W Z3G3doSwJ27NbVOvrdhLMivMmJ8Xr8ON/4V07Pf7KWMdxC/XzMETDrnkTlFQbcaco/X8 oCGikN4Peq64TYN/OAuGjuHodaeFmoDT9d0faIROW2T+uNNPr2QDkxiNHscOEQBZJuLk dBGKJgpjSRxf+dZyw9PnKRLaX3xOK3PyOdciMCrrOFn4yTR20VLVcqK7IkVR8VwpwWuy xTGx0WVzo8X/Hzeu22fXODkxSI8QZgMur30L6//0HrXByJJfkd7fBbphMygg6MRXganQ WF7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=W6J9UkKF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y24si499404edu.80.2020.06.10.15.01.19; Wed, 10 Jun 2020 15:01:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=W6J9UkKF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726460AbgFJV6f (ORCPT + 99 others); Wed, 10 Jun 2020 17:58:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726447AbgFJV6e (ORCPT ); Wed, 10 Jun 2020 17:58:34 -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 7DB0CC08C5C1 for ; Wed, 10 Jun 2020 14:58:34 -0700 (PDT) Received: by mail-vs1-xe41.google.com with SMTP id j13so2247806vsn.3 for ; Wed, 10 Jun 2020 14:58:34 -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=Q55NYjy9IRmkKRciGyl293b435BFJrXWdUL8I09kIMU=; b=W6J9UkKFqBOh6IZVBDPOthBCXab0QZziKeEa8pn13Vr5J8K7h1X58Xb6OmuCCjEhOb 92gem+OhVNk7kSF2F0BUdLkFKKg5ROVVbpsqxDgCpafDITiIZamI2Vry6Aog71jIZo8h NiD26bt+GKRoofdVOB/75RW7uwmApZl8QFmK1s6MT//oW9G+svD3zlytHSextcXbDuOv y9pQW8NIgzMZzDeYq/95xGCrFZR1LNU3HnOc4zwE/u+v8axp4rGvGkkNauOwDQCqQjf9 2j8VU13YtK2Z4G+LXtKQblPwmmZ0YbNkS/g2LzBxhn7LOE6G4a9uJFutNjZyOutkrtp+ BPZQ== 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=Q55NYjy9IRmkKRciGyl293b435BFJrXWdUL8I09kIMU=; b=KjHeazCXqZPZY6NhmaI878ErxOwol6NCrsDx4S53Tg5gbxxm6NRocblOlfnxs4vbWC qLsbuFPCb2t8/Tj9Uj79LK4vSmNEhYQeM/UiRiDkGOESKlgCC42o11mQWUJ7GuBjaDA7 NnJetoVLEeRV/JybikyBuyu5ilW8Owfis4r/iih9qM/5E9TrdP+UrmNE4qg3d70bI/9f IlKbw8n4Wb+7Oekbft+tNwSLOUj+crxua7K23udUJh56JTBjpbpjTRc9CAKoSA+URcQK fR0h5MNJnhD5i3OtZgICtShXB2JjK2I9kFAQaYqkJKt6QpGMNFDYabXzc+XWteYlSuzw orFQ== X-Gm-Message-State: AOAM530hV8xjiDXkmMy7CmjpeHpUqm/WfdXdlUbNeSOF5/TVvs7PPmnl 5RyA/WSr9OwqB9WSQisZHQdvowbkaR5Csqf5MLYBOA== X-Received: by 2002:a67:f982:: with SMTP id b2mr4385200vsq.202.1591826312742; Wed, 10 Jun 2020 14:58:32 -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: From: Ben Gardon Date: Wed, 10 Jun 2020 14:58:21 -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 Wed, Jun 10, 2020 at 12:01 PM Ben Gardon wrote: > > 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 > > - Oops I didn't catch this on my first read through, but in patch 16 in this series I see some references to KVM_NR_MEM_OBJS being removed. As a result I would not expect this patch to build. Other references to this value should probably replaced with KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE as well. > > #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 > >