Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1640559ybv; Sun, 23 Feb 2020 11:26:46 -0800 (PST) X-Google-Smtp-Source: APXvYqx/PxO9+tmKAOEY4gXUCnukZGDi2ROIKraoLBlwR/jSYeGq95Pa5EKg8Em5Z2gGIrV+Mqmf X-Received: by 2002:aca:b4c6:: with SMTP id d189mr10439958oif.17.1582486006578; Sun, 23 Feb 2020 11:26:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582486006; cv=none; d=google.com; s=arc-20160816; b=HJ4gXRhh+4LSRwKIPoxPUPAq5dvzhEvRUZrf8iWoXaM/Z0G8ZyAnJkJx7oYpkuveXL lGVGtV7l56/OusaIcLH2qQFJihm3dQy26KdFJGBT+3RMpaKfbGP54X/9vpdtHP+8yVsI V4wsXWpaQzMmiRZozqn/8WhwNNn6AvbLO4RenhTBn3sMzShx+GOmYpnwdtiZXfvCp41c OZgQ4/cOMXSHXWIH/1jeo/2RUcvUXOh+Bnw6FgIVv4MjaZitYT+cJclzqxtxZN1Q+DX8 hTvaOXH6dqSqa8u/8PxwUYlHZy5z91bFi8Eb9sKnAmUwr1TEN7eXPdoTZ29nhJW0H+nn cmuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WdAkDw0jQFrUByye8xgaI8zjWL8waIYULZhRupYTANc=; b=ZQpJwIqhgncE+CFXscP2t+iXdTO4zo2OSLV9m3SHO0s25gEOiwzr/d5BWBj0KjSU2j zWI8e9+ghMJ5hu0baPXiUH3TFDAjytD+UyK71k9WTOBHbyGnHhTSRjCTba+ec2dUq+Wn WEonkblc1ehIwc5IvliUKwId9xlBdV41wnTjqmJQwC0AwOsF8YaFrwAPPwNXsoqEMLk0 /Z4F/aPCVxnZhsNtgl2CT9QhfXsFQx+GptJw6LuveI7mmcoKIvC2uBGrPvfbV/GL5AzR 0WIwGIA1GBkCTCxdu5gw/fLGOW5//7neHZmKL6f4Uo7TtIB4poiZfw8Iqfy1lKaRCCzv VjIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IHiDd7qE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z4si4349305oix.48.2020.02.23.11.26.33; Sun, 23 Feb 2020 11:26:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IHiDd7qE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727167AbgBWTZb (ORCPT + 99 others); Sun, 23 Feb 2020 14:25:31 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:30719 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726302AbgBWTZa (ORCPT ); Sun, 23 Feb 2020 14:25:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582485929; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WdAkDw0jQFrUByye8xgaI8zjWL8waIYULZhRupYTANc=; b=IHiDd7qEhNAlRXdbCLWd6kDDeMjk9G36AlsvrsrfM+CmgCviaibZSQ0b7z6aXGVyE9oIZH oxc2Fpz3iEPli3LQUlN8aefXsOD0NJs/YFKT/rTLY/kP5Kdh6j4SPGI+qr3JURwvprZkDD A4ZM5qfqHG6f755Y9ys0iQi0FA7y0j0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-383-2r8xQ-VeOtOrXPcYfZce8A-1; Sun, 23 Feb 2020 14:25:26 -0500 X-MC-Unique: 2r8xQ-VeOtOrXPcYfZce8A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3F1BF107ACC5; Sun, 23 Feb 2020 19:25:24 +0000 (UTC) Received: from mail (ovpn-120-118.rdu2.redhat.com [10.10.120.118]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3C33A5C1B2; Sun, 23 Feb 2020 19:25:21 +0000 (UTC) From: Andrea Arcangeli To: Will Deacon , Catalin Marinas , Rafael Aquini , Mark Salter Cc: Jon Masters , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Michal Hocko , QI Fuli Subject: [PATCH 1/3] mm: use_mm: fix for arches checking mm_users to optimize TLB flushes Date: Sun, 23 Feb 2020 14:25:18 -0500 Message-Id: <20200223192520.20808-2-aarcange@redhat.com> In-Reply-To: <20200223192520.20808-1-aarcange@redhat.com> References: <20200223192520.20808-1-aarcange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org alpha, ia64, mips, powerpc, sh, sparc are relying on a check on mm->mm_users to know if they can skip some remote TLB flushes for single threaded processes. Most callers of use_mm() tend to invoke mmget_not_zero() or get_task_mm() before use_mm() to ensure the mm will remain alive in between use_mm() and unuse_mm(). Some callers however don't increase mm_users and they instead rely on serialization in __mmput() to ensure the mm will remain alive in between use_mm() and unuse_mm(). Not increasing mm_users during use_mm() is however unsafe for aforementioned arch TLB flushes optimizations. So either mmget()/mmput() should be added to the problematic callers of use_mm()/unuse_mm() or we can embed them in use_mm()/unuse_mm() which is more robust. Signed-off-by: Andrea Arcangeli --- mm/mmu_context.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/mmu_context.c b/mm/mmu_context.c index 3e612ae748e9..ced0e1218c0f 100644 --- a/mm/mmu_context.c +++ b/mm/mmu_context.c @@ -30,6 +30,7 @@ void use_mm(struct mm_struct *mm) mmgrab(mm); tsk->active_mm =3D mm; } + mmget(mm); tsk->mm =3D mm; switch_mm(active_mm, mm, tsk); task_unlock(tsk); @@ -57,6 +58,7 @@ void unuse_mm(struct mm_struct *mm) task_lock(tsk); sync_mm_rss(mm); tsk->mm =3D NULL; + mmput(mm); /* active_mm is still 'mm' */ enter_lazy_tlb(mm, tsk); task_unlock(tsk);