Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp2693563rwb; Sun, 15 Jan 2023 20:45:22 -0800 (PST) X-Google-Smtp-Source: AMrXdXtYFmwdsX8EHTl4ulIOO0sbdOFMip8ziLXaD1YRYGJ0CRNvJCFHBSY8Ma6FDt7Xho0FyjGI X-Received: by 2002:a50:fe89:0:b0:49b:53dc:fe0 with SMTP id d9-20020a50fe89000000b0049b53dc0fe0mr16442973edt.40.1673844322694; Sun, 15 Jan 2023 20:45:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673844322; cv=none; d=google.com; s=arc-20160816; b=b+8z3QB5kuhKxwTWFKyG6f4VYYg3a4oiaFrTphirF+VafwYqB8RuGUJVvqE6NMYymL +/f0fE+4kXeI4sBikk80g1b0krKRrVNs+dSpjJwZydXWrMstH0QARgliW5xs6KbbqxVX bNzUewXZQsMWcPyBysJDuxJTglPM80VSl1qczOtgdY2rHMuS0rTc/0sirgMq0q2fs2Mf BI97Fq0+WAIKv++HSJZgugEmcbhlAtyXeVw7NcTHGe6TOl/GUa57HIHcxJqTKtMTHJA4 cLQD4leVvnFV1cVDaX7LfNf0U9y2hEyxnK4KMqJsFa2foFp2hAyyHRA6kQSU3vExRq8V xrZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:cc:to; bh=TRe4lgkaKOw6SEun/NNZBPjYa/jSHTdunIuLes65o8c=; b=KOqm0ScwkJXkneyj+efG0Ie9FcTmcyvH1C4RSMaT8TBBgB3PBhszACfs82vlmg5E/Q euqsaV/MZVW351Bx6X64VI5OunXBptfiFaxchoONAwG9XlAy9CFbZALljgVc6fYvLfGy aBHAP/MPSdT8twEOHUN608vxKAIyLQyBB9FSkdXxd+FpvWrjaUITKESq4EbAknH73ZgE dH9+yjh9vWtNWuRVeWI34z2BP3q66F8FGjzmadXMcDM+XNdyMEF2SSV2EcdZ/wCrSkhc 2PccQhaGRwKtLt02iVDMDoFkoZcHnkfHiI9OocezW0U5te+gktePMENAPYs5hxKZJkVU TImg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u5-20020a50eac5000000b0045d4b7ad162si27103758edp.546.2023.01.15.20.45.09; Sun, 15 Jan 2023 20:45:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231859AbjAPE2Z (ORCPT + 52 others); Sun, 15 Jan 2023 23:28:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231506AbjAPE2W (ORCPT ); Sun, 15 Jan 2023 23:28:22 -0500 Received: from outgoing2021.csail.mit.edu (outgoing2021.csail.mit.edu [128.30.2.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 709D44C3F for ; Sun, 15 Jan 2023 20:28:21 -0800 (PST) Received: from c-24-17-218-140.hsd1.wa.comcast.net ([24.17.218.140] helo=srivatsab3MD6R.vmware.com) by outgoing2021.csail.mit.edu with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.95) (envelope-from ) id 1pHH69-00EU45-Mo; Sun, 15 Jan 2023 23:27:53 -0500 To: Juergen Gross , linux-kernel@vger.kernel.org, x86@kernel.org, virtualization@lists.linux-foundation.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Alexey Makhalov , VMware PV-Drivers Reviewers , Boris Ostrovsky , xen-devel@lists.xenproject.org References: <20230112152132.4399-1-jgross@suse.com> From: "Srivatsa S. Bhat" Subject: Re: [PATCH] x86/paravirt: merge activate_mm and dup_mmap callbacks Message-ID: <3fcb5078-852e-0886-c084-7fb0cfa5b757@csail.mit.edu> Date: Sun, 15 Jan 2023 20:27:50 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20230112152132.4399-1-jgross@suse.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Juergen, On 1/12/23 7:21 AM, Juergen Gross wrote: > The two paravirt callbacks .mmu.activate_mm and .mmu.dup_mmap are > sharing the same implementations in all cases: for Xen PV guests they > are pinning the PGD of the new mm_struct, and for all other cases > they are a NOP. > I was expecting that the duplicated functions xen_activate_mm() and xen_dup_mmap() would be merged into a common one, and that both .mmu.activate_mm and .mmu.dup_mmap callbacks would be mapped to that common implementation for Xen PV. > So merge them to a common callback .mmu.enter_mmap (in contrast to the > corresponding already existing .mmu.exit_mmap). > Instead, this patch seems to be merging the callbacks themselves... I see that's not an issue right now since there is no other actual user for these callbacks. But are we sure that merging the callbacks just because the current user (Xen PV) has the same implementation for both is a good idea? The callbacks are invoked at distinct points from fork/exec, so wouldn't it be valuable to retain that distinction in semantics in the callbacks as well? However, if you believe that two separate callbacks are not really required here (because there is no significant difference in what they mean, rather than because their callback implementations happen to be the same right now), then could you please expand on this and call it out in the commit message, please? Thank you! Regards, Srivatsa VMware Photon OS > As the first parameter of the old callbacks isn't used, drop it from > the replacement one. > > Signed-off-by: Juergen Gross > --- > arch/x86/include/asm/mmu_context.h | 4 ++-- > arch/x86/include/asm/paravirt.h | 14 +++----------- > arch/x86/include/asm/paravirt_types.h | 7 ++----- > arch/x86/kernel/paravirt.c | 3 +-- > arch/x86/xen/mmu_pv.c | 12 ++---------- > 5 files changed, 10 insertions(+), 30 deletions(-) > > diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h > index b8d40ddeab00..6a14b6c2165c 100644 > --- a/arch/x86/include/asm/mmu_context.h > +++ b/arch/x86/include/asm/mmu_context.h > @@ -134,7 +134,7 @@ extern void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, > > #define activate_mm(prev, next) \ > do { \ > - paravirt_activate_mm((prev), (next)); \ > + paravirt_enter_mmap(next); \ > switch_mm((prev), (next), NULL); \ > } while (0); > > @@ -167,7 +167,7 @@ static inline void arch_dup_pkeys(struct mm_struct *oldmm, > static inline int arch_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm) > { > arch_dup_pkeys(oldmm, mm); > - paravirt_arch_dup_mmap(oldmm, mm); > + paravirt_enter_mmap(mm); > return ldt_dup_context(oldmm, mm); > } > > diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h > index 73e9522db7c1..07bbdceaf35a 100644 > --- a/arch/x86/include/asm/paravirt.h > +++ b/arch/x86/include/asm/paravirt.h > @@ -332,16 +332,9 @@ static inline void tss_update_io_bitmap(void) > } > #endif > > -static inline void paravirt_activate_mm(struct mm_struct *prev, > - struct mm_struct *next) > +static inline void paravirt_enter_mmap(struct mm_struct *next) > { > - PVOP_VCALL2(mmu.activate_mm, prev, next); > -} > - > -static inline void paravirt_arch_dup_mmap(struct mm_struct *oldmm, > - struct mm_struct *mm) > -{ > - PVOP_VCALL2(mmu.dup_mmap, oldmm, mm); > + PVOP_VCALL1(mmu.enter_mmap, next); > } > > static inline int paravirt_pgd_alloc(struct mm_struct *mm) > @@ -787,8 +780,7 @@ extern void default_banner(void); > > #ifndef __ASSEMBLY__ > #ifndef CONFIG_PARAVIRT_XXL > -static inline void paravirt_arch_dup_mmap(struct mm_struct *oldmm, > - struct mm_struct *mm) > +static inline void paravirt_enter_mmap(struct mm_struct *mm) > { > } > #endif > diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h > index 8c1da419260f..71bf64b963df 100644 > --- a/arch/x86/include/asm/paravirt_types.h > +++ b/arch/x86/include/asm/paravirt_types.h > @@ -164,11 +164,8 @@ struct pv_mmu_ops { > unsigned long (*read_cr3)(void); > void (*write_cr3)(unsigned long); > > - /* Hooks for intercepting the creation/use of an mm_struct. */ > - void (*activate_mm)(struct mm_struct *prev, > - struct mm_struct *next); > - void (*dup_mmap)(struct mm_struct *oldmm, > - struct mm_struct *mm); > + /* Hook for intercepting the creation/use of an mm_struct. */ > + void (*enter_mmap)(struct mm_struct *mm); > > /* Hooks for allocating and freeing a pagetable top-level */ > int (*pgd_alloc)(struct mm_struct *mm); > diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c > index 327757afb027..ff1109b9c6cd 100644 > --- a/arch/x86/kernel/paravirt.c > +++ b/arch/x86/kernel/paravirt.c > @@ -352,8 +352,7 @@ struct paravirt_patch_template pv_ops = { > .mmu.make_pte = PTE_IDENT, > .mmu.make_pgd = PTE_IDENT, > > - .mmu.dup_mmap = paravirt_nop, > - .mmu.activate_mm = paravirt_nop, > + .mmu.enter_mmap = paravirt_nop, > > .mmu.lazy_mode = { > .enter = paravirt_nop, > diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c > index ee29fb558f2e..b3b8d289b9ab 100644 > --- a/arch/x86/xen/mmu_pv.c > +++ b/arch/x86/xen/mmu_pv.c > @@ -885,14 +885,7 @@ void xen_mm_unpin_all(void) > spin_unlock(&pgd_lock); > } > > -static void xen_activate_mm(struct mm_struct *prev, struct mm_struct *next) > -{ > - spin_lock(&next->page_table_lock); > - xen_pgd_pin(next); > - spin_unlock(&next->page_table_lock); > -} > - > -static void xen_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm) > +static void xen_enter_mmap(struct mm_struct *mm) > { > spin_lock(&mm->page_table_lock); > xen_pgd_pin(mm); > @@ -2153,8 +2146,7 @@ static const typeof(pv_ops) xen_mmu_ops __initconst = { > .make_p4d = PV_CALLEE_SAVE(xen_make_p4d), > #endif > > - .activate_mm = xen_activate_mm, > - .dup_mmap = xen_dup_mmap, > + .enter_mmap = xen_enter_mmap, > .exit_mmap = xen_exit_mmap, > > .lazy_mode = { >