From patchwork Fri Jul 27 21:17:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jane Chu X-Patchwork-Id: 10547741 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 931E614BC for ; Fri, 27 Jul 2018 21:17:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 422EE28445 for ; Fri, 27 Jul 2018 21:17:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 344ED2BE79; Fri, 27 Jul 2018 21:17:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B3842B62D for ; Fri, 27 Jul 2018 21:17:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE75B6B0003; Fri, 27 Jul 2018 17:17:40 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E965A6B0005; Fri, 27 Jul 2018 17:17:40 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D5EF86B0006; Fri, 27 Jul 2018 17:17:40 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by kanga.kvack.org (Postfix) with ESMTP id 7A9A16B0003 for ; Fri, 27 Jul 2018 17:17:40 -0400 (EDT) Received: by mail-wr1-f70.google.com with SMTP id t10-v6so3919702wrs.17 for ; Fri, 27 Jul 2018 14:17:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id; bh=FeD56HSiwh1LVtS9tlX8UGgNfpreoW2uJ2w9Dzh34Pk=; b=CKH+tGfWQSYqhoMAab5Jz49+hXORFM454qa9NveWr17sZynVhn61zJmd0oMagWVyzC 3n7E/PyiFViI26NTA/lSBBbEC3jdvYIytdxzbJLPjdVPtLas0FnOW/ElhsH913Jkfune GpILQVvdT5ONOdzofq1+e1Lfw4ULm6WqnQEsiKf3HCbRIQPFZ3gO/JADktRf3Jmnk3H4 0hAV6ZG/uII71gzTB0LNewIcWqpwGqtxXFmIM/HrYW5HC4fIBr0O3fElxp0Q8dznGVHi UkflW0ZwNq1j4ps53+h3Xtt7Wj6uzqjR1BuKKh0fo7sCy1cs5lcsp2yGzvFDQ8Mbyv6P JKHA== X-Gm-Message-State: AOUpUlE8z5JNE1iE56mk9F6H0TR0JTbClPLOD7Eej2CfmIpwC8eWkrRA 9ZFvx94HLsfTPdRQA92esOjPjY/Ro5Mv/HhXM6j0BgFwt3Una+4GzGkaQRnGyVwDSPYphW//+Yf FMAGZYPffalOvLb5dbPvhwbyqVM2RDuhlFkZlbhkhzKk1Tif5GOUqKlwfm1kT3SxsJw== X-Received: by 2002:a1c:9d02:: with SMTP id g2-v6mr5334741wme.122.1532726259825; Fri, 27 Jul 2018 14:17:39 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd1D6WuwjqBwquhgFFFb+D7njbk048L17G/QojYQSdZJualS2+GJ3N5yTIzJEU74FE9mnfn X-Received: by 2002:a1c:9d02:: with SMTP id g2-v6mr5334688wme.122.1532726258761; Fri, 27 Jul 2018 14:17:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532726258; cv=none; d=google.com; s=arc-20160816; b=zAvS3Ui3DU5T3Lgyk9M/Kyin5BTA4fbND+8WkxjnDmjKgNAfueusPmHO1SvowN8cos 9eoKMqkSfQtVbNzKLWiqvW2ukmmaiXL7Jf21ghEh9M64qFUXzXoI2N/kMHHLDn/55pNS hhU6PjaVXUyBoQWEXCXskW1WWA+QDz2IZffo2V/bk3i5GfCvt6ZZOObXuXb2kwOgXnxN yn8sV2JedapaovwtHY+jybPxIindbHjaOFw94zubrxCQYQybdW17qyeRxoWkx/5mmgVM 1GI5tdbDjjx2z97AyQYcxqcr2CjBpL8vT5yk5tflZrB4UweCtNEeQF+AVDSTIJDdc9+s w8vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=FeD56HSiwh1LVtS9tlX8UGgNfpreoW2uJ2w9Dzh34Pk=; b=tx/FdXXkLeqSPioF520CiPzpSMHngWMLuzJlKehEUU7D2W1WdzGXhcnQoF/cZyhtww 0utSqsoPY+4bze78agWgAXF5cLB5QN9gOo9YOLZu+AwHG8ATzWuj0UzhlRc73fRd4f/F QwGv/B1nL3pAP/83sdCiSbfVW/fELAcZ3v4LcmRRedMiZS2JSIzDv7EQmp0GGIbLGyKs HZvthYvoNUCt/iz35BZjewvQr3IWV7z9dE1LA4bmhUgEcJt88dkRZodbHT/bE4zJKLQo cCH6XOpT6L036Dj53UhXxSDJdPaKC8OgIXe6hwn4eLM0WUGVSh3eP4J4EbW3Xi9Kykp3 MkEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=VOXbXRQW; spf=pass (google.com: domain of jane.chu@oracle.com designates 156.151.31.85 as permitted sender) smtp.mailfrom=jane.chu@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from userp2120.oracle.com (userp2120.oracle.com. [156.151.31.85]) by mx.google.com with ESMTPS id d12-v6si4610151wra.117.2018.07.27.14.17.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Jul 2018 14:17:38 -0700 (PDT) Received-SPF: pass (google.com: domain of jane.chu@oracle.com designates 156.151.31.85 as permitted sender) client-ip=156.151.31.85; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=VOXbXRQW; spf=pass (google.com: domain of jane.chu@oracle.com designates 156.151.31.85 as permitted sender) smtp.mailfrom=jane.chu@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w6RLEju1016148; Fri, 27 Jul 2018 21:17:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=FeD56HSiwh1LVtS9tlX8UGgNfpreoW2uJ2w9Dzh34Pk=; b=VOXbXRQWfQnzsnqg85FKWMIB0Rm8WTIljg9YNjXm9cE5IsCenlgiFuDFmLeMxri5OB5L gUQXJviuiQ09ShAG1QsP2cddAvHO7Qn5IK3CDrg+lBQmFjISMQ6I2FrFIHhNmavSMu1D jD5JSi//n81ittidsz3khZAV1219DACNh5QutR+XlCPtZ7nutMsCZmVGeYnoF7Sn1T9x 8vcd0lIDmATSzEs7lvAkhvDLZROuUV9DV5XRl2pJXZyAmG1/uBzRW60Ul56CKFzxg58h yD7kERQuevGyp4qjJA/SHbk7uL9QRyV5IvNghW2v3jGkT+7fv3oITbKM6r4mAjdbRu0N 1w== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2kbwfq8n7k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Jul 2018 21:17:34 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w6RLHXG1021808 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Jul 2018 21:17:34 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w6RLHWvd010961; Fri, 27 Jul 2018 21:17:32 GMT Received: from brm-x4600-03.us.oracle.com (/10.80.150.114) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 27 Jul 2018 14:17:32 -0700 From: Jane Chu To: akpm@linux-foundation.org Cc: dan.j.williams@intel.com, mhocko@suse.com, jack@suse.cz, jglisse@redhat.com, mike.kravetz@oracle.com, dave@stgolabs.net, linux-mm@kvack.org, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org, jane.chu@oracle.com Subject: [PATCH] ipc/shm.c add ->pagesize function to shm_vm_ops Date: Fri, 27 Jul 2018 15:17:27 -0600 Message-Id: <20180727211727.5020-1-jane.chu@oracle.com> X-Mailer: git-send-email 2.15.GIT X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8967 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807270215 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: X-Virus-Scanned: ClamAV using ClamSMTP Commit 05ea88608d4e13 (mm, hugetlbfs: introduce ->pagesize() to vm_operations_struct) adds a new ->pagesize() function to hugetlb_vm_ops, intended to cover all hugetlbfs backed files. With System V shared memory model, if "huge page" is specified, the "shared memory" is backed by hugetlbfs files, but the mappings initiated via shmget/shmat have their original vm_ops overwritten with shm_vm_ops, so we need to add a ->pagesize function to shm_vm_ops. Otherwise, vma_kernel_pagesize() returns PAGE_SIZE given a hugetlbfs backed vma, result in below BUG: fs/hugetlbfs/inode.c 443 if (unlikely(page_mapped(page))) { 444 BUG_ON(truncate_op); [ 242.268342] hugetlbfs: oracle (4592): Using mlock ulimits for SHM_HUGETLB is deprecated [ 282.653208] ------------[ cut here ]------------ [ 282.708447] kernel BUG at fs/hugetlbfs/inode.c:444! [ 282.818957] Modules linked in: nfsv3 rpcsec_gss_krb5 nfsv4 ... [ 284.025873] CPU: 35 PID: 5583 Comm: oracle_5583_sbt Not tainted 4.14.35-1829.el7uek.x86_64 #2 [ 284.246609] task: ffff9bf0507aaf80 task.stack: ffffa9e625628000 [ 284.317455] RIP: 0010:remove_inode_hugepages+0x3db/0x3e2 .... [ 285.292389] Call Trace: [ 285.321630] hugetlbfs_evict_inode+0x1e/0x3e [ 285.372707] evict+0xdb/0x1af [ 285.408185] iput+0x1a2/0x1f7 [ 285.443661] dentry_unlink_inode+0xc6/0xf0 [ 285.492661] __dentry_kill+0xd8/0x18d [ 285.536459] dput+0x1b5/0x1ed [ 285.571939] __fput+0x18b/0x216 [ 285.609495] ____fput+0xe/0x10 [ 285.646030] task_work_run+0x90/0xa7 [ 285.688788] exit_to_usermode_loop+0xdd/0x116 [ 285.740905] do_syscall_64+0x187/0x1ae [ 285.785740] entry_SYSCALL_64_after_hwframe+0x150/0x0 Suggested-by: Mike Kravetz Signed-off-by: Jane Chu Reviewed-by: Mike Kravetz Acked-by: Michal Hocko Acked-by: Davidlohr Bueso --- include/linux/mm.h | 7 +++++++ ipc/shm.c | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index a0fbb9ffe380..0c759379f2d9 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -387,6 +387,13 @@ enum page_entry_size { * These are the virtual MM functions - opening of an area, closing and * unmapping it (needed to keep files on disk up-to-date etc), pointer * to the functions called when a no-page or a wp-page exception occurs. + * + * Note, when a new function is introduced to vm_operations_struct and + * added to hugetlb_vm_ops, please consider adding the function to + * shm_vm_ops. This is because under System V memory model, though + * mappings created via shmget/shmat with "huge page" specified are + * backed by hugetlbfs files, their original vm_ops are overwritten with + * shm_vm_ops. */ struct vm_operations_struct { void (*open)(struct vm_area_struct * area); diff --git a/ipc/shm.c b/ipc/shm.c index 051a3e1fb8df..fefa00d310fb 100644 --- a/ipc/shm.c +++ b/ipc/shm.c @@ -427,6 +427,17 @@ static int shm_split(struct vm_area_struct *vma, unsigned long addr) return 0; } +static unsigned long shm_pagesize(struct vm_area_struct *vma) +{ + struct file *file = vma->vm_file; + struct shm_file_data *sfd = shm_file_data(file); + + if (sfd->vm_ops->pagesize) + return sfd->vm_ops->pagesize(vma); + + return PAGE_SIZE; +} + #ifdef CONFIG_NUMA static int shm_set_policy(struct vm_area_struct *vma, struct mempolicy *new) { @@ -554,6 +565,7 @@ static const struct vm_operations_struct shm_vm_ops = { .close = shm_close, /* callback for when the vm-area is released */ .fault = shm_fault, .split = shm_split, + .pagesize = shm_pagesize, #if defined(CONFIG_NUMA) .set_policy = shm_set_policy, .get_policy = shm_get_policy,