From patchwork Mon Sep 26 15:26:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 12988975 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 213AAC07E9D for ; Mon, 26 Sep 2022 15:26:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AE9A76B00FE; Mon, 26 Sep 2022 11:26:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A27696B00FF; Mon, 26 Sep 2022 11:26:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8779C8E0066; Mon, 26 Sep 2022 11:26:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 788176B00FE for ; Mon, 26 Sep 2022 11:26:35 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4739440C31 for ; Mon, 26 Sep 2022 15:26:35 +0000 (UTC) X-FDA: 79954613550.02.9186EBE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf21.hostedemail.com (Postfix) with ESMTP id F27ED1C0005 for ; Mon, 26 Sep 2022 15:26:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664205994; 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=zzTxRsO9Y8SBM3+5dXXY7X+zNQ7CrC7lsh1iB+qx+p0=; b=X7L1fh8wd+c/Ba5hoLCCRRdMrPMfg0rV7GaLVFygn/xqROvO8M1yI6zyIqbriRCW9MYRWS 7Hh3Tm88k3bIyDlNP5iSfmkz8gTw4qswHZKH122SspSTmSLmc9QodB8nQyjNYLVOtZN1uA wrQVxctJctHCTRnI/nRwOtS7fXukwvE= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-210-ozXPzZguOvCPaIuPr2SQTA-1; Mon, 26 Sep 2022 11:26:31 -0400 X-MC-Unique: ozXPzZguOvCPaIuPr2SQTA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 801D63C6EAA2; Mon, 26 Sep 2022 15:26:30 +0000 (UTC) Received: from t480s.fritz.box (unknown [10.39.193.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9948BC15BA5; Mon, 26 Sep 2022 15:26:27 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, David Hildenbrand , Linus Torvalds , Andrew Morton , Mel Gorman , Dave Chinner , Nadav Amit , Peter Xu , Andrea Arcangeli , Hugh Dickins , Vlastimil Babka , Michael Ellerman , Nicholas Piggin , Mike Rapoport , Anshuman Khandual Subject: [PATCH RFC 2/5] mm/mprotect: minor can_change_pte_writable() cleanups Date: Mon, 26 Sep 2022 17:26:15 +0200 Message-Id: <20220926152618.194810-3-david@redhat.com> In-Reply-To: <20220926152618.194810-1-david@redhat.com> References: <20220926152618.194810-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664205995; a=rsa-sha256; cv=none; b=KFn8afqkZcCdNntTDDSwfNEw7BaUU/Wx7B5GDsHWwCBMJ7Bj7Pj1LeLnYsvW5eUC3J7NoG PK+moxw0Ky6zk3wnLZN0Y8AFoz85HEdGFdlLM+NKgakGLFQaoCp/YZtgGjlmEyigF4udCS qsgCwh7Zqso8qS1f+4JO9+iRjFlvbPs= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=X7L1fh8w; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664205995; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zzTxRsO9Y8SBM3+5dXXY7X+zNQ7CrC7lsh1iB+qx+p0=; b=vPn8DezLb0k6Yejoln+eqBWbHmuPaVUEwHqntOboMYpfAUptj9fVWoE9HH0Nr0fNZTZn0X hfzeNT4cEnMVlnVTUffIk22JMnbO3absa2htQhKOWGdVLdX5QF99j5GfqQXF31cbszqxJn B5Y4pgxIAx0uDt/8JBwAEs1xqGLCw+c= X-Rspamd-Server: rspam03 X-Rspam-User: Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=X7L1fh8w; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com X-Stat-Signature: iohxn4gid1y5grmknkzkbci4jqwt1m3a X-Rspamd-Queue-Id: F27ED1C0005 X-HE-Tag: 1664205994-259043 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: We want to replicate this code for handling PMDs soon. No need to crash the kernel, warning and rejecting is good enough. As this will no longer get optimized out, drop the pte_write() check: no harm would be done. While at it, add a comment why PROT_NONE mapped pages are excluded. Signed-off-by: David Hildenbrand --- mm/mprotect.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/mprotect.c b/mm/mprotect.c index c6c13a0a4bcc..95323bc9a951 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -43,8 +43,10 @@ static inline bool can_change_pte_writable(struct vm_area_struct *vma, { struct page *page; - VM_BUG_ON(!(vma->vm_flags & VM_WRITE) || pte_write(pte)); + if (WARN_ON_ONCE(!(vma->vm_flags & VM_WRITE))) + return false; + /* Don't touch entries that are not even readable (NUMA hinting). */ if (pte_protnone(pte)) return false;