From mboxrd@z Thu Jan 1 00:00:00 1970 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 01E4FC6FA82 for ; Mon, 26 Sep 2022 15:28:18 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MbmqP4xVsz3bP1 for ; Tue, 27 Sep 2022 01:28:17 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=BjvieWru; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=BjvieWru; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=redhat.com (client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=david@redhat.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=BjvieWru; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=BjvieWru; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4MbmnV0BVkz3bXn for ; Tue, 27 Sep 2022 01:26:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664205995; 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=BjvieWruxsCkO+TjtjdpEnlM78K+qXNa9RbCvX+HTFAIJoBR/EsOpyUZPB9oywsAdTWU6n UZmuePGAXqn+2cSdq2hRDQVJTya7sUd1Zeo+KZzajRaM/9790Zem7e6zXFJpT2yGWshF3Q Y3Q0FeijftoIO5P0FS1E80xxx4XfOZA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664205995; 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=BjvieWruxsCkO+TjtjdpEnlM78K+qXNa9RbCvX+HTFAIJoBR/EsOpyUZPB9oywsAdTWU6n UZmuePGAXqn+2cSdq2hRDQVJTya7sUd1Zeo+KZzajRaM/9790Zem7e6zXFJpT2yGWshF3Q Y3Q0FeijftoIO5P0FS1E80xxx4XfOZA= 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 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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrea Arcangeli , David Hildenbrand , linuxppc-dev@lists.ozlabs.org, Anshuman Khandual , Dave Chinner , Mel Gorman , Peter Xu , linux-mm@kvack.org, Hugh Dickins , Nadav Amit , Nicholas Piggin , Mike Rapoport , Andrew Morton , Linus Torvalds , Vlastimil Babka Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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; -- 2.37.3