1. 06 3月, 2023 2 次提交
  2. 25 2月, 2023 1 次提交
  3. 17 2月, 2023 6 次提交
  4. 13 2月, 2023 2 次提交
  5. 09 2月, 2023 3 次提交
  6. 31 1月, 2023 2 次提交
  7. 19 1月, 2023 2 次提交
  8. 16 1月, 2023 1 次提交
  9. 04 1月, 2023 4 次提交
  10. 08 12月, 2022 6 次提交
  11. 02 12月, 2022 2 次提交
    • D
      mm/hugetlb: fix hugetlb not supporting softdirty tracking · 9742b1b6
      David Hildenbrand 提交于
      stable inclusion
      from stable-v5.10.140
      commit 62af37c5cd7f5fd071086cab645844bf5bcdc0ef
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I63FTT
      
      Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=62af37c5cd7f5fd071086cab645844bf5bcdc0ef
      
      --------------------------------
      
      commit f96f7a40 upstream.
      
      Patch series "mm/hugetlb: fix write-fault handling for shared mappings", v2.
      
      I observed that hugetlb does not support/expect write-faults in shared
      mappings that would have to map the R/O-mapped page writable -- and I
      found two case where we could currently get such faults and would
      erroneously map an anon page into a shared mapping.
      
      Reproducers part of the patches.
      
      I propose to backport both fixes to stable trees.  The first fix needs a
      small adjustment.
      
      This patch (of 2):
      
      Staring at hugetlb_wp(), one might wonder where all the logic for shared
      mappings is when stumbling over a write-protected page in a shared
      mapping.  In fact, there is none, and so far we thought we could get away
      with that because e.g., mprotect() should always do the right thing and
      map all pages directly writable.
      
      Looks like we were wrong:
      
      --------------------------------------------------------------------------
       #include <stdio.h>
       #include <stdlib.h>
       #include <string.h>
       #include <fcntl.h>
       #include <unistd.h>
       #include <errno.h>
       #include <sys/mman.h>
      
       #define HUGETLB_SIZE (2 * 1024 * 1024u)
      
       static void clear_softdirty(void)
       {
               int fd = open("/proc/self/clear_refs", O_WRONLY);
               const char *ctrl = "4";
               int ret;
      
               if (fd < 0) {
                       fprintf(stderr, "open(clear_refs) failed\n");
                       exit(1);
               }
               ret = write(fd, ctrl, strlen(ctrl));
               if (ret != strlen(ctrl)) {
                       fprintf(stderr, "write(clear_refs) failed\n");
                       exit(1);
               }
               close(fd);
       }
      
       int main(int argc, char **argv)
       {
               char *map;
               int fd;
      
               fd = open("/dev/hugepages/tmp", O_RDWR | O_CREAT);
               if (!fd) {
                       fprintf(stderr, "open() failed\n");
                       return -errno;
               }
               if (ftruncate(fd, HUGETLB_SIZE)) {
                       fprintf(stderr, "ftruncate() failed\n");
                       return -errno;
               }
      
               map = mmap(NULL, HUGETLB_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
               if (map == MAP_FAILED) {
                       fprintf(stderr, "mmap() failed\n");
                       return -errno;
               }
      
               *map = 0;
      
               if (mprotect(map, HUGETLB_SIZE, PROT_READ)) {
                       fprintf(stderr, "mmprotect() failed\n");
                       return -errno;
               }
      
               clear_softdirty();
      
               if (mprotect(map, HUGETLB_SIZE, PROT_READ|PROT_WRITE)) {
                       fprintf(stderr, "mmprotect() failed\n");
                       return -errno;
               }
      
               *map = 0;
      
               return 0;
       }
      --------------------------------------------------------------------------
      
      Above test fails with SIGBUS when there is only a single free hugetlb page.
       # echo 1 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
       # ./test
       Bus error (core dumped)
      
      And worse, with sufficient free hugetlb pages it will map an anonymous page
      into a shared mapping, for example, messing up accounting during unmap
      and breaking MAP_SHARED semantics:
       # echo 2 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
       # ./test
       # cat /proc/meminfo | grep HugePages_
       HugePages_Total:       2
       HugePages_Free:        1
       HugePages_Rsvd:    18446744073709551615
       HugePages_Surp:        0
      
      Reason in this particular case is that vma_wants_writenotify() will
      return "true", removing VM_SHARED in vma_set_page_prot() to map pages
      write-protected. Let's teach vma_wants_writenotify() that hugetlb does not
      support softdirty tracking.
      
      Link: https://lkml.kernel.org/r/20220811103435.188481-1-david@redhat.com
      Link: https://lkml.kernel.org/r/20220811103435.188481-2-david@redhat.com
      Fixes: 64e45507 ("mm: softdirty: enable write notifications on VMAs after VM_SOFTDIRTY cleared")
      Signed-off-by: NDavid Hildenbrand <david@redhat.com>
      Reviewed-by: NMike Kravetz <mike.kravetz@oracle.com>
      Cc: Peter Feiner <pfeiner@google.com>
      Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
      Cc: Cyrill Gorcunov <gorcunov@openvz.org>
      Cc: Pavel Emelyanov <xemul@parallels.com>
      Cc: Jamie Liu <jamieliu@google.com>
      Cc: Hugh Dickins <hughd@google.com>
      Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
      Cc: Bjorn Helgaas <bhelgaas@google.com>
      Cc: Muchun Song <songmuchun@bytedance.com>
      Cc: Peter Xu <peterx@redhat.com>
      Cc: <stable@vger.kernel.org>	[3.18+]
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NDavid Hildenbrand <david@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      Reviewed-by: NWei Li <liwei391@huawei.com>
      9742b1b6
    • M
      mm/huge_memory.c: use helper function migration_entry_to_page() · 5dabdf42
      Miaohe Lin 提交于
      stable inclusion
      from stable-v5.10.140
      commit c7c77185fa3e9f8c3358426c2584a5b1dc1fdf0f
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I63FTT
      
      Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=c7c77185fa3e9f8c3358426c2584a5b1dc1fdf0f
      
      --------------------------------
      
      [ Upstream commit a44f89dc ]
      
      It's more recommended to use helper function migration_entry_to_page()
      to get the page via migration entry.  We can also enjoy the PageLocked()
      check there.
      
      Link: https://lkml.kernel.org/r/20210318122722.13135-7-linmiaohe@huawei.comSigned-off-by: NMiaohe Lin <linmiaohe@huawei.com>
      Reviewed-by: NPeter Xu <peterx@redhat.com>
      Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Michel Lespinasse <walken@google.com>
      Cc: Ralph Campbell <rcampbell@nvidia.com>
      Cc: Thomas Hellstrm (Intel) <thomas_os@shipmail.org>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Cc: Wei Yang <richard.weiyang@linux.alibaba.com>
      Cc: William Kucharski <william.kucharski@oracle.com>
      Cc: Yang Shi <yang.shi@linux.alibaba.com>
      Cc: yuleixzhang <yulei.kernel@gmail.com>
      Cc: Zi Yan <ziy@nvidia.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      Reviewed-by: NWei Li <liwei391@huawei.com>
      5dabdf42
  12. 01 12月, 2022 5 次提交
  13. 30 11月, 2022 2 次提交
  14. 24 11月, 2022 1 次提交
  15. 23 11月, 2022 1 次提交
    • L
      cgroup: support cgroup writeback on cgroupv1 · 644547a9
      Lu Jialin 提交于
      hulkl inclusion
      category: feature
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5ZG61
      
      -------------------------------
      
      In cgroupv1, cgroup writeback is not supproted for two problems:
      1) Blkcg_css and memcg_css are mounted on different cgroup trees.
         Therefore, blkcg_css cannot be found according to a certain memcg_css.
      2) Buffer I/O is worked by kthread, which is in the root_blkcg.
         Therefore, blkcg cannot limit wbps and wiops of buffer I/O.
      
      We solve the two problems to support cgroup writeback on cgroupv1.
      1) A memcg is attached to the blkcg_root css when the memcg was created.
      2) We add a member "wb_blkio_ino" in mem_cgroup_legacy_files.
         User can attach a memcg to a cerntain blkcg through echo the file
         inode of the blkcg into the wb_blkio of the memcg.
      3) inode_cgwb_enabled() return true when memcg and io are both mounted
         on cgroupv2 or both on cgroupv1.
      4) Buffer I/O can find a blkcg according to its memcg.
      
      Thus, a memcg can find a certain blkcg, and cgroup writeback can be
      supported on cgroupv1.
      Signed-off-by: NLu Jialin <lujialin4@huawei.com>
      644547a9