Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2115433ybl; Thu, 29 Aug 2019 03:52:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqwyMlpFltvhYABvoQhwtApgk4lSiGqtcFurtW3PAsR1IryrcyCiSwkk4IoMIHpFocYIVWFy X-Received: by 2002:a62:7503:: with SMTP id q3mr10906720pfc.151.1567075961661; Thu, 29 Aug 2019 03:52:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567075961; cv=none; d=google.com; s=arc-20160816; b=okMrzvWV5ZH12Pkipe9aOKK0TVM8SfuQXbQ7x0PHdrE5bAkraUo6fTLg7zL2hTwfmm 3s+Rixr1OBmT3IbXGMDS+wnnx6S6d8RKGzm2eYJeoZeijBLPOo0F66LZ+4XL+q5jyofP ez6+cL6RYyFKznb+6Whi7u1hvTJiwiEqKX0zOnl2P28+FaAhc5KHpj5DVbVR6uX2I8qK GocTIh3EvKq7aqRF1zf+U5sCxfeSS8eYqudom0Ia0LbVdVzn0gIedWp9aTfAw0kSVCFX 2nonXl7O6k13j61+iZF1LauQLgLj2ueXzrR5R6hZEAQGR9pqMERO9yjlpJJr7JRl/4cV OOkw== 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=icDtwYt8kLZhb7LERBsr+QuEKIDsUxUnjb7Q0ZAFzYc=; b=SicV62JrgPCUkYHdOJS91pINuwJF/W+lfy1i3PecdUV4X+3dkArOBThllYivgSY7lS a1NoJBYS9I2eTpeyR0q6iKPUBHJlqXatu2eGtRxFJkKmg+eRmQ0coApSB7KOqPIu35wk Kl4PCRASuj3Cz42032nqa6iRh9Ci7aNzLDe3GqOxVZ5lIbICH8VvTZaUW6AWRvp/KMHr SBw2goikfaHp5k4husfdu4CXVZc8KkpFLyuI2oB704TBOG1q8mRIK7bwN3/OaP9L5GR7 1yXkXewNAyF+39TFHmDWyycCq6VCQ8TSACf2dwMfTyg7UbCA/5/OGTei1Jglgz8Nq/DB hBEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ilPqGS73; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x1si1685710pgt.258.2019.08.29.03.52.25; Thu, 29 Aug 2019 03:52:41 -0700 (PDT) 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=@kernel.org header.s=default header.b=ilPqGS73; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728489AbfH2KvJ (ORCPT + 99 others); Thu, 29 Aug 2019 06:51:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:58360 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728294AbfH2Kuu (ORCPT ); Thu, 29 Aug 2019 06:50:50 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2FA412173E; Thu, 29 Aug 2019 10:50:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567075849; bh=L1yVC3rnPFRRolPJlkmoEEORLM7PJgCXDPecs1CxcTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ilPqGS73Z/N0d4nvJJQ+AkbPPI6iP2RnNbr1gsxoGXINDheHjck+G0zWwZ1OSpUQV KldS1Nlw757lhEXd1rMnXOnKzE3dSWIT/RjUkKelsG5SWA8AmHYtYk7NZ0DdBkf1TR NjL2c7frt/GHwPphnE1ZM6VYpggQaYpTcHnCLL50= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tyler Hicks , Todd Kjos , Greg Kroah-Hartman , Sasha Levin , devel@driverdev.osuosl.org Subject: [PATCH AUTOSEL 4.14 05/14] binder: take read mode of mmap_sem in binder_alloc_free_page() Date: Thu, 29 Aug 2019 06:50:34 -0400 Message-Id: <20190829105043.2508-5-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190829105043.2508-1-sashal@kernel.org> References: <20190829105043.2508-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tyler Hicks [ Upstream commit 60d4885710836595192c42d3e04b27551d30ec91 ] Restore the behavior of locking mmap_sem for reading in binder_alloc_free_page(), as was first done in commit 3013bf62b67a ("binder: reduce mmap_sem write-side lock"). That change was inadvertently reverted by commit 5cec2d2e5839 ("binder: fix race between munmap() and direct reclaim"). In addition, change the name of the label for the error path to accurately reflect that we're taking the lock for reading. Backporting note: This fix is only needed when *both* of the commits mentioned above are applied. That's an unlikely situation since they both landed during the development of v5.1 but only one of them is targeted for stable. Fixes: 5cec2d2e5839 ("binder: fix race between munmap() and direct reclaim") Signed-off-by: Tyler Hicks Acked-by: Todd Kjos Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/android/binder_alloc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index e0b0399ff7ec8..81c67459259ec 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -949,8 +949,8 @@ enum lru_status binder_alloc_free_page(struct list_head *item, mm = alloc->vma_vm_mm; if (!mmget_not_zero(mm)) goto err_mmget; - if (!down_write_trylock(&mm->mmap_sem)) - goto err_down_write_mmap_sem_failed; + if (!down_read_trylock(&mm->mmap_sem)) + goto err_down_read_mmap_sem_failed; vma = binder_alloc_get_vma(alloc); list_lru_isolate(lru, item); @@ -965,7 +965,7 @@ enum lru_status binder_alloc_free_page(struct list_head *item, trace_binder_unmap_user_end(alloc, index); } - up_write(&mm->mmap_sem); + up_read(&mm->mmap_sem); mmput(mm); trace_binder_unmap_kernel_start(alloc, index); @@ -980,7 +980,7 @@ enum lru_status binder_alloc_free_page(struct list_head *item, mutex_unlock(&alloc->mutex); return LRU_REMOVED_RETRY; -err_down_write_mmap_sem_failed: +err_down_read_mmap_sem_failed: mmput_async(mm); err_mmget: err_page_already_freed: -- 2.20.1