From patchwork Tue May 21 20:51:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rick Edgecombe X-Patchwork-Id: 10954499 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2858676 for ; Tue, 21 May 2019 20:53:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16C30288CF for ; Tue, 21 May 2019 20:53:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A60328B08; Tue, 21 May 2019 20:53:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4909A288CF for ; Tue, 21 May 2019 20:53:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 15F256B0007; Tue, 21 May 2019 16:53:19 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 04F066B000D; Tue, 21 May 2019 16:53:18 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB7106B0003; Tue, 21 May 2019 16:53:18 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by kanga.kvack.org (Postfix) with ESMTP id 9D64F6B0006 for ; Tue, 21 May 2019 16:53:18 -0400 (EDT) Received: by mail-pl1-f199.google.com with SMTP id y1so12133122plr.13 for ; Tue, 21 May 2019 13:53:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=qq5XpzPoyzrxc7VeunrLCYkiPjJ8tOqQGgXIagmQiCM=; b=MobiiCZGFAvLN16xlOFJsSG4kqAxXfK0VGm5R11fEV7YXVYUl7R7nfyTT+rV6Nbn13 BnW3VdfjsKONFJe9mQ0FzGtMtRr4/t1hHKvjT9Zljszjw5/eC8uCcurcJiIc9HChthE0 IF36s+4aQLynWG78x4MtrFc8DdHFzjSOJi7Hrm/FaQuuBUh7zCRT2LqgOWzJ8ElBa168 cpxijHQVKkpolicrDkNVbgwpmIiEssTAyNe/mF6EX91GrWFK1zg8Fo3ix0rrMV2iJOsl 9AOf45jhgPhUj6mudMv000u+75LYe9k+2QN4DPnLZhGdB7sx0vFarZaE9xeyWs1UCACc eUGw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: APjAAAXGk0a5HfcoC/HTT7y8jSC0HRDKVisQhWFZaBt2pBD3ZUzpyjdt TXPzBRAhrvkEaee6iwR2gJPjz36CZXeVTS9RFKiUG04bS19FyAmChzSdBwNTZgMGOJKLImPMuuz jhkpJ1RRB3g4LuIjeeca80aD8TxAwbuPMfkpRKRBB54OioisjcF+91SUVC7PsuIf1CA== X-Received: by 2002:a65:628d:: with SMTP id f13mr33306166pgv.177.1558471998200; Tue, 21 May 2019 13:53:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqyIpJ7DKuVnnyOkaMDYu+Ux9lXl7Q1pEd79jJ6fKexvS2Z+d9Q1AhHW2qwqQPF8MCSd+VEO X-Received: by 2002:a65:628d:: with SMTP id f13mr33306104pgv.177.1558471997405; Tue, 21 May 2019 13:53:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558471997; cv=none; d=google.com; s=arc-20160816; b=ECUJOaFtVNniDy0MD7N3r+fsZhwstG2b+Y82Qjpu1l+5GrHMRrpPUwRad7YDUIyHQ4 7qnB8SiapxAzpZtR2oZkXlC4MjLvyGhBqHHljrDcxZzsPeh/QnpgBr+qDOmHlhwtxEn0 gmO22hZcdVBMavm6NA+mK7m7mAy9KnXFzWKo9y/H7lAJ55QE3a8AqOQ4HSgZ07kRXvj4 V8/5qbAkkWk8/Y1hYnim9jV/RBaa54Cc1tnoQrlc4q6rnre04FWHmuNC9UjYZL3hXwui 81g8mPHpeEL9n8zD2JP9/FeeAwaaAISLsMW/UpFhAX33DnRC7/rDMuy9HExQBJQY2y3B 447A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=qq5XpzPoyzrxc7VeunrLCYkiPjJ8tOqQGgXIagmQiCM=; b=PpFqN58F5jGW4qI6/JBXlU9dXjtBkr1FXzuF5S2WhWyHPPS+YcVqW7Ww9mxcoiNrq2 MVxzIfNw6thg7AMDQgmAZwqRDudZSm4YhuDZsZouRLnowC9zLPOTbNv+sr2r96adc2O6 g+pKPI6q9bZP1vQPMO9I1q2TZXnbSjzg50vJ66tXOAHb4FtPg6ZZyug9bFvUwaSr8RVe wgrip+MKYb0Sn8/CpkJ89DvnEozwtKuReFYGUgX045rLJrN2+jfQIz61c2FxiNhNt2eg VNqcFQPgevFqTyUdsLg/rFDBc4j8IhAN3uQkqM8DkvjoakNhr2kIalJVFCit+hoA2cC7 pBQQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga18.intel.com (mga18.intel.com. [134.134.136.126]) by mx.google.com with ESMTPS id 7si24611937pll.99.2019.05.21.13.53.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 May 2019 13:53:17 -0700 (PDT) Received-SPF: pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.126 as permitted sender) client-ip=134.134.136.126; Authentication-Results: mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 May 2019 13:53:16 -0700 X-ExtLoop1: 1 Received: from rpedgeco-mobl.amr.corp.intel.com (HELO localhost.intel.com) ([10.254.91.116]) by orsmga001.jf.intel.com with ESMTP; 21 May 2019 13:53:16 -0700 From: Rick Edgecombe To: linux-kernel@vger.kernel.org, peterz@infradead.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, luto@kernel.org Cc: dave.hansen@intel.com, namit@vmware.com, Rick Edgecombe , Meelis Roos , "David S. Miller" , Borislav Petkov , Ingo Molnar Subject: [PATCH v4 1/2] vmalloc: Fix calculation of direct map addr range Date: Tue, 21 May 2019 13:51:36 -0700 Message-Id: <20190521205137.22029-2-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190521205137.22029-1-rick.p.edgecombe@intel.com> References: <20190521205137.22029-1-rick.p.edgecombe@intel.com> MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP The calculation of the direct map address range to flush was wrong. This could cause problems on x86 if a RO direct map alias ever got loaded into the TLB. This shouldn't normally happen, but it could cause the permissions to remain RO on the direct map alias, and then the page would return from the page allocator to some other component as RO and cause a crash. So fix fix the address range calculation so the flush will include the direct map range. Fixes: 868b104d7379 ("mm/vmalloc: Add flag for freeing of special permsissions") Cc: Meelis Roos Cc: Peter Zijlstra Cc: "David S. Miller" Cc: Dave Hansen Cc: Borislav Petkov Cc: Andy Lutomirski Cc: Ingo Molnar Cc: Nadav Amit Signed-off-by: Rick Edgecombe --- mm/vmalloc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index c42872ed82ac..836888ae01f6 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2159,9 +2159,10 @@ static void vm_remove_mappings(struct vm_struct *area, int deallocate_pages) * the vm_unmap_aliases() flush includes the direct map. */ for (i = 0; i < area->nr_pages; i++) { - if (page_address(area->pages[i])) { + addr = (unsigned long)page_address(area->pages[i]); + if (addr) { start = min(addr, start); - end = max(addr, end); + end = max(addr + PAGE_SIZE, end); } } From patchwork Tue May 21 20:51:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rick Edgecombe X-Patchwork-Id: 10954501 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C914176 for ; Tue, 21 May 2019 20:53:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B891A288CF for ; Tue, 21 May 2019 20:53:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACAF528B08; Tue, 21 May 2019 20:53:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C598288CF for ; Tue, 21 May 2019 20:53:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 50AFE6B0006; Tue, 21 May 2019 16:53:19 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 473C56B0003; Tue, 21 May 2019 16:53:19 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15DBF6B0003; Tue, 21 May 2019 16:53:18 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id A96866B0007 for ; Tue, 21 May 2019 16:53:18 -0400 (EDT) Received: by mail-pf1-f199.google.com with SMTP id k22so98985pfg.18 for ; Tue, 21 May 2019 13:53:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=dBwMVE9KbttCg2XLI675VZQsOGlnJ1c9VoXvCDMDOLs=; b=OHABhJwLFlGrup1GjG4jzphCJtwJw0iZHk6OAj4mZaq/HI6T+zjA493mVKqmGrOqmj hjWwl1JjUJDvffbEjlRLhDo3EbWla9QSyo6YdyeWj9AvVG1xZWMKK8i2L8Y+L8JpQtrg 699sMjg9dNwr6ESA2DpKes6tsS6yNj+1gAu2sWNqekGZYdu0L5XEh1qN3T737D7JI2Oy 31cV+p8HKvghfGIJbBa/d77tO3ukBuvDB9d8iSDTdU6C82oOsaOixRPu+XHP+XnsCK8P emRCXAULJDsuR7vftyQMUVTY8z8bdHjgHut2vQe13g6vblRwZWZIbbWHXCYW+k3pKH3h EuwQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: APjAAAVi8oqeouYDdindhJ0lxKWCX2+FC9Zx7mPXhha8WDIFkpAWmlzU AF1kMmctazkYnfzRzw26OYJJ1rKqJonM+QwyO4vdodPSlnPHddDOPBgP+aQSQtLciIJ/H3DG/5z pdPmFrcuAHsEL48UO1qg6H2CvVHmwzbwPGxHB786KSGuGl9lrTqjZXF9qoYP067xyfQ== X-Received: by 2002:aa7:9e51:: with SMTP id z17mr90195603pfq.212.1558471998352; Tue, 21 May 2019 13:53:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqx+TW5/fMZQAAIFKdETXtzGvr+Sm6cqSMmJY3iSS7FeEUbZtefPAjtwdzLfJ/Ui9g12XBi8 X-Received: by 2002:aa7:9e51:: with SMTP id z17mr90195527pfq.212.1558471997638; Tue, 21 May 2019 13:53:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558471997; cv=none; d=google.com; s=arc-20160816; b=b31cL7N692ttBhBV9ePpLnRXkPB87ihV8YgHMv9dRRcXT4xnAFcEKyyF+rrYRdqBRN adR6Ub36foOJ+ebvhYKe6DHVxQ4U3Hwpohz3td8jVzkmFWa/5wAuT6yNyg9QcCMhJY2U 5WTKuHSRDyKIn7ejI8B5rmOxKExgCCrlfAV+RhAVINMpyLxhcc24XnShIxfLIGP4pIVi aSrKoZNuSdASO5BbbagHrnUTp6sEthyoBf1Wit+hfDf6CTGCdFFP+Xbn0SQEevmFU7Jx f6Mu7ZrfqN+uiFHWwDPq+Zx9SGs2MD/eAr0ufR4VLYNepZk9sIXOJFS7Lzv2eI8IJeqG wFYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=dBwMVE9KbttCg2XLI675VZQsOGlnJ1c9VoXvCDMDOLs=; b=OMuyPzKr0F1dqimSFRmqdJCG0GAg6j8rrUo66YwL2AR3csowbBM3EIOSHp7h/q2Y81 FChIuV0hjHHKvoiiSwWyEnibv4YQ2zEQCwH0iEMFpZXvNkwmhSwNHQ/UMfUR0SCARTEV L+5Fxzm5pVUjggStcmUFtFPZoxhz0Z7gyUboXm3AUDnwoWE4i2nn3QR7LYUbluHQDCWa SNeb5UYHRHyyXiLvXnUPoU2Qob+PTBW0rhNWY7iQbNtXRPXSa5uWnPFmmjFyRF0ZmWGC RnW8Vx4aDsySXgndFIpQS/KqVH4nmPdlX2F/bZp9Qc5pUwl5++9FggJZJ/eWt1zXDHjd LO0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga18.intel.com (mga18.intel.com. [134.134.136.126]) by mx.google.com with ESMTPS id 7si24611937pll.99.2019.05.21.13.53.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 May 2019 13:53:17 -0700 (PDT) Received-SPF: pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.126 as permitted sender) client-ip=134.134.136.126; Authentication-Results: mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 May 2019 13:53:17 -0700 X-ExtLoop1: 1 Received: from rpedgeco-mobl.amr.corp.intel.com (HELO localhost.intel.com) ([10.254.91.116]) by orsmga001.jf.intel.com with ESMTP; 21 May 2019 13:53:16 -0700 From: Rick Edgecombe To: linux-kernel@vger.kernel.org, peterz@infradead.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, luto@kernel.org Cc: dave.hansen@intel.com, namit@vmware.com, Rick Edgecombe , Meelis Roos , "David S. Miller" , Borislav Petkov , Ingo Molnar Subject: [PATCH v4 2/2] vmalloc: Avoid rare case of flushing tlb with weird arguements Date: Tue, 21 May 2019 13:51:37 -0700 Message-Id: <20190521205137.22029-3-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190521205137.22029-1-rick.p.edgecombe@intel.com> References: <20190521205137.22029-1-rick.p.edgecombe@intel.com> MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP In a rare case, flush_tlb_kernel_range() could be called with a start higher than the end. Most architectures should be fine with with this, but some may not like it, so avoid doing this. In vm_remove_mappings(), in case page_address() returns 0 for all pages, _vm_unmap_aliases() will be called with start = ULONG_MAX, end = 0 and flush = 1. If at the same time, the vmalloc purge operation is triggered by something else while the current operation is between remove_vm_area() and _vm_unmap_aliases(), then the vm mapping just removed will be already purged. In this case the call of vm_unmap_aliases() may not find any other mappings to flush and so end up flushing start = ULONG_MAX, end = 0. So only set flush = true if we find something in the direct mapping that we need to flush, and this way this can't happen. Fixes: 868b104d7379 ("mm/vmalloc: Add flag for freeing of special permsissions") Cc: Meelis Roos Cc: Peter Zijlstra Cc: "David S. Miller" Cc: Dave Hansen Cc: Borislav Petkov Cc: Andy Lutomirski Cc: Ingo Molnar Cc: Nadav Amit Signed-off-by: Rick Edgecombe --- mm/vmalloc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 836888ae01f6..537d1134b40e 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2125,6 +2125,7 @@ static void vm_remove_mappings(struct vm_struct *area, int deallocate_pages) unsigned long addr = (unsigned long)area->addr; unsigned long start = ULONG_MAX, end = 0; int flush_reset = area->flags & VM_FLUSH_RESET_PERMS; + int flush_dmap = 0; int i; /* @@ -2163,6 +2164,7 @@ static void vm_remove_mappings(struct vm_struct *area, int deallocate_pages) if (addr) { start = min(addr, start); end = max(addr + PAGE_SIZE, end); + flush_dmap = 1; } } @@ -2172,7 +2174,7 @@ static void vm_remove_mappings(struct vm_struct *area, int deallocate_pages) * reset the direct map permissions to the default. */ set_area_direct_map(area, set_direct_map_invalid_noflush); - _vm_unmap_aliases(start, end, 1); + _vm_unmap_aliases(start, end, flush_dmap); set_area_direct_map(area, set_direct_map_default_noflush); }