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 X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85701C43381 for ; Wed, 20 Mar 2019 17:08:44 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 522382184D for ; Wed, 20 Mar 2019 17:08:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 522382184D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=vt.edu Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=kernelnewbies-bounces@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.91) (envelope-from ) id 1h6ehE-0000cF-Lu; Wed, 20 Mar 2019 13:08:08 -0400 Received: from omr2.cc.ipv6.vt.edu ([2607:b400:92:8400:0:33:fb76:806e] helo=omr2.cc.vt.edu) by shelob.surriel.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1h6ehB-0000c2-On for kernelnewbies@kernelnewbies.org; Wed, 20 Mar 2019 13:08:05 -0400 Received: from mr1.cc.vt.edu (mr1.cc.ipv6.vt.edu [IPv6:2607:b400:92:8300:0:31:1732:8aa4]) by omr2.cc.vt.edu (8.14.4/8.14.4) with ESMTP id x2KH82Bw025654 for ; Wed, 20 Mar 2019 13:08:02 -0400 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by mr1.cc.vt.edu (8.14.7/8.14.7) with ESMTP id x2KH7vpg019294 for ; Wed, 20 Mar 2019 13:08:02 -0400 Received: by mail-qk1-f200.google.com with SMTP id r9so21614891qkl.4 for ; Wed, 20 Mar 2019 10:08:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:in-reply-to:references :mime-version:date:message-id; bh=0tles7hc4i0mm+n9hUljlDb3qAhwTz/lb8vvfe0x5hg=; b=JOI5ikEi36RJ2Zg+yJ3tiYm78fiPWSvz2ibo6BEyBAoithDz+XHZLAy1CqtMgBPgB2 0ZkQQk5LoNy3yowCrC+q5uW/XxKh9AP6CS+yADs7kVhulYuuoIIRzFjeVKvcBlxmqYit sNgMw2hZs8uFiCsyJh4CALrpDSwCnIiLwrLD+0+nkP0GKpMrrVvWFcRo4nieE5Wq38QG Zf3SjdbUCg3ROPYpldeN9gc5m22azmZnMfq6xpGbh/Tn3WrJRZKFDalKOotsgeN50mHa JeqKCds7crtJe7+FPVtAK5LZe1+pEQF/YdvL4hLaolIuYNV4NO+qzOTcx85/EgLoPE0k b7qw== X-Gm-Message-State: APjAAAXzBe908JNK4QMwA4F6lFOv3i+SN008mR67+eB4KhQE+OlzoLNO 3bGl0uo65eXZwOL5TU/jlpBz5VHWp1qsmYGhD1wEBlxGXWwh7fBG4RS2U64cJ58UYb4FUYfyZWG U7j3mIuOsTFpE92pEL/YnVODUABUDxL7+4fwWQs4= X-Received: by 2002:a05:620a:1428:: with SMTP id k8mr7206082qkj.185.1553101677463; Wed, 20 Mar 2019 10:07:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqyU9d7EBrC5pnNXPDD+2Sy+78F+q+rqcW8J2Kp2t0ni7UUQJrhxmy/yNSZ+3Q+cccKhoUu6VA== X-Received: by 2002:a05:620a:1428:: with SMTP id k8mr7206060qkj.185.1553101677262; Wed, 20 Mar 2019 10:07:57 -0700 (PDT) Received: from turing-police ([2601:5c0:c001:4341::359]) by smtp.gmail.com with ESMTPSA id k17sm1260528qtj.59.2019.03.20.10.07.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 10:07:56 -0700 (PDT) From: "Valdis Kl=?utf-8?Q?=c4=93?=tnieks" X-Google-Original-From: "Valdis Kl=?utf-8?Q?=c4=93?=tnieks" X-Mailer: exmh version 2.9.0 11/07/2018 with nmh-1.7+dev To: Lev Olshvang Subject: Re: What will happen if 2 processes map same physical page In-reply-to: <6967041553089359@myt2-66bcb87429e6.qloud-c.yandex.net> References: <6967041553089359@myt2-66bcb87429e6.qloud-c.yandex.net> Mime-Version: 1.0 Date: Wed, 20 Mar 2019 13:07:55 -0400 Message-ID: <16760.1553101675@turing-police> Cc: linux-il , kernelnewbies X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kernelnewbies-bounces@kernelnewbies.org On Wed, 20 Mar 2019 16:42:39 +0300, Lev Olshvang said: > The question is it ipossiblle in Linux/MMU/TLB that 2 processes map to > the same physical address? Totally possible. That's how mmap shared memory works, and why shared libraries are possible. > Will CPU or TLB discover that second process tries to reach occupied physical page? Well, the hardware won't discover it as a "second" process, it only knows it's processing *this* memory access. > What if first process set page permission to read and second whats to write to this page ? Perfectly OK - the two processes have separate page table mappings, with separate permission bits. So (for example) physical page 0x17F000 is mapped to virtual address 0x2034D000 with read-only permission n process 1's page tables, and to virtual address 0x98FF3000 with read-write permission in process 2's page tables. No problem. (And before you ask, yes it's possible for process 2 to running on one core doing a write to the page at the exact same time that process 1 is doing a read on another core. Depending on the hardware cache design, this may or may not get process 1 updated data. This is why locking and memory barriers are important. See Documentation/memory-barriers.txt for more details) "And then there's the Alpha" - a processor design that got much of its speed by being weird about this stuff. :) > Perhaps during context switch all page access permissions of first process is > flashed out from MMU ? Actually, the kernel just points the MMU at a new set of page table entries and lets the TLB reload as needed. In particular, on most architectures, the kernel tries really hard to ensure that all processes share at least part of their page table mappings so the kernel is always mapped at the same place, meaning that there's a better chance that on a syscall, the TLB already has hot entries for large parts of the kernel so no TLB reloads are needed. _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies