Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3635983imu; Mon, 28 Jan 2019 08:12:20 -0800 (PST) X-Google-Smtp-Source: ALg8bN7KRg9DHzx8b7T8XRrSRi8FghUUNKrDxC8iii7J/mvDpfgg4R6sDJ/T+EDS3Y+ZF5YlcCrs X-Received: by 2002:a63:e655:: with SMTP id p21mr20150228pgj.70.1548691940294; Mon, 28 Jan 2019 08:12:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548691940; cv=none; d=google.com; s=arc-20160816; b=LXdznEoMaRgvyMjG38LBnsQRqP7M3PIEh78f67lTtVrwLUhORs/kAfHgu0+6dhhE03 OBLYcEC1EW2tcPJ10CGs2x3efaggy5awsPhk6zADlliXW7nlnUIF/X7IQPQEQbHfLk6U 5Xcnw4x4mMl+wMU/iJ5W1kYwTb6jOTxhAhlJxNbUmfUYti6UZcklBjsIGRBXzytLCjjp 5Na4+NQbc/1FJTu2CsSWuoTvACE4MVSlEGiM1zjIeTsA0DYH5Pot1NfFXW7uJ6zs5txz OoesqOPTuK9WAIWQPNQTmUSe2h4cKFWf598VtrQlDxbSyrEtKJv2KZBBISqO2CP4pgaK jj9A== 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=j2mUv9pDc9I2PCUDlktnFbYfz/e21IWW0HAwSwT32kI=; b=m2JGTdDZBhRpUSLQ2TLVxLf+5cQUUXbsGB15UpmK+r2nIYES11Xc9UfSO/clcab1U0 ohVeGD+2puxwlx1NtHBA9TfxvVMBJHQ8PlJHipIsHWHMeotnCf+DoxZsgYMlSGOhlGlu 7sr8uSzGJuXiwjOOZuUJckFidoF33lI4PHwezff47eDfggbbdP09kzhTKzkTS0FGlRRF RmW2MR+fnJmAT3rNxnyNUrcxqmdL7RWJyCpgb6i8Ht0DcQlUHZMRM+0bRioQHD/ov6Q1 n/fec6ZXEEaug6O66ydLlBKSd3e/tm5NrCMaIDEc15Jo2t702WVFM8saVfQ/UiaN74/t owmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZBW+86b1; 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 t5si31658461pgm.79.2019.01.28.08.12.04; Mon, 28 Jan 2019 08:12:20 -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=@kernel.org header.s=default header.b=ZBW+86b1; 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 S1732776AbfA1QKW (ORCPT + 99 others); Mon, 28 Jan 2019 11:10:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:36158 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732766AbfA1QKV (ORCPT ); Mon, 28 Jan 2019 11:10:21 -0500 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 E619E2171F; Mon, 28 Jan 2019 16:10:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691820; bh=smksVjHmBgGlBWiX3aftH5cmLjUKG7JYTo/oSFQbUcM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZBW+86b1iJYEIlz0HiRRJBOu+TZR9KboKprITniEaKqsnFrTCdgRlHiDzDIlPT7Pe BNa+fRdAwsuVM6gCJ6g2shonrop5w5HXoBm4phH7MYOAjoYnb16KmwiaMsSyjRY1/O NIPklgjWeVCwtXmug9F2/wFo1JowV7mx4K9lbJKk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Anton Ivanov , Richard Weinberger , Sasha Levin , linux-um@lists.infradead.org Subject: [PATCH AUTOSEL 4.19 228/258] um: Avoid marking pages with "changed protection" Date: Mon, 28 Jan 2019 10:58:54 -0500 Message-Id: <20190128155924.51521-228-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 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: Anton Ivanov [ Upstream commit 8892d8545f2d0342b9c550defbfb165db237044b ] Changing protection is a very high cost operation in UML because in addition to an extra syscall it also interrupts mmap merge sequences generated by the tlb. While the condition is not particularly common it is worth avoiding. Signed-off-by: Anton Ivanov Signed-off-by: Richard Weinberger Signed-off-by: Sasha Levin --- arch/um/include/asm/pgtable.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/um/include/asm/pgtable.h b/arch/um/include/asm/pgtable.h index 7485398d0737..9c04562310b3 100644 --- a/arch/um/include/asm/pgtable.h +++ b/arch/um/include/asm/pgtable.h @@ -197,12 +197,17 @@ static inline pte_t pte_mkold(pte_t pte) static inline pte_t pte_wrprotect(pte_t pte) { - pte_clear_bits(pte, _PAGE_RW); + if (likely(pte_get_bits(pte, _PAGE_RW))) + pte_clear_bits(pte, _PAGE_RW); + else + return pte; return(pte_mknewprot(pte)); } static inline pte_t pte_mkread(pte_t pte) { + if (unlikely(pte_get_bits(pte, _PAGE_USER))) + return pte; pte_set_bits(pte, _PAGE_USER); return(pte_mknewprot(pte)); } @@ -221,6 +226,8 @@ static inline pte_t pte_mkyoung(pte_t pte) static inline pte_t pte_mkwrite(pte_t pte) { + if (unlikely(pte_get_bits(pte, _PAGE_RW))) + return pte; pte_set_bits(pte, _PAGE_RW); return(pte_mknewprot(pte)); } -- 2.19.1