Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp435595rwb; Thu, 12 Jan 2023 07:59:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXvIQNE0d+Egfjax1y07ijJ6mcsfY6cPsVYUj5oHQKKq0SC/NUzP1UKJbzVsGd6MurEW9StQ X-Received: by 2002:a17:90a:66c1:b0:228:d42c:d5d6 with SMTP id z1-20020a17090a66c100b00228d42cd5d6mr6807301pjl.27.1673539181598; Thu, 12 Jan 2023 07:59:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673539181; cv=none; d=google.com; s=arc-20160816; b=O3Q4rvt4D0jQN+SbJOrLD9kMAODxH322BLFkR31D4vV5Haxq/J++0S3EbfIkvCbD/9 pBTXg4qd0/nwOFIfMyYmsEuSGu/DLCTiqy90/DcDgyCBZ8MxHRKtiu3qQvnOn2OKaShn 4xiydn/v94SlNyzZFN6EmQvs3IJWutxQB3cNWr0EKz02v7dHLl3KuoOfFazRlOUW5qOX f6sGqJgj9o/B+4nOvbFooENOlkODovrX1tfwLkEFD+CCmy9LLflyWuQqPkh2Ckg0EH2a yCOQ5V2w/W8hjbmaC5wvlrKiRXNyXpcTyiPcunw/vijca0vQLevuSNVAS8Fd70/bE3QS l43Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=2n0IdQPvR+Gxy3g7DvPKITwTHiT/5QBMjcXvwvG5gq8=; b=txKm5fZ2xs/Uj2cD7iMdc5rOud5NcU1CijflwZ69xY0A947r71x+zB3kf1YZHtQiqL tXTfNyMpYdJkS+6YzKahI2jXc3PEOG8SCOfTJEnB4JiTlvnlUTgzz/h+6vBmqQeRI84i IqU/5/mpPfRwgjan90hAIUl2OMvHAjQ3CudfpGAZzKRyiwLX+7d7uKE0+IceOXhh6dZU qWPrT6sI8BZpk9rFjzVVIDEjGoBPXhFzlpRjegJhrdUPGNlyJBvrL9L9/27KB1xlGMIJ 1/brJjLz6PiGlIWGbDg6KrWq4XV0Y2dEySZwGGjMaAuJIbSETVFSlynoF8zCf7Zm0Clc PHOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=aBmyfXqL; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k36-20020a635a64000000b004a48ed37ffdsi17474945pgm.196.2023.01.12.07.59.34; Thu, 12 Jan 2023 07:59:41 -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; dkim=pass header.i=@suse.com header.s=susede1 header.b=aBmyfXqL; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240375AbjALP3r (ORCPT + 50 others); Thu, 12 Jan 2023 10:29:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240481AbjALP2p (ORCPT ); Thu, 12 Jan 2023 10:28:45 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A62752C59 for ; Thu, 12 Jan 2023 07:21:36 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4D54D40269; Thu, 12 Jan 2023 15:21:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1673536894; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=2n0IdQPvR+Gxy3g7DvPKITwTHiT/5QBMjcXvwvG5gq8=; b=aBmyfXqLewedueE1l8HgnS8oOWeLEQsBebQ3+JmtzpZzl9WKiSECnoSe2djtAFYUFg2yN/ acxUR6stqti7Qe76GIxbS5WMojGnRTf19LbpN8XK+a9njRm4QPpWpJ8Z+aGoVqnwra2MEk bbQFMgCf9WV/aQ3RDAqPmCnv9Vf1osI= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E045513776; Thu, 12 Jan 2023 15:21:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 1KxjNX0lwGM6IwAAMHmgww (envelope-from ); Thu, 12 Jan 2023 15:21:33 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org, virtualization@lists.linux-foundation.org Cc: Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , "Srivatsa S. Bhat (VMware)" , Alexey Makhalov , VMware PV-Drivers Reviewers , Boris Ostrovsky , xen-devel@lists.xenproject.org Subject: [PATCH] x86/paravirt: merge activate_mm and dup_mmap callbacks Date: Thu, 12 Jan 2023 16:21:32 +0100 Message-Id: <20230112152132.4399-1-jgross@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 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. So merge them to a common callback .mmu.enter_mmap (in contrast to the corresponding already existing .mmu.exit_mmap). 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 = { -- 2.35.3