From patchwork Thu Sep 27 08:50:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147691 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1726377lji; Thu, 27 Sep 2018 01:51:12 -0700 (PDT) X-Google-Smtp-Source: ACcGV63yB6GVaaQN3qf+W+/S/v8Ac2Ss1AxuHzHy6kdQodK68xwvO72H02gIurAdnlgVT+E831JU X-Received: by 2002:a17:902:aa02:: with SMTP id be2-v6mr9861092plb.294.1538038272774; Thu, 27 Sep 2018 01:51:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538038272; cv=none; d=google.com; s=arc-20160816; b=izCFFe2VTaAyOYKe9silRCJ1Qz9oqbHgZQE3Z80I7kWSKecKpgkdSd9NjeSXqqh3jz ceHv0rBxwio7tjHFralp1fjmSvHE9LyXC14SjmwQnBD4YjPpYJOfnB+SkzfiIBJDkEza ESAhrTzeVNVUGfaAIWiZJ2rA19WTz9Z5IgZvtz0X6ETtk7nTv7PF96yE5oer5NbrXJS5 Sf8qg7VhoA8xjUlsEJznTW73V318B7ThVK2Bg5IfX40L66ILZdvVYo/gyPtdgSK7otpJ GIFmpZRh9b3D1ArwS4alm18Ooofnc7rszI5Yi+7dbDZcsZfVqFVIBSP34YBTFq7Fehzq lPZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=iV7F4d1AYaAve1kQcC/87SijzJzQIBKlPBUcmLRWBv0=; b=GgJbSnzNkwUFmiV8K5CByzeGv2M2A3Ae/7dLwB4zHSo88QVudNksFHe1E6YNOFZjYj 2zvyxxWOk2zo/Y8b4TuRUZA0nb+nFLNDYQ9vijwpk5rmaQUDFSJNYKxI1zek5CGOyJ9K +/rBHH6m/snmLMyu9uZy+RzXHMU/KBSpiHhTbMrd8ojX+LCe9N3BUiz3zzC+9ktJ4RZP Bkf1GfQX+CTBHx/JA4sxGBp5KAdeGIWQG+zzzhku11cO+msz0kDzY8rRIFiSY1yrfqcb LA+eDwOX0jDKAYlY0HNilTjSy52uWy9/BjuERmuR0RDZNa5MHTxXJpDlC6h69ZasitkT X56w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TkZmmJdB; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y14-v6si1513151plp.458.2018.09.27.01.51.12; Thu, 27 Sep 2018 01:51:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-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=@linaro.org header.s=google header.b=TkZmmJdB; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727415AbeI0PIT (ORCPT + 3 others); Thu, 27 Sep 2018 11:08:19 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:37796 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727362AbeI0PIT (ORCPT ); Thu, 27 Sep 2018 11:08:19 -0400 Received: by mail-wm1-f67.google.com with SMTP id y26-v6so4490124wma.2 for ; Thu, 27 Sep 2018 01:51:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iV7F4d1AYaAve1kQcC/87SijzJzQIBKlPBUcmLRWBv0=; b=TkZmmJdBo/SUvBqPKL+IcIanULSh9vtUwZ5eAdAWdba7syillbGVRCXzXNAyovEjhx h2S6gEAG/tX9CkTqagjlyppkJboAiR4CryMJID7lv2wLQwboMOyNG52rWbZxH0umVy3V MG8h/p/0E1462SFuOvI2Jg4mLzQjLYjD1h+gk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iV7F4d1AYaAve1kQcC/87SijzJzQIBKlPBUcmLRWBv0=; b=gSYMJwXlyzgwOCg1/yjy0q1Ljh5USDttNnUCr4rqtm5KWTL2zbyVC3L+x8lTEZpr/C tbN9sUkre8C4/YjgWIZP8rHqdQnuoKm50KkeiipJ9cIjwpE6Q9YP3VelLI7zPT922q2v q67Cn6Jq1wpGNGBJrQmp7mBaHtdQI5sET8h3J7Q/FozQZnzHVG4kckFyGq/5QMSA87/Y SPeWCrNJFNNffjKKah5vI7fYvDa6uCNUIKHnJRJEv+lQLdS7wscEVqC47cAL6Ahc08gH n4ogDKYQmeBojDpyx5AR94TWtzWATZl9HxWEtZXFACqOp32F4mIMnQIL/iqQEcsL8o5b B0aA== X-Gm-Message-State: ABuFfohnj2itA3jd2+nYJ5o8g4ShbHA043ukBUglZiyQIsh0SLnLrefx g+xaGa0AvL8aKOFGRf34NsDm/A== X-Received: by 2002:a1c:e5cf:: with SMTP id c198-v6mr7058866wmh.113.1538038267937; Thu, 27 Sep 2018 01:51:07 -0700 (PDT) Received: from rev03.home ([2a01:cb1d:112:6f00:546e:3c44:5966:2f5e]) by smtp.gmail.com with ESMTPSA id p11-v6sm1304055wrd.74.2018.09.27.01.51.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 01:51:07 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-efi@vger.kernel.org, Aaron Ma , Alistair Strachan , Ben Hutchings , Bhupesh Sharma , Hans de Goede , Ivan Hu , Jeremy Linton , Marc Zyngier , Matt Fleming , Peter Robinson , Sai Praneeth Prakhya , Sebastian Andrzej Siewior , Stefan Agner Subject: [PATCH 08/11] efi/x86: drop task_lock() from efi_switch_mm() Date: Thu, 27 Sep 2018 10:50:35 +0200 Message-Id: <20180927085039.8391-9-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180927085039.8391-1-ard.biesheuvel@linaro.org> References: <20180927085039.8391-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Sebastian Andrzej Siewior efi_switch_mm() is a wrapper around switch_mm() which saves current's ->active_mm, sets the requests mm as ->active_mm and invokes switch_mm(). I don't think that task_lock() is required during that procedure. It protects ->mm which isn't changed here. It needs to be mentioned that during the whole procedure (switch to EFI's mm and back) the preemption needs to be disabled. A context switch at this point would reset the cr3 value based on current->mm. Also, this function may not be invoked at the same time on a different CPU because it would overwrite the efi_scratch.prev_mm information. Remove task_lock() and also update the comment to reflect it. Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Ard Biesheuvel --- arch/x86/platform/efi/efi_64.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) -- 2.18.0 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index ee5d08f25ce4..e8da7f492970 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c @@ -619,18 +619,16 @@ void __init efi_dump_pagetable(void) /* * Makes the calling thread switch to/from efi_mm context. Can be used - * for SetVirtualAddressMap() i.e. current->active_mm == init_mm as well - * as during efi runtime calls i.e current->active_mm == current_mm. - * We are not mm_dropping()/mm_grabbing() any mm, because we are not - * losing/creating any references. + * in a kernel thread and user context. Preemption needs to remain disabled + * while the EFI-mm is borrowed. mmgrab()/mmdrop() is not used because the mm + * can not change under us. + * It should be ensured that there are no concurent calls to this function. */ void efi_switch_mm(struct mm_struct *mm) { - task_lock(current); efi_scratch.prev_mm = current->active_mm; current->active_mm = mm; switch_mm(efi_scratch.prev_mm, mm, NULL); - task_unlock(current); } #ifdef CONFIG_EFI_MIXED