From patchwork Fri Jan 26 08:06:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13532171 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E97E1C47422 for ; Fri, 26 Jan 2024 08:06:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FAA78D0005; Fri, 26 Jan 2024 03:06:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A9378D0002; Fri, 26 Jan 2024 03:06:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 44B448D0005; Fri, 26 Jan 2024 03:06:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 2F84F8D0002 for ; Fri, 26 Jan 2024 03:06:50 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id EFD971A0800 for ; Fri, 26 Jan 2024 08:06:49 +0000 (UTC) X-FDA: 81720730938.24.9DD9B1D Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf17.hostedemail.com (Postfix) with ESMTP id 4C52440019 for ; Fri, 26 Jan 2024 08:06:48 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=XPTenpJ9; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of 3F2izZQoKCOgiYcbiKRWONQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3F2izZQoKCOgiYcbiKRWONQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706256408; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=Q+MkK7elkwozxtf29PmL54XsONOmn3SLZnF2nfqAuzw=; b=4zpP4k3b3kFWo6xfa3lfwenLt88X2eh5lmWPmX0Hg4qT85vLK9KGomipZUOo1Gnuh7uXmt yyl+ozwE76H+2ybiXVz/j0nd0sUpcxPJ4k+lwqMXqQO1M8DRTgpYm2CWLAE1G8QL+phUK0 Hd0tf9y6r/j+VdFseA0I0/CyTNW1IV0= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=XPTenpJ9; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of 3F2izZQoKCOgiYcbiKRWONQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3F2izZQoKCOgiYcbiKRWONQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706256408; a=rsa-sha256; cv=none; b=CiKeq0EvsiC7dPPDvDYVTcVWjRrp+uotCK9fBb1VDyQc3g3x/Ch/uaaWdqbWy76HDBRdDR LWK1/WjMc6eYk5Q5ttK/mQOXhcOQQL+jl79PF/ymZV6UU3B824Ef9wV5YAo199zhxf9kDA bqmzO5WmoiZFGN2w8h23RDPSlElzrk4= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-602d22a54caso449417b3.3 for ; Fri, 26 Jan 2024 00:06:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706256407; x=1706861207; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Q+MkK7elkwozxtf29PmL54XsONOmn3SLZnF2nfqAuzw=; b=XPTenpJ9uLrH9R5hfHLaEth2WSYw/nlI1uv/aIYltBp4HqJN/MUkcnUqmz2Hxw6k0l M/ysPH38QiX5ahpYjtDiGGHY2vJ3Q79NccosonMmvQEIrCkMHEhGYpwjNQDafcvg1oDv 6MNL2pfjQlenYVGU7uMLjvY2onIzkCHtgJbzzQqGncxdjXzd4JtRi3OTr4D/tkGaybdI pMnXKfrUlLb36Exa500lip8hzJqJtlhDyH6TMyMy6LU70paec6ANrWCTbjRVwRfdNUYk ZP5Mb7DUylIQZjkt0jO6SEC5JXOAUdqbcxOlQcqdvIOQtRfgrdEGoqEwlFrnyQ9z7ibf Qxhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706256407; x=1706861207; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Q+MkK7elkwozxtf29PmL54XsONOmn3SLZnF2nfqAuzw=; b=v+CCGwUYt53R/0kS9XuAgsScURiMTQvxEPOl6WLSSfa851T9Vy287cFGCotiTlmpqi tg+eK37Ne6Agq5hwCsR43fbug6uPN4aQh2zcqIULiDIa6PDdrkXLNCYbT81VDfap9+K2 HYgKbiuVSZjxgX3PWanGSQdS7FFV2zaJwBPLSxtELfno8HFnax0HHdR/UlwRQOA5kJ/D e6PCt27wpqAJNVH+M4u48isUzXOpvMgg3UoL9HJdoEB5Fc+Af6g2fQ04yFCmeV1qudXq Ur9HUqVZjldq4d/wnlGaOhqLwneD+ThsqV0T4m3FKzCuygAmAfkrW99Tr7nXs7rsEixO aaMQ== X-Gm-Message-State: AOJu0YyI9oNM79Ofdh3DxbctOf8iz4IwjW8ZLVUJEbN8eQTwseUo1MiS W22Hpru51x+RmoHzmlyVs2IH+UlN5lsHpjRRGBOOrg0nc7YC/UeQkaa1K+Mr9MgArM2wwa3FxEK U4/fPjFinDeXUWbAA4g== X-Google-Smtp-Source: AGHT+IGU5QcjnbH97KOXGogNkkBb9OokhEIyAYw9IuZL/21fWEaWMGFuIPPbGaaXup7UnihTrxa26iMXfIYaPd+W X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a81:99cc:0:b0:5e7:12cc:a60f with SMTP id q195-20020a8199cc000000b005e712cca60fmr380957ywg.6.1706256407325; Fri, 26 Jan 2024 00:06:47 -0800 (PST) Date: Fri, 26 Jan 2024 08:06:43 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240126080644.1714297-1-yosryahmed@google.com> Subject: [PATCH 1/2] x86/mm: delete unused cpu argument to leave_mm() From: Yosry Ahmed To: Ingo Molnar Cc: Thomas Gleixner , Borislav Petkov , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Andrew Morton , x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 4C52440019 X-Stat-Signature: zt5dd8irmfto4buwiq15okdp6o6wb8zr X-HE-Tag: 1706256408-852965 X-HE-Meta: U2FsdGVkX19E7quhTvXXZY/TIMxWO19FAeXyTSEOuKB5Tosd2zHfpxWOWOXtlPf6OUSrn/oxvxMRQ4Tii4nYbr0rlFf49bti7Le50tcasU8g7+P3StFgQGrivrg5ApRi5kJe+9LVaSly82BIr7tfWkIjBBS0t/16BLkk9ilgtQirYMIGE6rm5fvGzwGDmsVrnnlGrXUftp9BqBhWEiKSn62oVA9KxlOzHkMuhh3pgGCdKwY3GAPPJcqcogW/xsatImL323Y1KnJtOnFO475N9Ya5bzyJjhESuHDQt7foJrQQVz0QSbIJWFoYKSZDDZE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Qz1rXJVs9kBStO7VjLf36rq5A52xKKfaKzlNKTASzSehQ7jjdBmMUz4oRUMCam8nSOqdN8WBexCh29wY3R6Sb65Wq/yjjrKoi4sGjAluRRbYlaJLhIMRAVnVtG8xkrw7YSkcnN1Rtp79wnYj/D6U/IlV/cE/T6thDcmQIkXRbby8h2MPOhD105fjNUkz2T+SZ8HxhutLXkYPbBe0ewotx6jrx9yYq2PoUOiUqb2wYt1hapKRyzR7JDaDJevVMspnXti2/aMnsH4BIMmMNyCZfqnrdfzBQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The argument is unused since commit 3d28ebceaffa ("x86/mm: Rework lazy TLB to track the actual loaded mm"), delete it. Signed-off-by: Yosry Ahmed --- arch/x86/include/asm/mmu.h | 2 +- arch/x86/kernel/alternative.c | 2 +- arch/x86/mm/tlb.c | 2 +- arch/x86/xen/mmu_pv.c | 2 +- drivers/cpuidle/cpuidle.c | 2 +- include/linux/mmu_context.h | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h index 0da5c227f490c..ce4677b8b7356 100644 --- a/arch/x86/include/asm/mmu.h +++ b/arch/x86/include/asm/mmu.h @@ -75,7 +75,7 @@ typedef struct { .lock = __MUTEX_INITIALIZER(mm.context.lock), \ } -void leave_mm(int cpu); +void leave_mm(void); #define leave_mm leave_mm #endif /* _ASM_X86_MMU_H */ diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index cc130b57542ac..66bd265c7a587 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -1805,7 +1805,7 @@ static inline temp_mm_state_t use_temporary_mm(struct mm_struct *mm) * restoring the previous mm. */ if (this_cpu_read(cpu_tlbstate_shared.is_lazy)) - leave_mm(smp_processor_id()); + leave_mm(); temp_state.mm = this_cpu_read(cpu_tlbstate.loaded_mm); switch_mm_irqs_off(NULL, mm, current); diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 5768d386efab6..80b0caa82a91b 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -299,7 +299,7 @@ static void load_new_mm_cr3(pgd_t *pgdir, u16 new_asid, unsigned long lam, write_cr3(new_mm_cr3); } -void leave_mm(int cpu) +void leave_mm(void) { struct mm_struct *loaded_mm = this_cpu_read(cpu_tlbstate.loaded_mm); diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c index 72af496a160c8..218773cfb009f 100644 --- a/arch/x86/xen/mmu_pv.c +++ b/arch/x86/xen/mmu_pv.c @@ -913,7 +913,7 @@ static void drop_mm_ref_this_cpu(void *info) struct mm_struct *mm = info; if (this_cpu_read(cpu_tlbstate.loaded_mm) == mm) - leave_mm(smp_processor_id()); + leave_mm(); /* * If this cpu still has a stale cr3 reference, then make sure diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 737a026ef58a3..02e40fd7d948c 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -237,7 +237,7 @@ noinstr int cpuidle_enter_state(struct cpuidle_device *dev, } if (target_state->flags & CPUIDLE_FLAG_TLB_FLUSHED) - leave_mm(dev->cpu); + leave_mm(); /* Take note of the planned idle state. */ sched_idle_set_state(target_state); diff --git a/include/linux/mmu_context.h b/include/linux/mmu_context.h index f2b7a3f040999..bbaec80c78c50 100644 --- a/include/linux/mmu_context.h +++ b/include/linux/mmu_context.h @@ -11,7 +11,7 @@ #endif #ifndef leave_mm -static inline void leave_mm(int cpu) { } +static inline void leave_mm(void) { } #endif /* From patchwork Fri Jan 26 08:06:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13532172 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1E49C48260 for ; Fri, 26 Jan 2024 08:06:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 60B6B8D0008; Fri, 26 Jan 2024 03:06:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A9C38D0002; Fri, 26 Jan 2024 03:06:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 425C28D0008; Fri, 26 Jan 2024 03:06:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 28C798D0002 for ; Fri, 26 Jan 2024 03:06:52 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C06398046A for ; Fri, 26 Jan 2024 08:06:51 +0000 (UTC) X-FDA: 81720731022.13.8273BD3 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf03.hostedemail.com (Postfix) with ESMTP id 08EB920016 for ; Fri, 26 Jan 2024 08:06:49 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=gLccipLw; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of 3GWizZQoKCOokaedkMTYQPSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--yosryahmed.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3GWizZQoKCOokaedkMTYQPSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706256410; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=qO38tEb5zM4VymKs6ibKE+57i3iPVkOa3/Idb5enOqs=; b=Q7NKzSU8qBEy4+0OerqY9NLaad0iVibeHpX9tlwnqZHz3JbUFkj7E30qvqRVhlMpqcysxA 643ZxHTVmbgTN9RAF/AsBSfz16WkRww3QPaS4d/1bN2YXrh4/22fKt+SCWAzbGIkXL464z 8nn0xkV0xxSsA86lMqVLxgGMtPgKrYg= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=gLccipLw; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of 3GWizZQoKCOokaedkMTYQPSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--yosryahmed.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3GWizZQoKCOokaedkMTYQPSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706256410; a=rsa-sha256; cv=none; b=PBQaglGnOTFmoHr7yXvBcvm7E1gu6xpZGmu54/28JEGglR4y2zmpDxIgV+rHjy1tYlEJ19 EWayNNtTs/qPdBO4pSt10T+dWBlxDFTIjd1PwrHpcaHdqNfnfiOR6UPEJe9ZAvrTVDbK5N fVhbhDAeX6vmyxUfN9HvYhVTnhV7x1Y= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc24de01bd9so231626276.1 for ; Fri, 26 Jan 2024 00:06:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706256409; x=1706861209; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=qO38tEb5zM4VymKs6ibKE+57i3iPVkOa3/Idb5enOqs=; b=gLccipLwXdYj34JXAlFIrZ9VLDYGawhu+LVFQlqM8J2VFjDtq+dxGxJJCdYTEOZdL7 koWHkGsOAuex09IAbTsZUuEQ8LqcCUYCEuLwIBED1/jPjAv0CTwn6i6a0CZeFy7u+paa tvylTzCEAgvmGtV6ti/TX4aakaUb6Y6cOZ08KNym2IBzhdnc9E+Oi1A4dj/t0KfpZVyf RLA44tYSnOVbtP6WQQiZ/IIa1AiDdr8N6bC+CSyDZ0tus+vPbDUu3FG8KWAXVRxd9lU3 zaIOQI4xeY/CSt0zjvQC502JSPzT2pXxI4KC18fK9OLZMeGHtIIL/mD1FlZQlCiu80V/ +W/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706256409; x=1706861209; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qO38tEb5zM4VymKs6ibKE+57i3iPVkOa3/Idb5enOqs=; b=U38dCmJJz7ONsa1bAo92r16dCL5mjwNIvLXoQ4XM3Re0cHpGtVzxTqWkBovyy9IM1M i4p986lk7L7404YgMZLNlG1sbxlnXaNyeRS6tOiiHr23HSqowSOELixEmBCmPo8eKX1x +m0hp4rRPx+yKtEXMmPYUBxbPNqkHZFz5hAMFMjbki26HA0iEX+cGgbhsjtMRCTlS1jC /k3bFRZGtymQzBoaUGg9wacQdGUh+hEOzN8+ldLVBYvhZ/1oIMaA40pj/TBNid+JRkVy mvJkzR2RvhJU05JQbphanyg1O2Ybl5uzdGSk7Rjb1zCv1SjEWZ2lX7VRgMDBiqiRuwPu 6GJw== X-Gm-Message-State: AOJu0YzvdF9Y4hINiAORiFjGXuX3oFeLPOUflKEyaIQdDXI6VS2/eGmk i7+5WRa5y8CfGlf5wPr5OKG4lhE37rlZIj4kdB5MfRwjKRoZLdsGRNtiSzSF74xWSyFPG/XNN0O im/Wo8SFsrxCUxmcacQ== X-Google-Smtp-Source: AGHT+IGtSc7FTilAvbWm1bnuTEL3QKF1axH5jK6w0o1wwqlROcZ4vY9lg44aTpbRR3M0/L4W8/DAZIlzpDwiNTHT X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:2085:b0:dc2:5525:f6b with SMTP id di5-20020a056902208500b00dc255250f6bmr539405ybb.7.1706256409103; Fri, 26 Jan 2024 00:06:49 -0800 (PST) Date: Fri, 26 Jan 2024 08:06:44 +0000 In-Reply-To: <20240126080644.1714297-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240126080644.1714297-1-yosryahmed@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240126080644.1714297-2-yosryahmed@google.com> Subject: [PATCH 2/2] x86/mm: clarify "prev" usage in switch_mm_irqs_off() From: Yosry Ahmed To: Ingo Molnar Cc: Thomas Gleixner , Borislav Petkov , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Andrew Morton , x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspam-User: X-Stat-Signature: kactfbiqscji7jwffbooacxksw3qrxn3 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 08EB920016 X-HE-Tag: 1706256409-137720 X-HE-Meta: U2FsdGVkX18QodMyVBJtpcCeepNAgDXUyl2qzNQNrGLcEi6uOZ5ZG8ZvIfSpovhKTKuHcROhVpi9HfzcGxafwvp7mxxyGFZ9GPvoPNOleyhdLYJ90LOs0JnUZlqT7P/TiFI2K6ZHlJZ1BsGKYej1V1Kk4qMBOUDtYDgD8NP26B0Ky38zED9cXzg7/ptAXUfIbz8v0L6uWF4162qQ/xZNT95fwohqG9JoRS5iKAxN4ApCtQ2hxZ7tbsuazHUhag0wiUnyzJxV2WZlP5xeL17ZFBte6kGn9JKkPqdFvWcw1aC9pWFcm2hHVlKz3iyfadLqEUjesQ8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UGt45kmyNm6AevJrza4d3ZDopNOhnXXC/DTmPTRk4i5tuO420oSryXieuvqytJbnQETxwGjNQjDhS6bYvN/cx5NooSdbA0GLVmoaCW1JRn9m9kJNeEC3e3BtGl1UKnMyfXKFpJpa48gVpsRJRqX0MFekoqNdkKDPLD5z6/DQHtLo/lP9kFjjGxZup0hAzK+D1f7rozcet7x8XqQ/E92gcXgkXI2zbuqsUrGdUuomLvBY9PLeNEd9XSWWNltzeKekzrE+OBz93yG0AtyzLivNNrA6z+gEqSRHpOEPyIg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In the x86 implementation of switch_mm_irqs_off(), we do not use the "prev" argument passed in by the caller, we use exclusively use "real_prev", which is cpu_tlbstate.loaded_mm. This is not obvious at the first sight. Furthermore, a comment describes a condition that happens when called with prev == next, but this should not affect the function in any way since prev is unused. Apparently, the comment is intended to clarify why we don't rely on prev == next to decide whether we need to update CR3, but again, it is not obvious. The comment also references the fact that leave_mm() calls with prev == NULL and tsk == NULL, but this also shouldn't matter because prev is unused and tsk is only used in one function which has a NULL check. Clarify things by renaming (prev -> unused) and (real_prev -> prev), also move and rewrite the comment as an explanation for why we don't rely on "prev" supplied by the caller in x86 code and use our own. Hopefully this makes reading the code easier. Signed-off-by: Yosry Ahmed --- arch/x86/mm/tlb.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 80b0caa82a91b..bf9605caf24f7 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -492,10 +492,16 @@ void cr4_update_pce(void *ignored) static inline void cr4_update_pce_mm(struct mm_struct *mm) { } #endif -void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, +/* + * The "prev" argument passed by the caller does not always match CR3. For + * example, the scheduler passes in active_mm when switching from lazy TLB mode + * to normal mode, but switch_mm_irqs_off() can be called from x86 code without + * updating active_mm. Use cpu_tlbstate.loaded_mm instead. + */ +void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next, struct task_struct *tsk) { - struct mm_struct *real_prev = this_cpu_read(cpu_tlbstate.loaded_mm); + struct mm_struct *prev = this_cpu_read(cpu_tlbstate.loaded_mm); u16 prev_asid = this_cpu_read(cpu_tlbstate.loaded_mm_asid); unsigned long new_lam = mm_lam_cr3_mask(next); bool was_lazy = this_cpu_read(cpu_tlbstate_shared.is_lazy); @@ -504,15 +510,6 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, bool need_flush; u16 new_asid; - /* - * NB: The scheduler will call us with prev == next when switching - * from lazy TLB mode to normal mode if active_mm isn't changing. - * When this happens, we don't assume that CR3 (and hence - * cpu_tlbstate.loaded_mm) matches next. - * - * NB: leave_mm() calls us with prev == NULL and tsk == NULL. - */ - /* We don't want flush_tlb_func() to run concurrently with us. */ if (IS_ENABLED(CONFIG_PROVE_LOCKING)) WARN_ON_ONCE(!irqs_disabled()); @@ -527,7 +524,7 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, * isn't free. */ #ifdef CONFIG_DEBUG_VM - if (WARN_ON_ONCE(__read_cr3() != build_cr3(real_prev->pgd, prev_asid, + if (WARN_ON_ONCE(__read_cr3() != build_cr3(prev->pgd, prev_asid, tlbstate_lam_cr3_mask()))) { /* * If we were to BUG here, we'd be very likely to kill @@ -559,7 +556,7 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, * provides that full memory barrier and core serializing * instruction. */ - if (real_prev == next) { + if (prev == next) { /* Not actually switching mm's */ VM_WARN_ON(this_cpu_read(cpu_tlbstate.ctxs[prev_asid].ctx_id) != next->context.ctx_id); @@ -574,7 +571,7 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, * mm_cpumask. The TLB shootdown code can figure out from * cpu_tlbstate_shared.is_lazy whether or not to send an IPI. */ - if (WARN_ON_ONCE(real_prev != &init_mm && + if (WARN_ON_ONCE(prev != &init_mm && !cpumask_test_cpu(cpu, mm_cpumask(next)))) cpumask_set_cpu(cpu, mm_cpumask(next)); @@ -616,10 +613,10 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, * Skip kernel threads; we never send init_mm TLB flushing IPIs, * but the bitmap manipulation can cause cache line contention. */ - if (real_prev != &init_mm) { + if (prev != &init_mm) { VM_WARN_ON_ONCE(!cpumask_test_cpu(cpu, - mm_cpumask(real_prev))); - cpumask_clear_cpu(cpu, mm_cpumask(real_prev)); + mm_cpumask(prev))); + cpumask_clear_cpu(cpu, mm_cpumask(prev)); } /* @@ -656,9 +653,9 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, this_cpu_write(cpu_tlbstate.loaded_mm, next); this_cpu_write(cpu_tlbstate.loaded_mm_asid, new_asid); - if (next != real_prev) { + if (next != prev) { cr4_update_pce_mm(next); - switch_ldt(real_prev, next); + switch_ldt(prev, next); } }